summaryrefslogtreecommitdiffstats
path: root/src/test/java
diff options
context:
space:
mode:
authorMatthieuGeerebaert <matthieu.geerebaert@orange.com>2018-03-28 13:36:26 +0200
committerMatthieuGeerebaert <matthieu.geerebaert@orange.com>2018-04-03 23:35:04 +0200
commit99bf586a6eb9799c4f33e43976d741f2807ea287 (patch)
tree817406c30c99f366c000afc3fe0963b6b32499e7 /src/test/java
parent65fd3da0ea090f3c1fc82cea0c49547dbf362fcf (diff)
Add serviceCatalog rest services
- Add get and find serviceSpecification operations - Add API exceptions management - Consumes SDC apis - Add tests - Fix pom.xml conflict Change-Id: Id103d83dc8a981885100daabe868cdf18a922975 Issue-ID: EXTAPI-39 Signed-off-by: MatthieuGeerebaert <matthieu.geerebaert@orange.com>
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/onap/nbi/apis/resources/ApiTest.java89
-rw-r--r--src/test/java/org/onap/nbi/apis/resources/ServiceCatalogAssertions.java135
-rw-r--r--src/test/java/org/onap/nbi/apis/resources/StatusResourceTest.java (renamed from src/test/java/org/onap/nbi/apis/status/StatusTest.java)5
3 files changed, 227 insertions, 2 deletions
diff --git a/src/test/java/org/onap/nbi/apis/resources/ApiTest.java b/src/test/java/org/onap/nbi/apis/resources/ApiTest.java
new file mode 100644
index 0000000..05d332c
--- /dev/null
+++ b/src/test/java/org/onap/nbi/apis/resources/ApiTest.java
@@ -0,0 +1,89 @@
+package org.onap.nbi.apis.resources;
+
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.nbi.apis.servicecatalog.ServiceSpecificationResource;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.context.embedded.LocalServerPort;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.util.LinkedMultiValueMap;
+import org.springframework.util.MultiValueMap;
+import com.github.tomakehurst.wiremock.WireMockServer;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
+public class ApiTest {
+
+ @LocalServerPort
+ int randomServerPort;
+
+ String realServerPort;
+
+
+ static public WireMockServer wireMockServer = new WireMockServer(8091);
+
+ @Autowired
+ ServiceSpecificationResource serviceSpecificationResource;
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ wireMockServer.start();
+ }
+
+ @AfterClass
+ public static void tearsDown() throws Exception {
+ wireMockServer.stop();
+
+ }
+
+ @After
+ public void tearsDownUpPort() throws Exception {
+ wireMockServer.resetToDefaultMappings();
+ }
+
+ @Test
+ @Ignore
+ public void testServiceResourceGetCatalog() throws Exception {
+
+ ResponseEntity<Object> resource =
+ serviceSpecificationResource.getServiceSpecification("1e3feeb0-8e36-46c6-862c-236d9c626439", null);
+ ServiceCatalogAssertions.assertGetServiceCatalog(resource);
+
+ }
+
+ @Test
+ public void testServiceCatalogGetResourceWithoutTosca() throws Exception {
+
+ ResponseEntity<Object> resource = serviceSpecificationResource
+ .getServiceSpecification("1e3feeb0-8e36-46c6-862c-236d9c626439_withoutTosca", null);
+ ServiceCatalogAssertions.asserGetServiceCatalogWithoutTosca(resource);
+
+ }
+
+ @Test
+ public void testServiceCatalogFind() throws Exception {
+
+ ResponseEntity<Object> resource = serviceSpecificationResource.findServiceSpecification(null);
+ ServiceCatalogAssertions.assertFindServiceCatalog(resource);
+
+ }
+
+
+ @Test
+ public void testServiceCatalogFindWithFilter() throws Exception {
+
+ MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
+ params.add("fields", "name");
+ ResponseEntity<Object> resource = serviceSpecificationResource.findServiceSpecification(params);
+ ServiceCatalogAssertions.assertFindServiceCatalogWIthFilter(resource);
+
+ }
+
+}
diff --git a/src/test/java/org/onap/nbi/apis/resources/ServiceCatalogAssertions.java b/src/test/java/org/onap/nbi/apis/resources/ServiceCatalogAssertions.java
new file mode 100644
index 0000000..19e2a2a
--- /dev/null
+++ b/src/test/java/org/onap/nbi/apis/resources/ServiceCatalogAssertions.java
@@ -0,0 +1,135 @@
+package org.onap.nbi.apis.resources;
+
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+
+public class ServiceCatalogAssertions {
+
+
+ public static void assertGetServiceCatalog(ResponseEntity<Object> resource) {
+ assertThat(resource.getStatusCode()).isEqualTo(HttpStatus.OK);
+ LinkedHashMap service = (LinkedHashMap) resource.getBody();
+ assertThat(service.get("id")).isEqualTo("1e3feeb0-8e36-46c6-862c-236d9c626439");
+ assertThat(service.get("name")).isEqualTo("vFW");
+ assertThat(service.get("invariantUUID")).isEqualTo("b58a118e-eeb9-4f6e-bdca-e292f84d17df");
+ assertThat(service.get("toscaModelURL")).isEqualTo("/sdc/v1/catalog/services/1e3feeb0-8e36-46c6-862c-236d9c626439/toscaModel");
+ assertThat(service.get("distributionStatus")).isEqualTo("DISTRIBUTED");
+ assertThat(service.get("version")).isEqualTo("2.0");
+ assertThat(service.get("lifecycleStatus")).isEqualTo("CERTIFIED");
+ assertThat(service.get("@type")).isEqualTo("ONAPservice");
+ assertThat(((ArrayList) service.get("attachment")).size()).isEqualTo(5);
+ LinkedHashMap relatedParty = (LinkedHashMap) service.get("relatedParty");
+ assertThat(relatedParty.get("name")).isEqualTo("Joni Mitchell");
+ assertThat(relatedParty.get("role")).isEqualTo("lastUpdater");
+
+
+ assertThat(((ArrayList) service.get("resourceSpecification")).size()).isEqualTo(2);
+ LinkedHashMap resource1 = (LinkedHashMap) ((ArrayList) service.get("resourceSpecification")).get(0);
+ assertThat(resource1.get("name")).isEqualTo("vFW-vSINK");
+ assertThat(resource1.get("instanceName")).isEqualTo("vFW-vSINK 0");
+ assertThat(resource1.get("resourceInvariantUUID")).isEqualTo("18b90934-aa82-456f-938e-e74a07a426f3");
+ assertThat(resource1.get("@type")).isEqualTo("ONAPresource");
+ assertThat(resource1.get("modelCustomizationId")).isEqualTo("f7ae574e-fd5f-41e7-9b21-75e001561c96");
+ assertThat(resource1.get("modelCustomizationName")).isEqualTo("vFW-vSINK");
+
+ assertThat(((ArrayList) service.get("serviceSpecCharacteristic")).size()).isEqualTo(4);
+ ArrayList serviceSPecCharacteristics = (ArrayList) service.get("serviceSpecCharacteristic");
+ for (Object serviceSPecCharacteristic : serviceSPecCharacteristics) {
+ LinkedHashMap serviceSPecCharacteristicMap = (LinkedHashMap) serviceSPecCharacteristic;
+ if (serviceSPecCharacteristicMap.get("name").toString().equals("cpus")) {
+ assertThat(serviceSPecCharacteristicMap.get("valueType")).isEqualTo("integer");
+ assertThat(serviceSPecCharacteristicMap.get("@type")).isEqualTo("ONAPserviceCharacteristic");
+ ArrayList serviceSpecCharacteristicValues = (ArrayList) serviceSPecCharacteristicMap.get("serviceSpecCharacteristicValue");
+ for (Object serviceSpecCharacteristicValue : serviceSpecCharacteristicValues) {
+ LinkedHashMap serviceSpecCharacteristicValueMap = (LinkedHashMap) serviceSpecCharacteristicValue;
+ if (serviceSpecCharacteristicValueMap.get("value").toString().equals("2")) {
+ assertThat(serviceSpecCharacteristicValueMap.get("isDefault")).isEqualTo(true);
+ assertThat(serviceSpecCharacteristicValueMap.get("valueType")).isEqualTo("integer");
+ } else {
+ assertThat(serviceSpecCharacteristicValueMap.get("isDefault")).isEqualTo(false);
+ assertThat(serviceSpecCharacteristicValueMap.get("valueType")).isEqualTo("integer");
+ }
+ }
+ }
+ }
+ }
+
+
+
+ public static void asserGetServiceCatalogWithoutTosca(ResponseEntity<Object> resource) {
+ assertThat(resource.getStatusCode()).isEqualTo(HttpStatus.PARTIAL_CONTENT);
+ LinkedHashMap service = (LinkedHashMap) resource.getBody();
+ assertThat(service.get("id")).isEqualTo("1e3feeb0-8e36-46c6-862c-236d9c626439");
+ assertThat(service.get("name")).isEqualTo("vFW");
+ assertThat(service.get("invariantUUID")).isEqualTo("b58a118e-eeb9-4f6e-bdca-e292f84d17df");
+ assertThat(service.get("toscaModelURL")).isEqualTo("/sdc/v1/catalog/services/1e3feeb0-8e36-46c6-862c-236d9c626439toto/toscaModel");
+ assertThat(service.get("distributionStatus")).isEqualTo("DISTRIBUTED");
+ assertThat(service.get("version")).isEqualTo("2.0");
+ assertThat(service.get("lifecycleStatus")).isEqualTo("CERTIFIED");
+ assertThat(service.get("@type")).isEqualTo("ONAPservice");
+ assertThat(((ArrayList) service.get("attachment")).size()).isEqualTo(5);
+ LinkedHashMap relatedParty = (LinkedHashMap) service.get("relatedParty");
+ assertThat(relatedParty.get("name")).isEqualTo("Joni Mitchell");
+ assertThat(relatedParty.get("role")).isEqualTo("lastUpdater");
+
+
+ assertThat(((ArrayList) service.get("resourceSpecification")).size()).isEqualTo(2);
+ LinkedHashMap resource1 = (LinkedHashMap) ((ArrayList) service.get("resourceSpecification")).get(0);
+ assertThat(resource1.get("name")).isEqualTo("vFW-vSINK");
+ assertThat(resource1.get("instanceName")).isEqualTo("vFW-vSINK 0");
+ assertThat(resource1.get("resourceInvariantUUID")).isEqualTo("18b90934-aa82-456f-938e-e74a07a426f3");
+ assertThat(resource1.get("@type")).isEqualTo("ONAPresource");
+ assertThat(resource1.get("modelCustomizationId")).isNull();
+ assertThat(resource1.get("modelCustomizationName")).isNull();
+
+ assertThat(service.get("serviceSpecCharacteristic")).isNull();
+ }
+
+
+
+
+ public static void assertFindServiceCatalog(ResponseEntity<Object> resource) {
+ assertThat(resource.getStatusCode()).isEqualTo(HttpStatus.OK);
+ ArrayList body = (ArrayList) resource.getBody();
+ assertThat(body.size()).isEqualTo(21);
+ LinkedHashMap service1 = (LinkedHashMap) body.get(0);
+ assertThat(service1.get("id")).isEqualTo("446afaf6-79b5-420e-aff8-7551b00bb510");
+ assertThat(service1.get("name")).isEqualTo("FreeRadius-service");
+ assertThat(service1.get("invariantUUID")).isEqualTo("7e4781e8-6c6e-41c5-b889-6a321d5f2490");
+ assertThat(service1.get("category")).isEqualTo("Network L4+");
+ assertThat(service1.get("distributionStatus")).isEqualTo("DISTRIBUTED");
+ assertThat(service1.get("version")).isEqualTo("1.0");
+ assertThat(service1.get("lifecycleStatus")).isEqualTo("CERTIFIED");
+ LinkedHashMap relatedParty = (LinkedHashMap) service1.get("relatedParty");
+ assertThat(relatedParty.get("role")).isEqualTo("lastUpdater");
+ }
+
+
+
+ public static void assertFindServiceCatalogWIthFilter(ResponseEntity<Object> resource) {
+ assertThat(resource.getStatusCode()).isEqualTo(HttpStatus.OK);
+ ArrayList body = (ArrayList) resource.getBody();
+ assertThat(body.size()).isEqualTo(21);
+
+
+ ObjectNode service1 = (ObjectNode) body.get(0);
+ assertThat(service1.get("id")).isNull();
+ assertThat(service1.get("name").asText()).isEqualTo("FreeRadius-service");
+ assertThat(service1.get("invariantUUID")).isNull();
+ assertThat(service1.get("category")).isNull();
+ assertThat(service1.get("distributionStatus")).isNull();
+ assertThat(service1.get("version")).isNull();
+ assertThat(service1.get("lifecycleStatus")).isNull();
+ assertThat(service1.get("relatedParty")).isNull();
+ }
+
+}
+
diff --git a/src/test/java/org/onap/nbi/apis/status/StatusTest.java b/src/test/java/org/onap/nbi/apis/resources/StatusResourceTest.java
index d262e15..40e11c2 100644
--- a/src/test/java/org/onap/nbi/apis/status/StatusTest.java
+++ b/src/test/java/org/onap/nbi/apis/resources/StatusResourceTest.java
@@ -1,10 +1,11 @@
-package org.onap.nbi.apis.status;
+package org.onap.nbi.apis.resources;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.onap.nbi.apis.status.StatusResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpStatus;
@@ -16,7 +17,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
-public class StatusTest {
+public class StatusResourceTest {
@Autowired
StatusResource statusResource;