Skip to content

Commit

Permalink
Remove trailing slashes from controller tests (spring-cloud#5693)
Browse files Browse the repository at this point in the history
This commit accounts for the fact that as of Spring Framework 6.0, the trailing 
slash matching configuration option has been deprecated and its default value 
set to false. The mvc tests are adjusted to remove the trailing slash from their
endpoint urls.
  • Loading branch information
cppwfs authored Feb 22, 2024
1 parent 340bd27 commit 411d625
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,17 @@
@EnableJpaAuditing
@EnableMapRepositories("org.springframework.cloud.dataflow.server.job")
@EnableTransactionManagement
public class TestDependencies extends WebMvcConfigurationSupport {
public class TestDependencies implements WebMvcConfigurer {

@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
configurer.setUseSuffixPatternMatch(false);
}

@Override
public void addFormatters(FormatterRegistry registry) {
registry.addConverter(new AppBootVersionConverter());
}

@Bean
public RestControllerAdvice restControllerAdvice() {
Expand Down Expand Up @@ -855,20 +865,4 @@ public PlatformTransactionManager transactionManager(
return transactionManager;
}

@Bean
public WebMvcConfigurer configurer() {
return new WebMvcConfigurer() {

@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
configurer.setUseSuffixPatternMatch(false);
}

@Override
public void addFormatters(FormatterRegistry registry) {
registry.addConverter(new AppBootVersionConverter());
}
};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public void testVersionOverride() throws Exception {
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();
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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,17 @@ public void setupMocks() throws Exception {

startDate = ZonedDateTime.now();

mockMvc.perform(post("/streams/definitions/").param("name", "myStream").param("definition", "time | log")
mockMvc.perform(post("/streams/definitions").param("name", "myStream").param("definition", "time | log")
.accept(MediaType.APPLICATION_JSON)).andExpect(status().isCreated());
mockMvc.perform(post("/streams/definitions/").param("name", "myStream1").param("definition", "time | log")
mockMvc.perform(post("/streams/definitions").param("name", "myStream1").param("definition", "time | log")
.accept(MediaType.APPLICATION_JSON)).andExpect(status().isCreated());

// Verify that the 4 app create and 2 stream create audit records have been recorded before setting the between date.
Awaitility.await().atMost(Duration.ofMillis(30000)).until(() -> auditRecordRepository.count() == INITIAL_AUDIT_CREATE_COUNT);

betweenDate = ZonedDateTime.now();

mockMvc.perform(post("/streams/definitions/").param("name", "myStream2").param("definition", "time | log")
mockMvc.perform(post("/streams/definitions").param("name", "myStream2").param("definition", "time | log")
.accept(MediaType.APPLICATION_JSON)).andExpect(status().isCreated());

// Verify that the 4 app create and 3 stream create audit records have been recorded before setting the end date.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,15 @@ public void testGetExecutionWithJobProperties() throws Exception {
public void testGetAllExecutionsFailed() throws Exception {
createDirtyJob();
// expecting to ignore dirty job
mockMvc.perform(get("/jobs/executions/").accept(MediaType.APPLICATION_JSON))
mockMvc.perform(get("/jobs/executions").accept(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().isOk())
.andExpect(jsonPath("$._embedded.jobExecutionResourceList", hasSize(10)));
}

@Test
public void testGetAllExecutions() throws Exception {
mockMvc.perform(get("/jobs/executions/").accept(MediaType.APPLICATION_JSON))
mockMvc.perform(get("/jobs/executions").accept(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().isOk())
.andExpect(jsonPath("$._embedded.jobExecutionResourceList", hasSize(10)))
Expand All @@ -244,13 +244,13 @@ public void testGetAllExecutions() throws Exception {

@Test
public void testGetAllExecutionsPageOffsetLargerThanIntMaxValue() throws Exception {
verify5XXErrorIsThrownForPageOffsetError(get("/jobs/executions/"));
verifyBorderCaseForMaxInt(get("/jobs/executions/"));
verify5XXErrorIsThrownForPageOffsetError(get("/jobs/executions"));
verifyBorderCaseForMaxInt(get("/jobs/executions"));
}

@Test
public void testGetExecutionsByName() throws Exception {
mockMvc.perform(get("/jobs/executions/").param("name", JobExecutionUtils.JOB_NAME_ORIG)
mockMvc.perform(get("/jobs/executions").param("name", JobExecutionUtils.JOB_NAME_ORIG)
.accept(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().isOk())
Expand All @@ -262,13 +262,13 @@ public void testGetExecutionsByName() throws Exception {
@Test
public void testGetExecutionsByNamePageOffsetLargerThanIntMaxValue() throws Exception {
verify5XXErrorIsThrownForPageOffsetError(
get("/jobs/executions/").param("name", JobExecutionUtils.JOB_NAME_ORIG));
verifyBorderCaseForMaxInt(get("/jobs/executions/").param("name", JobExecutionUtils.JOB_NAME_ORIG));
get("/jobs/executions").param("name", JobExecutionUtils.JOB_NAME_ORIG));
verifyBorderCaseForMaxInt(get("/jobs/executions").param("name", JobExecutionUtils.JOB_NAME_ORIG));
}

@Test
public void testGetExecutionsByNameMultipleResult() throws Exception {
mockMvc.perform(get("/jobs/executions/").param("name", JobExecutionUtils.JOB_NAME_FOOBAR)
mockMvc.perform(get("/jobs/executions").param("name", JobExecutionUtils.JOB_NAME_FOOBAR)
.accept(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().isOk())
Expand All @@ -281,7 +281,7 @@ public void testGetExecutionsByNameMultipleResult() throws Exception {

@Test
public void testFilteringByStatusAndName_EmptyNameAndStatusGiven() throws Exception {
mockMvc.perform(get("/jobs/executions/")
mockMvc.perform(get("/jobs/executions")
.param("name", "")
.param("status", "FAILED")
.accept(MediaType.APPLICATION_JSON))
Expand All @@ -296,7 +296,7 @@ public void testFilteringByStatusAndName_EmptyNameAndStatusGiven() throws Except

@Test
public void testFilteringByUnknownStatus() throws Exception {
mockMvc.perform(get("/jobs/executions/")
mockMvc.perform(get("/jobs/executions")
.param("status", "UNKNOWN")
.accept(MediaType.APPLICATION_JSON))
.andDo(print())
Expand All @@ -306,7 +306,7 @@ public void testFilteringByUnknownStatus() throws Exception {

@Test
public void testFilteringByStatusAndName_NameAndStatusGiven() throws Exception {
mockMvc.perform(get("/jobs/executions/")
mockMvc.perform(get("/jobs/executions")
.param("name", JobExecutionUtils.BASE_JOB_NAME + "%")
.param("status", "COMPLETED")
.accept(MediaType.APPLICATION_JSON))
Expand All @@ -319,14 +319,14 @@ public void testFilteringByStatusAndName_NameAndStatusGiven() throws Exception {

@Test
public void testGetExecutionsByNameNotFound() throws Exception {
mockMvc.perform(get("/jobs/executions/").param("name", "BAZ").accept(MediaType.APPLICATION_JSON))
mockMvc.perform(get("/jobs/executions").param("name", "BAZ").accept(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().isNotFound());
}

@Test
public void testWildcardMatchMultipleResult() throws Exception {
mockMvc.perform(get("/jobs/executions/")
mockMvc.perform(get("/jobs/executions")
.param("name", JobExecutionUtils.BASE_JOB_NAME + "_FOO_ST%").accept(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().isOk())
Expand All @@ -339,7 +339,7 @@ public void testWildcardMatchMultipleResult() throws Exception {

@Test
public void testWildcardMatchSingleResult() throws Exception {
mockMvc.perform(get("/jobs/executions/")
mockMvc.perform(get("/jobs/executions")
.param("name", "m_Job_ORIG").accept(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().isOk())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void testGetAllExecutionsJobExecutionOnly() throws Exception {

@Test
public void testGetExecutionsByName() throws Exception {
mockMvc.perform(get("/jobs/thinexecutions/").param("name", JobExecutionUtils.JOB_NAME_ORIG)
mockMvc.perform(get("/jobs/thinexecutions").param("name", JobExecutionUtils.JOB_NAME_ORIG)
.accept(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().isOk())
Expand All @@ -135,7 +135,7 @@ public void testGetExecutionsByName() throws Exception {
public void testGetExecutionsByDateRange() throws Exception {
final Date toDate = new Date();
final Date fromDate = DateUtils.addMinutes(toDate, -10);
mockMvc.perform(get("/jobs/thinexecutions/")
mockMvc.perform(get("/jobs/thinexecutions")
.param("fromDate",
new SimpleDateFormat(TimeUtils.DEFAULT_DATAFLOW_DATE_TIME_PARAMETER_FORMAT_PATTERN)
.format(fromDate))
Expand All @@ -150,7 +150,7 @@ public void testGetExecutionsByDateRange() throws Exception {

@Test
public void testGetExecutionsByJobInstanceId() throws Exception {
mockMvc.perform(get("/jobs/thinexecutions/").param("jobInstanceId", "1")
mockMvc.perform(get("/jobs/thinexecutions").param("jobInstanceId", "1")
.accept(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().isOk())
Expand All @@ -161,7 +161,7 @@ public void testGetExecutionsByJobInstanceId() throws Exception {

@Test
public void testGetExecutionsByTaskExecutionId() throws Exception {
mockMvc.perform(get("/jobs/thinexecutions/").param("taskExecutionId", "4")
mockMvc.perform(get("/jobs/thinexecutions").param("taskExecutionId", "4")
.accept(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().isOk())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,15 @@ public void testGetInstance() throws Exception {

@Test
public void testGetInstancesByName() throws Exception {
mockMvc.perform(get("/jobs/instances/").param("name", JOB_NAME_ORIG).accept(MediaType.APPLICATION_JSON))
mockMvc.perform(get("/jobs/instances").param("name", JOB_NAME_ORIG).accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$._embedded.jobInstanceResourceList[0].jobName", is(JOB_NAME_ORIG)))
.andExpect(jsonPath("$._embedded.jobInstanceResourceList", hasSize(1)));
}

@Test
public void testGetExecutionsByNameMultipleResult() throws Exception {
mockMvc.perform(get("/jobs/instances/").param("name", JOB_NAME_FOOBAR).accept(MediaType.APPLICATION_JSON))
mockMvc.perform(get("/jobs/instances").param("name", JOB_NAME_FOOBAR).accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$._embedded.jobInstanceResourceList[0].jobName", is(JOB_NAME_FOOBAR)))
.andExpect(jsonPath("$._embedded.jobInstanceResourceList[0].jobExecutions[0].executionId", is(4)))
Expand All @@ -162,7 +162,7 @@ public void testGetExecutionsByNameMultipleResult() throws Exception {

@Test
public void testGetInstanceByNameNotFound() throws Exception {
mockMvc.perform(get("/jobs/instances/").param("name", "BAZ").accept(MediaType.APPLICATION_JSON))
mockMvc.perform(get("/jobs/instances").param("name", "BAZ").accept(MediaType.APPLICATION_JSON))
.andExpect(status().is4xxClientError())
.andExpect(content().string(containsString("NoSuchJobException")));
}
Expand Down
Loading

0 comments on commit 411d625

Please sign in to comment.