Skip to content

Commit 411d625

Browse files
authored
Remove trailing slashes from controller tests (#5693)
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.
1 parent 340bd27 commit 411d625

10 files changed

+103
-109
lines changed

spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/configuration/TestDependencies.java

+11-17
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,17 @@
238238
@EnableJpaAuditing
239239
@EnableMapRepositories("org.springframework.cloud.dataflow.server.job")
240240
@EnableTransactionManagement
241-
public class TestDependencies extends WebMvcConfigurationSupport {
241+
public class TestDependencies implements WebMvcConfigurer {
242+
243+
@Override
244+
public void configurePathMatch(PathMatchConfigurer configurer) {
245+
configurer.setUseSuffixPatternMatch(false);
246+
}
247+
248+
@Override
249+
public void addFormatters(FormatterRegistry registry) {
250+
registry.addConverter(new AppBootVersionConverter());
251+
}
242252

243253
@Bean
244254
public RestControllerAdvice restControllerAdvice() {
@@ -855,20 +865,4 @@ public PlatformTransactionManager transactionManager(
855865
return transactionManager;
856866
}
857867

858-
@Bean
859-
public WebMvcConfigurer configurer() {
860-
return new WebMvcConfigurer() {
861-
862-
@Override
863-
public void configurePathMatch(PathMatchConfigurer configurer) {
864-
configurer.setUseSuffixPatternMatch(false);
865-
}
866-
867-
@Override
868-
public void addFormatters(FormatterRegistry registry) {
869-
registry.addConverter(new AppBootVersionConverter());
870-
}
871-
};
872-
}
873-
874868
}

spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/controller/AppRegistryControllerTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ public void testVersionOverride() throws Exception {
264264
public void testVersionOverrideNonExistentApp() throws Exception {
265265
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))
266266
.andDo(print()).andExpect(status().isCreated());
267-
MvcResult mvcResult = this.mockMvc.perform(put("/apps/sink/log1/1.3.0.RELEASE/")).andDo(print()).andExpect(status().is4xxClientError()).andReturn();
267+
MvcResult mvcResult = this.mockMvc.perform(put("/apps/sink/log1/1.3.0.RELEASE")).andDo(print()).andExpect(status().is4xxClientError()).andReturn();
268268
Assert.isInstanceOf(NoSuchAppRegistrationException.class, mvcResult.getResolvedException());
269269
}
270270

spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/controller/AuditRecordControllerTests.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,17 @@ public void setupMocks() throws Exception {
124124

125125
startDate = ZonedDateTime.now();
126126

127-
mockMvc.perform(post("/streams/definitions/").param("name", "myStream").param("definition", "time | log")
127+
mockMvc.perform(post("/streams/definitions").param("name", "myStream").param("definition", "time | log")
128128
.accept(MediaType.APPLICATION_JSON)).andExpect(status().isCreated());
129-
mockMvc.perform(post("/streams/definitions/").param("name", "myStream1").param("definition", "time | log")
129+
mockMvc.perform(post("/streams/definitions").param("name", "myStream1").param("definition", "time | log")
130130
.accept(MediaType.APPLICATION_JSON)).andExpect(status().isCreated());
131131

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

135135
betweenDate = ZonedDateTime.now();
136136

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

140140
// Verify that the 4 app create and 3 stream create audit records have been recorded before setting the end date.

spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/controller/JobExecutionControllerTests.java

+14-14
Original file line numberDiff line numberDiff line change
@@ -227,15 +227,15 @@ public void testGetExecutionWithJobProperties() throws Exception {
227227
public void testGetAllExecutionsFailed() throws Exception {
228228
createDirtyJob();
229229
// expecting to ignore dirty job
230-
mockMvc.perform(get("/jobs/executions/").accept(MediaType.APPLICATION_JSON))
230+
mockMvc.perform(get("/jobs/executions").accept(MediaType.APPLICATION_JSON))
231231
.andDo(print())
232232
.andExpect(status().isOk())
233233
.andExpect(jsonPath("$._embedded.jobExecutionResourceList", hasSize(10)));
234234
}
235235

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

245245
@Test
246246
public void testGetAllExecutionsPageOffsetLargerThanIntMaxValue() throws Exception {
247-
verify5XXErrorIsThrownForPageOffsetError(get("/jobs/executions/"));
248-
verifyBorderCaseForMaxInt(get("/jobs/executions/"));
247+
verify5XXErrorIsThrownForPageOffsetError(get("/jobs/executions"));
248+
verifyBorderCaseForMaxInt(get("/jobs/executions"));
249249
}
250250

251251
@Test
252252
public void testGetExecutionsByName() throws Exception {
253-
mockMvc.perform(get("/jobs/executions/").param("name", JobExecutionUtils.JOB_NAME_ORIG)
253+
mockMvc.perform(get("/jobs/executions").param("name", JobExecutionUtils.JOB_NAME_ORIG)
254254
.accept(MediaType.APPLICATION_JSON))
255255
.andDo(print())
256256
.andExpect(status().isOk())
@@ -262,13 +262,13 @@ public void testGetExecutionsByName() throws Exception {
262262
@Test
263263
public void testGetExecutionsByNamePageOffsetLargerThanIntMaxValue() throws Exception {
264264
verify5XXErrorIsThrownForPageOffsetError(
265-
get("/jobs/executions/").param("name", JobExecutionUtils.JOB_NAME_ORIG));
266-
verifyBorderCaseForMaxInt(get("/jobs/executions/").param("name", JobExecutionUtils.JOB_NAME_ORIG));
265+
get("/jobs/executions").param("name", JobExecutionUtils.JOB_NAME_ORIG));
266+
verifyBorderCaseForMaxInt(get("/jobs/executions").param("name", JobExecutionUtils.JOB_NAME_ORIG));
267267
}
268268

269269
@Test
270270
public void testGetExecutionsByNameMultipleResult() throws Exception {
271-
mockMvc.perform(get("/jobs/executions/").param("name", JobExecutionUtils.JOB_NAME_FOOBAR)
271+
mockMvc.perform(get("/jobs/executions").param("name", JobExecutionUtils.JOB_NAME_FOOBAR)
272272
.accept(MediaType.APPLICATION_JSON))
273273
.andDo(print())
274274
.andExpect(status().isOk())
@@ -281,7 +281,7 @@ public void testGetExecutionsByNameMultipleResult() throws Exception {
281281

282282
@Test
283283
public void testFilteringByStatusAndName_EmptyNameAndStatusGiven() throws Exception {
284-
mockMvc.perform(get("/jobs/executions/")
284+
mockMvc.perform(get("/jobs/executions")
285285
.param("name", "")
286286
.param("status", "FAILED")
287287
.accept(MediaType.APPLICATION_JSON))
@@ -296,7 +296,7 @@ public void testFilteringByStatusAndName_EmptyNameAndStatusGiven() throws Except
296296

297297
@Test
298298
public void testFilteringByUnknownStatus() throws Exception {
299-
mockMvc.perform(get("/jobs/executions/")
299+
mockMvc.perform(get("/jobs/executions")
300300
.param("status", "UNKNOWN")
301301
.accept(MediaType.APPLICATION_JSON))
302302
.andDo(print())
@@ -306,7 +306,7 @@ public void testFilteringByUnknownStatus() throws Exception {
306306

307307
@Test
308308
public void testFilteringByStatusAndName_NameAndStatusGiven() throws Exception {
309-
mockMvc.perform(get("/jobs/executions/")
309+
mockMvc.perform(get("/jobs/executions")
310310
.param("name", JobExecutionUtils.BASE_JOB_NAME + "%")
311311
.param("status", "COMPLETED")
312312
.accept(MediaType.APPLICATION_JSON))
@@ -319,14 +319,14 @@ public void testFilteringByStatusAndName_NameAndStatusGiven() throws Exception {
319319

320320
@Test
321321
public void testGetExecutionsByNameNotFound() throws Exception {
322-
mockMvc.perform(get("/jobs/executions/").param("name", "BAZ").accept(MediaType.APPLICATION_JSON))
322+
mockMvc.perform(get("/jobs/executions").param("name", "BAZ").accept(MediaType.APPLICATION_JSON))
323323
.andDo(print())
324324
.andExpect(status().isNotFound());
325325
}
326326

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

340340
@Test
341341
public void testWildcardMatchSingleResult() throws Exception {
342-
mockMvc.perform(get("/jobs/executions/")
342+
mockMvc.perform(get("/jobs/executions")
343343
.param("name", "m_Job_ORIG").accept(MediaType.APPLICATION_JSON))
344344
.andDo(print())
345345
.andExpect(status().isOk())

spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/controller/JobExecutionThinControllerTests.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public void testGetAllExecutionsJobExecutionOnly() throws Exception {
123123

124124
@Test
125125
public void testGetExecutionsByName() throws Exception {
126-
mockMvc.perform(get("/jobs/thinexecutions/").param("name", JobExecutionUtils.JOB_NAME_ORIG)
126+
mockMvc.perform(get("/jobs/thinexecutions").param("name", JobExecutionUtils.JOB_NAME_ORIG)
127127
.accept(MediaType.APPLICATION_JSON))
128128
.andDo(print())
129129
.andExpect(status().isOk())
@@ -135,7 +135,7 @@ public void testGetExecutionsByName() throws Exception {
135135
public void testGetExecutionsByDateRange() throws Exception {
136136
final Date toDate = new Date();
137137
final Date fromDate = DateUtils.addMinutes(toDate, -10);
138-
mockMvc.perform(get("/jobs/thinexecutions/")
138+
mockMvc.perform(get("/jobs/thinexecutions")
139139
.param("fromDate",
140140
new SimpleDateFormat(TimeUtils.DEFAULT_DATAFLOW_DATE_TIME_PARAMETER_FORMAT_PATTERN)
141141
.format(fromDate))
@@ -150,7 +150,7 @@ public void testGetExecutionsByDateRange() throws Exception {
150150

151151
@Test
152152
public void testGetExecutionsByJobInstanceId() throws Exception {
153-
mockMvc.perform(get("/jobs/thinexecutions/").param("jobInstanceId", "1")
153+
mockMvc.perform(get("/jobs/thinexecutions").param("jobInstanceId", "1")
154154
.accept(MediaType.APPLICATION_JSON))
155155
.andDo(print())
156156
.andExpect(status().isOk())
@@ -161,7 +161,7 @@ public void testGetExecutionsByJobInstanceId() throws Exception {
161161

162162
@Test
163163
public void testGetExecutionsByTaskExecutionId() throws Exception {
164-
mockMvc.perform(get("/jobs/thinexecutions/").param("taskExecutionId", "4")
164+
mockMvc.perform(get("/jobs/thinexecutions").param("taskExecutionId", "4")
165165
.accept(MediaType.APPLICATION_JSON))
166166
.andDo(print())
167167
.andExpect(status().isOk())

spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/controller/JobInstanceControllerTests.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,15 @@ public void testGetInstance() throws Exception {
144144

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

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

163163
@Test
164164
public void testGetInstanceByNameNotFound() throws Exception {
165-
mockMvc.perform(get("/jobs/instances/").param("name", "BAZ").accept(MediaType.APPLICATION_JSON))
165+
mockMvc.perform(get("/jobs/instances").param("name", "BAZ").accept(MediaType.APPLICATION_JSON))
166166
.andExpect(status().is4xxClientError())
167167
.andExpect(content().string(containsString("NoSuchJobException")));
168168
}

0 commit comments

Comments
 (0)