MicroPipelineResource { @Produces(value = "application/json") @Timed(name = "pipeline-instantiation") @POST public MicroPipelineInstantiationResponse instantiatePipeline(final MicroPipelineConfiguration configuration) { if(configuration == null) return new MicroPipelineInstantiationResponse("", MicroPipelineValidationResult.MISSING_CONFIGURATION, ERROR_MSG_PIPELINE_CONFIGURATION_MISSING); if(StringUtils.isBlank(configuration.getId())) return new MicroPipelineInstantiationResponse("", MicroPipelineValidationResult.MISSING_CONFIGURATION, ERROR_MSG_PIPELINE_ID_MISSING); try { String id = this.microPipelineManager.executePipeline(configuration); return new MicroPipelineInstantiationResponse(id, MicroPipelineValidationResult.OK, ""); } catch (RequiredInputMissingException e) { return new MicroPipelineInstantiationResponse(configuration.getId(), MicroPipelineValidationResult.MISSING_CONFIGURATION, e.getMessage()); } catch (QueueInitializationFailedException e) { return new MicroPipelineInstantiationResponse(configuration.getId(), MicroPipelineValidationResult.QUEUE_INITIALIZATION_FAILED, e.getMessage()); } catch (ComponentInitializationFailedException e) { return new MicroPipelineInstantiationResponse(configuration.getId(), MicroPipelineValidationResult.COMPONENT_INITIALIZATION_FAILED, e.getMessage()); } catch (PipelineInstantiationFailedException e) { return new MicroPipelineInstantiationResponse(configuration.getId(), MicroPipelineValidationResult.PIPELINE_INITIALIZATION_FAILED, e.getMessage()); } catch (NonUniqueIdentifierException e) { return new MicroPipelineInstantiationResponse(configuration.getId(), MicroPipelineValidationResult.NON_UNIQUE_PIPELINE_ID, e.getMessage()); } catch(Exception e) { return new MicroPipelineInstantiationResponse(configuration.getId(), MicroPipelineValidationResult.TECHNICAL_ERROR, e.getMessage()); } } MicroPipelineResource(final MicroPipelineManager microPipelineManager); @Produces(value = "application/json") @Timed(name = "pipeline-instantiation") @POST MicroPipelineInstantiationResponse instantiatePipeline(final MicroPipelineConfiguration configuration); @Produces(value = "application/json") @Timed(name = "pipeline-instantiation") @PUT @Path("{pipelineId}") MicroPipelineInstantiationResponse updatePipeline(@PathParam("pipelineId") final String pipelineId, final MicroPipelineConfiguration configuration); @Produces(value = "application/json") @Timed(name = "pipeline-shutdown") @DELETE @Path("{pipelineId}") MicroPipelineShutdownResponse shutdown(@PathParam("pipelineId") final String pipelineId); @Produces(value = "application/json" ) @Timed(name = "pipeline-list" ) @GET @Path("list") ListRegisteredMicroPipelinesResponse listRegisteredPipelines(@QueryParam("mode") final String mode); static final String ERROR_MSG_PIPELINE_ID_MISSING; static final String ERROR_MSG_PIPELINE_CONFIGURATION_MISSING; static final String ERROR_MSG_PIPELINE_IDS_DIFFER; static final String LIST_PIPELINES_MODE_FULL; static final String LIST_PIPELINES_MODE_SIMPLE; }
@Test public void testInstantiatePipeline_withNullPipelineId() throws Exception { MicroPipelineConfiguration cfg = Mockito.mock(MicroPipelineConfiguration.class); Mockito.when(cfg.getId()).thenReturn(null); MicroPipelineManager microPipelineManager = Mockito.mock(MicroPipelineManager.class); MicroPipelineInstantiationResponse response = new MicroPipelineResource(microPipelineManager).instantiatePipeline(cfg); Assert.assertNotNull("The response must not be null", response); Assert.assertEquals("Values must be equal", MicroPipelineValidationResult.MISSING_CONFIGURATION, response.getState()); Assert.assertEquals("Values must be equal", MicroPipelineResource.ERROR_MSG_PIPELINE_ID_MISSING, response.getMessage()); Assert.assertTrue("Id must be empty", StringUtils.isBlank(response.getPipelineId())); Mockito.verify(microPipelineManager, Mockito.never()).executePipeline(cfg); }
@Test public void testInstantiatePipeline_withNullConfiguration() throws Exception { MicroPipelineManager microPipelineManager = Mockito.mock(MicroPipelineManager.class); MicroPipelineInstantiationResponse response = new MicroPipelineResource(microPipelineManager).instantiatePipeline(null); Assert.assertNotNull("The response must not be null", response); Assert.assertEquals("Values must be equal", MicroPipelineValidationResult.MISSING_CONFIGURATION, response.getState()); Assert.assertEquals("Values must be equal", MicroPipelineResource.ERROR_MSG_PIPELINE_CONFIGURATION_MISSING, response.getMessage()); Assert.assertTrue("Value must be empty", StringUtils.isBlank(response.getPipelineId())); }
@Test public void testInstantiatePipeline_withPipelineConfigurationMissingSetting() throws Exception { MicroPipelineConfiguration cfg = Mockito.mock(MicroPipelineConfiguration.class); Mockito.when(cfg.getId()).thenReturn("testInstantiatePipeline_withPipelineConfigurationMissingSetting"); MicroPipelineManager microPipelineManager = Mockito.mock(MicroPipelineManager.class); Mockito.when(microPipelineManager.executePipeline(cfg)).thenThrow(new RequiredInputMissingException("Missing setting")); MicroPipelineInstantiationResponse response = new MicroPipelineResource(microPipelineManager).instantiatePipeline(cfg); Assert.assertNotNull("The response must not be null", response); Assert.assertEquals("Values must be equal", MicroPipelineValidationResult.MISSING_CONFIGURATION, response.getState()); Assert.assertEquals("Values must be equal", "Missing setting", response.getMessage()); Assert.assertEquals("Values must be equal", "testInstantiatePipeline_withPipelineConfigurationMissingSetting", response.getPipelineId()); Mockito.verify(cfg, Mockito.times(2)).getId(); Mockito.verify(microPipelineManager).executePipeline(cfg); }
@Test public void testInstantiatePipeline_withQueueInitException() throws Exception { MicroPipelineConfiguration cfg = Mockito.mock(MicroPipelineConfiguration.class); Mockito.when(cfg.getId()).thenReturn("testInstantiatePipeline_withQueueInitException"); MicroPipelineManager microPipelineManager = Mockito.mock(MicroPipelineManager.class); Mockito.when(microPipelineManager.executePipeline(cfg)).thenThrow(new QueueInitializationFailedException("Queue init failed")); MicroPipelineInstantiationResponse response = new MicroPipelineResource(microPipelineManager).instantiatePipeline(cfg); Assert.assertNotNull("The response must not be null", response); Assert.assertEquals("Values must be equal", MicroPipelineValidationResult.QUEUE_INITIALIZATION_FAILED, response.getState()); Assert.assertEquals("Values must be equal", "Queue init failed", response.getMessage()); Assert.assertEquals("Values must be equal", "testInstantiatePipeline_withQueueInitException", response.getPipelineId()); Mockito.verify(cfg, Mockito.times(2)).getId(); Mockito.verify(microPipelineManager).executePipeline(cfg); }
@Test public void testInstantiatePipeline_withComponentInitException() throws Exception { MicroPipelineConfiguration cfg = Mockito.mock(MicroPipelineConfiguration.class); Mockito.when(cfg.getId()).thenReturn("testInstantiatePipeline_withComponentInitException"); MicroPipelineManager microPipelineManager = Mockito.mock(MicroPipelineManager.class); Mockito.when(microPipelineManager.executePipeline(cfg)).thenThrow(new ComponentInitializationFailedException("Component init failed")); MicroPipelineInstantiationResponse response = new MicroPipelineResource(microPipelineManager).instantiatePipeline(cfg); Assert.assertNotNull("The response must not be null", response); Assert.assertEquals("Values must be equal", MicroPipelineValidationResult.COMPONENT_INITIALIZATION_FAILED, response.getState()); Assert.assertEquals("Values must be equal", "Component init failed", response.getMessage()); Assert.assertEquals("Values must be equal", "testInstantiatePipeline_withComponentInitException", response.getPipelineId()); Mockito.verify(cfg, Mockito.times(2)).getId(); Mockito.verify(microPipelineManager).executePipeline(cfg); }
@Test public void testInstantiatePipeline_withPipelineInitException() throws Exception { MicroPipelineConfiguration cfg = Mockito.mock(MicroPipelineConfiguration.class); Mockito.when(cfg.getId()).thenReturn("testInstantiatePipeline_withPipelineInitException"); MicroPipelineManager microPipelineManager = Mockito.mock(MicroPipelineManager.class); Mockito.when(microPipelineManager.executePipeline(cfg)).thenThrow(new PipelineInstantiationFailedException("Pipeline init failed")); MicroPipelineInstantiationResponse response = new MicroPipelineResource(microPipelineManager).instantiatePipeline(cfg); Assert.assertNotNull("The response must not be null", response); Assert.assertEquals("Values must be equal", MicroPipelineValidationResult.PIPELINE_INITIALIZATION_FAILED, response.getState()); Assert.assertEquals("Values must be equal", "Pipeline init failed", response.getMessage()); Assert.assertEquals("Values must be equal", "testInstantiatePipeline_withPipelineInitException", response.getPipelineId()); Mockito.verify(cfg, Mockito.times(2)).getId(); Mockito.verify(microPipelineManager).executePipeline(cfg); }
@Test public void testInstantiatePipeline_withGeneralException() throws Exception { MicroPipelineConfiguration cfg = Mockito.mock(MicroPipelineConfiguration.class); Mockito.when(cfg.getId()).thenReturn("testInstantiatePipeline_withGeneralException"); MicroPipelineManager microPipelineManager = Mockito.mock(MicroPipelineManager.class); Mockito.when(microPipelineManager.executePipeline(cfg)).thenThrow(new NullPointerException("General error")); MicroPipelineInstantiationResponse response = new MicroPipelineResource(microPipelineManager).instantiatePipeline(cfg); Assert.assertNotNull("The response must not be null", response); Assert.assertEquals("Values must be equal", MicroPipelineValidationResult.TECHNICAL_ERROR, response.getState()); Assert.assertEquals("Values must be equal", "General error", response.getMessage()); Assert.assertEquals("Values must be equal", "testInstantiatePipeline_withGeneralException", response.getPipelineId()); Mockito.verify(cfg, Mockito.times(2)).getId(); Mockito.verify(microPipelineManager).executePipeline(cfg); }
@Test public void testInstantiatePipeline_withNonUniqueIdException() throws Exception { MicroPipelineConfiguration cfg = Mockito.mock(MicroPipelineConfiguration.class); Mockito.when(cfg.getId()).thenReturn("testInstantiatePipeline_withNonUniqueIdException"); MicroPipelineManager microPipelineManager = Mockito.mock(MicroPipelineManager.class); Mockito.when(microPipelineManager.executePipeline(cfg)).thenThrow(new NonUniqueIdentifierException("Non-unique id")); MicroPipelineInstantiationResponse response = new MicroPipelineResource(microPipelineManager).instantiatePipeline(cfg); Assert.assertNotNull("The response must not be null", response); Assert.assertEquals("Values must be equal", MicroPipelineValidationResult.NON_UNIQUE_PIPELINE_ID, response.getState()); Assert.assertEquals("Values must be equal", "Non-unique id", response.getMessage()); Assert.assertEquals("Values must be equal", "testInstantiatePipeline_withNonUniqueIdException", response.getPipelineId()); Mockito.verify(cfg, Mockito.times(2)).getId(); Mockito.verify(microPipelineManager).executePipeline(cfg); }
@Test public void testInstantiatePipeline_withValidConfiguration() throws Exception { MicroPipelineConfiguration cfg = Mockito.mock(MicroPipelineConfiguration.class); Mockito.when(cfg.getId()).thenReturn("testInstantiatePipeline_withValidConfiguration"); MicroPipelineManager microPipelineManager = Mockito.mock(MicroPipelineManager.class); Mockito.when(microPipelineManager.executePipeline(cfg)).thenReturn("testInstantiatePipeline_withValidConfiguration"); MicroPipelineInstantiationResponse response = new MicroPipelineResource(microPipelineManager).instantiatePipeline(cfg); Assert.assertNotNull("The response must not be null", response); Assert.assertEquals("Values must be equal", MicroPipelineValidationResult.OK, response.getState()); Assert.assertTrue("Message must be empty", StringUtils.isBlank(response.getMessage())); Assert.assertEquals("Values must be equal", "testInstantiatePipeline_withValidConfiguration", response.getPipelineId()); Mockito.verify(cfg).getId(); Mockito.verify(microPipelineManager).executePipeline(cfg); }