diff --git a/spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/controller/AppRegistryControllerTests.java b/spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/controller/AppRegistryControllerTests.java index 256d47de86..3a3c4aa67c 100644 --- a/spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/controller/AppRegistryControllerTests.java +++ b/spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/controller/AppRegistryControllerTests.java @@ -121,9 +121,11 @@ public void setupMocks() { @Test public void testRegisterVersionedApp() throws Exception { - mockMvc.perform(post("/apps/sink/log1/1.2.0.RELEASE").param("uri", "maven://org.springframework.cloud.stream.app:log-sink-rabbit:1.2.0.RELEASE").accept(MediaType.APPLICATION_JSON)) + mockMvc.perform(post("/apps/sink/log1/1.2.0.RELEASE").param("uri", "maven://org.springframework.cloud.stream.app:log-sink-rabbit:1.2.0.RELEASE") + .accept(MediaType.APPLICATION_JSON)) .andDo(print()).andExpect(status().isCreated()); - assertThat(this.appRegistryService.find("log1", ApplicationType.sink).getUri().toString(), is("maven://org.springframework.cloud.stream.app:log-sink-rabbit:1.2.0.RELEASE")); + assertThat(this.appRegistryService.find("log1", ApplicationType.sink).getUri().toString(), + is("maven://org.springframework.cloud.stream.app:log-sink-rabbit:1.2.0.RELEASE")); } @Test @@ -142,7 +144,7 @@ public void testRegisterAppWithInvalidName() throws Exception { @Test public void testRegisterAppWithNameLongerThan255Characters() throws Exception { mockMvc.perform(post( - "/apps/sink/sinkAppToTestIfLengthIsGreaterThanTwoHundredAndFiftyFiveCharacterssinkAppToTestIfLengthIsGreaterThanTwoHundredAndFiftyFiveCharacterssinkAppToTestIfLengthIsGreaterThanTwoHundredAndFiftyFiveCharacterssinkAppToTestIfLengthIsGreaterThanTwoHundredAndFiftyFiveCharacters") + "/apps/sink/sinkAppToTestIfLengthIsGreaterThanTwoHundredAndFiftyFiveCharacterssinkAppToTestIfLengthIsGreaterThanTwoHundredAndFiftyFiveCharacterssinkAppToTestIfLengthIsGreaterThanTwoHundredAndFiftyFiveCharacterssinkAppToTestIfLengthIsGreaterThanTwoHundredAndFiftyFiveCharacters") .param("uri", "maven://org.springframework.cloud.stream.app:log-sink-rabbit:1.2.0.RELEASE") .accept(MediaType.APPLICATION_JSON)) .andDo(print()).andExpect(status().is4xxClientError()); @@ -150,117 +152,186 @@ public void testRegisterAppWithNameLongerThan255Characters() throws Exception { @Test public void testRegisterApp() throws Exception { - mockMvc.perform(post("/apps/sink/log1").param("uri", "maven://org.springframework.cloud.stream.app:log-sink-rabbit:1.2.0.RELEASE").accept(MediaType.APPLICATION_JSON)) + mockMvc.perform(post("/apps/sink/log1").param("uri", "maven://org.springframework.cloud.stream.app:log-sink-rabbit:1.2.0.RELEASE") + .accept(MediaType.APPLICATION_JSON)) .andDo(print()).andExpect(status().isCreated()); - assertThat(this.appRegistryService.find("log1", ApplicationType.sink).getUri().toString(), is("maven://org.springframework.cloud.stream.app:log-sink-rabbit:1.2.0.RELEASE")); + assertThat(this.appRegistryService.find("log1", ApplicationType.sink).getUri().toString(), + is("maven://org.springframework.cloud.stream.app:log-sink-rabbit:1.2.0.RELEASE")); } @Test public void testAppInfoNonExistingApp() throws Exception { - MvcResult mvcResult = this.mockMvc.perform(get("/apps/sink/log1")).andDo(print()).andExpect(status().is4xxClientError()).andReturn(); + MvcResult mvcResult = this.mockMvc.perform(get("/apps/sink/log1")) + .andDo(print()) + .andExpect(status().is4xxClientError()) + .andReturn(); Assert.isInstanceOf(NoSuchAppRegistrationException.class, mvcResult.getResolvedException()); } @Test public void testAppInfoNonExistingVersionedApp() throws Exception { - MvcResult mvcResult = this.mockMvc.perform(get("/apps/sink/log1/1.0.0")).andDo(print()).andExpect(status().is4xxClientError()).andReturn(); + MvcResult mvcResult = this.mockMvc.perform(get("/apps/sink/log1/1.0.0")) + .andDo(print()).andExpect(status().is4xxClientError()) + .andReturn(); Assert.isInstanceOf(NoSuchAppRegistrationException.class, mvcResult.getResolvedException()); } @Test public void testDefaultVersion() throws Exception { - this.mockMvc.perform(post("/apps/sink/log1").param("uri", "maven://org.springframework.cloud.stream.app:log-sink-rabbit:1.2.0.RELEASE").accept(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isCreated()); - - this.mockMvc.perform(get("/apps/sink/log1")) - .andDo(print()) - .andExpect(status().isOk()) + this.mockMvc.perform(post("/apps/sink/log1") + .param("uri", "maven://org.springframework.cloud.stream.app:log-sink-rabbit:1.2.0.RELEASE") + .accept(MediaType.APPLICATION_JSON) + ).andDo(print()) + .andExpect(status().isCreated()); - .andExpect(jsonPath("$.name", is("log1"))) - .andExpect(jsonPath("$.type", is("sink"))) - .andExpect(jsonPath("$.uri", is("maven://org.springframework.cloud.stream.app:log-sink-rabbit:1.2.0.RELEASE"))) - .andExpect(jsonPath("$.version", is("1.2.0.RELEASE"))) - .andExpect(jsonPath("$.defaultVersion", is(true))); - } + this.mockMvc.perform(get("/apps/sink/log1")) + .andDo(print()) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.name", is("log1"))) + .andExpect(jsonPath("$.type", is("sink"))) + .andExpect(jsonPath("$.uri", is("maven://org.springframework.cloud.stream.app:log-sink-rabbit:1.2.0.RELEASE"))) + .andExpect(jsonPath("$.version", is("1.2.0.RELEASE"))) + .andExpect(jsonPath("$.defaultVersion", is(true))); + } @Test public void testVersionOverride() throws Exception { - this.mockMvc.perform(post("/apps/sink/log1").param("uri", "maven://org.springframework.cloud.stream.app:log-sink-rabbit:1.2.0.RELEASE").accept(MediaType.APPLICATION_JSON)) - .andDo(print()).andExpect(status().isCreated()); - this.mockMvc.perform(post("/apps/sink/log1").param("uri", "maven://org.springframework.cloud.stream.app:log-sink-rabbit:1.3.0.RELEASE").accept(MediaType.APPLICATION_JSON)) - .andDo(print()).andExpect(status().isCreated()); - this.mockMvc.perform(put("/apps/sink/log1/1.3.0.RELEASE")).andDo(print()).andExpect(status().isAccepted()); + this.mockMvc.perform(post("/apps/sink/log1") + .param("uri", "maven://org.springframework.cloud.stream.app:log-sink-rabbit:1.2.0.RELEASE") + .accept(MediaType.APPLICATION_JSON)) + .andDo(print()) + .andExpect(status().isCreated()); + this.mockMvc.perform(post("/apps/sink/log1") + .param("uri", "maven://org.springframework.cloud.stream.app:log-sink-rabbit:1.3.0.RELEASE") + .accept(MediaType.APPLICATION_JSON)) + .andDo(print()) + .andExpect(status().isCreated()); + this.mockMvc.perform(put("/apps/sink/log1/1.3.0.RELEASE")) + .andDo(print()) + .andExpect(status().isAccepted()); this.mockMvc.perform(get("/apps/sink/log1")) - .andDo(print()) - .andExpect(status().isOk()) - - .andExpect(jsonPath("$.name", is("log1"))) - .andExpect(jsonPath("$.type", is("sink"))) - .andExpect(jsonPath("$.uri", is("maven://org.springframework.cloud.stream.app:log-sink-rabbit:1.3.0.RELEASE"))) - .andExpect(jsonPath("$.version", is("1.3.0.RELEASE"))) - .andExpect(jsonPath("$.defaultVersion", is(true))); + .andDo(print()) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.name", is("log1"))) + .andExpect(jsonPath("$.type", is("sink"))) + .andExpect(jsonPath("$.uri", is("maven://org.springframework.cloud.stream.app:log-sink-rabbit:1.3.0.RELEASE"))) + .andExpect(jsonPath("$.version", is("1.3.0.RELEASE"))) + .andExpect(jsonPath("$.defaultVersion", is(true))); } @Test public void testVersionOverrideNonExistentApp() throws Exception { - this.mockMvc.perform(post("/apps/sink/log1").param("uri", "maven://org.springframework.cloud.stream.app:log-sink-rabbit:1.2.0.RELEASE").accept(MediaType.APPLICATION_JSON)) - .andDo(print()).andExpect(status().isCreated()); - MvcResult mvcResult = this.mockMvc.perform(put("/apps/sink/log1/1.3.0.RELEASE/")).andDo(print()).andExpect(status().is4xxClientError()).andReturn(); + this.mockMvc.perform(post("/apps/sink/log1") + .param("uri", "maven://org.springframework.cloud.stream.app:log-sink-rabbit:1.2.0.RELEASE") + .accept(MediaType.APPLICATION_JSON)) + .andDo(print()) + .andExpect(status().isCreated()); + MvcResult mvcResult = this.mockMvc.perform(put("/apps/sink/log1/1.3.0.RELEASE/")) + .andDo(print()) + .andExpect(status().is4xxClientError()) + .andReturn(); Assert.isInstanceOf(NoSuchAppRegistrationException.class, mvcResult.getResolvedException()); } @Test public void testRegisterApplicationTwice() throws Exception { - mockMvc.perform(post("/apps/processor/blubba").param("uri", "maven://org.springframework.cloud.stream.app:log-sink-rabbit:1.2.0.RELEASE").accept(MediaType.APPLICATION_JSON)) - .andDo(print()).andExpect(status().isCreated()); - mockMvc.perform(post("/apps/processor/blubba").param("uri", "maven://org.springframework.cloud.stream.app:log-sink-rabbit:1.2.0.RELEASE").accept(MediaType.APPLICATION_JSON)) + mockMvc.perform(post("/apps/processor/blubba") + .param("uri", "maven://org.springframework.cloud.stream.app:log-sink-rabbit:1.2.0.RELEASE") + .accept(MediaType.APPLICATION_JSON)) + .andDo(print()) + .andExpect(status().isCreated()); + mockMvc.perform(post("/apps/processor/blubba") + .param("uri", "maven://org.springframework.cloud.stream.app:log-sink-rabbit:1.2.0.RELEASE") + .accept(MediaType.APPLICATION_JSON)) .andDo(print()).andExpect(status().isConflict()); } @Test public void testVersionWithMismatchBaseUri() throws Exception { - mockMvc.perform(post("/apps/processor/maven1").param("uri", "maven://org.springframework.cloud.stream.app:log-sink-rabbit:1.2.0.RELEASE").accept(MediaType.APPLICATION_JSON)) - .andDo(print()).andExpect(status().isCreated()); - mockMvc.perform(post("/apps/processor/maven1").param("uri", "maven://org.springframework.cloud.stream.app:time-source-rabbit:1.2.1.RELEASE").accept(MediaType.APPLICATION_JSON)) - .andDo(print()).andExpect(status().is5xxServerError()); - mockMvc.perform(post("/apps/processor/docker1").param("uri", "docker:prefix1/my-source:0.1.0").accept(MediaType.APPLICATION_JSON)) - .andDo(print()).andExpect(status().isCreated()); - mockMvc.perform(post("/apps/processor/docker1").param("uri", "docker:prefix2/my-source:0.2.0").accept(MediaType.APPLICATION_JSON)) - .andDo(print()).andExpect(status().is5xxServerError()); - mockMvc.perform(post("/apps/processor/http1").param("uri", "https://example.com/my-app1-1.1.1.RELEASE.jar").accept(MediaType.APPLICATION_JSON)) - .andDo(print()).andExpect(status().isCreated()); - mockMvc.perform(post("/apps/processor/http1").param("uri", "https://example.com/my-app2-1.1.2.RELEASE.jar").accept(MediaType.APPLICATION_JSON)) - .andDo(print()).andExpect(status().is5xxServerError()); + mockMvc.perform(post("/apps/processor/maven1") + .param("uri", "maven://org.springframework.cloud.stream.app:log-sink-rabbit:1.2.0.RELEASE") + .accept(MediaType.APPLICATION_JSON)) + .andDo(print()) + .andExpect(status().isCreated()); + mockMvc.perform(post("/apps/processor/maven1") + .param("uri", "maven://org.springframework.cloud.stream.app:time-source-rabbit:1.2.1.RELEASE") + .accept(MediaType.APPLICATION_JSON)) + .andDo(print()) + .andExpect(status().is5xxServerError()); + mockMvc.perform(post("/apps/processor/docker1") + .param("uri", "docker:prefix1/my-source:0.1.0") + .accept(MediaType.APPLICATION_JSON)) + .andDo(print()) + .andExpect(status().isCreated()); + mockMvc.perform(post("/apps/processor/docker1") + .param("uri", "docker:prefix2/my-source:0.2.0") + .accept(MediaType.APPLICATION_JSON)) + .andDo(print()) + .andExpect(status().is5xxServerError()); + mockMvc.perform(post("/apps/processor/http1") + .param("uri", "https://example.com/my-app1-1.1.1.RELEASE.jar") + .accept(MediaType.APPLICATION_JSON)) + .andDo(print()) + .andExpect(status().isCreated()); + mockMvc.perform(post("/apps/processor/http1") + .param("uri", "https://example.com/my-app2-1.1.2.RELEASE.jar") + .accept(MediaType.APPLICATION_JSON)) + .andDo(print()) + .andExpect(status().is5xxServerError()); // in case you actually have version in part of an uri - mockMvc.perform(post("/apps/processor/maven2").param("uri", "maven://org.springframework.cloud.stream.app.1.2.0.RELEASE:log-sink-rabbit:1.2.0.RELEASE").accept(MediaType.APPLICATION_JSON)) - .andDo(print()).andExpect(status().isCreated()); - mockMvc.perform(post("/apps/processor/maven2").param("uri", "maven://org.springframework.cloud.stream.app.1.2.0.RELEASE:time-source-rabbit:1.2.1.RELEASE").accept(MediaType.APPLICATION_JSON)) - .andDo(print()).andExpect(status().is5xxServerError()); - mockMvc.perform(post("/apps/processor/docker2").param("uri", "docker:prefix1.0.1.0/my-source:0.1.0").accept(MediaType.APPLICATION_JSON)) - .andDo(print()).andExpect(status().isCreated()); - mockMvc.perform(post("/apps/processor/docker2").param("uri", "docker:prefix2.0.1.0/my-source:0.2.0").accept(MediaType.APPLICATION_JSON)) - .andDo(print()).andExpect(status().is5xxServerError()); - mockMvc.perform(post("/apps/processor/http2").param("uri", "https://1.1.1.example.com/my-app1-1.1.1.RELEASE.jar").accept(MediaType.APPLICATION_JSON)) - .andDo(print()).andExpect(status().isCreated()); - mockMvc.perform(post("/apps/processor/http2").param("uri", "https://1.1.1.example.com/my-app2-1.1.2.RELEASE.jar").accept(MediaType.APPLICATION_JSON)) - .andDo(print()).andExpect(status().is5xxServerError()); + mockMvc.perform(post("/apps/processor/maven2") + .param("uri", "maven://org.springframework.cloud.stream.app.1.2.0.RELEASE:log-sink-rabbit:1.2.0.RELEASE") + .accept(MediaType.APPLICATION_JSON)) + .andDo(print()) + .andExpect(status().isCreated()); + mockMvc.perform(post("/apps/processor/maven2") + .param("uri", "maven://org.springframework.cloud.stream.app.1.2.0.RELEASE:time-source-rabbit:1.2.1.RELEASE") + .accept(MediaType.APPLICATION_JSON)) + .andDo(print()) + .andExpect(status().is5xxServerError()); + mockMvc.perform(post("/apps/processor/docker2") + .param("uri", "docker:prefix1.0.1.0/my-source:0.1.0") + .accept(MediaType.APPLICATION_JSON)) + .andDo(print()) + .andExpect(status().isCreated()); + mockMvc.perform(post("/apps/processor/docker2") + .param("uri", "docker:prefix2.0.1.0/my-source:0.2.0") + .accept(MediaType.APPLICATION_JSON)) + .andDo(print()) + .andExpect(status().is5xxServerError()); + mockMvc.perform(post("/apps/processor/http2") + .param("uri", "https://1.1.1.example.com/my-app1-1.1.1.RELEASE.jar") + .accept(MediaType.APPLICATION_JSON)) + .andDo(print()) + .andExpect(status().isCreated()); + mockMvc.perform(post("/apps/processor/http2") + .param("uri", "https://1.1.1.example.com/my-app2-1.1.2.RELEASE.jar") + .accept(MediaType.APPLICATION_JSON)) + .andDo(print()) + .andExpect(status().is5xxServerError()); } @Test public void testRegisterAll() throws Exception { - mockMvc.perform(post("/apps").param("apps", "sink.foo=maven://org.springframework.cloud.stream.app:log-sink-rabbit:1.2.0.RELEASE").accept(MediaType.APPLICATION_JSON)) - .andDo(print()).andExpect(status().isCreated()); - assertThat(this.appRegistryService.find("foo", ApplicationType.sink).getUri().toString(), is("maven://org.springframework.cloud.stream.app:log-sink-rabbit:1.2.0.RELEASE")); + mockMvc.perform(post("/apps") + .param("apps", "sink.foo=maven://org.springframework.cloud.stream.app:log-sink-rabbit:1.2.0.RELEASE") + .accept(MediaType.APPLICATION_JSON)) + .andDo(print()) + .andExpect(status().isCreated()); + assertThat(this.appRegistryService.find("foo", ApplicationType.sink).getUri().toString(), + is("maven://org.springframework.cloud.stream.app:log-sink-rabbit:1.2.0.RELEASE")); } @Test public void testRegisterAllFromFile() throws Exception { - mockMvc.perform(post("/apps").param("uri", "classpath:/register-all.txt").accept(MediaType.APPLICATION_JSON)) - .andDo(print()).andExpect(status().isCreated()); - assertThat(this.appRegistryService.find("foo", ApplicationType.sink).getUri().toString(), is("maven://org.springframework.cloud.stream.app:log-sink-rabbit:1.2.0.RELEASE")); + mockMvc.perform(post("/apps") + .param("uri", "classpath:/register-all.txt").accept(MediaType.APPLICATION_JSON)) + .andDo(print()) + .andExpect(status().isCreated()); + assertThat(this.appRegistryService.find("foo", ApplicationType.sink).getUri().toString(), + is("maven://org.springframework.cloud.stream.app:log-sink-rabbit:1.2.0.RELEASE")); } @Test @@ -291,22 +362,34 @@ public void testRegisterAllWithForce() throws Exception { @Test public void testRegisterAllWithBadApplication() throws Exception { - mockMvc.perform(post("/apps").param("apps", "sink-foo=maven://org.springframework.cloud.stream.app:log-sink-rabbit:1.2.0.RELEASE").accept(MediaType.APPLICATION_JSON)) - .andDo(print()).andExpect(status().is5xxServerError()); + mockMvc.perform(post("/apps") + .param("apps", "sink-foo=maven://org.springframework.cloud.stream.app:log-sink-rabbit:1.2.0.RELEASE") + .accept(MediaType.APPLICATION_JSON)) + .andDo(print()) + .andExpect(status().is5xxServerError()); } @Test public void testListApplications() throws Exception { - mockMvc.perform(get("/apps").accept(MediaType.APPLICATION_JSON)).andDo(print()).andExpect(status().isOk()) + mockMvc.perform(get("/apps") + .accept(MediaType.APPLICATION_JSON)) + .andDo(print()) + .andExpect(status().isOk()) .andExpect(jsonPath("_embedded.appRegistrationResourceList", hasSize(4))); } @Test public void testListAppsWithMultiVersions() throws Exception { this.appRegistryService.importAll(false, new ClassPathResource("META-INF/test-apps-multi-versions.properties")); - mockMvc.perform(get("/apps").accept(MediaType.APPLICATION_JSON)).andDo(print()).andExpect(status().isOk()) + mockMvc.perform(get("/apps") + .accept(MediaType.APPLICATION_JSON)) + .andDo(print()) + .andExpect(status().isOk()) .andExpect(jsonPath("$._embedded.appRegistrationResourceList[*]", hasSize(9))); - mockMvc.perform(get("/apps?defaultVersion=true").accept(MediaType.APPLICATION_JSON)).andDo(print()).andExpect(status().isOk()) + mockMvc.perform(get("/apps?defaultVersion=true") + .accept(MediaType.APPLICATION_JSON)) + .andDo(print()) + .andExpect(status().isOk()) .andExpect(jsonPath("$._embedded.appRegistrationResourceList[*]", hasSize(6))) .andExpect(jsonPath("$._embedded.appRegistrationResourceList[?(@.name == 'time' && @.type == 'source')]", hasSize(1))) .andExpect(jsonPath("$._embedded.appRegistrationResourceList[?(@.name == 'time' && @.type == 'source')].defaultVersion", contains(true))) @@ -324,56 +407,82 @@ public void testListAppsWithMultiVersions() throws Exception { @Test public void testListApplicationsByType() throws Exception { - mockMvc.perform(get("/apps?type=task").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()) + mockMvc.perform(get("/apps?type=task") + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) .andExpect(jsonPath("_embedded.appRegistrationResourceList", hasSize(1))); } @Test public void testListApplicationsBySearch() throws Exception { - mockMvc.perform(get("/apps?search=timestamp").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()) + mockMvc.perform(get("/apps?search=timestamp") + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) .andExpect(jsonPath("_embedded.appRegistrationResourceList", hasSize(1))); - mockMvc.perform(get("/apps?search=time").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()) + mockMvc.perform(get("/apps?search=time") + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) .andExpect(jsonPath("_embedded.appRegistrationResourceList", hasSize(2))); } @Test public void testListApplicationsByTypeAndSearch() throws Exception { - mockMvc.perform(get("/apps?type=task&search=time").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()) + mockMvc.perform(get("/apps?type=task&search=time") + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) .andExpect(jsonPath("_embedded.appRegistrationResourceList", hasSize(1))); - mockMvc.perform(get("/apps?type=source&search=time").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()) + mockMvc.perform(get("/apps?type=source&search=time") + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) .andExpect(jsonPath("_embedded.appRegistrationResourceList", hasSize(1))); - mockMvc.perform(get("/apps?type=sink&search=time").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()) + mockMvc.perform(get("/apps?type=sink&search=time") + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) .andExpect(jsonPath("_embedded.appRegistrationResourceList").doesNotExist()); } @Test public void testFindNonExistentApp() throws Exception { - mockMvc.perform(get("/apps/source/foo").accept(MediaType.APPLICATION_JSON)) - .andExpect(status().is4xxClientError()).andReturn().getResponse().getContentAsString() + mockMvc.perform(get("/apps/source/foo") + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().is4xxClientError()) + .andReturn() + .getResponse() + .getContentAsString() .contains("NoSuchAppRegistrationException"); } @Test public void testRegisterAndListApplications() throws Exception { - mockMvc.perform(get("/apps").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()) + mockMvc.perform(get("/apps") + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) .andExpect(jsonPath("_embedded.appRegistrationResourceList", hasSize(4))); - mockMvc.perform(post("/apps/processor/blubba").param("uri", "maven://org.springframework.cloud.stream.app:log-sink-rabbit:1.2.0.RELEASE").accept(MediaType.APPLICATION_JSON)) + mockMvc.perform(post("/apps/processor/blubba") + .param("uri", "maven://org.springframework.cloud.stream.app:log-sink-rabbit:1.2.0.RELEASE") + .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isCreated()); - mockMvc.perform(get("/apps").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()) + mockMvc.perform(get("/apps") + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) .andExpect(jsonPath("_embedded.appRegistrationResourceList", hasSize(5))); } @Test public void testListSingleApplication() throws Exception { - mockMvc.perform(get("/apps/source/time").accept(MediaType.APPLICATION_JSON)).andDo(print()) - .andExpect(status().isOk()).andExpect(jsonPath("name", is("time"))) + mockMvc.perform(get("/apps/source/time") + .accept(MediaType.APPLICATION_JSON)) + .andDo(print()) + .andExpect(status().isOk()) + .andExpect(jsonPath("name", is("time"))) .andExpect(jsonPath("type", is("source"))) .andExpect(jsonPath("$.options[*]", hasSize(1))); } @Test public void testListSingleApplicationExhaustive() throws Exception { - mockMvc.perform(get("/apps/source/time?exhaustive=true").accept(MediaType.APPLICATION_JSON)) + mockMvc.perform(get("/apps/source/time?exhaustive=true") + .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()).andExpect(jsonPath("name", is("time"))) .andExpect(jsonPath("type", is("source"))) .andExpect(jsonPath("$.options[*]", hasSize(2001))); @@ -382,36 +491,53 @@ public void testListSingleApplicationExhaustive() throws Exception { @Test @Transactional public void testUnregisterApplication() throws Exception { - mockMvc.perform(post("/apps/processor/blubba").param("uri", "maven://org.springframework.cloud.stream.app:log-sink-rabbit:1.2.0.RELEASE").accept(MediaType.APPLICATION_JSON)) + mockMvc.perform(post("/apps/processor/blubba") + .param("uri", "maven://org.springframework.cloud.stream.app:log-sink-rabbit:1.2.0.RELEASE") + .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isCreated()); - mockMvc.perform(delete("/apps/processor/blubba").accept(MediaType.APPLICATION_JSON)) + mockMvc.perform(delete("/apps/processor/blubba") + .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()); } @Test @Transactional public void testUnregisterAllApplications() throws Exception { - mockMvc.perform(delete("/apps").accept(MediaType.APPLICATION_JSON)) + mockMvc.perform(delete("/apps") + .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()); - mockMvc.perform(post("/apps/sink/log").param("uri", "maven://org.springframework.cloud.stream.app:log-sink-rabbit:1.2.0.RELEASE").accept(MediaType.APPLICATION_JSON)) + mockMvc.perform(post("/apps/sink/log") + .param("uri", "maven://org.springframework.cloud.stream.app:log-sink-rabbit:1.2.0.RELEASE") + .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isCreated()); - mockMvc.perform(post("/apps/source/time").param("uri", "maven://org.springframework.cloud.stream.app:time-source-rabbit:1.2.0.RELEASE").accept(MediaType.APPLICATION_JSON)) + mockMvc.perform(post("/apps/source/time") + .param("uri", "maven://org.springframework.cloud.stream.app:time-source-rabbit:1.2.0.RELEASE") + .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isCreated()); - mockMvc.perform(get("/apps/source/time").accept(MediaType.APPLICATION_JSON)).andDo(print()) - .andExpect(status().isOk()).andExpect(jsonPath("name", is("time"))) + mockMvc.perform(get("/apps/source/time") + .accept(MediaType.APPLICATION_JSON)) + .andDo(print()) + .andExpect(status().isOk()) + .andExpect(jsonPath("name", is("time"))) .andExpect(jsonPath("type", is("source"))); - mockMvc.perform(get("/apps/sink/log").accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()).andExpect(jsonPath("name", is("log"))) + mockMvc.perform(get("/apps/sink/log") + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("name", is("log"))) .andExpect(jsonPath("type", is("sink"))); - mockMvc.perform(delete("/apps").accept(MediaType.APPLICATION_JSON)) + mockMvc.perform(delete("/apps") + .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()); - mockMvc.perform(get("/apps").accept(MediaType.APPLICATION_JSON)).andDo(print()).andExpect(status().isOk()) + mockMvc.perform(get("/apps") + .accept(MediaType.APPLICATION_JSON)) + .andDo(print()) + .andExpect(status().isOk()) .andExpect(jsonPath("_embedded.appRegistrationResourceList").doesNotExist()); } @@ -421,27 +547,33 @@ public void testUnregisterApplicationUsedInStream() throws Exception { setupUnregistrationTestStreams(); // This log sink v1.2 is part of a deployed stream, so it can not be unregistered - mockMvc.perform(delete("/apps/sink/log/1.2.0.RELEASE").accept(MediaType.APPLICATION_JSON)) + mockMvc.perform(delete("/apps/sink/log/1.2.0.RELEASE") + .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isConflict()); // This log sink v1.0.BS is part of a deployed stream, so it can be unregistered - mockMvc.perform(delete("/apps/sink/log/3.2.0").accept(MediaType.APPLICATION_JSON)) + mockMvc.perform(delete("/apps/sink/log/3.2.0") + .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()); // This time source v1.0 BS is not part of a deployed stream, so it can be unregistered - mockMvc.perform(delete("/apps/source/time/3.2.0").accept(MediaType.APPLICATION_JSON)) + mockMvc.perform(delete("/apps/source/time/3.2.0") + .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()); // This time source is part of a deployed stream, so it can not be unregistered. - mockMvc.perform(delete("/apps/source/time/1.2.0.RELEASE").accept(MediaType.APPLICATION_JSON)) + mockMvc.perform(delete("/apps/source/time/1.2.0.RELEASE") + .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isConflict()); // This is unrelated to a stream, so should work - mockMvc.perform(delete("/apps/task/timestamp/1.3.0.RELEASE").accept(MediaType.APPLICATION_JSON)) + mockMvc.perform(delete("/apps/task/timestamp/1.3.0.RELEASE") + .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()); // Transformer processor is not deployed, so should work - mockMvc.perform(delete("/apps/processor/transformer").accept(MediaType.APPLICATION_JSON)) + mockMvc.perform(delete("/apps/processor/transformer") + .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()); } @@ -453,10 +585,13 @@ public void testUnregisterAllApplicationsWhenApplicationUsedInStream() throws Ex streamDefinitionRepository.deleteById("ticktock"); skipperClient.delete("ticktock", true); - mockMvc.perform(delete("/apps").accept(MediaType.APPLICATION_JSON)) + mockMvc.perform(delete("/apps") + .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()); - mockMvc.perform(get("/apps").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()) + mockMvc.perform(get("/apps") + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) .andExpect(jsonPath("_embedded.appRegistrationResourceList").doesNotExist()); } @@ -465,33 +600,40 @@ private void setupUnregistrationTestStreams() throws Exception { // Register time source v1.2 mockMvc.perform(post("/apps/source/time") - .param("uri", "maven://org.springframework.cloud.stream.app:time-source-rabbit:1.2.0.RELEASE").accept(MediaType.APPLICATION_JSON)) + .param("uri", "maven://org.springframework.cloud.stream.app:time-source-rabbit:1.2.0.RELEASE") + .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isCreated()); // Make sure the 1.2 time source is registered. - mockMvc.perform(get("/apps/source/time/1.2.0.RELEASE").accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()).andExpect(jsonPath("name", is("time"))) + mockMvc.perform(get("/apps/source/time/1.2.0.RELEASE") + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("name", is("time"))) .andExpect(jsonPath("type", is("source"))); // Register log sink v1.2 mockMvc.perform(post("/apps/sink/log") - .param("uri", "maven://org.springframework.cloud.stream.app:log-sink-rabbit:1.2.0.RELEASE").accept(MediaType.APPLICATION_JSON)) + .param("uri", "maven://org.springframework.cloud.stream.app:log-sink-rabbit:1.2.0.RELEASE") + .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isCreated()); // Make sure the 1.2 log sink is registered. - mockMvc.perform(get("/apps/sink/log/1.2.0.RELEASE").accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()).andExpect(jsonPath("name", is("log"))) + mockMvc.perform(get("/apps/sink/log/1.2.0.RELEASE") + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("name", is("log"))) .andExpect(jsonPath("type", is("sink"))); // Register a transformer mockMvc.perform(post("/apps/processor/transformer") - .param("uri", "maven://org.springframework.cloud.stream.app:transformer-processor-rabbit:1.2.0.RELEASE").accept(MediaType.APPLICATION_JSON)) + .param("uri", "maven://org.springframework.cloud.stream.app:transformer-processor-rabbit:1.2.0.RELEASE") + .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isCreated()); // Register a task mockMvc.perform(post("/apps/task/timestamp") - .param("uri", "maven://org.springframework.cloud.task.app:timestamp-task:1.3.0.RELEASE") - .accept(MediaType.APPLICATION_JSON)) + .param("uri", "maven://org.springframework.cloud.task.app:timestamp-task:1.3.0.RELEASE") + .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isCreated()); // Create stream definition @@ -525,33 +667,40 @@ public void testUnregisterApplicationUsedInStreamNotDeployed() throws Exception // Register time source v1.2 mockMvc.perform(post("/apps/source/time") - .param("uri", "maven://org.springframework.cloud.stream.app:time-source-rabbit:1.2.0.RELEASE").accept(MediaType.APPLICATION_JSON)) + .param("uri", "maven://org.springframework.cloud.stream.app:time-source-rabbit:1.2.0.RELEASE") + .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isCreated()); // Make sure the 1.2 time source is registered. - mockMvc.perform(get("/apps/source/time/1.2.0.RELEASE").accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()).andExpect(jsonPath("name", is("time"))) + mockMvc.perform(get("/apps/source/time/1.2.0.RELEASE") + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("name", is("time"))) .andExpect(jsonPath("type", is("source"))); // Register log sink v1.2 mockMvc.perform(post("/apps/sink/log") - .param("uri", "maven://org.springframework.cloud.stream.app:log-sink-rabbit:1.2.0.RELEASE").accept(MediaType.APPLICATION_JSON)) + .param("uri", "maven://org.springframework.cloud.stream.app:log-sink-rabbit:1.2.0.RELEASE") + .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isCreated()); // Make sure the 1.2 log sink is registered. - mockMvc.perform(get("/apps/sink/log/1.2.0.RELEASE").accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()).andExpect(jsonPath("name", is("log"))) + mockMvc.perform(get("/apps/sink/log/1.2.0.RELEASE") + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("name", is("log"))) .andExpect(jsonPath("type", is("sink"))); // Register a transformer mockMvc.perform(post("/apps/processor/transformer") - .param("uri", "maven://org.springframework.cloud.stream.app:transformer-processor-rabbit:1.2.0.RELEASE").accept(MediaType.APPLICATION_JSON)) + .param("uri", "maven://org.springframework.cloud.stream.app:transformer-processor-rabbit:1.2.0.RELEASE") + .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isCreated()); // Register a task mockMvc.perform(post("/apps/task/timestamp") - .param("uri", "maven://org.springframework.cloud.task.app:timestamp-task:1.3.0.RELEASE") - .accept(MediaType.APPLICATION_JSON)) + .param("uri", "maven://org.springframework.cloud.task.app:timestamp-task:1.3.0.RELEASE") + .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isCreated()); // Create stream definition @@ -563,106 +712,136 @@ public void testUnregisterApplicationUsedInStreamNotDeployed() throws Exception when(skipperClient.status(eq("ticktock"))).thenThrow(new ReleaseNotFoundException("")); // This log sink v1.2 is part of a deployed stream, so it can be unregistered - mockMvc.perform(delete("/apps/sink/log/1.2.0.RELEASE").accept(MediaType.APPLICATION_JSON)) + mockMvc.perform(delete("/apps/sink/log/1.2.0.RELEASE") + .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()); // This log sink v1.0.BS is part of a deployed stream, so it can be unregistered - mockMvc.perform(delete("/apps/sink/log/3.2.0").accept(MediaType.APPLICATION_JSON)) + mockMvc.perform(delete("/apps/sink/log/3.2.0") + .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()); // This time source v1.0 BS is not part of a deployed stream, so it can be unregistered - mockMvc.perform(delete("/apps/source/time/3.2.0").accept(MediaType.APPLICATION_JSON)) + mockMvc.perform(delete("/apps/source/time/3.2.0") + .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()); // This time source is part of a deployed stream, so it can not be unregistered. - mockMvc.perform(delete("/apps/source/time/1.2.0.RELEASE").accept(MediaType.APPLICATION_JSON)) + mockMvc.perform(delete("/apps/source/time/1.2.0.RELEASE") + .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()); // This is unrelated to a stream, so should work - mockMvc.perform(delete("/apps/task/timestamp/1.3.0.RELEASE").accept(MediaType.APPLICATION_JSON)) + mockMvc.perform(delete("/apps/task/timestamp/1.3.0.RELEASE") + .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()); // Transformer processor is not deployed, so should work - mockMvc.perform(delete("/apps/processor/transformer").accept(MediaType.APPLICATION_JSON)) + mockMvc.perform(delete("/apps/processor/transformer") + .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()); } @Test public void testUnregisterUnversionedApplicationNotFound() throws Exception { - mockMvc.perform(delete("/apps/processor/transformer").accept(MediaType.APPLICATION_JSON)) + mockMvc.perform(delete("/apps/processor/transformer") + .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isNotFound()); } @Test public void testUnregisterApplicationNotFound() throws Exception { - mockMvc.perform(delete("/apps/processor/transformer/blubba").accept(MediaType.APPLICATION_JSON)) + mockMvc.perform(delete("/apps/processor/transformer/blubba") + .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isNotFound()); } @Test public void testPagination() throws Exception { - mockMvc.perform(get("/apps").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()) + mockMvc.perform(get("/apps") + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) .andExpect(jsonPath("page.size", is(20))) .andExpect(jsonPath("page.totalElements", is(4))) .andExpect(jsonPath("page.totalPages", is(1))) .andExpect(jsonPath("page.number", is(0))); - mockMvc.perform(get("/apps?page=0&size=10").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()) + mockMvc.perform(get("/apps?page=0&size=10") + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) .andExpect(jsonPath("page.size", is(10))) .andExpect(jsonPath("page.totalElements", is(4))) .andExpect(jsonPath("page.totalPages", is(1))) .andExpect(jsonPath("page.number", is(0))); - mockMvc.perform(get("/apps?page=0&size=1").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()) + mockMvc.perform(get("/apps?page=0&size=1") + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) .andExpect(jsonPath("page.size", is(1))) .andExpect(jsonPath("page.totalElements", is(4))) .andExpect(jsonPath("page.totalPages", is(4))) .andExpect(jsonPath("page.number", is(0))); - mockMvc.perform(get("/apps?page=1&size=2").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()) + mockMvc.perform(get("/apps?page=1&size=2") + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) .andExpect(jsonPath("page.size", is(2))) .andExpect(jsonPath("page.totalElements", is(4))) .andExpect(jsonPath("page.totalPages", is(2))) .andExpect(jsonPath("page.number", is(1))); - mockMvc.perform(get("/apps?page=0&size=3").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()) + mockMvc.perform(get("/apps?page=0&size=3") + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) .andExpect(jsonPath("page.size", is(3))) .andExpect(jsonPath("page.totalElements", is(4))) .andExpect(jsonPath("page.totalPages", is(2))) .andExpect(jsonPath("page.number", is(0))); - mockMvc.perform(get("/apps?page=1&size=3").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()) + mockMvc.perform(get("/apps?page=1&size=3") + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) .andExpect(jsonPath("page.size", is(3))) .andExpect(jsonPath("page.totalElements", is(4))) .andExpect(jsonPath("page.totalPages", is(2))) .andExpect(jsonPath("page.number", is(1))); - mockMvc.perform(get("/apps?page=5&size=2").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()) + mockMvc.perform(get("/apps?page=5&size=2") + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) .andExpect(jsonPath("page.size", is(2))) .andExpect(jsonPath("page.totalElements", is(4))) .andExpect(jsonPath("page.totalPages", is(2))) .andExpect(jsonPath("page.number", is(5))); - mockMvc.perform(get("/apps?page=0&size=10&search=i").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()) + mockMvc.perform(get("/apps?page=0&size=10&search=i") + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) .andExpect(jsonPath("page.size", is(10))) .andExpect(jsonPath("page.totalElements", is(3))) .andExpect(jsonPath("page.totalPages", is(1))) .andExpect(jsonPath("page.number", is(0))); - mockMvc.perform(get("/apps?page=0&size=1&search=i").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()) + mockMvc.perform(get("/apps?page=0&size=1&search=i") + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) .andExpect(jsonPath("page.size", is(1))) .andExpect(jsonPath("page.totalElements", is(3))) .andExpect(jsonPath("page.totalPages", is(3))) .andExpect(jsonPath("page.number", is(0))); - mockMvc.perform(get("/apps?page=1&size=2&search=i").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()) + mockMvc.perform(get("/apps?page=1&size=2&search=i") + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) .andExpect(jsonPath("page.size", is(2))) .andExpect(jsonPath("page.totalElements", is(3))) .andExpect(jsonPath("page.totalPages", is(2))) .andExpect(jsonPath("page.number", is(1))); - mockMvc.perform(get("/apps?page=5&size=2&search=i").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()) + mockMvc.perform(get("/apps?page=5&size=2&search=i") + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) .andExpect(jsonPath("page.size", is(2))) .andExpect(jsonPath("page.totalElements", is(3))) .andExpect(jsonPath("page.totalPages", is(2))) @@ -671,17 +850,22 @@ public void testPagination() throws Exception { @Test public void testListApplicationsByVersion() throws Exception { - mockMvc.perform(get("/apps?version=3.2.0").accept(MediaType.APPLICATION_JSON)) + mockMvc.perform(get("/apps?version=3.2.0") + .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("_embedded.appRegistrationResourceList", hasSize(4))); } @Test public void testListApplicationsByVersionAndSearch() throws Exception { - mockMvc.perform(get("/apps?version=3.2.0&search=time").accept(MediaType.APPLICATION_JSON)).andDo(print()) + mockMvc.perform(get("/apps?version=3.2.0&search=time") + .accept(MediaType.APPLICATION_JSON)) + .andDo(print()) .andExpect(status().isOk()) .andExpect(jsonPath("_embedded.appRegistrationResourceList", hasSize(2))); - mockMvc.perform(get("/apps?version=3.2.0&search=timestamp").accept(MediaType.APPLICATION_JSON)).andDo(print()) + mockMvc.perform(get("/apps?version=3.2.0&search=timestamp") + .accept(MediaType.APPLICATION_JSON)) + .andDo(print()) .andExpect(status().isOk()) .andExpect(jsonPath("_embedded.appRegistrationResourceList", hasSize(1))); }