aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/test/java/org/onap/vid/asdc
diff options
context:
space:
mode:
authorSonsino, Ofir (os0695) <os0695@intl.att.com>2018-07-10 14:20:54 +0300
committerSonsino, Ofir (os0695) <os0695@intl.att.com>2018-07-10 14:20:54 +0300
commitc72d565bb58226b20625b2bce5f0019046bee649 (patch)
tree8658e49595705b02e47ddc14afa20d6bb7123547 /vid-app-common/src/test/java/org/onap/vid/asdc
parentef8a6b47847012fd59ea20da21d8d3d7c4a301ed (diff)
Merge 1806 code of vid-common
Change-Id: I75d52abed4a24dfe3827d79edc4a2938726aa87a Issue-ID: VID-208 Signed-off-by: Sonsino, Ofir (os0695) <os0695@intl.att.com>
Diffstat (limited to 'vid-app-common/src/test/java/org/onap/vid/asdc')
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/asdc/BaseClientTest.java322
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/asdc/InMemoryClientTest.java79
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/asdc/RestfulClientTest.java107
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/asdc/beans/ResourceTest.java391
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/asdc/beans/tosca/CapabilityTest.java124
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/asdc/beans/tosca/ConstraintTest.java221
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/asdc/beans/tosca/PropertyTest.java18
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/asdc/beans/tosca/RequirementTest.java92
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/asdc/parser/ToscaParserImpl2Test.java299
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/asdc/rest/RestfulAsdcClientTest.java248
10 files changed, 307 insertions, 1594 deletions
diff --git a/vid-app-common/src/test/java/org/onap/vid/asdc/BaseClientTest.java b/vid-app-common/src/test/java/org/onap/vid/asdc/BaseClientTest.java
deleted file mode 100644
index 40a05fd90..000000000
--- a/vid-app-common/src/test/java/org/onap/vid/asdc/BaseClientTest.java
+++ /dev/null
@@ -1,322 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * VID ASDC Client
- * ================================================================================
- * Copyright (C) 2017 AT&T 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.vid.asdc;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Map;
-import java.util.UUID;
-
-import javax.ws.rs.NotFoundException;
-
-import org.hamcrest.core.IsEqual;
-import org.junit.Assert;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ErrorCollector;
-import org.onap.vid.asdc.beans.Artifact;
-import org.onap.vid.asdc.beans.Resource;
-import org.onap.vid.asdc.beans.Service;
-import org.onap.vid.asdc.beans.Service.DistributionStatus;
-import org.onap.vid.asdc.beans.tosca.Group;
-import org.onap.vid.asdc.beans.tosca.Input;
-import org.onap.vid.asdc.beans.tosca.NodeTemplate;
-import org.onap.vid.asdc.beans.tosca.ToscaCsar;
-import org.onap.vid.asdc.beans.tosca.ToscaModel;
-
-/**
- * The Class BaseClientTest.
- */
-public class BaseClientTest {
-
- /** The collector. */
- @Rule
- public ErrorCollector collector = new ErrorCollector();
-
- /**
- * Run resource tests.
- *
- * @param client the client
- * @throws AsdcCatalogException the asdc catalog exception
- */
- protected void runResourceTests(AsdcClient client) throws AsdcCatalogException {
- final Collection<Resource> resources = client.getResources();
-
- collector.checkThat("getResources() returned nothing", resources.isEmpty(), IsEqual.equalTo(false));
-
- final Resource resource = resources.iterator().next();
-
- testResource(resource);
-
- final Resource thisResource = client.getResource(UUID.fromString(resource.getUuid()));
-
- collector.checkThat(thisResource, IsEqual.equalTo(resource));
-
- for (Resource aResource : resources) {
- if (aResource.getArtifacts() != null && !aResource.getArtifacts().isEmpty()) {
-
- final Artifact artifact = aResource.getArtifacts().iterator().next();
-
- testArtifact(artifact);
-
- final UUID resourceUuid = UUID.fromString(aResource.getUuid());
- final UUID artifactUuid = UUID.fromString(artifact.getArtifactUUID());
- final Artifact thisArtifact = client.getResourceArtifact(resourceUuid, artifactUuid);
-
- collector.checkThat(artifact, IsEqual.equalTo(thisArtifact));
- }
- }
-
- try {
- final Collection<Resource> badResources = client.getResources(Collections.singletonMap("category", new String[] {"Bad Resources"}));
-
- for (Resource badResource : badResources) {
- collector.checkThat(badResource.getCategory(), IsEqual.equalTo("Bad Resources"));
- }
- } catch (NotFoundException e) {
- //No resources of this category were found
- }
-
- try {
- final Collection<Resource> reallyBadResources = client.getResources(Collections.singletonMap("subCategory", new String[] {"Really Bad Resources"}));
-
- for (Resource reallyBadResource : reallyBadResources) {
- collector.checkThat(reallyBadResource.getSubCategory(), IsEqual.equalTo("Really Bad Resources"));
- }
- } catch (NotFoundException e) {
- //No resources of this subcategory were found
- }
-
- /*final ToscaCsar toscaCsar = client.getResourceToscaModel(UUID.fromString(resource.getUuid()));
-
- testToscaCsar(toscaCsar);*/
- }
-
- /**
- * Run service tests.
- *
- * @param client the client
- * @throws AsdcCatalogException the asdc catalog exception
- */
- protected void runServiceTests(AsdcClient client) throws AsdcCatalogException {
- final Collection<Service> services = client.getServices();
-
- collector.checkThat("getServices() returned nothing", services.isEmpty(), IsEqual.equalTo(false));
-
- final Service service = services.iterator().next();
-
- testService(service);
-
- final Service thisService = client.getService(UUID.fromString(service.getUuid()));
-
- collector.checkThat(thisService, IsEqual.equalTo(service));
-
- for (Service aService : services) {
- if (aService.getArtifacts() != null && ! aService.getArtifacts().isEmpty()) {
- final Artifact artifact = aService.getArtifacts().iterator().next();
-
- testArtifact(artifact);
-
- final UUID serviceUuid = UUID.fromString(aService.getUuid());
- final UUID artifactUuid = UUID.fromString(artifact.getArtifactUUID());
- final Artifact thisArtifact = client.getServiceArtifact(serviceUuid, artifactUuid);
-
- collector.checkThat(artifact, IsEqual.equalTo(thisArtifact));
- break;
- }
- }
-
- try {
- final Collection<Service> distributedServices = client.getServices(Collections.singletonMap("distributionStatus", new String[] {"DISTRIBUTED"}));
-
- for (Service distributedService : distributedServices) {
- collector.checkThat(distributedService.getDistributionStatus(), IsEqual.equalTo(DistributionStatus.DISTRIBUTED));
- }
- } catch (NotFoundException e) {
- //No services of this distributionStatus were found
- }
-
- try {
- final Collection<Service> badServices = client.getServices(Collections.singletonMap("category", new String[] {"Bad Services"}));
-
- for (Service badService : badServices) {
- collector.checkThat(badService.getCategory(), IsEqual.equalTo("Bad Services"));
- }
- } catch (NotFoundException e) {
- //No services of this category were found
- }
-
- /*final ToscaCsar toscaCsar = client.getServiceToscaModel(UUID.fromString(service.getUuid()));
-
- testToscaCsar(toscaCsar);*/
- }
-
- /**
- * Test service.
- *
- * @param service the service
- */
- private void testService(Service service) {
- service.getArtifacts();
- service.getCategory();
- service.getDistributionStatus();
- service.getInvariantUUID();
- service.getLastUpdaterUserId();
- service.getLastUpdaterFullName();
- service.getLifecycleState();
- service.getName();
- service.getResources();
- service.getToscaModelURL();
- service.getUuid();
- service.getVersion();
- }
-
- /**
- * Test resource.
- *
- * @param resource the resource
- */
- private void testResource(Resource resource) {
- resource.getArtifacts();
- resource.getCategory();
- resource.getInvariantUUID();
- resource.getLastUpdaterUserId();
- resource.getLastUpdaterFullName();
- resource.getLifecycleState();
- resource.getName();
- resource.getResources();
- resource.getResourceType();
- resource.getSubCategory();
- resource.getToscaModel();
- resource.getToscaModelURL();
- resource.getToscaResourceName();
- resource.getUuid();
- resource.getVersion();
- }
-
- /**
- * Test artifact.
- *
- * @param artifact the artifact
- */
- private void testArtifact(Artifact artifact) {
- artifact.getArtifactChecksum();
- artifact.getArtifactDescription();
- artifact.getArtifactName();
- artifact.getArtifactTimeout();
- artifact.getArtifactType();
- artifact.getArtifactURL();
- artifact.getArtifactUUID();
- artifact.getArtifactVersion();
- artifact.getGeneratedFromUUID();
- }
-
- /**
- * Test tosca csar.
- *
- * @param toscaCsar the tosca csar
- */
- private void testToscaCsar(ToscaCsar toscaCsar) {
- testToscaModel(toscaCsar.getParent());
-
- for (ToscaModel childModel : toscaCsar.getChildren()) {
- testToscaModel(childModel);
- }
- }
-
- /**
- * Test tosca model.
- *
- * @param toscaModel the tosca model
- */
- private void testToscaModel(ToscaModel toscaModel) {
-
- toscaModel.getDescription();
- toscaModel.getMetadata().getCategory();
- toscaModel.getMetadata().getDescription();
- toscaModel.getMetadata().getInvariantUUID();
- toscaModel.getMetadata().getName();
- toscaModel.getMetadata().getType();
- toscaModel.getMetadata().gettemplate_name();
- toscaModel.getMetadata().getUUID();
- toscaModel.getMetadata().getVersion();
- //toscaModel.getMetadata().isServiceEcompNaming();
- toscaModel.getMetadata().isServiceHoming();
-
- if (!toscaModel.gettopology_template().getInputs().isEmpty()) {
- final Input input = toscaModel.gettopology_template().getInputs().values().iterator().next();
- input.getDefault();
- input.getDescription();
- input.getType();
- input.toString();
- }
-
- if (!toscaModel.gettopology_template().getnode_templates().isEmpty()) {
- final NodeTemplate nodeTemplate = toscaModel.gettopology_template().getnode_templates().values().iterator().next();
- nodeTemplate.getMetadata();
- nodeTemplate.getProperties();
- nodeTemplate.getRequirements();
- nodeTemplate.getType();
- }
-
- if (!toscaModel.gettopology_template().getGroups().isEmpty()) {
- final Group group = toscaModel.gettopology_template().getGroups().values().iterator().next();
- group.getMembers();
- group.getMetadata();
- group.getType();
- }
-
- if (!toscaModel.getImports().isEmpty()) {
- for (Map<String, Map<String, String>> imports : toscaModel.getImports()) {
- imports.values().iterator().next().get("file");
- }
- }
-
- toscaModel.gettopology_template().getsubstitution_mappings().getnode_type();
-
- if (!toscaModel.gettopology_template().getsubstitution_mappings().getCapabilities().isEmpty()) {
- toscaModel.gettopology_template().getsubstitution_mappings().getCapabilities();
- }
-
- toscaModel.gettosca_definitions_version();
- }
-
- /**
- * Test try catch asdc catalog exception.
- */
- @Test
- public void testTryCatchAsdcCatalogException() {
- try {
- throw new AsdcCatalogException("testing");
- } catch (AsdcCatalogException e) {
- Assert.assertEquals("testing", e.getMessage());
- }
-
- final Exception cause = new Exception();
-
- try {
- throw new AsdcCatalogException("testing", cause);
- } catch (AsdcCatalogException e) {
- Assert.assertEquals("testing", e.getMessage());
- Assert.assertEquals(cause, e.getCause());
- }
- }
-}
diff --git a/vid-app-common/src/test/java/org/onap/vid/asdc/InMemoryClientTest.java b/vid-app-common/src/test/java/org/onap/vid/asdc/InMemoryClientTest.java
deleted file mode 100644
index 5687e628b..000000000
--- a/vid-app-common/src/test/java/org/onap/vid/asdc/InMemoryClientTest.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * VID ASDC Client
- * ================================================================================
- * Copyright (C) 2017 AT&T 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.vid.asdc;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URISyntaxException;
-
-import org.codehaus.jackson.map.ObjectMapper;
-import org.json.JSONObject;
-import org.json.JSONTokener;
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.vid.asdc.memory.InMemoryAsdcClient;
-
-/**
- * The Class InMemoryClientTest.
- */
-public class InMemoryClientTest extends BaseClientTest {
-
- /** The catalog. */
- private JSONObject catalog;
-
- /**
- * Sets the up.
- *
- * @throws URISyntaxException the URI syntax exception
- * @throws IOException Signals that an I/O exception has occurred.
- */
- @Before
- public void setUp() throws URISyntaxException, IOException {
- final InputStream asdcCatalogFile = getClass().getClassLoader().getResourceAsStream("catalog.json");
-
- final JSONTokener tokener = new JSONTokener(asdcCatalogFile);
-
- catalog = new JSONObject(tokener);
- }
-
- /**
- * Test resources.
- *
- * @throws AsdcCatalogException the asdc catalog exception
- */
- @Test
- public void testResources() throws AsdcCatalogException {
-
- runResourceTests(new InMemoryAsdcClient.Builder().catalog(catalog).mapper(new ObjectMapper()).build());
- }
-
- /**
- * Test services.
- *
- * @throws AsdcCatalogException the asdc catalog exception
- * @throws URISyntaxException the URI syntax exception
- */
- @Test
- public void testServices() throws AsdcCatalogException, URISyntaxException {
-
- runServiceTests(new InMemoryAsdcClient.Builder().catalog(catalog).build());
- }
-}
diff --git a/vid-app-common/src/test/java/org/onap/vid/asdc/RestfulClientTest.java b/vid-app-common/src/test/java/org/onap/vid/asdc/RestfulClientTest.java
deleted file mode 100644
index ae0563420..000000000
--- a/vid-app-common/src/test/java/org/onap/vid/asdc/RestfulClientTest.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * VID ASDC Client
- * ================================================================================
- * Copyright (C) 2017 AT&T 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.vid.asdc;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.Properties;
-
-import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.SSLSession;
-import javax.ws.rs.client.Client;
-import javax.ws.rs.client.ClientBuilder;
-
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.onap.vid.asdc.rest.RestfulAsdcClient;
-
-/**
- * The Class RestfulClientTest.
- */
-@Ignore
-public class RestfulClientTest extends BaseClientTest {
-
- /** The rest client. */
- private Client restClient;
-
- /** The uri. */
- private URI uri;
-
- /** The properties. */
- private Properties properties;
-
- /** The auth. */
- private String auth;
-
- /**
- * Sets the up.
- *
- * @throws URISyntaxException the URI syntax exception
- * @throws IOException Signals that an I/O exception has occurred.
- */
- @Before
- public void setUp() throws URISyntaxException, IOException {
- final InputStream propertiesFile = getClass().getClassLoader().getResourceAsStream("asdc.properties");
-
- properties = new Properties();
- properties.load(propertiesFile);
-
- final String protocol = properties.getProperty("protocol", "http");
-
- restClient = ClientBuilder.newBuilder()
- .hostnameVerifier(new HostnameVerifier() {
-
- @Override
- public boolean verify(String arg0, SSLSession arg1) {
- return true;
- }
- })
- .build();
- uri = new URI(protocol + "://" + properties.getProperty("host", "localhost") + ":" + properties.getProperty("port", "80") + "/");
- auth = properties.getProperty("auth");
- }
-
- /**
- * Test resources.
- *
- * @throws AsdcCatalogException the asdc catalog exception
- */
- @Test
- public void testResources() throws AsdcCatalogException {
-
- runResourceTests(new RestfulAsdcClient.Builder(restClient, uri).auth(auth).build());
- }
-
- /**
- * Test services.
- *
- * @throws AsdcCatalogException the asdc catalog exception
- * @throws URISyntaxException the URI syntax exception
- */
- @Test
- public void testServices() throws AsdcCatalogException, URISyntaxException {
-
- runServiceTests(new RestfulAsdcClient.Builder(restClient, uri).auth(auth).build());
- }
-}
diff --git a/vid-app-common/src/test/java/org/onap/vid/asdc/beans/ResourceTest.java b/vid-app-common/src/test/java/org/onap/vid/asdc/beans/ResourceTest.java
deleted file mode 100644
index af42409cd..000000000
--- a/vid-app-common/src/test/java/org/onap/vid/asdc/beans/ResourceTest.java
+++ /dev/null
@@ -1,391 +0,0 @@
-package org.onap.vid.asdc.beans;
-
-import java.util.Collection;
-
-import org.junit.Test;
-import org.onap.vid.asdc.beans.Resource.LifecycleState;
-import org.onap.vid.asdc.beans.Resource.Type;
-
-
-public class ResourceTest {
-
- private Resource createTestSubject() {
- return new Resource();
- }
-
-
- @Test
- public void testGetUuid() throws Exception {
- Resource testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getUuid();
- }
-
-
- @Test
- public void testGetInvariantUUID() throws Exception {
- Resource testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getInvariantUUID();
- }
-
-
- @Test
- public void testGetName() throws Exception {
- Resource testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getName();
- }
-
-
- @Test
- public void testGetDescription() throws Exception {
- Resource testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getDescription();
- }
-
-
- @Test
- public void testGetVersion() throws Exception {
- Resource testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getVersion();
- }
-
-
- @Test
- public void testGetToscaModelURL() throws Exception {
- Resource testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getToscaModelURL();
- }
-
-
- @Test
- public void testGetCategory() throws Exception {
- Resource testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getCategory();
- }
-
-
- @Test
- public void testGetSubCategory() throws Exception {
- Resource testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getSubCategory();
- }
-
-
- @Test
- public void testGetResourceType() throws Exception {
- Resource testSubject;
- Type result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getResourceType();
- }
-
-
- @Test
- public void testGetLifecycleState() throws Exception {
- Resource testSubject;
- LifecycleState result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getLifecycleState();
- }
-
-
- @Test
- public void testGetLastUpdaterUserId() throws Exception {
- Resource testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getLastUpdaterUserId();
- }
-
-
- @Test
- public void testGetLastUpdaterFullName() throws Exception {
- Resource testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getLastUpdaterFullName();
- }
-
-
- @Test
- public void testGetToscaModel() throws Exception {
- Resource testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getToscaModel();
- }
-
-
- @Test
- public void testGetToscaResourceName() throws Exception {
- Resource testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getToscaResourceName();
- }
-
-
- @Test
- public void testGetArtifacts() throws Exception {
- Resource testSubject;
- Collection<Artifact> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getArtifacts();
- }
-
-
- @Test
- public void testGetResources() throws Exception {
- Resource testSubject;
- Collection<SubResource> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getResources();
- }
-
-
- @Test
- public void testSetUuid() throws Exception {
- Resource testSubject;
- String uuid = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setUuid(uuid);
- }
-
-
- @Test
- public void testSetInvariantUUID() throws Exception {
- Resource testSubject;
- String invariantUUID = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setInvariantUUID(invariantUUID);
- }
-
-
- @Test
- public void testSetName() throws Exception {
- Resource testSubject;
- String name = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setName(name);
- }
-
-
- @Test
- public void testSetDescription() throws Exception {
- Resource testSubject;
- String description = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setDescription(description);
- }
-
-
- @Test
- public void testSetVersion() throws Exception {
- Resource testSubject;
- String version = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setVersion(version);
- }
-
-
- @Test
- public void testSetToscaModelURL() throws Exception {
- Resource testSubject;
- String toscaModelURL = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setToscaModelURL(toscaModelURL);
- }
-
-
- @Test
- public void testSetCategory() throws Exception {
- Resource testSubject;
- String category = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setCategory(category);
- }
-
-
- @Test
- public void testSetSubCategory() throws Exception {
- Resource testSubject;
- String subCategory = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setSubCategory(subCategory);
- }
-
-
- @Test
- public void testSetResourceType() throws Exception {
- Resource testSubject;
- Type resourceType = null;
-
- // default test
- testSubject = createTestSubject();
- testSubject.setResourceType(resourceType);
- }
-
-
- @Test
- public void testSetLifecycleState() throws Exception {
- Resource testSubject;
- LifecycleState lifecycleState = null;
-
- // default test
- testSubject = createTestSubject();
- testSubject.setLifecycleState(lifecycleState);
- }
-
-
- @Test
- public void testSetLastUpdaterUserId() throws Exception {
- Resource testSubject;
- String lastUpdaterUserId = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setLastUpdaterUserId(lastUpdaterUserId);
- }
-
-
- @Test
- public void testSetLastUpdaterFullName() throws Exception {
- Resource testSubject;
- String lastUpdaterFullName = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setLastUpdaterFullName(lastUpdaterFullName);
- }
-
-
- @Test
- public void testSetToscaModel() throws Exception {
- Resource testSubject;
- String toscaModel = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setToscaModel(toscaModel);
- }
-
-
- @Test
- public void testSetToscaResourceName() throws Exception {
- Resource testSubject;
- String toscaResourceName = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setToscaResourceName(toscaResourceName);
- }
-
-
- @Test
- public void testSetArtifacts() throws Exception {
- Resource testSubject;
- Collection<Artifact> artifacts = null;
-
- // default test
- testSubject = createTestSubject();
- testSubject.setArtifacts(artifacts);
- }
-
-
- @Test
- public void testSetResources() throws Exception {
- Resource testSubject;
- Collection<SubResource> resources = null;
-
- // default test
- testSubject = createTestSubject();
- testSubject.setResources(resources);
- }
-
-
- @Test
- public void testHashCode() throws Exception {
- Resource testSubject;
- int result;
-
- // default test
- testSubject = createTestSubject();
- testSubject.setUuid("cb49608f-5a24-4789-b0f7-2595473cb997");
- result = testSubject.hashCode();
- }
-
-
- @Test
- public void testEquals() throws Exception {
- Resource testSubject;
- Object o = null;
- boolean result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.equals(o);
- }
-} \ No newline at end of file
diff --git a/vid-app-common/src/test/java/org/onap/vid/asdc/beans/tosca/CapabilityTest.java b/vid-app-common/src/test/java/org/onap/vid/asdc/beans/tosca/CapabilityTest.java
deleted file mode 100644
index 7609e36d1..000000000
--- a/vid-app-common/src/test/java/org/onap/vid/asdc/beans/tosca/CapabilityTest.java
+++ /dev/null
@@ -1,124 +0,0 @@
-package org.onap.vid.asdc.beans.tosca;
-
-import java.util.Collection;
-import java.util.Map;
-
-import org.junit.Test;
-
-
-public class CapabilityTest {
-
- private Capability createTestSubject() {
- return new Capability();
- }
-
-
- @Test
- public void testGetType() throws Exception {
- Capability testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getType();
- }
-
-
- @Test
- public void testGetDescription() throws Exception {
- Capability testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getDescription();
- }
-
-
- @Test
- public void testGetOccurrences() throws Exception {
- Capability testSubject;
- Collection<String> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getOccurrences();
- }
-
-
- @Test
- public void testGetProperties() throws Exception {
- Capability testSubject;
- Map<String, Property> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getProperties();
- }
-
-
- @Test
- public void testGetValid_source_types() throws Exception {
- Capability testSubject;
- Collection<String> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getValid_source_types();
- }
-
-
- @Test
- public void testSetType() throws Exception {
- Capability testSubject;
- String type = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setType(type);
- }
-
-
- @Test
- public void testSetDescription() throws Exception {
- Capability testSubject;
- String description = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setDescription(description);
- }
-
-
- @Test
- public void testSetOccurrences() throws Exception {
- Capability testSubject;
- Collection<String> occurrences = null;
-
- // default test
- testSubject = createTestSubject();
- testSubject.setOccurrences(occurrences);
- }
-
-
- @Test
- public void testSetProperties() throws Exception {
- Capability testSubject;
- Map<String, Property> properties = null;
-
- // default test
- testSubject = createTestSubject();
- testSubject.setProperties(properties);
- }
-
-
- @Test
- public void testSetValid_source_types() throws Exception {
- Capability testSubject;
- Collection<String> valid_source_types = null;
-
- // default test
- testSubject = createTestSubject();
- testSubject.setValid_source_types(valid_source_types);
- }
-} \ No newline at end of file
diff --git a/vid-app-common/src/test/java/org/onap/vid/asdc/beans/tosca/ConstraintTest.java b/vid-app-common/src/test/java/org/onap/vid/asdc/beans/tosca/ConstraintTest.java
deleted file mode 100644
index ebba7d172..000000000
--- a/vid-app-common/src/test/java/org/onap/vid/asdc/beans/tosca/ConstraintTest.java
+++ /dev/null
@@ -1,221 +0,0 @@
-package org.onap.vid.asdc.beans.tosca;
-
-import java.util.List;
-
-import org.junit.Test;
-
-public class ConstraintTest {
-
- private Constraint createTestSubject() {
- return new Constraint();
- }
-
-
- @Test
- public void testGetvalid_values() throws Exception {
- Constraint testSubject;
- List<Object> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getvalid_values();
- }
-
-
- @Test
- public void testGetEqual() throws Exception {
- Constraint testSubject;
- Object result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getEqual();
- }
-
-
- @Test
- public void testGetGreater_than() throws Exception {
- Constraint testSubject;
- Object result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getGreater_than();
- }
-
-
- @Test
- public void testGetGreater_or_equal() throws Exception {
- Constraint testSubject;
- Object result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getGreater_or_equal();
- }
-
-
- @Test
- public void testGetLess_than() throws Exception {
- Constraint testSubject;
- Object result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getLess_than();
- }
-
-
- @Test
- public void testGetLess_or_equal() throws Exception {
- Constraint testSubject;
- Object result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getLess_or_equal();
- }
-
-
- @Test
- public void testGetIn_range() throws Exception {
- Constraint testSubject;
- List<Object> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getIn_range();
- }
-
-
- @Test
- public void testGetLength() throws Exception {
- Constraint testSubject;
- Object result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getLength();
- }
-
-
- @Test
- public void testGetMin_length() throws Exception {
- Constraint testSubject;
- Object result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getMin_length();
- }
-
-
- @Test
- public void testGetMax_length() throws Exception {
- Constraint testSubject;
- Object result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getMax_length();
- }
-
-
- @Test
- public void testSetvalid_values() throws Exception {
- Constraint testSubject;
- List<Object> vlist = null;
-
- // default test
- testSubject = createTestSubject();
- testSubject.setvalid_values(vlist);
- }
-
-
- @Test
- public void testSetEqual() throws Exception {
- Constraint testSubject;
- Object e = null;
-
- // default test
- testSubject = createTestSubject();
- testSubject.setEqual(e);
- }
-
-
- @Test
- public void testSetGreater_than() throws Exception {
- Constraint testSubject;
- Object e = null;
-
- // default test
- testSubject = createTestSubject();
- testSubject.setGreater_than(e);
- }
-
-
- @Test
- public void testSetLess_than() throws Exception {
- Constraint testSubject;
- Object e = null;
-
- // default test
- testSubject = createTestSubject();
- testSubject.setLess_than(e);
- }
-
-
- @Test
- public void testSetIn_range() throws Exception {
- Constraint testSubject;
- List<Object> e = null;
-
- // default test
- testSubject = createTestSubject();
- testSubject.setIn_range(e);
- }
-
-
- @Test
- public void testSetLength() throws Exception {
- Constraint testSubject;
- Object e = null;
-
- // default test
- testSubject = createTestSubject();
- testSubject.setLength(e);
- }
-
-
- @Test
- public void testSetMin_length() throws Exception {
- Constraint testSubject;
- Object e = null;
-
- // default test
- testSubject = createTestSubject();
- testSubject.setMin_length(e);
- }
-
-
- @Test
- public void testSetMax_length() throws Exception {
- Constraint testSubject;
- Object e = null;
-
- // default test
- testSubject = createTestSubject();
- testSubject.setMax_length(e);
- }
-
-
- @Test
- public void testToString() throws Exception {
- Constraint testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.toString();
- }
-} \ No newline at end of file
diff --git a/vid-app-common/src/test/java/org/onap/vid/asdc/beans/tosca/PropertyTest.java b/vid-app-common/src/test/java/org/onap/vid/asdc/beans/tosca/PropertyTest.java
index e638b518d..cb68eac92 100644
--- a/vid-app-common/src/test/java/org/onap/vid/asdc/beans/tosca/PropertyTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/asdc/beans/tosca/PropertyTest.java
@@ -38,15 +38,6 @@ public class PropertyTest {
result = testSubject.getEntry_schema();
}
- @Test
- public void testGet_default() throws Exception {
- Property testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.get_default();
- }
@Test
public void testSetType() throws Exception {
@@ -78,15 +69,6 @@ public class PropertyTest {
testSubject.setEntry_schema(entry_schema);
}
- @Test
- public void testSet_default() throws Exception {
- Property testSubject;
- String _default = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.set_default(_default);
- }
@Test
public void testGetDefault() throws Exception {
diff --git a/vid-app-common/src/test/java/org/onap/vid/asdc/beans/tosca/RequirementTest.java b/vid-app-common/src/test/java/org/onap/vid/asdc/beans/tosca/RequirementTest.java
deleted file mode 100644
index ae5ff5293..000000000
--- a/vid-app-common/src/test/java/org/onap/vid/asdc/beans/tosca/RequirementTest.java
+++ /dev/null
@@ -1,92 +0,0 @@
-package org.onap.vid.asdc.beans.tosca;
-
-import java.util.Collection;
-
-import org.junit.Test;
-
-public class RequirementTest {
-
- private Requirement createTestSubject() {
- return new Requirement();
- }
-
- @Test
- public void testGetOccurrences() throws Exception {
- Requirement testSubject;
- Collection<String> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getOccurrences();
- }
-
- @Test
- public void testGetCapability() throws Exception {
- Requirement testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getCapability();
- }
-
- @Test
- public void testGetNode() throws Exception {
- Requirement testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getNode();
- }
-
- @Test
- public void testGetRelationship() throws Exception {
- Requirement testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getRelationship();
- }
-
- @Test
- public void testSetOccurrences() throws Exception {
- Requirement testSubject;
- Collection<String> occurrences = null;
-
- // default test
- testSubject = createTestSubject();
- testSubject.setOccurrences(occurrences);
- }
-
- @Test
- public void testSetCapability() throws Exception {
- Requirement testSubject;
- String capability = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setCapability(capability);
- }
-
- @Test
- public void testSetNode() throws Exception {
- Requirement testSubject;
- String node = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setNode(node);
- }
-
- @Test
- public void testSetRelationship() throws Exception {
- Requirement testSubject;
- String relationship = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setRelationship(relationship);
- }
-} \ No newline at end of file
diff --git a/vid-app-common/src/test/java/org/onap/vid/asdc/parser/ToscaParserImpl2Test.java b/vid-app-common/src/test/java/org/onap/vid/asdc/parser/ToscaParserImpl2Test.java
index 9f572feb7..1282a6f78 100644
--- a/vid-app-common/src/test/java/org/onap/vid/asdc/parser/ToscaParserImpl2Test.java
+++ b/vid-app-common/src/test/java/org/onap/vid/asdc/parser/ToscaParserImpl2Test.java
@@ -1,56 +1,288 @@
package org.onap.vid.asdc.parser;
import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.google.common.collect.ImmutableList;
+import net.javacrumbs.jsonunit.JsonAssert;
+import org.apache.commons.io.IOUtils;
import org.apache.log4j.Logger;
-import org.junit.Assert;
-import org.onap.vid.controllers.WebConfig;
-import org.onap.vid.model.VfModule;
-import org.onap.vid.model.VolumeGroup;
-import org.onap.vid.properties.AsdcClientConfiguration;
-import org.onap.portalsdk.core.util.SystemProperties;
+import org.json.JSONObject;
+import org.json.JSONTokener;
import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
import org.onap.sdc.toscaparser.api.Group;
import org.onap.sdc.toscaparser.api.NodeTemplate;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
-import org.springframework.test.context.web.WebAppConfiguration;
-import org.springframework.web.context.WebApplicationContext;
-import org.testng.annotations.BeforeMethod;
+import org.onap.vid.asdc.AsdcCatalogException;
+import org.onap.vid.asdc.AsdcClient;
+import org.onap.vid.asdc.local.LocalAsdcClient;
+import org.onap.vid.model.*;
+import org.onap.vid.controllers.ToscaParserMockHelper;
+import org.testng.Assert;
+import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.Map;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Path;
+import java.util.*;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.onap.vid.testUtils.TestUtils.assertJsonStringEqualsIgnoreNulls;
@Test
-@ContextConfiguration(classes = { WebConfig.class, AsdcClientConfiguration.class, SystemProperties.class })
-@WebAppConfiguration
-public class ToscaParserImpl2Test extends AbstractTestNGSpringContextTests {
+public class ToscaParserImpl2Test {
private final String myUUID = "myUUID";
private static final Logger log = Logger.getLogger(ToscaParserImpl2Test.class);
- @Autowired
- private ToscaParserImpl2 toscaParserImpl2;
+ private ToscaParserImpl2 toscaParserImpl2 = new ToscaParserImpl2();
+
+ private AsdcClient asdcClient;
+ private ObjectMapper om = new ObjectMapper();
+
+ @BeforeClass
+ void init() throws IOException {
+
+ final InputStream asdcServicesFile = this.getClass().getClassLoader().getResourceAsStream("sdcservices.json");
+
+ final JSONTokener jsonTokener = new JSONTokener(IOUtils.toString(asdcServicesFile));
+ final JSONObject sdcServicesCatalog = new JSONObject(jsonTokener);
+
+ asdcClient = new LocalAsdcClient.Builder().catalog(sdcServicesCatalog).build();
+
+ }
+
+ //@Test
+ public void assertEqualsBetweenServices() throws Exception {
+ for (ToscaParserMockHelper mockHelper : getExpectedServiceModel()) {
+ Service expectedService = mockHelper.getNewServiceModel().getService();
+ Service actualService = toscaParserImpl2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getService();
+ assertJsonStringEqualsIgnoreNulls(om.writeValueAsString(expectedService), om.writeValueAsString(actualService));
+ }
+ }
+
+ //@Test
+ public void assertEqualBetweenObjects() throws Exception {
+ for (ToscaParserMockHelper mockHelper : getExpectedServiceModel()) {
+ final Path csarPath = getCsarPath(mockHelper.getUuid());
+ System.out.println("Comparing for csar " + csarPath);
+ ServiceModel actualServiceModel = toscaParserImpl2.makeServiceModel(csarPath, getServiceByUuid(mockHelper.getUuid()));
+ assertJsonStringEqualsIgnoreNulls(om.writeValueAsString(mockHelper.getNewServiceModel()), om.writeValueAsString(actualServiceModel));
+ }
+ }
+
+ //@Test
+ public void assertEqualsBetweenNetworkNodes() throws Exception {
+ for (ToscaParserMockHelper mockHelper : getExpectedServiceModel()) {
+ Map<String, Network> expectedNetworksMap = mockHelper.getNewServiceModel().getNetworks();
+ Map<String, Network> actualNetworksMap = toscaParserImpl2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getNetworks();
+ for (Map.Entry<String, Network> entry : expectedNetworksMap.entrySet()) {
+ Network expectedNetwork = entry.getValue();
+ Network actualNetwork = actualNetworksMap.get(entry.getKey());
+ Assert.assertEquals(expectedNetwork.getModelCustomizationName(), actualNetwork.getModelCustomizationName());
+ verifyBaseNodeProperties(expectedNetwork, actualNetwork);
+ compareProperties(expectedNetwork.getProperties(), actualNetwork.getProperties());
+ }
+ }
+ }
+
+ //Because we are not supporting the old flow, the JSON are different by definition.
+ //@Test
+ public void assertEqualsBetweenVnfsOfTosca() throws Exception {
+ for (ToscaParserMockHelper mockHelper : getExpectedServiceModel()) {
+ Map<String, VNF> expectedVnfsMap = mockHelper.getNewServiceModel().getVnfs();
+ Map<String, VNF> actualVnfsMap = toscaParserImpl2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getVnfs();
+ for (Map.Entry<String, VNF> entry : expectedVnfsMap.entrySet()) {
+ VNF expectedVnf = entry.getValue();
+ VNF actualVnf = actualVnfsMap.get(entry.getKey());
+ verifyBaseNodeProperties(expectedVnf, actualVnf);
+ Assert.assertEquals(expectedVnf.getModelCustomizationName(), actualVnf.getModelCustomizationName());
+ compareProperties(expectedVnf.getProperties(), actualVnf.getProperties());
+ assertJsonStringEqualsIgnoreNulls(om.writeValueAsString(expectedVnf), om.writeValueAsString(actualVnf));
+ }
+ }
+ }
+
+ //@Test
+ public void assertEqualsBetweenCollectionResourcesOfTosca() throws Exception {
+ for (ToscaParserMockHelper mockHelper : getExpectedServiceModel()) {
+ Map<String, CR> expectedVnfsMap = mockHelper.getNewServiceModel().getCollectionResource();
+ Map<String, CR> actualCRsMap = toscaParserImpl2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getCollectionResource();
+ if(!actualCRsMap.isEmpty()) {
+ for (Map.Entry<String, CR> entry : expectedVnfsMap.entrySet()) {
+ CR expectedCR = entry.getValue();
+ CR actualCR = actualCRsMap.get(entry.getKey());
+ verifyCollectionResource(expectedCR, actualCR);
+ Assert.assertEquals(expectedCR.getName(), actualCR.getName());
+ compareProperties(expectedCR.getProperties(), actualCR.getProperties());
+ assertJsonStringEqualsIgnoreNulls(om.writeValueAsString(expectedCR), om.writeValueAsString(actualCR));
+ }
+ }
+ }
+ }
+
+ private void verifyCollectionResource(CR expectedCR, CR actualCR) {
+ verifyBaseNodeProperties(expectedCR, actualCR);
+ Assert.assertEquals(expectedCR.getCategory(), actualCR.getCategory());
+ Assert.assertEquals(expectedCR.getSubcategory(), actualCR.getSubcategory());
+ Assert.assertEquals(expectedCR.getResourceVendor(), actualCR.getResourceVendor());
+ Assert.assertEquals(expectedCR.getResourceVendorRelease(), actualCR.getResourceVendorRelease());
+ Assert.assertEquals(expectedCR.getResourceVendorModelNumber(), actualCR.getResourceVendorModelNumber());
+ Assert.assertEquals(expectedCR.getCustomizationUUID(), actualCR.getCustomizationUUID());
+ verifyNetworkCollections(expectedCR.getNetworksCollection(), actualCR.getNetworksCollection());
+ }
+
+ private void verifyNetworkCollections(Map<String, NetworkCollection> expectedNetworksCollection, Map<String, NetworkCollection> actualNetworksCollection) {
+ for (Map.Entry<String, NetworkCollection> property : expectedNetworksCollection.entrySet()) {
+ NetworkCollection expectedValue = property.getValue();
+ String key = property.getKey();
+ NetworkCollection actualValue = actualNetworksCollection.get(key);
+ verifyNetworkCollection(expectedValue, actualValue);
+ }
+ }
+
+ private void verifyNetworkCollection(NetworkCollection expectedValue, NetworkCollection actualValue) {
+ Assert.assertEquals(expectedValue.getInvariantUuid(), actualValue.getInvariantUuid());
+ Assert.assertEquals(expectedValue.getName(), actualValue.getName());
+ Assert.assertEquals(expectedValue.getUuid(), actualValue.getUuid());
+ Assert.assertEquals(expectedValue.getVersion(), actualValue.getVersion());
+ Assert.assertEquals(expectedValue.getNetworkCollectionProperties().getNetworkCollectionDescription(), actualValue.getNetworkCollectionProperties().getNetworkCollectionDescription());
+ Assert.assertEquals(expectedValue.getNetworkCollectionProperties().getNetworkCollectionFunction(), actualValue.getNetworkCollectionProperties().getNetworkCollectionFunction());
+ }
+
+
+ //@Test
+ public void assertEqualsBetweenVolumeGroups() throws Exception {
+ for (ToscaParserMockHelper mockHelper : getExpectedServiceModel()) {
+ Map<String, VolumeGroup> actualVolumeGroups = toscaParserImpl2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getVolumeGroups();
+ Map<String, VolumeGroup> expectedVolumeGroups = mockHelper.getNewServiceModel().getVolumeGroups();
+ assertJsonStringEqualsIgnoreNulls(om.writeValueAsString(expectedVolumeGroups), om.writeValueAsString(actualVolumeGroups));
+ }
+ }
+
+ //@Test
+ public void assertEqualsBetweenVfModules() throws Exception {
+ for (ToscaParserMockHelper mockHelper : getExpectedServiceModel()) {
+ Map<String, VfModule> actualVfModules = toscaParserImpl2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getVfModules();
+ Map<String, VfModule> expectedVfModules = mockHelper.getNewServiceModel().getVfModules();
+ assertJsonStringEqualsIgnoreNulls(om.writeValueAsString(expectedVfModules), om.writeValueAsString(actualVfModules));
+ }
+ }
+
+ //@Test
+ public void assertEqualsBetweenPolicyConfigurationNodes() throws Exception {
+ for (ToscaParserMockHelper mockHelper : getExpectedServiceModel()) {
+ Map<String, PortMirroringConfig> actualConfigurations = toscaParserImpl2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getConfigurations();
+ Map<String, PortMirroringConfig> expectedConfigurations = mockHelper.getNewServiceModel().getConfigurations();
+ JsonAssert.assertJsonEquals(actualConfigurations, expectedConfigurations);
+ }
+ }
+ //@Test
+ public void assertEqualsBetweenPolicyConfigurationByPolicyFalse() throws Exception {
+ ToscaParserMockHelper mockHelper = new ToscaParserMockHelper(Constants.configurationByPolicyFalseUuid, Constants.configurationByPolicyFalseFilePath);
+ InputStream jsonFile = this.getClass().getClassLoader().getResourceAsStream(mockHelper.getFilePath());
+ String expectedJsonAsString = IOUtils.toString(jsonFile, StandardCharsets.UTF_8.name());
+ NewServiceModel newServiceModel1 = om.readValue(expectedJsonAsString, NewServiceModel.class);
+ mockHelper.setNewServiceModel(newServiceModel1);
+ Map<String, PortMirroringConfig> expectedConfigurations = mockHelper.getNewServiceModel().getConfigurations();
+ Map<String, PortMirroringConfig> actualConfigurations = toscaParserImpl2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getConfigurations();
+
+ setPprobeServiceProxy(expectedConfigurations);
+
+ JsonAssert.assertJsonEquals(expectedConfigurations, actualConfigurations);
+ }
+
+ private void setPprobeServiceProxy(Map<String, PortMirroringConfig> expectedConfigurations){
+ //Port Mirroring Configuration By Policy 0 doesn't contains pProbe.
+ // But due to sdc design if pProbe not exists parser expects to get it from other source.
+ // In a follow implementation provided the expected pProbe.
+ PortMirroringConfig pmconfig = expectedConfigurations.get("Port Mirroring Configuration By Policy 0");
+ pmconfig.setCollectorNodes(new ArrayList<>(Arrays.asList("pprobeservice_proxy 4")));
+
+ }
+ //@Test
+ public void assertEqualsBetweenServiceProxyNodes() throws Exception {
+ for (ToscaParserMockHelper mockHelper : getExpectedServiceModel()) {
+ Map<String, ServiceProxy> actualServiceProxies = toscaParserImpl2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getServiceProxies();
+ Map<String, ServiceProxy> expectedServiceProxies = mockHelper.getNewServiceModel().getServiceProxies();
+ JsonAssert.assertJsonEquals(actualServiceProxies, expectedServiceProxies);
+ }
+ }
+
+ private void verifyBaseNodeProperties(Node expectedNode, Node actualNode) {
+ Assert.assertEquals(expectedNode.getName(), actualNode.getName());
+ Assert.assertEquals(expectedNode.getCustomizationUuid(), actualNode.getCustomizationUuid());
+ Assert.assertEquals(expectedNode.getDescription(), actualNode.getDescription());
+ Assert.assertEquals(expectedNode.getInvariantUuid(), actualNode.getInvariantUuid());
+ Assert.assertEquals(expectedNode.getUuid(), actualNode.getUuid());
+ Assert.assertEquals(expectedNode.getVersion(), actualNode.getVersion());
+ }
+
+ private void compareProperties(Map<String, String> expectedProperties, Map<String, String> actualProperties) {
+ for (Map.Entry<String, String> property : expectedProperties.entrySet()) {
+ String expectedValue = property.getValue();
+ String key = property.getKey();
+ String actualValue = actualProperties.get(key);
+ Assert.assertEquals(expectedValue, actualValue);
+ }
+ }
+
+ private ToscaParserMockHelper[] getExpectedServiceModel() throws IOException {
+ ToscaParserMockHelper[] mockHelpers = {
+ new ToscaParserMockHelper(Constants.vlUuid, Constants.vlFilePath),
+ new ToscaParserMockHelper(Constants.vfUuid, Constants.vfFilePath),
+ new ToscaParserMockHelper(Constants.crUuid, Constants.crFilePath),
+ new ToscaParserMockHelper(Constants.vfWithAnnotationUuid, Constants.vfWithAnnotationFilePath),
+ new ToscaParserMockHelper(Constants.vfWithVfcGroup, Constants.vfWithVfcGroupFilePath),
+ new ToscaParserMockHelper(Constants.configurationUuid, Constants.configurationFilePath)
+ };
+ for (ToscaParserMockHelper mockHelper : mockHelpers) {
+ InputStream jsonFile = this.getClass().getClassLoader().getResourceAsStream(mockHelper.getFilePath());
+ System.out.println(jsonFile);
+ String expectedJsonAsString = IOUtils.toString(jsonFile, StandardCharsets.UTF_8.name());
+ NewServiceModel newServiceModel1 = om.readValue(expectedJsonAsString, NewServiceModel.class);
+ mockHelper.setNewServiceModel(newServiceModel1);
+ }
+ return mockHelpers;
+ }
+
+
+ private Path getCsarPath(String uuid) throws AsdcCatalogException {
+ return asdcClient.getServiceToscaModel(UUID.fromString(uuid));
+ }
+
+ private org.onap.vid.asdc.beans.Service getServiceByUuid(String uuid) throws AsdcCatalogException {
+ return asdcClient.getService(UUID.fromString(uuid));
+ }
+
+ public class Constants {
+ public static final String configurationUuid = "ee6d61be-4841-4f98-8f23-5de9da846ca7";
+ public static final String configurationFilePath = "policy-configuration-csar.JSON";
+ static final String vfUuid = "48a52540-8772-4368-9cdb-1f124ea5c931";
+ static final String vfWithAnnotationUuid = "f4d84bb4-a416-4b4e-997e-0059973630b9";
+ static final String vlUuid = "cb49608f-5a24-4789-b0f7-2595473cb997";
+ static final String crUuid = "76f27dfe-33e5-472f-8e0b-acf524adc4f0";
+ static final String vfWithVfcGroup = "6bce7302-70bd-4057-b48e-8d5b99e686ca";
+ // public static final String PNFUuid = "68101369-6f08-4e99-9a28-fa6327d344f3";
+ static final String vfFilePath = "vf-csar.JSON";
+ static final String vlFilePath = "vl-csar.JSON";
+ static final String crFilePath = "cr-csar.JSON";
+ static final String vfWithAnnotationFilePath = "vf-with-annotation-csar.json";
+ static final String vfWithVfcGroupFilePath = "vf-with-vfcInstanceGroups.json";
+ public static final String configurationByPolicyFalseUuid = "ee6d61be-4841-4f98-8f23-5de9da845544";
+ public static final String configurationByPolicyFalseFilePath = "policy-configuration-by-policy-false.JSON";
- @Autowired
- private WebApplicationContext wac;
- @BeforeMethod
- private void verifyWiring() {
- Assert.assertNotNull(wac);
- Assert.assertNotNull(toscaParserImpl2);
}
+
+
@Test
- public void testGetNFModuleFromVf() throws Exception {
+ public void testGetNFModuleFromVf() {
ISdcCsarHelper csarHelper = getMockedSdcCsarHelper();
Map<String, VfModule> vfModulesFromVF = toscaParserImpl2.getVfModulesFromVF(csarHelper, myUUID);
@@ -60,12 +292,10 @@ public class ToscaParserImpl2Test extends AbstractTestNGSpringContextTests {
hasKey("withoutVol"),
hasKey("withVol")
));
-
- verify(csarHelper, only()).getVfModulesByVf(anyString());
}
@Test
- public void testGetVolumeGroupsFromVF() throws Exception {
+ public void testGetVolumeGroupsFromVF() {
ISdcCsarHelper csarHelper = getMockedSdcCsarHelper();
Map<String, VolumeGroup> volumeGroupsFromVF = toscaParserImpl2.getVolumeGroupsFromVF(csarHelper, myUUID);
@@ -74,15 +304,11 @@ public class ToscaParserImpl2Test extends AbstractTestNGSpringContextTests {
aMapWithSize(1),
hasKey("withVol")
));
-
- verify(csarHelper, only()).getVfModulesByVf(anyString());
}
private ISdcCsarHelper getMockedSdcCsarHelper() {
ISdcCsarHelper csarHelper = mock(ISdcCsarHelper.class);
-// ThreadLocalsHolder.setCollector(new ExceptionCollector("c:\\temp\\foo"));
-
Group withVol = createMinimalGroup("withVol", true);
Group withoutVol = createMinimalGroup("withoutVol", false);
@@ -115,11 +341,8 @@ public class ToscaParserImpl2Test extends AbstractTestNGSpringContextTests {
customDef = new LinkedHashMap<>();
vfModule = addNewNamedMap(customDef, "org.onap.groups.VfModule");
vfModuleProperties = addNewNamedMap(vfModule, "properties");
-// vfModule.put("derived_from", "tosca.groups.Root");
-// vfModule.put("description", "Grouped all heat resources which are in the same VF Module");
volumeGroup = addNewNamedMap(vfModuleProperties, "volume_group");
-// volumeGroup.put("description", "volume_group");
volumeGroup.put("type", "boolean");
volumeGroup.put("default", false);
volumeGroup.put("required", true);
diff --git a/vid-app-common/src/test/java/org/onap/vid/asdc/rest/RestfulAsdcClientTest.java b/vid-app-common/src/test/java/org/onap/vid/asdc/rest/RestfulAsdcClientTest.java
index c1833bb75..75b84b2db 100644
--- a/vid-app-common/src/test/java/org/onap/vid/asdc/rest/RestfulAsdcClientTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/asdc/rest/RestfulAsdcClientTest.java
@@ -1,225 +1,69 @@
package org.onap.vid.asdc.rest;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.Collection;
-import java.util.Map;
-import java.util.Properties;
-import java.util.UUID;
+import org.apache.commons.lang3.exception.ExceptionUtils;
+import org.onap.vid.testUtils.TestUtils;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
-import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.SSLSession;
+import javax.ws.rs.NotFoundException;
+import javax.ws.rs.ProcessingException;
import javax.ws.rs.client.Client;
-import javax.ws.rs.client.ClientBuilder;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.vid.asdc.AsdcCatalogException;
-import org.onap.vid.asdc.beans.Artifact;
-import org.onap.vid.asdc.beans.Resource;
-import org.onap.vid.asdc.beans.Service;
+import java.net.URI;
+import java.util.UUID;
+import java.util.function.Consumer;
-import nu.xom.Builder;
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.when;
+import static org.testng.AssertJUnit.fail;
public class RestfulAsdcClientTest {
- private RestfulAsdcClient createTestSubject() {
- return new RestfulAsdcClient.Builder(restClient, uri).auth(auth)
- .build();
+ @DataProvider
+ public static Object[][] javaxExceptions() {
+
+ return new Object[][] {
+ {NotFoundException.class, (Consumer<Client>) javaxClientMock ->
+ when(javaxClientMock.target(any(URI.class))).thenThrow(
+ new NotFoundException("HTTP 404 Not Found"))},
+ {ProcessingException.class, (Consumer<Client>) javaxClientMock ->
+ when(javaxClientMock.target(any(URI.class))).thenThrow(
+ new ProcessingException("java.net.ConnectException: Connection refused: connect"))},
+ };
}
- /** The rest client. */
- private Client restClient;
-
- /** The uri. */
- private URI uri;
-
- /** The properties. */
- private Properties properties;
-
- /** The auth. */
- private String auth;
-
- /**
- * Sets the up.
- *
- * @throws URISyntaxException
- * the URI syntax exception
- * @throws IOException
- * Signals that an I/O exception has occurred.
- */
- @Before
- public void setUp() throws URISyntaxException, IOException {
- final InputStream propertiesFile = getClass().getClassLoader()
- .getResourceAsStream("asdc.properties");
- properties = new Properties();
- properties.load(propertiesFile);
+ @Test(dataProvider = "javaxExceptions")
+ public void whenJavaxClientThrowException_thenExceptionRethrown(Class<? extends Throwable> expectedType, Consumer<Client> setupMocks) throws Exception {
+ /*
+ Call chain is like:
+ this test -> RestfulAsdcClient -> javax's Client
- final String protocol = properties.getProperty("protocol", "http");
+ In this test, *RestfulAsdcClient* is under test (actual implementation is used), while javax's Client is
+ mocked to return pseudo-responses or - better - throw exceptions.
+ */
- restClient = ClientBuilder.newBuilder()
- .hostnameVerifier(new HostnameVerifier() {
+ // prepare mocks
+ TestUtils.JavaxRsClientMocks mocks = new TestUtils.JavaxRsClientMocks();
+ Client javaxClientMock = mocks.getFakeClient();
- @Override
- public boolean verify(String arg0, SSLSession arg1) {
- return true;
- }
- })
+ // prepare real RestfulAsdcClient (Under test)
+ RestfulAsdcClient restfulAsdcClient = new RestfulAsdcClient.Builder(javaxClientMock, new URI(""))
+ .auth("")
.build();
- uri = new URI(protocol + "://" + properties.getProperty("host", "localhost") + ":"
- + properties.getProperty("port", "80") + "/");
- auth = properties.getProperty("auth");
- }
-
- @Test
- public void testGetResource() throws Exception {
- RestfulAsdcClient testSubject;
- UUID uuid = UUID.fromString("123e4567-e89b-12d3-a456-556642440000");
- Resource result;
-
- // default test
- testSubject = createTestSubject();
- try {
- result = testSubject.getResource(uuid);
- } catch (Exception e) {
-
- }
- }
-
- @Test
- public void testGetResourceArtifact() throws Exception {
- RestfulAsdcClient testSubject;
- UUID resourceUuid = UUID.fromString("123e4567-e89b-12d3-a456-556642440000");
- UUID artifactUuid = UUID.fromString("123e4567-e89b-12d3-a456-556642440000");
- Artifact result;
-
- // default test
- testSubject = createTestSubject();
- try {
- result = testSubject.getResourceArtifact(resourceUuid, artifactUuid);
- } catch (Exception e) {
-
- }
- }
-
- @Test
- public void testGetResources() throws Exception {
- RestfulAsdcClient testSubject;
- Collection<Resource> result;
-
- // default test
- testSubject = createTestSubject();
- try {
- result = testSubject.getResources();
- } catch (Exception e) {
-
- }
- }
-
- @Test
- public void testGetResources_1() throws Exception {
- RestfulAsdcClient testSubject;
- Map<String, String[]> filter = null;
- Collection<Resource> result;
-
- // default test
- testSubject = createTestSubject();
- try {
- result = testSubject.getResources(filter);
- } catch (Exception e) {
-
- }
- }
-
- @Test
- public void testGetResourceToscaModel() throws Exception {
- RestfulAsdcClient testSubject;
- UUID resourceUuid = UUID.fromString("123e4567-e89b-12d3-a456-556642440000");
-
- // default test
- testSubject = createTestSubject();
- try {
- testSubject.getResourceToscaModel(resourceUuid);
- } catch (Exception e) {
- }
- }
+ /// TEST:
+ setupMocks.accept(javaxClientMock);
- @Test
- public void testGetService() throws Exception {
- RestfulAsdcClient testSubject;
- UUID uuid = UUID.fromString("123e4567-e89b-12d3-a456-556642440000");
- Service result;
-
- // default test
- testSubject = createTestSubject();
try {
- result = testSubject.getService(uuid);
+ restfulAsdcClient.getServiceToscaModel(UUID.randomUUID());
} catch (Exception e) {
-
+ assertThat("root cause incorrect for " + ExceptionUtils.getStackTrace(e), ExceptionUtils.getRootCause(e), instanceOf(expectedType));
+ return; //OK
}
- }
-
- @Test
- public void testGetServiceArtifact() throws Exception {
- RestfulAsdcClient testSubject;
- UUID serviceUuid = UUID.fromString("123e4567-e89b-12d3-a456-556642440000");
- UUID artifactUuid = UUID.fromString("123e4567-e89b-12d3-a456-556642440000");
- Artifact result;
-
- // default test
- testSubject = createTestSubject();
- try {
- result = testSubject.getServiceArtifact(serviceUuid, artifactUuid);
- } catch (Exception e) {
-
- }
- }
-
- @Test
- public void testGetServices() throws Exception {
- RestfulAsdcClient testSubject;
- Collection<Service> result;
- // default test
- testSubject = createTestSubject();
- try {
- result = testSubject.getServices();
- } catch (Exception e) {
-
- }
- }
-
- @Test
- public void testGetServices_1() throws Exception {
- RestfulAsdcClient testSubject;
- Map<String, String[]> filter = null;
- Collection<Service> result;
-
- // default test
- testSubject = createTestSubject();
- try {
- result = testSubject.getServices(filter);
- } catch (Exception e) {
-
- }
- }
-
- @Test
- public void testGetServiceToscaModel() throws Exception {
- RestfulAsdcClient testSubject;
- UUID serviceUuid = UUID.fromString("123e4567-e89b-12d3-a456-556642440000");
-
- // default test
- testSubject = createTestSubject();
- try {
- testSubject.getServiceToscaModel(serviceUuid);
- } catch (Exception e) {
-
- }
+ fail("exception shall rethrown by getServiceToscaModel once javax client throw exception ");
}
-} \ No newline at end of file
+}