TaupageYamlPlugin extends AbstractEC2InstancePlugin { @Override protected void process(final EC2InstanceContext context) { if (context.isTaupageAmi().orElse(false)) { if (!context.getTaupageYaml().isPresent()) { violationSink.put( context.violation() .withType(MISSING_USER_DATA) .withPluginFullyQualifiedClassName(TaupageYamlPlugin.class) .build()); return; } if (!context.getApplicationId().isPresent()) { violationSink.put( context.violation() .withType(MISSING_APPLICATION_ID_IN_USER_DATA) .withPluginFullyQualifiedClassName(TaupageYamlPlugin.class) .build()); } if (!context.getSource().isPresent()) { violationSink.put( context.violation() .withType(MISSING_SOURCE_IN_USER_DATA) .withPluginFullyQualifiedClassName(TaupageYamlPlugin.class) .build()); } } } @Autowired  TaupageYamlPlugin(final EC2InstanceContextProvider contextProvider, final ViolationSink violationSink);   }
@Test public void testProcessNoViolations() throws Exception { when(mockContext.isTaupageAmi()).thenReturn(Optional.of(true)); when(mockContext.getTaupageYaml()).thenReturn(Optional.of(new TaupageYaml(null, null, null, null))); when(mockContext.getApplicationId()).thenReturn(Optional.of("1234")); when(mockContext.getSource()).thenReturn(Optional.of("source")); plugin.process(mockContext); verify(mockContext).isTaupageAmi(); verify(mockContext).getTaupageYaml(); verify(mockContext).getApplicationId(); verify(mockContext).getSource(); }
@Test public void testProcessNoTaupageAmi() throws Exception { when(mockContext.isTaupageAmi()).thenReturn(Optional.of(false)); plugin.process(mockContext); verify(mockContext).isTaupageAmi(); }
@Test public void testProcessNullableTaupageAmi() throws Exception { when(mockContext.isTaupageAmi()).thenReturn(Optional.empty()); plugin.process(mockContext); verify(mockContext).isTaupageAmi(); }
@Test public void testProcessMissingTaupageYaml() throws Exception { when(mockContext.isTaupageAmi()).thenReturn(Optional.of(true)); when(mockContext.getTaupageYaml()).thenReturn(Optional.empty()); plugin.process(mockContext); verify(mockContext).isTaupageAmi(); verify(mockContext).getTaupageYaml(); verify(mockContext).violation(); verify(mockViolationSink).put(argThat(hasType(MISSING_USER_DATA))); }
@Test public void testProcessMissingAppIdViolation() throws Exception { when(mockContext.isTaupageAmi()).thenReturn(Optional.of(true)); when(mockContext.getTaupageYaml()).thenReturn(Optional.of(new TaupageYaml(null, null, null, null))); when(mockContext.getSource()).thenReturn(Optional.of("source")); when(mockContext.getApplicationId()).thenReturn(Optional.empty()); plugin.process(mockContext); verify(mockContext).isTaupageAmi(); verify(mockContext).getTaupageYaml(); verify(mockContext).getApplicationId(); verify(mockContext).getSource(); verify(mockContext).violation(); verify(mockViolationSink).put(argThat(hasType(MISSING_APPLICATION_ID_IN_USER_DATA))); }
@Test public void testProcessMissingSourceViolation() throws Exception { when(mockContext.isTaupageAmi()).thenReturn(Optional.of(true)); when(mockContext.getApplicationId()).thenReturn(Optional.of("1234")); when(mockContext.getTaupageYaml()).thenReturn(Optional.of(new TaupageYaml(null, null, null, null))); when(mockContext.getSource()).thenReturn(Optional.empty()); plugin.process(mockContext); verify(mockContext).isTaupageAmi(); verify(mockContext).getTaupageYaml(); verify(mockContext).getApplicationId(); verify(mockContext).getSource(); verify(mockContext).violation(); verify(mockViolationSink).put(argThat(hasType(MISSING_SOURCE_IN_USER_DATA))); }