MicroPipelineResource { @Produces(value = "application/json") @Timed(name = "pipeline-shutdown") @DELETE @Path("{pipelineId}") public MicroPipelineShutdownResponse shutdown(@PathParam("pipelineId") final String pipelineId) { if(StringUtils.isBlank(pipelineId)) return new MicroPipelineShutdownResponse(pipelineId, MicroPipelineShutdownState.PIPELINE_ID_MISSING, ERROR_MSG_PIPELINE_ID_MISSING); try { return new MicroPipelineShutdownResponse(this.microPipelineManager.shutdownPipeline(pipelineId), MicroPipelineShutdownState.OK, ""); } catch(Exception e) { return new MicroPipelineShutdownResponse(pipelineId, MicroPipelineShutdownState.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 testShutdownPipeline_withEmptyPipelineId() throws Exception { MicroPipelineManager manager = Mockito.mock(MicroPipelineManager.class); MicroPipelineShutdownResponse response = new MicroPipelineResource(manager).shutdown(""); Assert.assertNotNull("The response must not be null", response); Assert.assertEquals("Values must be equal", MicroPipelineResource.ERROR_MSG_PIPELINE_ID_MISSING, response.getMessage()); Assert.assertEquals("Values must be equal", MicroPipelineShutdownState.PIPELINE_ID_MISSING, response.getState()); Mockito.verify(manager, Mockito.never()).shutdownPipeline(""); }
@Test public void testShutdownPipeline_withManagerThrowingNPE() throws Exception { MicroPipelineManager manager = Mockito.mock(MicroPipelineManager.class); Mockito.when(manager.shutdownPipeline("testShutdownPipeline_withManagerThrowingNPE")).thenThrow(new NullPointerException("General error")); MicroPipelineShutdownResponse response = new MicroPipelineResource(manager).shutdown("testShutdownPipeline_withManagerThrowingNPE"); Assert.assertNotNull("The response must not be null", response); Assert.assertEquals("Values must be equal", "General error", response.getMessage()); Assert.assertEquals("Values must be equal", MicroPipelineShutdownState.TECHNICAL_ERROR, response.getState()); Assert.assertEquals("Values must be equal", "testShutdownPipeline_withManagerThrowingNPE", response.getPipelineId()); Mockito.verify(manager).shutdownPipeline("testShutdownPipeline_withManagerThrowingNPE"); }
@Test public void testShutdownPipeline_withValidPipelineId() throws Exception { MicroPipelineManager manager = Mockito.mock(MicroPipelineManager.class); Mockito.when(manager.shutdownPipeline("testShutdownPipeline_withValidPipelineId")).thenReturn("testShutdownPipeline_withValidPipelineId"); MicroPipelineShutdownResponse response = new MicroPipelineResource(manager).shutdown("testShutdownPipeline_withValidPipelineId"); Assert.assertNotNull("The response must not be null", response); Assert.assertTrue("Message must be empty", StringUtils.isBlank(response.getMessage())); Assert.assertEquals("Values must be equal", MicroPipelineShutdownState.OK, response.getState()); Assert.assertEquals("Values must be equal", "testShutdownPipeline_withValidPipelineId", response.getPipelineId()); Mockito.verify(manager).shutdownPipeline("testShutdownPipeline_withValidPipelineId"); }