|
7 | 7 |
|
8 | 8 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; |
9 | 9 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; |
| 10 | +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; |
10 | 11 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; |
11 | 12 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; |
12 | 13 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; |
|
20 | 21 | import org.junit.jupiter.api.BeforeAll; |
21 | 22 | import org.junit.jupiter.api.MethodOrderer; |
22 | 23 | import org.junit.jupiter.api.Order; |
| 24 | +import org.junit.jupiter.api.Test; |
23 | 25 | import org.junit.jupiter.api.TestInstance; |
24 | 26 | import org.junit.jupiter.api.TestMethodOrder; |
25 | 27 | import org.junit.jupiter.params.ParameterizedTest; |
@@ -71,13 +73,19 @@ class AttachmentsControllerIntegrationTest { |
71 | 73 | private static Stream<Arguments> testUrls() { |
72 | 74 | return Stream.of( |
73 | 75 | Arguments.of( |
74 | | - "/app/default/layer/lyr:snapshot-geoserver:postgis:begroeidterreindeel/feature/21f95499702e3a5d05230d2ae596ea1c/attachment"), |
| 76 | + "/app/default/layer/lyr:snapshot-geoserver:postgis:begroeidterreindeel/feature/21f95499702e3a5d05230d2ae596ea1c/attachments"), |
75 | 77 | Arguments.of( |
76 | | - "/app/default/layer/lyr:snapshot-geoserver:oracle:WATERDEEL/feature/93294fda97a19c37080849c5c1fddbf3/attachment"), |
| 78 | + "/app/default/layer/lyr:snapshot-geoserver:oracle:WATERDEEL/feature/93294fda97a19c37080849c5c1fddbf3/attachments"), |
77 | 79 | Arguments.of( |
78 | | - "/app/default/layer/lyr:snapshot-geoserver:sqlserver:wegdeel/feature/2d323d3d98a2101c01ef1c6274085254/attachment")); |
| 80 | + "/app/default/layer/lyr:snapshot-geoserver:sqlserver:wegdeel/feature/2d323d3d98a2101c01ef1c6274085254/attachments")); |
79 | 81 | } |
80 | 82 |
|
| 83 | + private static final String layerNotEditableUrl = |
| 84 | + "/app/default/layer/lyr:snapshot-geoserver:postgis:bak/feature/dbbe3dd9c3e45f1261faf5f74c67e19e/attachments"; |
| 85 | + |
| 86 | + private static final String attachmentsNotSupportedUrl = |
| 87 | + "/app/default/layer/lyr:snapshot-geoserver:postgis:osm_polygon/feature/299933373/attachments"; |
| 88 | + |
81 | 89 | @BeforeAll |
82 | 90 | void initialize() { |
83 | 91 | mockMvc = MockMvcBuilders.webAppContextSetup(context).build(); |
@@ -138,6 +146,60 @@ void addAttachmentUnauthorised(String url) throws Exception { |
138 | 146 | .andExpect(status().isUnauthorized()); |
139 | 147 | } |
140 | 148 |
|
| 149 | + @Order(1) |
| 150 | + @Test |
| 151 | + @WithMockUser( |
| 152 | + username = "tm-admin", |
| 153 | + authorities = {ADMIN}) |
| 154 | + void addAttachmentsNotSupported() throws Exception { |
| 155 | + String url = apiBasePath + attachmentsNotSupportedUrl; |
| 156 | + |
| 157 | + byte[] svgBytes = new ClassPathResource("test/lichtpunt.svg").getContentAsByteArray(); |
| 158 | + |
| 159 | + MockMultipartFile svgFile = new MockMultipartFile("attachment", "lichtpunt.svg", "image/svg+xml", svgBytes); |
| 160 | + |
| 161 | + mockMvc.perform(MockMvcRequestBuilders.multipart(url) |
| 162 | + .file(attachmentMetadata) |
| 163 | + .file(svgFile) |
| 164 | + .with(request -> { |
| 165 | + request.setMethod("PUT"); |
| 166 | + return request; |
| 167 | + }) |
| 168 | + .with(setServletPath(url)) |
| 169 | + .accept(MediaType.APPLICATION_JSON)) |
| 170 | + .andExpect(status().isBadRequest()) |
| 171 | + .andDo(print()) |
| 172 | + .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) |
| 173 | + .andExpect(jsonPath("$.message").value("Layer does not support attachments")); |
| 174 | + } |
| 175 | + |
| 176 | + @Order(1) |
| 177 | + @Test |
| 178 | + @WithMockUser( |
| 179 | + username = "tm-admin", |
| 180 | + authorities = {ADMIN}) |
| 181 | + void addAttachmentsToNonEditableLayer() throws Exception { |
| 182 | + String url = apiBasePath + layerNotEditableUrl; |
| 183 | + |
| 184 | + byte[] svgBytes = new ClassPathResource("test/lichtpunt.svg").getContentAsByteArray(); |
| 185 | + |
| 186 | + MockMultipartFile svgFile = new MockMultipartFile("attachment", "lichtpunt.svg", "image/svg+xml", svgBytes); |
| 187 | + |
| 188 | + mockMvc.perform(MockMvcRequestBuilders.multipart(url) |
| 189 | + .file(attachmentMetadata) |
| 190 | + .file(svgFile) |
| 191 | + .with(request -> { |
| 192 | + request.setMethod("PUT"); |
| 193 | + return request; |
| 194 | + }) |
| 195 | + .with(setServletPath(url)) |
| 196 | + .accept(MediaType.APPLICATION_JSON)) |
| 197 | + .andExpect(status().isBadRequest()) |
| 198 | + .andDo(print()) |
| 199 | + .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) |
| 200 | + .andExpect(jsonPath("$.message").value("Layer is not editable")); |
| 201 | + } |
| 202 | + |
141 | 203 | @Order(2) |
142 | 204 | @ParameterizedTest |
143 | 205 | @MethodSource("testUrls") |
|
0 commit comments