MicroPipelineValidator { public MicroPipelineValidationResult validate(final MicroPipelineConfiguration configuration) { if(configuration == null) return MicroPipelineValidationResult.MISSING_CONFIGURATION; if(configuration.getComponents() == null || configuration.getComponents().isEmpty()) return MicroPipelineValidationResult.MISSING_COMPONENTS; if(configuration.getQueues() == null || configuration.getQueues().isEmpty()) return MicroPipelineValidationResult.MISSING_QUEUES; Set<String> queueIdentifiers = new HashSet<>(); for(final StreamingMessageQueueConfiguration queueCfg : configuration.getQueues()) { if(StringUtils.isBlank(queueCfg.getId())) return MicroPipelineValidationResult.MISSING_QUEUE_ID; String tempId = StringUtils.lowerCase(StringUtils.trim(queueCfg.getId())); if(queueIdentifiers.contains(tempId)) return MicroPipelineValidationResult.NON_UNIQUE_QUEUE_ID; queueIdentifiers.add(tempId); } Set<String> componentIdentifiers = new HashSet<>(); for(final MicroPipelineComponentConfiguration componentCfg : configuration.getComponents()) { MicroPipelineValidationResult componentValidationResult = validateComponent(componentCfg, queueIdentifiers, componentIdentifiers); if(componentValidationResult != MicroPipelineValidationResult.OK) return componentValidationResult; componentIdentifiers.add(StringUtils.lowerCase(StringUtils.trim(componentCfg.getId()))); } return MicroPipelineValidationResult.OK; }  MicroPipelineValidationResult validate(final MicroPipelineConfiguration configuration);  }
@Test public void testValidate_withNullInput() { Assert.assertEquals("Required configuration missing", MicroPipelineValidationResult.MISSING_CONFIGURATION, new MicroPipelineValidator().validate(null)); }
@Test public void testValidate_withEmptyComponentsList() { @SuppressWarnings("unchecked") List<StreamingMessageQueueConfiguration> mockQueueCfg = Mockito.mock(ArrayList.class); Mockito.when(mockQueueCfg.isEmpty()).thenReturn(false); MicroPipelineConfiguration mockCfg = Mockito.mock(MicroPipelineConfiguration.class); Mockito.when(mockCfg.getQueues()).thenReturn(mockQueueCfg); Mockito.when(mockCfg.getComponents()).thenReturn(null); Assert.assertEquals("Components missing", MicroPipelineValidationResult.MISSING_COMPONENTS, new MicroPipelineValidator().validate(mockCfg)); Mockito.verify(mockCfg, Mockito.times(1)).getComponents(); Mockito.verify(mockCfg, Mockito.never()).getQueues(); }
@Test public void testValidate_withEmptyQueuesList() { @SuppressWarnings("unchecked") List<MicroPipelineComponentConfiguration> mockComponentCfg = Mockito.mock(ArrayList.class); Mockito.when(mockComponentCfg.isEmpty()).thenReturn(false); MicroPipelineConfiguration mockCfg = Mockito.mock(MicroPipelineConfiguration.class); Mockito.when(mockCfg.getComponents()).thenReturn(mockComponentCfg); Mockito.when(mockCfg.getQueues()).thenReturn(null); Assert.assertEquals("Queues missing", MicroPipelineValidationResult.MISSING_QUEUES, new MicroPipelineValidator().validate(mockCfg)); Mockito.verify(mockComponentCfg).isEmpty(); Mockito.verify(mockCfg, Mockito.times(2)).getComponents(); Mockito.verify(mockCfg, Mockito.times(1)).getQueues(); }
@Test public void testValidate_withValidConfiguration() { List<StreamingMessageQueueConfiguration> queues = new ArrayList<StreamingMessageQueueConfiguration>(); queues.add(new StreamingMessageQueueConfiguration("src-to-operator")); queues.add(new StreamingMessageQueueConfiguration("operator-to-emitter")); List<MicroPipelineComponentConfiguration> components = new ArrayList<MicroPipelineComponentConfiguration>(); MicroPipelineComponentConfiguration srcCfg = new MicroPipelineComponentConfiguration(); srcCfg.setFromQueue(""); srcCfg.setId("test-source-id"); srcCfg.setName("test-source-name"); srcCfg.setSettings(null); srcCfg.setToQueue("src-to-operator"); srcCfg.setType(MicroPipelineComponentType.SOURCE); srcCfg.setVersion("test-source-version"); components.add(srcCfg); MicroPipelineComponentConfiguration operatorCfg = new MicroPipelineComponentConfiguration(); operatorCfg.setFromQueue("src-to-operator"); operatorCfg.setId("test-operator-id"); operatorCfg.setName("test-operator-name"); operatorCfg.setSettings(null); operatorCfg.setToQueue("operator-to-emitter"); operatorCfg.setType(MicroPipelineComponentType.DELAYED_RESPONSE_OPERATOR); operatorCfg.setVersion("test-operator-version"); components.add(operatorCfg); MicroPipelineComponentConfiguration emitterCfg = new MicroPipelineComponentConfiguration(); emitterCfg.setFromQueue("operator-to-emitter"); emitterCfg.setId("test-emitter-id"); emitterCfg.setName("test-emitter-name"); emitterCfg.setSettings(null); emitterCfg.setToQueue(""); emitterCfg.setType(MicroPipelineComponentType.EMITTER); emitterCfg.setVersion("test-emitter-version"); components.add(emitterCfg); MicroPipelineConfiguration configuration = new MicroPipelineConfiguration(); configuration.setComponents(components); configuration.setQueues(queues); Assert.assertEquals("Valid configuration, no errors expected", MicroPipelineValidationResult.OK, new MicroPipelineValidator().validate(configuration)); }