Skip to content

Commit

Permalink
refactor(test): remove trailing slash from mock url template with spr…
Browse files Browse the repository at this point in the history
…ing boot upgrade to 3.x

With spring boot upgrade, spring framework also upgrades from 5.x to 6.x. In spring framework 6.0, the trailing slash matching configuration option has been deprecated and its default value set to false.
https://github.com/spring-projects/spring-framework/wiki/Spring-Framework-6.0-Release-Notes#web-applications

Due to this change, encountered the below test failure:
```
Condition failed with Exception:

mockMvc.perform(get("/authorize/")) .andExpect(status().isOk()) .andExpect(content().json(expected))
|       |       |                    |         |        |
|       |       |                    |         |        <org.springframework.test.web.servlet.result.StatusResultMatchers$$Lambda$1833/0x0000000801998000@1cadc7c1 arg$1=200 OK>
|       |       |                    |         <org.springframework.test.web.servlet.result.StatusResultMatchers@34106ddc>
|       |       |                    java.lang.AssertionError: Status expected:<200> but was:<404>
|       |       |                    	at org.springframework.test.util.AssertionErrors.fail(AssertionErrors.java:59)
|       |       |                    	at org.springframework.test.util.AssertionErrors.assertEquals(AssertionErrors.java:122)
|       |       |                    	at org.springframework.test.web.servlet.result.StatusResultMatchers.lambda$matcher$9(StatusResultMatchers.java:637)
|       |       |                    	at org.springframework.test.web.servlet.MockMvc$1.andExpect(MockMvc.java:214)
|       |       |                    	at com.netflix.spinnaker.fiat.controllers.AuthorizeControllerSpec.should get user from repo via endpoint(AuthorizeControllerSpec.groovy:180)
|       |       <org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder@4c5c8926 method=GET url=/authorize/ contextPath= servletPath= pathInfo=/authorize/ secure=null principal=null session=null remoteAddress=null characterEncoding=null content=[] contentType=application/json headers=[:] parameters=[:] queryParams=[:] cookies=[] locales=[] requestAttributes=[:] sessionAttributes=[:] flashAttributes=[:] postProcessors=[]>
|       <org.springframework.test.web.servlet.MockMvc$1@6a230707 val$mvcResult=org.springframework.test.web.servlet.DefaultMvcResult@5ed59e7f this$0=org.springframework.test.web.servlet.MockMvc@27477eb7>
<org.springframework.test.web.servlet.MockMvc@27477eb7 servlet=org.springframework.test.web.servlet.TestDispatcherServlet@512efef4 filters=[] servletContext=org.springframework.boot.test.mock.web.SpringBootMockServletContext@1cf516fa defaultRequestBuilder=org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder@5b96272e defaultResponseCharacterEncoding=null defaultResultMatchers=[] defaultResultHandlers=[]>

Condition failed with Exception:

mockMvc.perform(get("/authorize/")) .andExpect(status().isOk()) .andExpect(content().json(expected))
|       |       |                    |         |        |
|       |       |                    |         |        <org.springframework.test.web.servlet.result.StatusResultMatchers$$Lambda$1833/0x0000000801998000@1cadc7c1 arg$1=200 OK>
|       |       |                    |         <org.springframework.test.web.servlet.result.StatusResultMatchers@34106ddc>
|       |       |                    java.lang.AssertionError: Status expected:<200> but was:<404>
|       |       |                    	at org.springframework.test.util.AssertionErrors.fail(AssertionErrors.java:59)
|       |       |                    	at org.springframework.test.util.AssertionErrors.assertEquals(AssertionErrors.java:122)
|       |       |                    	at org.springframework.test.web.servlet.result.StatusResultMatchers.lambda$matcher$9(StatusResultMatchers.java:637)
|       |       |                    	at org.springframework.test.web.servlet.MockMvc$1.andExpect(MockMvc.java:214)
|       |       |                    	at com.netflix.spinnaker.fiat.controllers.AuthorizeControllerSpec.should get user from repo via endpoint(AuthorizeControllerSpec.groovy:180)
|       |       <org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder@4c5c8926 method=GET url=/authorize/ contextPath= servletPath= pathInfo=/authorize/ secure=null principal=null session=null remoteAddress=null characterEncoding=null content=[] contentType=application/json headers=[:] parameters=[:] queryParams=[:] cookies=[] locales=[] requestAttributes=[:] sessionAttributes=[:] flashAttributes=[:] postProcessors=[]>
|       <org.springframework.test.web.servlet.MockMvc$1@6a230707 val$mvcResult=org.springframework.test.web.servlet.DefaultMvcResult@5ed59e7f this$0=org.springframework.test.web.servlet.MockMvc@27477eb7>
<org.springframework.test.web.servlet.MockMvc@27477eb7 servlet=org.springframework.test.web.servlet.TestDispatcherServlet@512efef4 filters=[] servletContext=org.springframework.boot.test.mock.web.SpringBootMockServletContext@1cf516fa defaultRequestBuilder=org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder@5b96272e defaultResponseCharacterEncoding=null defaultResultMatchers=[] defaultResultHandlers=[]>

	at com.netflix.spinnaker.fiat.controllers.AuthorizeControllerSpec.should get user from repo via endpoint(AuthorizeControllerSpec.groovy:181)
Caused by: java.lang.AssertionError: Status expected:<200> but was:<404>
	at org.springframework.test.util.AssertionErrors.fail(AssertionErrors.java:59)
	at org.springframework.test.util.AssertionErrors.assertEquals(AssertionErrors.java:122)
	at org.springframework.test.web.servlet.result.StatusResultMatchers.lambda$matcher$9(StatusResultMatchers.java:637)
	at org.springframework.test.web.servlet.MockMvc$1.andExpect(MockMvc.java:214)
	at com.netflix.spinnaker.fiat.controllers.AuthorizeControllerSpec.should get user from repo via endpoint(AuthorizeControllerSpec.groovy:180)
```
In order to fix this issue, removed the trailing slash from the mock url `/authorize`.
  • Loading branch information
j-sandy committed Jan 3, 2025
1 parent d19553e commit 991c074
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class AuthorizeControllerSpec extends Specification {


then:
mockMvc.perform(get("/authorize/")).andExpect(status().is4xxClientError())
mockMvc.perform(get("/authorize")).andExpect(status().is4xxClientError())

when:
fiatServerConfigurationProperties.setGetAllEnabled(true)
Expand All @@ -176,7 +176,7 @@ class AuthorizeControllerSpec extends Specification {
roleAroleBUser.view])

then:
mockMvc.perform(get("/authorize/"))
mockMvc.perform(get("/authorize"))
.andExpect(status().isOk())
.andExpect(content().json(expected))
}
Expand Down

0 comments on commit 991c074

Please sign in to comment.