@Test public void testDeleteStoryOnBoard() throws Exception { UUID boardUuid = UUID.randomUUID(); UUID storyUuid = UUID.randomUUID(); this.mockMvc.perform( delete( "/boards/{boardUuid}/stories/{storyUuid}", boardUuid, storyUuid ) ) .andDo( print() ) .andExpect( status().isAccepted() ); verify( this.service, times( 1 ) ).deleteStory( any( UUID.class ), any( UUID.class ) ); }
@Test public void testUpdateStoryOnBoard() throws Exception { UUID boardUuid = UUID.randomUUID(); UUID storyUuid = UUID.randomUUID(); this.mockMvc.perform( put( "/boards/{boardUuid}/stories/{storyUuid}", boardUuid, storyUuid ).param( "name", "Test Story Updated" ) ) .andDo( print() ) .andExpect( status().isAccepted() ); verify( this.service, times( 1 ) ).updateStory( any( UUID.class ), any( UUID.class ), anyString() ); }
@Test public void testRenameBoard() throws Exception { UUID boardUuid = UUID.randomUUID(); this.mockMvc.perform( patch( "/boards/{boardUuid}", boardUuid ).param( "name", "Test Board" ) ) .andDo( print() ) .andExpect( status().isAccepted() );; verify( this.service, times( 1 ) ).renameBoard( any( UUID.class ), anyString() ); }
@Test public void testSaveEvents() throws Exception { this.mockMvc.perform( post( "/" ).content( BOARD_INITIALIZED_EVENT ) ) .andDo( print() ) .andExpect( status().isAccepted() ); verify( this.service, times( 1 ) ).processDomainEvent( any( Tuple.class ) ); }
@Test public void testDeleteStoryOnBoard() throws Exception { UUID boardUuid = UUID.randomUUID(); UUID storyUuid = UUID.randomUUID(); when( this.service.deleteStory( any( UUID.class ), any( UUID.class ) ) ).thenReturn( ResponseEntity.accepted().build() ); this.mockMvc.perform( RestDocumentationRequestBuilders.delete( "/boards/{boardUuid}/stories/{storyUuid}", boardUuid, storyUuid ) ) .andDo( print() ) .andExpect( status().isAccepted() ) .andDo( document("delete-story", pathParameters( parameterWithName( "boardUuid" ).description( "The unique id of the board" ), parameterWithName( "storyUuid" ).description( "The unique id of the story on the board to be deleted" ) ) )); verify( this.service, times( 1 ) ).deleteStory( any( UUID.class ), any( UUID.class ) ); }
@Test public void testUpdateStoryOnBoard() throws Exception { UUID boardUuid = UUID.randomUUID(); UUID storyUuid = UUID.randomUUID(); when( this.service.updateStory( any( UUID.class ), any( UUID.class ), anyString() ) ).thenReturn( ResponseEntity.accepted().build() ); this.mockMvc.perform( put( "/boards/{boardUuid}/stories/{storyUuid}", boardUuid, storyUuid ).param( "name", "Test Story Updated" ) ) .andDo( print() ) .andExpect( status().isAccepted() ) .andDo( document("update-story", pathParameters( parameterWithName( "boardUuid" ).description( "The unique id of the board" ), parameterWithName( "storyUuid" ).description( "The unique id of the story on the board" ) ), requestParameters( parameterWithName( "name" ).description( "The new name of the Board" ) ) )); verify( this.service, times( 1 ) ).updateStory( any( UUID.class ), any( UUID.class ), anyString() ); }
@Test public void testRenameBoard() throws Exception { UUID boardUuid = UUID.randomUUID(); when( this.service.renameBoard( any( UUID.class ), anyString() ) ).thenReturn( ResponseEntity.accepted().build() ); this.mockMvc.perform( patch( "/boards/{boardUuid}", boardUuid ).param( "name", "Test Board" ) ) .andDo( print() ) .andExpect( status().isAccepted() ) .andDo( document("rename-board", pathParameters( parameterWithName( "boardUuid" ).description( "The unique id of the board" ) ), requestParameters( parameterWithName( "name" ).description( "The new name of the Board" ) ) )); verify( this.service, times( 1 ) ).renameBoard( any( UUID.class ), anyString() ); }
@Test public void shouldStartAfterRun() throws Exception { // given JLineupRunStatus run = runStatusBuilder().withId("someRunId").withJobConfig(exampleConfig()).withState(State.AFTER_RUNNING).build(); when(jLineupService.startAfterRun("someRunId")).thenReturn(run); // when ResultActions result = mvc .perform(post("/testContextPath/runs/someRunId") .contextPath("/testContextPath") .contentType(MediaType.APPLICATION_JSON)); // then result .andExpect(status().isAccepted()) .andExpect(header().string("Location", "/testContextPath/runs/someRunId")); }
@Test public void shouldStartNewRun() throws Exception { // given JobConfig jobConfig = exampleConfig(); JLineupRunStatus run = runStatusBuilder().withId("someNewId").withJobConfig(jobConfig).withState(State.BEFORE_RUNNING).build(); when(jLineupService.startBeforeRun(any())).thenReturn(run); // when ResultActions result = mvc .perform(post("/testContextPath/runs") .contextPath("/testContextPath") .content(JobConfig.prettyPrint(jobConfig)) .contentType(MediaType.APPLICATION_JSON)); // then result .andExpect(status().isAccepted()) .andExpect(content().json("{\"id\":\"someNewId\"}")) .andExpect(header().string("Location", "/testContextPath/runs/someNewId")); verify(jLineupService).startBeforeRun(jobConfig); }
@Test public void deleteBindingWithAsyncAndHeadersSucceeds() throws Exception { setupCatalogService(); setupServiceInstanceBindingService(DeleteServiceInstanceBindingResponse.builder() .async(true) .operation("working") .build()); MvcResult mvcResult = mockMvc.perform(delete(buildDeleteUrl(PLATFORM_INSTANCE_ID, true)) .header(API_INFO_LOCATION_HEADER, API_INFO_LOCATION) .header(ORIGINATING_IDENTITY_HEADER, buildOriginatingIdentityHeader()) .accept(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON)) .andExpect(request().asyncStarted()) .andExpect(status().isOk()) .andReturn(); mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isAccepted()) .andExpect(jsonPath("$.operation", equalTo("working"))); verify(serviceInstanceBindingService).deleteServiceInstanceBinding(any(DeleteServiceInstanceBindingRequest.class)); DeleteServiceInstanceBindingRequest actualRequest = verifyDeleteBinding(); assertThat(actualRequest.isAsyncAccepted()).isEqualTo(true); assertHeaderValuesSet(actualRequest); }
@Test public void deleteServiceInstanceWithAsyncAndHeadersSucceeds() throws Exception { setupCatalogService(); setupServiceInstanceService(DeleteServiceInstanceResponse.builder() .async(true) .operation("working") .build()); MvcResult mvcResult = mockMvc.perform(delete(buildDeleteUrl(PLATFORM_INSTANCE_ID, true)) .header(API_INFO_LOCATION_HEADER, API_INFO_LOCATION) .header(ORIGINATING_IDENTITY_HEADER, buildOriginatingIdentityHeader()) .accept(MediaType.APPLICATION_JSON)) .andExpect(request().asyncStarted()) .andReturn(); mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isAccepted()) .andExpect(jsonPath("$.operation", equalTo("working"))); DeleteServiceInstanceRequest actualRequest = verifyDeleteServiceInstance(); assertThat(actualRequest.isAsyncAccepted()).isEqualTo(true); assertHeaderValuesSet(actualRequest); }
@Test public void updateServiceInstanceWithAsyncAndHeadersSucceeds() throws Exception { setupCatalogService(); setupServiceInstanceService(UpdateServiceInstanceResponse.builder() .async(true) .operation("working") .dashboardUrl("https://dashboard.example.com") .build()); MvcResult mvcResult = mockMvc.perform(patch(buildCreateUpdateUrl(PLATFORM_INSTANCE_ID, true)) .content(updateRequestBody) .header(API_INFO_LOCATION_HEADER, API_INFO_LOCATION) .header(ORIGINATING_IDENTITY_HEADER, buildOriginatingIdentityHeader()) .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)) .andExpect(request().asyncStarted()) .andReturn(); mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isAccepted()) .andExpect(jsonPath("$.operation", equalTo("working"))) .andExpect(jsonPath("$.dashboard_url", equalTo("https://dashboard.example.com"))); UpdateServiceInstanceRequest actualRequest = verifyUpdateServiceInstance(); assertThat(actualRequest.isAsyncAccepted()).isEqualTo(true); assertHeaderValuesSet(actualRequest); }
@Test public void createBindingToRouteWithAsyncHeadersSucceeds() throws Exception { setupCatalogService(); setupServiceInstanceBindingService(CreateServiceInstanceRouteBindingResponse.builder() .async(true) .operation("working") .bindingExisted(false) .build()); MvcResult mvcResult = mockMvc.perform(put(buildCreateUrl(null, true)) .content(createRequestBody) .accept(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON)) .andExpect(request().asyncStarted()) .andExpect(status().isOk()) .andReturn(); mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isAccepted()) .andExpect(jsonPath("$.operation", equalTo("working"))); CreateServiceInstanceBindingRequest actualRequest = verifyCreateBinding(); assertThat(actualRequest.isAsyncAccepted()).isEqualTo(true); assertHeaderValuesNotSet(actualRequest); }
@Test public void createServiceInstanceWithAsyncAndHeadersSucceeds() throws Exception { setupCatalogService(); setupServiceInstanceService(CreateServiceInstanceResponse.builder() .async(true) .build()); MvcResult mvcResult = mockMvc.perform(put(buildCreateUpdateUrl(PLATFORM_INSTANCE_ID, true)) .content(createRequestBody) .contentType(MediaType.APPLICATION_JSON) .header(API_INFO_LOCATION_HEADER, API_INFO_LOCATION) .header(ORIGINATING_IDENTITY_HEADER, buildOriginatingIdentityHeader()) .accept(MediaType.APPLICATION_JSON)) .andExpect(request().asyncStarted()) .andReturn(); mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isAccepted()); CreateServiceInstanceRequest actualRequest = verifyCreateServiceInstance(); assertThat(actualRequest.isAsyncAccepted()).isEqualTo(true); assertHeaderValuesSet(actualRequest); }
@Test public void createBindingToAppWithAsyncAndHeadersSucceeds() throws Exception { setupCatalogService(); setupServiceInstanceBindingService(CreateServiceInstanceAppBindingResponse.builder() .async(true) .operation("working") .bindingExisted(false) .build()); MvcResult mvcResult = mockMvc.perform(put(buildCreateUrl(PLATFORM_INSTANCE_ID, true)) .content(createRequestBody) .header(API_INFO_LOCATION_HEADER, API_INFO_LOCATION) .header(ORIGINATING_IDENTITY_HEADER, buildOriginatingIdentityHeader()) .accept(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON)) .andExpect(request().asyncStarted()) .andExpect(status().isOk()) .andReturn(); mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isAccepted()) .andExpect(jsonPath("$.operation", equalTo("working"))); CreateServiceInstanceBindingRequest actualRequest = verifyCreateBinding(); assertThat(actualRequest.isAsyncAccepted()).isEqualTo(true); assertHeaderValuesSet(actualRequest); }
@Test public void createServiceInstanceWithEmptyPlatformInstanceIdSucceeds() throws Exception { setupCatalogService(); setupServiceInstanceService(CreateServiceInstanceResponse.builder() .async(true) .build()); // force a condition where the platformInstanceId segment is present but empty // e.g. http://test.example.com//v2/service_instances/[guid] String url = "http://test.example.com/" + buildCreateUpdateUrl(); MvcResult mvcResult = mockMvc.perform(put(url) .content(createRequestBody) .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)) .andExpect(request().asyncStarted()) .andReturn(); mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isAccepted()); CreateServiceInstanceRequest actualRequest = verifyCreateServiceInstance(); assertHeaderValuesNotSet(actualRequest); }