summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--aai-resources/pom.xml7
-rw-r--r--aai-resources/src/test/java/org/onap/aai/entities/Model.java62
-rw-r--r--aai-resources/src/test/java/org/onap/aai/entities/ModelElement.java48
-rw-r--r--aai-resources/src/test/java/org/onap/aai/entities/ModelVersion.java72
-rw-r--r--aai-resources/src/test/java/org/onap/aai/rest/ModelDistributionTest.java165
-rw-r--r--aai-resources/src/test/resources/payloads/models/model-version.xml12
-rw-r--r--aai-resources/src/test/resources/payloads/models/network-service.xml15
7 files changed, 336 insertions, 45 deletions
diff --git a/aai-resources/pom.xml b/aai-resources/pom.xml
index 51f9651..51c9621 100644
--- a/aai-resources/pom.xml
+++ b/aai-resources/pom.xml
@@ -589,6 +589,13 @@
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <version>3.21.0</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
<groupId>org.skyscreamer</groupId>
<artifactId>jsonassert</artifactId>
<scope>test</scope>
diff --git a/aai-resources/src/test/java/org/onap/aai/entities/Model.java b/aai-resources/src/test/java/org/onap/aai/entities/Model.java
new file mode 100644
index 0000000..d33d2d0
--- /dev/null
+++ b/aai-resources/src/test/java/org/onap/aai/entities/Model.java
@@ -0,0 +1,62 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2024 Deutsche Telekom AG Intellectual Property. 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 com.fasterxml.jackson.annotation.JsonProperty;
+import java.util.List;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * Describes the model returned by aai-resources
+ */
+@Data
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
+public class Model {
+
+ @JsonProperty("model-invariant-id")
+ private String modelInvariantId;
+
+ @JsonProperty("model-role")
+ private String modelRole;
+
+ @JsonProperty("model-type")
+ private String modelType;
+
+ @JsonProperty("data-owner")
+ private String dataOwner;
+
+ @JsonProperty("data-source")
+ private String dataSource;
+
+ @JsonProperty("data-source-version")
+ private String dataSourceVersion;
+
+ @JsonProperty("resource-version")
+ private String resourceVersion;
+
+ @JsonProperty("model-vers")
+ List<ModelVersion> modelVersions;
+}
diff --git a/aai-resources/src/test/java/org/onap/aai/entities/ModelElement.java b/aai-resources/src/test/java/org/onap/aai/entities/ModelElement.java
new file mode 100644
index 0000000..ae85780
--- /dev/null
+++ b/aai-resources/src/test/java/org/onap/aai/entities/ModelElement.java
@@ -0,0 +1,48 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2024 Deutsche Telekom AG Intellectual Property. 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 com.fasterxml.jackson.annotation.JsonProperty;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
+public class ModelElement {
+
+ @JsonProperty("model-element-uuid")
+ private String modelElementUuid;
+
+ @JsonProperty("new-data-del-flag")
+ private String newDataDelFlag;
+
+ @JsonProperty("cardinality")
+ private String cardinality;
+
+ @JsonProperty("model-description")
+ private String modelDescription;
+}
diff --git a/aai-resources/src/test/java/org/onap/aai/entities/ModelVersion.java b/aai-resources/src/test/java/org/onap/aai/entities/ModelVersion.java
new file mode 100644
index 0000000..2e0a68c
--- /dev/null
+++ b/aai-resources/src/test/java/org/onap/aai/entities/ModelVersion.java
@@ -0,0 +1,72 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2024 Deutsche Telekom AG Intellectual Property. 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 com.fasterxml.jackson.annotation.JsonProperty;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
+public class ModelVersion {
+
+ @JsonProperty("model-version-id")
+ private String modelVersionId;
+
+ @JsonProperty("model-name")
+ private String modelName;
+
+ @JsonProperty("model-version")
+ private String modelVersion;
+
+ @JsonProperty("distribution-status")
+ private String distributionStatus;
+
+ @JsonProperty("model-description")
+ private String modelDescription;
+
+ @JsonProperty("sdnc-model-name")
+ private String sdncModelName;
+
+ @JsonProperty("sdnc-model-version")
+ private String sdncModelVersion;
+
+ @JsonProperty("data-owner")
+ private String dataOwner;
+
+ @JsonProperty("data-source")
+ private String dataSource;
+
+ @JsonProperty("data-source-version")
+ private String dataSourceVersion;
+
+ @JsonProperty("resource-version")
+ private String resourceVersion;
+
+ @JsonProperty("model-elements")
+ List<ModelElement> modelElements;
+}
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
index 6679c0b..9ea7f7e 100644
--- a/aai-resources/src/test/java/org/onap/aai/rest/ModelDistributionTest.java
+++ b/aai-resources/src/test/java/org/onap/aai/rest/ModelDistributionTest.java
@@ -19,53 +19,156 @@
*/
package org.onap.aai.rest;
-import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
-import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Paths;
-import java.util.Collections;
+import org.assertj.core.api.Assertions;
+import org.junit.jupiter.api.MethodOrderer;
+import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
-import org.springframework.http.HttpEntity;
-import org.springframework.http.HttpMethod;
-import org.springframework.http.HttpStatus;
+import org.junit.jupiter.api.TestMethodOrder;
+import org.onap.aai.config.WebClientConfiguration;
+import org.onap.aai.entities.Model;
+import org.onap.aai.entities.ModelVersion;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
+import org.springframework.context.annotation.Import;
+
import org.springframework.http.MediaType;
-import org.springframework.http.ResponseEntity;
-import org.springframework.web.util.DefaultUriBuilderFactory;
+import org.springframework.test.web.reactive.server.WebTestClient;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.dataformat.xml.XmlMapper;
/**
- * 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
+ * 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 {
+@Import(WebClientConfiguration.class)
+@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
+@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
+public class ModelDistributionTest {
+
+ ObjectMapper objectMapper = new XmlMapper();
+
+ @Autowired
+ WebTestClient webClient;
+ final String MODEL_FILE = "src/test/resources/payloads/models/network-service.xml";
@Test
+ @Order(1)
public void thatModelsCanBeDistributed() throws Exception {
- final String MODEL_FILE = "src/test/resources/payloads/models/network-service.xml";
- String uri = baseUrl + "/aai/v29/service-design-and-creation/models/model/d821d1aa-8a69-47a4-aa63-3dae1742c47c";
+ String uri = "/aai/v29/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());
+ webClient.get()
+ .uri(uri)
+ .accept(MediaType.APPLICATION_XML)
+ .exchange()
+ .expectStatus()
+ .isNotFound();
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());
+ webClient.put()
+ .uri(uri)
+ .accept(MediaType.APPLICATION_XML)
+ .header("Content-Type", MediaType.APPLICATION_XML_VALUE)
+ .bodyValue(modelPayload)
+ .exchange()
+ .expectStatus()
+ .isCreated();
+
+ String actual = webClient.get()
+ .uri(uri)
+ .accept(MediaType.APPLICATION_XML)
+ .exchange()
+ .expectStatus()
+ .isOk()
+ .returnResult(String.class)
+ .getResponseBody()
+ .blockFirst();
+
+ Model expectedModel = objectMapper.readValue(modelPayload, Model.class);
+ expectedModel.setModelVersions(null); // model versions are not being returned by the endpoint
+ Model actualModel = objectMapper.readValue(actual, Model.class);
+ Assertions.assertThat(expectedModel)
+ .usingRecursiveComparison()
+ .ignoringFields("resourceVersion")
+ .isEqualTo(actualModel);
+
+ webClient.delete()
+ .uri(uriBuilder -> uriBuilder
+ .path(uri)
+ .queryParam("resource-version", actualModel.getResourceVersion()).build())
+ .exchange()
+ .expectStatus()
+ .isNoContent();
+
+ }
+
+ @Test
+ @Order(2)
+ public void thatModelsCanBeRedistributed() throws Exception {
+ final String UPDATE_MODEL_FILE = "src/test/resources/payloads/models/model-version.xml";
+ String modelInvariantId = "d821d1aa-8a69-47a4-aa63-3dae1742c47c";
+ String modelVersionId = "8b713350-90fc-44b1-8c6e-a2b3973aa9d3";
+ String modelUri = "/aai/v29/service-design-and-creation/models/model/" + modelInvariantId;
+ String modelVersionUri = modelUri + "/model-vers/model-ver/" + modelVersionId;
+ webClient.get()
+ .uri(modelUri)
+ .accept(MediaType.APPLICATION_XML)
+ .exchange()
+ .expectStatus()
+ .isNotFound();
+
+ String modelPayload = new String(Files.readAllBytes(Paths.get(MODEL_FILE)));
+ webClient.put()
+ .uri(modelUri)
+ .accept(MediaType.APPLICATION_XML)
+ .header("Content-Type", MediaType.APPLICATION_XML_VALUE)
+ .bodyValue(modelPayload)
+ .exchange()
+ .expectStatus()
+ .isCreated();
+
+ String modelVersionResponse = webClient.get()
+ .uri(modelVersionUri)
+ .accept(MediaType.APPLICATION_XML)
+ .exchange()
+ .expectStatus()
+ .isOk()
+ .returnResult(String.class)
+ .getResponseBody()
+ .blockFirst();
+ ModelVersion modelVersion = objectMapper.readValue(modelVersionResponse, ModelVersion.class);
+ assertNull(modelVersion.getModelElements());
+
+ String updatePayload = new String(Files.readAllBytes(Paths.get(UPDATE_MODEL_FILE)))
+ .replace("resourceVersion", modelVersion.getResourceVersion());
+ webClient.put()
+ .uri(modelVersionUri)
+ .accept(MediaType.APPLICATION_XML)
+ .header("Content-Type", MediaType.APPLICATION_XML_VALUE)
+ .bodyValue(updatePayload)
+ .exchange()
+ .expectStatus()
+ .isOk();
+
+ modelVersionResponse = webClient.get()
+ .uri(modelVersionUri)
+ .accept(MediaType.APPLICATION_XML)
+ .exchange()
+ .expectStatus()
+ .isOk()
+ .returnResult(String.class)
+ .getResponseBody()
+ .blockFirst();
+ modelVersion = objectMapper.readValue(modelVersionResponse, ModelVersion.class);
+ assertEquals("2.0", modelVersion.getModelVersion());
}
}
diff --git a/aai-resources/src/test/resources/payloads/models/model-version.xml b/aai-resources/src/test/resources/payloads/models/model-version.xml
new file mode 100644
index 0000000..130bc68
--- /dev/null
+++ b/aai-resources/src/test/resources/payloads/models/model-version.xml
@@ -0,0 +1,12 @@
+<model-ver xmlns="http://org.onap.aai.inventory/v29">
+ <model-version-id>8b713350-90fc-44b1-8c6e-a2b3973aa9d3</model-version-id>
+ <model-name>test-svc-distribution</model-name>
+ <model-version>2.0</model-version>
+ <resource-version>resourceVersion</resource-version>
+ <model-elements>
+ <model-element>
+ <new-data-del-flag>T</new-data-del-flag>
+ <cardinality>unbounded</cardinality>
+ </model-element>
+ </model-elements>
+ </model-ver>
diff --git a/aai-resources/src/test/resources/payloads/models/network-service.xml b/aai-resources/src/test/resources/payloads/models/network-service.xml
index ee04def..977c186 100644
--- a/aai-resources/src/test/resources/payloads/models/network-service.xml
+++ b/aai-resources/src/test/resources/payloads/models/network-service.xml
@@ -8,19 +8,6 @@
<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
+</model>