diff options
author | Fiete Ostkamp <Fiete.Ostkamp@telekom.de> | 2024-10-28 09:19:36 +0100 |
---|---|---|
committer | Fiete Ostkamp <Fiete.Ostkamp@telekom.de> | 2024-10-28 15:09:09 +0100 |
commit | 09bb8a5c6512df6d98593b921dcabf05f1f1586b (patch) | |
tree | 2fad915192fb34ff556fb68392c085b89f9c6201 /aai-resources/src/main | |
parent | ecdcbe8aba5e468693a7f22970064c335881d3b9 (diff) |
Use WebTestClient in ResourceController tests
- this tests e2e behaviour of controller
- assert error responses
Issue-ID: AAI-4039
Change-Id: If7dc32dec13399ad3502101d2b76fd79940cd34d
Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de>
Diffstat (limited to 'aai-resources/src/main')
4 files changed, 74 insertions, 25 deletions
diff --git a/aai-resources/src/main/java/org/onap/aai/entities/PolicyException.java b/aai-resources/src/main/java/org/onap/aai/entities/PolicyException.java new file mode 100644 index 00000000..c8e6e2f9 --- /dev/null +++ b/aai-resources/src/main/java/org/onap/aai/entities/PolicyException.java @@ -0,0 +1,36 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2024 Deutsche Telekom. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.aai.entities; + +import java.util.List; + +import lombok.Builder; +import lombok.Data; +import lombok.extern.jackson.Jacksonized; + +@Data +@Builder +@Jacksonized +public class PolicyException { + private String messageId; + private String text; + private List<String> variables; +} diff --git a/aai-resources/src/main/java/org/onap/aai/entities/RequestError.java b/aai-resources/src/main/java/org/onap/aai/entities/RequestError.java index 3fb051b4..fb04e630 100644 --- a/aai-resources/src/main/java/org/onap/aai/entities/RequestError.java +++ b/aai-resources/src/main/java/org/onap/aai/entities/RequestError.java @@ -29,4 +29,5 @@ import lombok.extern.jackson.Jacksonized; @Jacksonized public class RequestError { private ServiceException serviceException; + private PolicyException policyException; } diff --git a/aai-resources/src/main/java/org/onap/aai/rest/ResourcesController.java b/aai-resources/src/main/java/org/onap/aai/rest/ResourcesController.java index ade12db0..12839d48 100644 --- a/aai-resources/src/main/java/org/onap/aai/rest/ResourcesController.java +++ b/aai-resources/src/main/java/org/onap/aai/rest/ResourcesController.java @@ -58,8 +58,12 @@ public class ResourcesController extends RESTAPI { @Path("/{uri: .+}") @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - public Response update(String content, @PathParam("version") String versionParam, - @PathParam("uri") @Encoded String uri, @Context HttpHeaders headers, @Context UriInfo info, + public Response update( + String content, + @PathParam("version") String versionParam, + @PathParam("uri") @Encoded String uri, + @Context HttpHeaders headers, + @Context UriInfo info, @Context HttpServletRequest req) { Set<String> roles = getRoles(req.getUserPrincipal(), req.getMethod()); MediaType mediaType = headers.getMediaType(); @@ -70,8 +74,12 @@ public class ResourcesController extends RESTAPI { @Path("/{uri: .+}/relationship-list/relationship") @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - public Response updateRelationship(String content, @PathParam("version") String versionParam, - @PathParam("uri") @Encoded String uri, @Context HttpHeaders headers, @Context UriInfo info, + public Response updateRelationship( + String content, + @PathParam("version") String versionParam, + @PathParam("uri") @Encoded String uri, + @Context HttpHeaders headers, + @Context UriInfo info, @Context HttpServletRequest req) { return resourcesService.updateRelationship(content, versionParam, uri, headers, info); @@ -81,8 +89,12 @@ public class ResourcesController extends RESTAPI { @Path("/{uri: .+}") @Consumes({"application/merge-patch+json"}) @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - public Response patch(String content, @PathParam("version") String versionParam, - @PathParam("uri") @Encoded String uri, @Context HttpHeaders headers, @Context UriInfo info, + public Response patch( + String content, + @PathParam("version") String versionParam, + @PathParam("uri") @Encoded String uri, + @Context HttpHeaders headers, + @Context UriInfo info, @Context HttpServletRequest req) { Set<String> roles = getRoles(req.getUserPrincipal(), req.getMethod()); MediaType mediaType = MediaType.APPLICATION_JSON_TYPE; @@ -140,8 +152,12 @@ public class ResourcesController extends RESTAPI { @DELETE @Path("/{uri: .+}") @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - public Response delete(@PathParam("version") String versionParam, @PathParam("uri") @Encoded String uri, - @Context HttpHeaders headers, @Context UriInfo info, @QueryParam("resource-version") String resourceVersion, + public Response delete( + @PathParam("version") String versionParam, + @PathParam("uri") @Encoded String uri, + @Context HttpHeaders headers, + @Context UriInfo info, + @QueryParam("resource-version") String resourceVersion, @Context HttpServletRequest req) { Set<String> roles = getRoles(req.getUserPrincipal(), req.getMethod()); return resourcesService.delete(versionParam, uri, headers, info, req, roles); @@ -149,21 +165,17 @@ public class ResourcesController extends RESTAPI { /** * This whole method does nothing because the body is being dropped while fielding the request. - * - * @param content the content - * @param versionParam the version param - * @param uri the uri - * @param headers the headers - * @param info the info - * @param req the req - * @return the response */ @DELETE @Path("/{uri: .+}/relationship-list/relationship") @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - public Response deleteRelationship(String content, @PathParam("version") String versionParam, - @PathParam("uri") @Encoded String uri, @Context HttpHeaders headers, @Context UriInfo info, + public Response deleteRelationship( + String content, + @PathParam("version") String versionParam, + @PathParam("uri") @Encoded String uri, + @Context HttpHeaders headers, + @Context UriInfo info, @Context HttpServletRequest req) { return resourcesService.deleteRelationship(content, versionParam, uri, headers, info); diff --git a/aai-resources/src/main/java/org/onap/aai/service/ResourcesService.java b/aai-resources/src/main/java/org/onap/aai/service/ResourcesService.java index da326a0d..d721ff27 100644 --- a/aai-resources/src/main/java/org/onap/aai/service/ResourcesService.java +++ b/aai-resources/src/main/java/org/onap/aai/service/ResourcesService.java @@ -81,7 +81,7 @@ public class ResourcesService { Loader loader; try { - validateRequest(info); + validateUriEncoding(info); SchemaVersion version = new SchemaVersion(versionParam); final HttpEntry traversalUriHttpEntry = SpringContextAware.getBean("traversalUriHttpEntry", HttpEntry.class); @@ -150,7 +150,7 @@ public class ResourcesService { boolean success = true; try { - validateRequest(info); + validateUriEncoding(info); SchemaVersion version = new SchemaVersion(versionParam); HttpEntry traversalUriHttpEntry = SpringContextAware.getBean("traversalUriHttpEntry", HttpEntry.class); @@ -208,7 +208,7 @@ public class ResourcesService { boolean success = true; try { - validateRequest(info); + validateUriEncoding(info); version = new SchemaVersion(versionParam); @@ -281,7 +281,7 @@ public class ResourcesService { boolean success = true; try { - this.validateRequest(info); + this.validateUriEncoding(info); SchemaVersion version = new SchemaVersion(versionParam); HttpEntry traversalUriHttpEntry = SpringContextAware.getBean("traversalUriHttpEntry", HttpEntry.class); @@ -337,7 +337,7 @@ public class ResourcesService { Loader loader = null; try { - validateRequest(info); + validateUriEncoding(info); SchemaVersion version = new SchemaVersion(versionParam); final HttpEntry traversalUriHttpEntry = SpringContextAware.getBean("traversalUriHttpEntry", HttpEntry.class); @@ -408,7 +408,7 @@ public class ResourcesService { try { - validateRequest(info); + validateUriEncoding(info); SchemaVersion version = new SchemaVersion(versionParam); HttpEntry traversalUriHttpEntry = SpringContextAware.getBean("traversalUriHttpEntry", HttpEntry.class); @@ -496,7 +496,7 @@ public class ResourcesService { return uri.toString().contains("/" + RestTokens.COUSIN + "/"); } - private void validateRequest(UriInfo info) throws AAIException, UnsupportedEncodingException { + private void validateUriEncoding(UriInfo info) throws AAIException, UnsupportedEncodingException { if (!ValidateEncoding.getInstance().validate(info)) { throw new AAIException("AAI_3008", "uri=" + getPath(info)); |