Skip to content

Commit 045554a

Browse files
committed
Use plurals for the attachments endpoint that related to a feature and add testcases
1 parent 2e638ac commit 045554a

File tree

3 files changed

+71
-9
lines changed

3 files changed

+71
-9
lines changed

src/main/java/org/tailormap/api/controller/AttachmentsController.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public AttachmentsController(EditUtil editUtil, FeatureSourceFactoryHelper featu
7676
*/
7777
@PutMapping(
7878
path = {
79-
"${tailormap-api.base-path}/{viewerKind}/{viewerName}/layer/{appLayerId}/feature/{featureId}/attachment"
79+
"${tailormap-api.base-path}/{viewerKind}/{viewerName}/layer/{appLayerId}/feature/{featureId}/attachments"
8080
},
8181
consumes = MediaType.MULTIPART_FORM_DATA_VALUE,
8282
produces = MediaType.APPLICATION_JSON_VALUE)
@@ -99,7 +99,7 @@ public ResponseEntity<Serializable> addAttachment(
9999
Set<@Valid AttachmentAttributeType> attachmentAttrSet =
100100
tmFeatureType.getSettings().getAttachmentAttributes();
101101
if (attachmentAttrSet == null || attachmentAttrSet.isEmpty()) {
102-
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Feature type does not support attachments");
102+
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Layer does not support attachments");
103103
}
104104

105105
AttachmentAttributeType attachmentAttributeType = attachmentAttrSet.stream()
@@ -111,7 +111,7 @@ public ResponseEntity<Serializable> addAttachment(
111111
.findFirst()
112112
.orElseThrow(() -> new ResponseStatusException(
113113
HttpStatus.BAD_REQUEST,
114-
"Feature type does not support attachments for attribute "
114+
"Layer does not support attachments for attribute "
115115
+ attachment.getAttributeName()
116116
+ " with mime type "
117117
+ attachment.getMimeType()
@@ -141,7 +141,7 @@ public ResponseEntity<Serializable> addAttachment(
141141
*/
142142
@GetMapping(
143143
path = {
144-
"${tailormap-api.base-path}/{viewerKind}/{viewerName}/layer/{appLayerId}/feature/{featureId}/attachment"
144+
"${tailormap-api.base-path}/{viewerKind}/{viewerName}/layer/{appLayerId}/feature/{featureId}/attachments"
145145
},
146146
produces = MediaType.APPLICATION_JSON_VALUE)
147147
@Transactional
@@ -256,7 +256,7 @@ private void checkFeatureTypeSupportsAttachments(TMFeatureType tmFeatureType) th
256256
Set<@Valid AttachmentAttributeType> attachmentAttrSet =
257257
tmFeatureType.getSettings().getAttachmentAttributes();
258258
if (attachmentAttrSet == null || attachmentAttrSet.isEmpty()) {
259-
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Feature type does not support attachments");
259+
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Layer does not support attachments");
260260
}
261261
}
262262
}

src/main/resources/openapi/viewer-api.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1718,7 +1718,7 @@ paths:
17181718
schema:
17191719
$ref: './status-responses.yaml#/components/schemas/ErrorResponse'
17201720

1721-
/{viewerKind}/{viewerName}/layer/{appLayerId}/feature/{featureId}/attachment:
1721+
/{viewerKind}/{viewerName}/layer/{appLayerId}/feature/{featureId}/attachments:
17221722
summary: 'Attachment operations on a single feature.'
17231723
description: 'Attachment operations on a single feature referenced by the featureId.'
17241724
parameters:

src/test/java/org/tailormap/api/controller/AttachmentsControllerIntegrationTest.java

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
99
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
10+
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
1011
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
1112
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;
1213
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
@@ -20,6 +21,7 @@
2021
import org.junit.jupiter.api.BeforeAll;
2122
import org.junit.jupiter.api.MethodOrderer;
2223
import org.junit.jupiter.api.Order;
24+
import org.junit.jupiter.api.Test;
2325
import org.junit.jupiter.api.TestInstance;
2426
import org.junit.jupiter.api.TestMethodOrder;
2527
import org.junit.jupiter.params.ParameterizedTest;
@@ -71,13 +73,19 @@ class AttachmentsControllerIntegrationTest {
7173
private static Stream<Arguments> testUrls() {
7274
return Stream.of(
7375
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"),
7577
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"),
7779
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"));
7981
}
8082

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+
8189
@BeforeAll
8290
void initialize() {
8391
mockMvc = MockMvcBuilders.webAppContextSetup(context).build();
@@ -138,6 +146,60 @@ void addAttachmentUnauthorised(String url) throws Exception {
138146
.andExpect(status().isUnauthorized());
139147
}
140148

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+
141203
@Order(2)
142204
@ParameterizedTest
143205
@MethodSource("testUrls")

0 commit comments

Comments
 (0)