diff options
author | Fiete Ostkamp <Fiete.Ostkamp@telekom.de> | 2023-11-07 14:16:24 +0100 |
---|---|---|
committer | Fiete Ostkamp <Fiete.Ostkamp@telekom.de> | 2023-11-07 16:03:55 +0100 |
commit | 7b1baebc0dd9f75bcfe0e56796c5116a77c1e3aa (patch) | |
tree | ab77117cd44212446cce952fbcf0b3e5c1f5e6dc /aai-resources/src/test/java/org/onap | |
parent | c0b226153be760f3a93102e8a3886f52faed4b4b (diff) |
Model distribution from model-loader is failing with resources service version >= 1.12.1
- pin eclipse.persistence version to last-working 2.6.2
- add test case to validate correct behaviour
- make api-version related assertions in LegacyMoxyConsumerTest dynamic based on default api version
Issue-ID: AAI-3675
Change-Id: I655ed28b1d0a6f94c788d68ff2d05ba9f30c4793
Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de>
Diffstat (limited to 'aai-resources/src/test/java/org/onap')
-rw-r--r-- | aai-resources/src/test/java/org/onap/aai/rest/LegacyMoxyConsumerTest.java | 95 | ||||
-rw-r--r-- | aai-resources/src/test/java/org/onap/aai/rest/ModelDistributionTest.java | 73 |
2 files changed, 120 insertions, 48 deletions
diff --git a/aai-resources/src/test/java/org/onap/aai/rest/LegacyMoxyConsumerTest.java b/aai-resources/src/test/java/org/onap/aai/rest/LegacyMoxyConsumerTest.java index 7c0161f..2855b57 100644 --- a/aai-resources/src/test/java/org/onap/aai/rest/LegacyMoxyConsumerTest.java +++ b/aai-resources/src/test/java/org/onap/aai/rest/LegacyMoxyConsumerTest.java @@ -65,8 +65,8 @@ import org.springframework.mock.web.MockHttpServletRequest; public class LegacyMoxyConsumerTest extends AAISetup { protected static final MediaType APPLICATION_JSON = MediaType.valueOf("application/json"); - private static final Set<Integer> VALID_HTTP_STATUS_CODES = new HashSet<>(); + private static final Logger logger = LoggerFactory.getLogger(LegacyMoxyConsumerTest.class.getName()); static { VALID_HTTP_STATUS_CODES.add(200); @@ -87,8 +87,8 @@ public class LegacyMoxyConsumerTest extends AAISetup { private List<MediaType> outputMediaTypes; private boolean initialized = false; + private String defaultSchemaVersion; - private static final Logger logger = LoggerFactory.getLogger(LegacyMoxyConsumerTest.class.getName()); @BeforeClass public static void setupRest() { @@ -121,6 +121,7 @@ public class LegacyMoxyConsumerTest extends AAISetup { aaiRequestContextList = new ArrayList<>(); aaiRequestContextList.add(""); + defaultSchemaVersion = schemaVersions.getDefaultVersion().toString(); when(httpHeaders.getAcceptableMediaTypes()).thenReturn(outputMediaTypes); when(httpHeaders.getRequestHeaders()).thenReturn(headersMultiMap); @@ -154,13 +155,13 @@ public class LegacyMoxyConsumerTest extends AAISetup { when(uriInfo.getPath(false)).thenReturn(uri); MockHttpServletRequest mockReqGet = new MockHttpServletRequest("GET", uri); - Response response = legacyMoxyConsumer.getLegacy("", null, null, schemaVersions.getDefaultVersion().toString(), + Response response = legacyMoxyConsumer.getLegacy("", null, null, defaultSchemaVersion, uri, "all", "false", httpHeaders, uriInfo, mockReqGet); assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus()); MockHttpServletRequest mockReq = new MockHttpServletRequest("PUT", uri); - response = legacyMoxyConsumer.update(payload, schemaVersions.getDefaultVersion().toString(), uri, httpHeaders, + response = legacyMoxyConsumer.update(payload, defaultSchemaVersion, uri, httpHeaders, uriInfo, mockReq); int code = response.getStatus(); @@ -172,7 +173,7 @@ public class LegacyMoxyConsumerTest extends AAISetup { queryParameters.add("depth", "10000"); - response = legacyMoxyConsumer.getLegacy("", null, null, schemaVersions.getDefaultVersion().toString(), uri, + response = legacyMoxyConsumer.getLegacy("", null, null, defaultSchemaVersion, uri, "10000", "false", httpHeaders, uriInfo, mockReqGet); code = response.getStatus(); @@ -192,7 +193,7 @@ public class LegacyMoxyConsumerTest extends AAISetup { queryParameters.add("resource-version", resourceVersion); mockReq = new MockHttpServletRequest("DELETE", uri); - response = legacyMoxyConsumer.delete(schemaVersions.getDefaultVersion().toString(), uri, httpHeaders, uriInfo, + response = legacyMoxyConsumer.delete(defaultSchemaVersion, uri, httpHeaders, uriInfo, "", mockReq); code = response.getStatus(); @@ -202,7 +203,7 @@ public class LegacyMoxyConsumerTest extends AAISetup { assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus()); - response = legacyMoxyConsumer.getLegacy("", null, null, schemaVersions.getDefaultVersion().toString(), uri, + response = legacyMoxyConsumer.getLegacy("", null, null, defaultSchemaVersion, uri, "all", "false", httpHeaders, uriInfo, mockReqGet); assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus()); @@ -221,7 +222,7 @@ public class LegacyMoxyConsumerTest extends AAISetup { when(uriInfo.getPath(false)).thenReturn(uri); MockHttpServletRequest mockReqGet = new MockHttpServletRequest("GET", uri); - Response response = legacyMoxyConsumer.getLegacy("", "1", "10", schemaVersions.getDefaultVersion().toString(), + Response response = legacyMoxyConsumer.getLegacy("", "1", "10", defaultSchemaVersion, uri, "all", "false", httpHeaders, uriInfo, mockReqGet); assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); } @@ -246,7 +247,7 @@ public class LegacyMoxyConsumerTest extends AAISetup { String.format("cloud-infrastructure/pservers/pserver/%s/relationship-list/relationship", hostname); MockHttpServletRequest mockReq = new MockHttpServletRequest("PUT", cloudToPserverRelationshipUri); Response response = legacyMoxyConsumer.updateRelationship(cloudToPserverRelationshipData, - schemaVersions.getDefaultVersion().toString(), cloudToPserverRelationshipUri, httpHeaders, uriInfo, + defaultSchemaVersion, cloudToPserverRelationshipUri, httpHeaders, uriInfo, mockReq); assertNotNull("Response from the legacy moxy consumer returned null", response); @@ -262,7 +263,7 @@ public class LegacyMoxyConsumerTest extends AAISetup { // TODO - Need to actually verify the relationship between pserver and cloud-region mockReq = new MockHttpServletRequest("DELETE", cloudToPserverRelationshipUri); response = legacyMoxyConsumer.deleteRelationship(cloudToPserverRelationshipData, - schemaVersions.getDefaultVersion().toString(), cloudToPserverRelationshipUri, httpHeaders, uriInfo, + defaultSchemaVersion, cloudToPserverRelationshipUri, httpHeaders, uriInfo, mockReq); code = response.getStatus(); @@ -295,7 +296,7 @@ public class LegacyMoxyConsumerTest extends AAISetup { when(uriInfo.getPath()).thenReturn(uri); when(uriInfo.getPath(false)).thenReturn(uri); MockHttpServletRequest mockReq = new MockHttpServletRequest("PUT", uri); - Response response = legacyMoxyConsumer.update(payload, schemaVersions.getDefaultVersion().toString(), uri, + Response response = legacyMoxyConsumer.update(payload, defaultSchemaVersion, uri, httpHeaders, uriInfo, mockReq); int code = response.getStatus(); @@ -312,7 +313,7 @@ public class LegacyMoxyConsumerTest extends AAISetup { when(uriInfo.getPath()).thenReturn(uri); when(uriInfo.getPath(false)).thenThrow(new IllegalArgumentException()); MockHttpServletRequest mockReq = new MockHttpServletRequest("PUT", uri); - Response response = legacyMoxyConsumer.update(payload, schemaVersions.getDefaultVersion().toString(), uri, + Response response = legacyMoxyConsumer.update(payload, defaultSchemaVersion, uri, httpHeaders, uriInfo, mockReq); int code = response.getStatus(); @@ -320,7 +321,7 @@ public class LegacyMoxyConsumerTest extends AAISetup { assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), code); logger.info("Response Code: " + code + "\tEntity: " + response.getEntity()); - response = legacyMoxyConsumer.updateRelationship(payload, schemaVersions.getDefaultVersion().toString(), uri, + response = legacyMoxyConsumer.updateRelationship(payload, defaultSchemaVersion, uri, httpHeaders, uriInfo, mockReq); code = response.getStatus(); @@ -328,19 +329,19 @@ public class LegacyMoxyConsumerTest extends AAISetup { assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), code); logger.info("Response Code: " + code + "\tEntity: " + response.getEntity()); mockReq = new MockHttpServletRequest("GET", uri); - response = legacyMoxyConsumer.getLegacy("", null, null, schemaVersions.getDefaultVersion().toString(), uri, + response = legacyMoxyConsumer.getLegacy("", null, null, defaultSchemaVersion, uri, "all", "false", httpHeaders, uriInfo, mockReq); assertNotNull("Response from the legacy moxy consumer returned null", response); assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), code); mockReq = new MockHttpServletRequest("DELETE", uri); - response = legacyMoxyConsumer.delete(schemaVersions.getDefaultVersion().toString(), uri, httpHeaders, uriInfo, + response = legacyMoxyConsumer.delete(defaultSchemaVersion, uri, httpHeaders, uriInfo, "", mockReq); code = response.getStatus(); assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), code); - response = legacyMoxyConsumer.deleteRelationship(payload, schemaVersions.getDefaultVersion().toString(), uri, + response = legacyMoxyConsumer.deleteRelationship(payload, defaultSchemaVersion, uri, httpHeaders, uriInfo, mockReq); code = response.getStatus(); assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), code); @@ -355,14 +356,14 @@ public class LegacyMoxyConsumerTest extends AAISetup { when(uriInfo.getPath()).thenReturn(uri); when(uriInfo.getPath(false)).thenReturn(uri); MockHttpServletRequest mockReq = new MockHttpServletRequest("PUT", uri); - Response response = legacyMoxyConsumer.update(payload, schemaVersions.getDefaultVersion().toString(), uri, + Response response = legacyMoxyConsumer.update(payload, defaultSchemaVersion, uri, httpHeaders, uriInfo, mockReq); int code = response.getStatus(); logger.info("Response Code: " + code + "\tEntity: " + response.getEntity()); assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), code); - response = legacyMoxyConsumer.updateRelationship(payload, schemaVersions.getDefaultVersion().toString(), uri, + response = legacyMoxyConsumer.updateRelationship(payload, defaultSchemaVersion, uri, httpHeaders, uriInfo, mockReq); code = response.getStatus(); @@ -370,7 +371,7 @@ public class LegacyMoxyConsumerTest extends AAISetup { assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), code); mockReq = new MockHttpServletRequest("GET", uri); - response = legacyMoxyConsumer.getLegacy("", null, null, schemaVersions.getDefaultVersion().toString(), uri, + response = legacyMoxyConsumer.getLegacy("", null, null, defaultSchemaVersion, uri, "all", "false", httpHeaders, uriInfo, mockReq); assertNotNull("Response from the legacy moxy consumer returned null", response); @@ -378,14 +379,14 @@ public class LegacyMoxyConsumerTest extends AAISetup { mockReq = new MockHttpServletRequest("DELETE", uri); queryParameters.add("resource-version", "3434394839483"); - response = legacyMoxyConsumer.delete(schemaVersions.getDefaultVersion().toString(), uri, httpHeaders, uriInfo, + response = legacyMoxyConsumer.delete(defaultSchemaVersion, uri, httpHeaders, uriInfo, "", mockReq); code = response.getStatus(); logger.info("Response Code: " + code + "\tEntity: " + response.getEntity()); assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), code); - response = legacyMoxyConsumer.deleteRelationship(payload, schemaVersions.getDefaultVersion().toString(), uri, + response = legacyMoxyConsumer.deleteRelationship(payload, defaultSchemaVersion, uri, httpHeaders, uriInfo, mockReq); code = response.getStatus(); assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), code); @@ -406,12 +407,12 @@ public class LegacyMoxyConsumerTest extends AAISetup { when(uriInfo.getPath(false)).thenReturn(uri); MockHttpServletRequest mockReq = new MockHttpServletRequest("GET", uri); - Response response = legacyMoxyConsumer.getLegacy("", null, null, schemaVersions.getDefaultVersion().toString(), + Response response = legacyMoxyConsumer.getLegacy("", null, null, defaultSchemaVersion, uri, "all", "false", httpHeaders, uriInfo, mockReq); assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus()); mockReq = new MockHttpServletRequest("PUT", uri); - response = legacyMoxyConsumer.update(payload, schemaVersions.getDefaultVersion().toString(), uri, httpHeaders, + response = legacyMoxyConsumer.update(payload, defaultSchemaVersion, uri, httpHeaders, uriInfo, mockReq); int code = response.getStatus(); @@ -429,7 +430,7 @@ public class LegacyMoxyConsumerTest extends AAISetup { outputMediaTypes.add(MediaType.valueOf("application/merge-patch+json")); mockReq = new MockHttpServletRequest("PATCH", uri); - response = legacyMoxyConsumer.patch(patchData, schemaVersions.getDefaultVersion().toString(), uri, httpHeaders, + response = legacyMoxyConsumer.patch(patchData, defaultSchemaVersion, uri, httpHeaders, uriInfo, mockReq); code = response.getStatus(); @@ -445,16 +446,16 @@ public class LegacyMoxyConsumerTest extends AAISetup { when(uriInfo.getPath(false)).thenReturn(uri); HttpServletRequest mockRequest = Mockito.mock(HttpServletRequest.class); - when(mockRequest.getRequestURL()).thenReturn(new StringBuffer("https://localhost:8447/aai/v15/" + uri)); + when(mockRequest.getRequestURL()).thenReturn(new StringBuffer(String.format("https://localhost:8447/aai/%s/", defaultSchemaVersion) + uri)); - Response response = legacyMoxyConsumer.getLegacy("", null, null, schemaVersions.getDefaultVersion().toString(), + Response response = legacyMoxyConsumer.getLegacy("", null, null, defaultSchemaVersion, uri, "all", "false", httpHeaders, uriInfo, mockRequest); assertNotNull("Response from the legacy moxy consumer returned null", response); assertEquals("Expected to not have the data already in memory", Response.Status.NOT_FOUND.getStatusCode(), response.getStatus()); - response = legacyMoxyConsumer.update(payload, schemaVersions.getDefaultVersion().toString(), uri, httpHeaders, + response = legacyMoxyConsumer.update(payload, defaultSchemaVersion, uri, httpHeaders, uriInfo, mockRequest); assertNotNull("Response from the legacy moxy consumer returned null", response); @@ -466,7 +467,7 @@ public class LegacyMoxyConsumerTest extends AAISetup { response.getStatus()); queryParameters.add("depth", "10000"); - response = legacyMoxyConsumer.getLegacy("", null, null, schemaVersions.getDefaultVersion().toString(), uri, + response = legacyMoxyConsumer.getLegacy("", null, null, defaultSchemaVersion, uri, "all", "false", httpHeaders, uriInfo, mockRequest); assertNotNull("Response from the legacy moxy consumer returned null", response); @@ -492,7 +493,7 @@ public class LegacyMoxyConsumerTest extends AAISetup { MockHttpServletRequest mockReq = new MockHttpServletRequest("DELETE", uri); Response response = legacyMoxyConsumer.deleteRelationship(payload, - schemaVersions.getDefaultVersion().toString(), uri, httpHeaders, uriInfo, mockReq); + defaultSchemaVersion, uri, httpHeaders, uriInfo, mockReq); int code = response.getStatus(); logger.info("Response Code: " + code + "\tEntity: " + response.getEntity()); @@ -505,11 +506,13 @@ public class LegacyMoxyConsumerTest extends AAISetup { } public String getResourcePayload(String resourceName) throws IOException { - return getPayload("payloads/resource/" + resourceName + ".json"); + String rawPayload = getPayload("payloads/resource/" + resourceName + ".json"); + return String.format(rawPayload, defaultSchemaVersion); } public String getRelationshipPayload(String relationshipName) throws IOException { - return getPayload("payloads/relationship/" + relationshipName + ".json"); + String rawPayload = getPayload("payloads/relationship/" + relationshipName + ".json"); + return String.format(rawPayload, defaultSchemaVersion); } public String getUri(String hostname) { @@ -580,7 +583,7 @@ public class LegacyMoxyConsumerTest extends AAISetup { when(httpHeaders.getRequestHeaders()).thenReturn(headersMultiMap); MockHttpServletRequest mockReqGet = new MockHttpServletRequest("GET", uri); - Response response = legacyMoxyConsumer.getLegacy("", null, null, schemaVersions.getDefaultVersion().toString(), + Response response = legacyMoxyConsumer.getLegacy("", null, null, defaultSchemaVersion, uri, "all", "false", httpHeaders, uriInfo, mockReqGet); assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); @@ -600,7 +603,7 @@ public class LegacyMoxyConsumerTest extends AAISetup { when(httpHeaders.getRequestHeaders()).thenReturn(headersMultiMap); MockHttpServletRequest mockReqGet = new MockHttpServletRequest("GET", uri); - Response response = legacyMoxyConsumer.getLegacy("", null, null, schemaVersions.getDefaultVersion().toString(), + Response response = legacyMoxyConsumer.getLegacy("", null, null, defaultSchemaVersion, uri, "all", "false", httpHeaders, uriInfo, mockReqGet); assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus()); @@ -626,7 +629,7 @@ public class LegacyMoxyConsumerTest extends AAISetup { String.format("cloud-infrastructure/pservers/pserver/%s/relationship-list/relationship", hostname); MockHttpServletRequest mockReq = new MockHttpServletRequest("PUT", cloudToPserverRelationshipUri); Response response = legacyMoxyConsumer.updateRelationship(cloudToPserverRelationshipData, - schemaVersions.getDefaultVersion().toString(), cloudToPserverRelationshipUri, httpHeaders, uriInfo, + defaultSchemaVersion, cloudToPserverRelationshipUri, httpHeaders, uriInfo, mockReq); assertNotNull("Response from the legacy moxy consumer returned null", response); @@ -639,17 +642,13 @@ public class LegacyMoxyConsumerTest extends AAISetup { response.getStatus()); logger.info("Response Code: " + code + "\tEntity: " + response.getEntity()); - String getRelationshipMockRequestUri = - String.format("cloud-infrastructure/pservers/pserver/%s/relationship-list", hostname); String getRelationshipUri = String.format("cloud-infrastructure/pservers/pserver/%s", hostname); HttpServletRequest mockRequest = Mockito.mock(HttpServletRequest.class); when(mockRequest.getRequestURL()) - .thenReturn(new StringBuffer("https://localhost:8447/aai/v15/" + getRelationshipUri)); - response = legacyMoxyConsumer.getRelationshipList("1", "1", schemaVersions.getDefaultVersion().toString(), + .thenReturn(new StringBuffer(String.format("https://localhost:8447/aai/%s/", defaultSchemaVersion) + getRelationshipUri)); + response = legacyMoxyConsumer.getRelationshipList("1", "1", defaultSchemaVersion, getRelationshipUri, "false", httpHeaders, mockRequest, uriInfo); - String s = response.getEntity().toString(); - code = response.getStatus(); if (!VALID_HTTP_STATUS_CODES.contains(code)) { logger.info("Response Code: " + code + "\tEntity: " + response.getEntity()); @@ -679,7 +678,7 @@ public class LegacyMoxyConsumerTest extends AAISetup { String.format("cloud-infrastructure/pservers/pserver/%s/relationship-list/relationship", hostname); MockHttpServletRequest mockReq = new MockHttpServletRequest("PUT", cloudToPserverRelationshipUri); Response response = legacyMoxyConsumer.updateRelationship(cloudToPserverRelationshipData, - schemaVersions.getDefaultVersion().toString(), cloudToPserverRelationshipUri, httpHeaders, uriInfo, + defaultSchemaVersion, cloudToPserverRelationshipUri, httpHeaders, uriInfo, mockReq); assertNotNull("Response from the legacy moxy consumer returned null", response); @@ -698,8 +697,8 @@ public class LegacyMoxyConsumerTest extends AAISetup { queryParameters.add("format", "resource"); HttpServletRequest mockRequest = Mockito.mock(HttpServletRequest.class); when(mockRequest.getRequestURL()) - .thenReturn(new StringBuffer("https://localhost:8447/aai/v15/" + getRelationshipUri)); - response = legacyMoxyConsumer.getRelationshipList("1", "1", schemaVersions.getDefaultVersion().toString(), + .thenReturn(new StringBuffer(String.format("https://localhost:8447/aai/%s/", defaultSchemaVersion) + getRelationshipUri)); + response = legacyMoxyConsumer.getRelationshipList("1", "1", defaultSchemaVersion, getRelationshipUri, "false", httpHeaders, mockRequest, uriInfo); queryParameters.remove("format"); @@ -762,9 +761,9 @@ public class LegacyMoxyConsumerTest extends AAISetup { MockHttpServletRequest mockReq = new MockHttpServletRequest("GET_RELATIONSHIP", getRelationshipMockRequestUri); HttpServletRequest mockRequest = Mockito.mock(HttpServletRequest.class); when(mockRequest.getRequestURL()) - .thenReturn(new StringBuffer("https://localhost:8447/aai/v15/" + getRelationshipUri)); + .thenReturn(new StringBuffer(String.format("https://localhost:8447/aai/%s/", defaultSchemaVersion) + getRelationshipUri)); Response response = - legacyMoxyConsumer.getRelationshipList("1", "1", schemaVersions.getDefaultVersion().toString(), + legacyMoxyConsumer.getRelationshipList("1", "1", defaultSchemaVersion, getRelationshipUri, "false", httpHeaders, mockRequest, uriInfo); int code = response.getStatus(); @@ -1090,7 +1089,7 @@ public class LegacyMoxyConsumerTest extends AAISetup { queryParameters.add("resource-version", resourceVersion); MockHttpServletRequest mockReq = new MockHttpServletRequest("DELETE", deleteUri); - Response deleteResponse = legacyMoxyConsumer.delete(schemaVersions.getDefaultVersion().toString(), deleteUri, + Response deleteResponse = legacyMoxyConsumer.delete(defaultSchemaVersion, deleteUri, httpHeaders, uriInfo, resourceVersion, mockReq); return deleteResponse; } @@ -1119,7 +1118,7 @@ public class LegacyMoxyConsumerTest extends AAISetup { when(uriInfo.getPath(false)).thenReturn(uri); MockHttpServletRequest mockReq = new MockHttpServletRequest("PUT", uri); - Response response = legacyMoxyConsumer.update(payload, schemaVersions.getDefaultVersion().toString(), uri, + Response response = legacyMoxyConsumer.update(payload, defaultSchemaVersion, uri, httpHeaders, uriInfo, mockReq); assertNotNull("Response from the legacy moxy consumer returned null", response); @@ -1135,7 +1134,7 @@ public class LegacyMoxyConsumerTest extends AAISetup { private Response getMockResponse(String mockUri) throws IOException, JSONException { MockHttpServletRequest mockReq = new MockHttpServletRequest("GET", mockUri); - Response response = legacyMoxyConsumer.getLegacy("", null, null, schemaVersions.getDefaultVersion().toString(), + Response response = legacyMoxyConsumer.getLegacy("", null, null, defaultSchemaVersion, mockUri, "10000", "false", httpHeaders, uriInfo, mockReq); String responseEntity = response.getEntity().toString(); int code = response.getStatus(); diff --git a/aai-resources/src/test/java/org/onap/aai/rest/ModelDistributionTest.java b/aai-resources/src/test/java/org/onap/aai/rest/ModelDistributionTest.java new file mode 100644 index 0000000..249ef52 --- /dev/null +++ b/aai-resources/src/test/java/org/onap/aai/rest/ModelDistributionTest.java @@ -0,0 +1,73 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2023 Deutsche Telekom AG. 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.rest; + +import static org.junit.Assert.assertEquals; + +import java.net.URI; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Collections; + +import org.json.JSONObject; +import org.junit.Test; +import org.onap.aai.rest.AbstractSpringRestTest; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.util.DefaultUriBuilderFactory; + +import com.fasterxml.jackson.databind.ObjectMapper; + +/** + * Test designed to imitate model-loader behaviour when distributing models via xml to aai-resources. + * Similar to test in https://gerrit.onap.org/r/gitweb?p=aai/model-loader.git;a=blob;f=src/test/java/org/onap/aai/modelloader/restclient/TestAaiRestClient.java;h=ebdfcfe45285f14efc2f706caa49f0191b108619;hb=HEAD#l46 + */ +public class ModelDistributionTest extends AbstractSpringRestTest { + + @Test + public void thatModelsCanBeDistributed() throws Exception { + final String MODEL_FILE = "src/test/resources/payloads/models/network-service.xml"; + String uri = baseUrl + "/aai/v27/service-design-and-creation/models/model/d821d1aa-8a69-47a4-aa63-3dae1742c47c"; + + headers.setAccept(Collections.singletonList(MediaType.APPLICATION_XML)); + headers.setContentType(null); + ResponseEntity<String> response = restTemplate.exchange(uri, HttpMethod.GET, new HttpEntity<>(headers), String.class); + assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode()); + + String modelPayload = new String(Files.readAllBytes(Paths.get(MODEL_FILE))); + headers.setContentType(MediaType.APPLICATION_XML); + headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); + response = restTemplate.exchange(uri, HttpMethod.PUT, new HttpEntity<>(modelPayload, headers), String.class); + assertEquals(HttpStatus.CREATED, response.getStatusCode()); + + headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); + response = restTemplate.exchange(uri, HttpMethod.GET, new HttpEntity<>(headers), String.class); + assertEquals(HttpStatus.OK, response.getStatusCode()); + + ObjectMapper mapper = new ObjectMapper(); + String resourceVersion = mapper.readTree(response.getBody()).get("resource-version").asText(); + URI resourceVersionUri = new DefaultUriBuilderFactory(uri.toString()).builder().queryParam("resource-version", resourceVersion).build(); + response = restTemplate.exchange(resourceVersionUri, HttpMethod.DELETE, new HttpEntity<>(headers), String.class); + assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode()); + } +} |