diff options
Diffstat (limited to 'aai-resources')
8 files changed, 191 insertions, 53 deletions
diff --git a/aai-resources/pom.xml b/aai-resources/pom.xml index 4336d67..2bfd698 100644 --- a/aai-resources/pom.xml +++ b/aai-resources/pom.xml @@ -93,6 +93,7 @@ <micrometer-jersey2>1.6.6</micrometer-jersey2> <testcontainers.version>1.6.1</testcontainers.version> <mockito.core.version>3.4.0</mockito.core.version> + <eclipse.persistence.version>2.6.2</eclipse.persistence.version> <!-- Setting some default value to not complain by editor but it will be overridden by gmaven plugin --> <!-- Integration tests will be skipped by default. Could be enabled here or by -DskipITs=false--> 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()); + } +} diff --git a/aai-resources/src/test/resources/application-test.properties b/aai-resources/src/test/resources/application-test.properties index 21e4ca7..e0ec501 100644 --- a/aai-resources/src/test/resources/application-test.properties +++ b/aai-resources/src/test/resources/application-test.properties @@ -56,7 +56,7 @@ schema.ingest.file=${server.local.startpath}/application.properties # Schema Version Related Attributes schema.uri.base.path=/aai # Lists all of the versions in the schema -schema.version.list=v10,v11,v12,v13,v14,v15 +schema.version.list=v10,v11,v12,v13,v14,v15,v16,v17,v18,v19,v20,v21,v22,v23,v24,v25,v26,v27 # Specifies from which version should the depth parameter to default to zero schema.version.depth.start=v10 # Specifies from which version should the related link be displayed in response payload @@ -69,7 +69,7 @@ schema.version.namespace.change.start=v12 # Specifies from which version should the client start seeing the edge label in payload schema.version.edge.label.start=v12 # Specifies the version that the application should default to -schema.version.api.default=v15 +schema.version.api.default=v27 schema.translator.list=config #To expose the Prometheus scraping endpoint in unit test diff --git a/aai-resources/src/test/resources/payloads/models/network-service.xml b/aai-resources/src/test/resources/payloads/models/network-service.xml new file mode 100644 index 0000000..4411513 --- /dev/null +++ b/aai-resources/src/test/resources/payloads/models/network-service.xml @@ -0,0 +1,26 @@ +<model xmlns="http://org.onap.aai.inventory/v27"> + <model-invariant-id>d821d1aa-8a69-47a4-aa63-3dae1742c47c</model-invariant-id> + <model-type>service</model-type> + <model-role>Network Service</model-role> + <model-vers> + <model-ver> + <model-version-id>8b713350-90fc-44b1-8c6e-a2b3973aa9d3</model-version-id> + <model-name>test-svc-distribution</model-name> + <model-version>1.0</model-version> + <model-description>test-svc-distribution</model-description> + <model-elements> + <model-element> + <new-data-del-flag>T</new-data-del-flag> + <cardinality>unbounded</cardinality> + <model-elements> + <model-element> + <new-data-del-flag>T</new-data-del-flag> + <cardinality>unbounded</cardinality> + <model-elements/> + </model-element> + </model-elements> + </model-element> + </model-elements> + </model-ver> + </model-vers> +</model>
\ No newline at end of file diff --git a/aai-resources/src/test/resources/payloads/relationship/pserver-complex-relationship-list2.json b/aai-resources/src/test/resources/payloads/relationship/pserver-complex-relationship-list2.json index 09dfb95..e9232b7 100644 --- a/aai-resources/src/test/resources/payloads/relationship/pserver-complex-relationship-list2.json +++ b/aai-resources/src/test/resources/payloads/relationship/pserver-complex-relationship-list2.json @@ -1 +1,15 @@ -{"relationship":[{"related-to":"complex","relationship-label":"org.onap.relationships.inventory.LocatedIn","related-link":"/aai/v15/cloud-infrastructure/complexes/complex/e13d4587-19ad-4bf5-80f5-c021efb5b61d","relationship-data":[{"relationship-key":"complex.physical-location-id","relationship-value":"e13d4587-19ad-4bf5-80f5-c021efb5b61d"}]}]}
\ No newline at end of file +{ + "relationship": [ + { + "related-to": "complex", + "relationship-label": "org.onap.relationships.inventory.LocatedIn", + "related-link": "/aai/%s/cloud-infrastructure/complexes/complex/e13d4587-19ad-4bf5-80f5-c021efb5b61d", + "relationship-data": [ + { + "relationship-key": "complex.physical-location-id", + "relationship-value": "e13d4587-19ad-4bf5-80f5-c021efb5b61d" + } + ] + } + ] +}
\ No newline at end of file diff --git a/aai-resources/src/test/resources/payloads/relationship/pserver-complex-relationship-list3.json b/aai-resources/src/test/resources/payloads/relationship/pserver-complex-relationship-list3.json index 3e62e42..a28d627 100644 --- a/aai-resources/src/test/resources/payloads/relationship/pserver-complex-relationship-list3.json +++ b/aai-resources/src/test/resources/payloads/relationship/pserver-complex-relationship-list3.json @@ -1 +1,26 @@ -{"results":[{"pserver":{"hostname":"590a8943-1200-43b3-825b-75dde6b8f44c","in-maint":false,"resource-version":"1544562911222","relationship-list":{"relationship":[{"related-to":"complex","relationship-label":"org.onap.relationships.inventory.LocatedIn","related-link":"/aai/v15/cloud-infrastructure/complexes/complex/e13d4587-19ad-4bf5-80f5-c021efb5b61e","relationship-data":[{"relationship-key":"complex.physical-location-id","relationship-value":"e13d4587-19ad-4bf5-80f5-c021efb5b61e"}]}]}}}]}
\ No newline at end of file +{ + "results": [ + { + "pserver": { + "hostname": "590a8943-1200-43b3-825b-75dde6b8f44c", + "in-maint": false, + "resource-version": "1544562911222", + "relationship-list": { + "relationship": [ + { + "related-to": "complex", + "relationship-label": "org.onap.relationships.inventory.LocatedIn", + "related-link": "/aai/%s/cloud-infrastructure/complexes/complex/e13d4587-19ad-4bf5-80f5-c021efb5b61e", + "relationship-data": [ + { + "relationship-key": "complex.physical-location-id", + "relationship-value": "e13d4587-19ad-4bf5-80f5-c021efb5b61e" + } + ] + } + ] + } + } + } + ] +}
\ No newline at end of file diff --git a/aai-resources/src/test/resources/payloads/resource/vserver2.json b/aai-resources/src/test/resources/payloads/resource/vserver2.json index 834c64f..7af1b31 100644 --- a/aai-resources/src/test/resources/payloads/resource/vserver2.json +++ b/aai-resources/src/test/resources/payloads/resource/vserver2.json @@ -12,7 +12,7 @@ "is-closed-loop-disabled": false, "relationship-list": {"relationship": [ { "related-to": "pserver", - "related-link": "/aai/v15/cloud-infrastructure/pservers/pserver/pserver-hostname-test02" + "related-link": "/aai/%s/cloud-infrastructure/pservers/pserver/pserver-hostname-test02" }]} }]} }]} |