aboutsummaryrefslogtreecommitdiffstats
path: root/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/imports
diff options
context:
space:
mode:
Diffstat (limited to 'test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/imports')
-rw-r--r--test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/CsarUtilsTest.java460
-rw-r--r--test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/ExportToscaTest.java458
-rw-r--r--test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/ImportCsarResourceTest.java1751
-rw-r--r--test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/ImportGenericResourceCITest.java600
-rw-r--r--test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/ImportNewResourceCITest.java1529
-rw-r--r--test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/ImportToscaCapabilitiesWithProperties.java416
-rw-r--r--test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/ImportToscaResourceTest.java2896
-rw-r--r--test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/ImportUpdateResourseCsarTest.java283
8 files changed, 8393 insertions, 0 deletions
diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/CsarUtilsTest.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/CsarUtilsTest.java
new file mode 100644
index 0000000000..650ed619b7
--- /dev/null
+++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/CsarUtilsTest.java
@@ -0,0 +1,460 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * 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.openecomp.sdc.ci.tests.execute.imports;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Map;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.io.FileUtils;
+import org.junit.Rule;
+import org.junit.rules.TestName;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.ArtifactUiDownloadData;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
+import org.openecomp.sdc.ci.tests.datatypes.enums.ArtifactTypeEnum;
+import org.openecomp.sdc.ci.tests.datatypes.enums.LifeCycleStatesEnum;
+import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
+import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
+import org.openecomp.sdc.ci.tests.utils.general.AtomicOperationUtils;
+import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
+import org.openecomp.sdc.ci.tests.utils.rest.ArtifactRestUtils;
+import org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils;
+import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
+import org.openecomp.sdc.common.util.YamlToObjectConverter;
+import org.testng.annotations.Test;
+import org.yaml.snakeyaml.Yaml;
+
+public class CsarUtilsTest extends ComponentBaseTest {
+
+ public static final String ASSET_TOSCA_TEMPLATE = "assettoscatemplate";
+
+ @Rule
+ public static TestName name = new TestName();
+
+ public CsarUtilsTest() {
+ super(name, CsarUtilsTest.class.getName());
+ }
+
+ @Test(enabled = true)
+ public void createServiceCsarBasicTest() throws Exception {
+
+ Service service = AtomicOperationUtils.createDefaultService(UserRoleEnum.DESIGNER, true).left().value();
+
+ Resource resourceVF = AtomicOperationUtils.createResourceByType(ResourceTypeEnum.VF, UserRoleEnum.DESIGNER, true).left().value();
+
+ AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.VENDOR_LICENSE, resourceVF, UserRoleEnum.DESIGNER,
+ true, true);
+ resourceVF = (Resource) AtomicOperationUtils
+ .changeComponentState(resourceVF, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
+
+ AtomicOperationUtils.addComponentInstanceToComponentContainer(resourceVF, service, UserRoleEnum.DESIGNER, true);
+
+ service = (Service) AtomicOperationUtils.changeComponentState(service, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
+
+ User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
+
+ byte[] downloadCSAR = downloadCSAR(sdncModifierDetails, service);
+
+ csarBasicValidation(service, downloadCSAR);
+ }
+
+ @Test(enabled = true)
+ public void createResourceCsarBasicTest() throws Exception {
+
+ Resource resourceVF = AtomicOperationUtils.createResourceByType(ResourceTypeEnum.VF, UserRoleEnum.DESIGNER, true).left().value();
+ resourceVF = (Resource) AtomicOperationUtils
+ .changeComponentState(resourceVF, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
+ User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
+
+ byte[] downloadCSAR = downloadCSAR(sdncModifierDetails, resourceVF);
+
+ csarBasicValidation(resourceVF, downloadCSAR);
+ }
+
+ @Test(enabled = true)
+ public void createServiceCsarInclDeploymentArtTest() throws Exception {
+
+ Service service = AtomicOperationUtils.createDefaultService(UserRoleEnum.DESIGNER, true).left().value();
+
+ Resource resourceVF1 = AtomicOperationUtils.createResourceByType(ResourceTypeEnum.VF, UserRoleEnum.DESIGNER, true).left().value();
+ Resource resourceVF2 = AtomicOperationUtils.createResourceByType(ResourceTypeEnum.VF, UserRoleEnum.DESIGNER, true).left().value();
+
+ resourceVF1 = (Resource) AtomicOperationUtils
+ .changeComponentState(resourceVF1, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
+
+ resourceVF2 = (Resource) AtomicOperationUtils
+ .changeComponentState(resourceVF2, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
+
+ AtomicOperationUtils.addComponentInstanceToComponentContainer(resourceVF1, service, UserRoleEnum.DESIGNER, true);
+ AtomicOperationUtils.addComponentInstanceToComponentContainer(resourceVF2, service, UserRoleEnum.DESIGNER, true);
+
+ AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.YANG_XML, service, UserRoleEnum.DESIGNER, true, true);
+
+ service = (Service) AtomicOperationUtils.changeComponentState(service, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
+
+ User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
+
+ byte[] downloadCSAR = downloadCSAR(sdncModifierDetails, service);
+
+ csarBasicValidation(service, downloadCSAR);
+
+ validateServiceCsar(resourceVF1, resourceVF2, service, downloadCSAR, 3, 5, 1);
+ }
+
+ @Test(enabled = true)
+ public void createResourceCsarInclDeploymentArtTest() throws Exception {
+
+ Resource resourceVF1 = AtomicOperationUtils.createResourceByType(ResourceTypeEnum.VF, UserRoleEnum.DESIGNER, true).left().value();
+
+ AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.YANG_XML, resourceVF1, UserRoleEnum.DESIGNER, true, true);
+ AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.HEAT_ARTIFACT, resourceVF1, UserRoleEnum.DESIGNER, true, true);
+
+ resourceVF1 = (Resource) AtomicOperationUtils
+ .changeComponentState(resourceVF1, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
+
+ User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
+
+ byte[] downloadCSAR = downloadCSAR(sdncModifierDetails, resourceVF1);
+
+ csarBasicValidation(resourceVF1, downloadCSAR);
+
+ validateVFCsar(resourceVF1, downloadCSAR, 1, 0, 1, 1);
+ }
+
+ private void csarBasicValidation(Component mainComponent, byte[] downloadCSAR) {
+ try (ByteArrayInputStream ins = new ByteArrayInputStream(downloadCSAR);
+ ZipInputStream zip = new ZipInputStream(ins);) {
+
+ String resourceYaml = null;
+ byte[] buffer = new byte[1024];
+ ZipEntry nextEntry = zip.getNextEntry();
+ StringBuffer sb = new StringBuffer();
+ int len;
+
+ while ((len = zip.read(buffer)) > 0) {
+ sb.append(new String(buffer, 0, len));
+ }
+
+ assertTrue(nextEntry.getName().equals("TOSCA-Metadata/TOSCA.meta"));
+
+ sb.setLength(0);
+ nextEntry = zip.getNextEntry();
+
+ while ((len = zip.read(buffer)) > 0) {
+ sb.append(new String(buffer, 0, len));
+ }
+
+ resourceYaml = sb.toString();
+
+ YamlToObjectConverter yamlToObjectConverter = new YamlToObjectConverter();
+ ArtifactDefinition artifactDefinition = mainComponent.getToscaArtifacts()
+ .get(ASSET_TOSCA_TEMPLATE);
+ String fileName = artifactDefinition.getArtifactName();
+ assertEquals("Tosca-Template file name: ", "Definitions/" + fileName, nextEntry.getName());
+ assertTrue("Tosca template Yaml validation: ", yamlToObjectConverter.isValidYaml(resourceYaml.getBytes()));
+
+ ins.close();
+ zip.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private void validateServiceCsar(Component certifiedVFC1, Component certifiedVFC2, Service fetchedService,
+ byte[] resultByte, int toscaEntryIndexToPass, int generatorEntryIndexToPass,
+ int deploymentArtifactIndexToPass) {
+
+ // TODO Test to validate everything is right (comment out after testing)
+ /*try {
+ FileUtils.writeByteArrayToFile(new File("c:/TestCSAR/" + fetchedService.getName() + ".zip"), resultByte);
+ } catch (IOException e) {
+ // Auto-generated catch block
+ e.printStackTrace();
+ }*/
+
+ try (ByteArrayInputStream ins = new ByteArrayInputStream(resultByte);
+ ZipInputStream zip = new ZipInputStream(ins);) {
+
+ String resourceYaml = null;
+ byte[] buffer = new byte[1024];
+ ZipEntry nextEntry = zip.getNextEntry();
+ StringBuffer sb = new StringBuffer();
+ int len;
+
+ while ((len = zip.read(buffer)) > 0) {
+ sb.append(new String(buffer, 0, len));
+ }
+
+ assertTrue(nextEntry.getName().equals("TOSCA-Metadata/TOSCA.meta"));
+
+ YamlToObjectConverter yamlToObjectConverter = new YamlToObjectConverter();
+
+ int toscaEntryIndex = 0;
+ int generatorEntryIndex = 0;
+ int deploymentArtifactIndex = 0;
+ String fileName = null;
+ ArtifactDefinition artifactDefinition;
+ Component componentToValidate = null;
+
+ artifactDefinition = fetchedService.getToscaArtifacts().get(ASSET_TOSCA_TEMPLATE);
+ String serviceFileName = artifactDefinition.getArtifactName();
+ artifactDefinition = certifiedVFC1.getToscaArtifacts().get(ASSET_TOSCA_TEMPLATE);
+ String vfc1FileName = artifactDefinition.getArtifactName();
+ artifactDefinition = certifiedVFC2.getToscaArtifacts().get(ASSET_TOSCA_TEMPLATE);
+ String vfc2FileName = artifactDefinition.getArtifactName();
+
+ while ((nextEntry = zip.getNextEntry()) != null) {
+ sb.setLength(0);
+
+ while ((len = zip.read(buffer)) > 0) {
+ sb.append(new String(buffer, 0, len));
+ }
+
+ String entryName = nextEntry.getName();
+
+ resourceYaml = sb.toString();
+ if (entryName.contains(serviceFileName)) {
+ componentToValidate = fetchedService;
+ fileName = "Definitions/" + serviceFileName;
+
+ assertEquals("Validate entry Name", (fileName), nextEntry.getName());
+ assertTrue(yamlToObjectConverter.isValidYaml(resourceYaml.getBytes()));
+ validateContent(resourceYaml, componentToValidate);
+ ++toscaEntryIndex;
+ continue;
+ }
+
+ if (entryName.contains(vfc1FileName)) {
+ componentToValidate = certifiedVFC1;
+ fileName = "Definitions/" + vfc1FileName;
+
+ assertEquals("Validate entry Name", (fileName), nextEntry.getName());
+ assertTrue(yamlToObjectConverter.isValidYaml(resourceYaml.getBytes()));
+ validateContent(resourceYaml, componentToValidate);
+ ++toscaEntryIndex;
+ continue;
+ }
+ if (entryName.contains(vfc2FileName)) {
+ componentToValidate = certifiedVFC2;
+ fileName = "Definitions/" + vfc2FileName;
+
+ assertEquals("Validate entry Name", (fileName), nextEntry.getName());
+ assertTrue(yamlToObjectConverter.isValidYaml(resourceYaml.getBytes()));
+ validateContent(resourceYaml, componentToValidate);
+ ++toscaEntryIndex;
+ continue;
+ }
+
+ if (entryName.contains(".xml") && !entryName.startsWith("Artifacts/AAI")) {
+ ++deploymentArtifactIndex;
+ continue;
+ }
+
+ if (entryName.startsWith("Artifacts/AAI")) {
+ ++generatorEntryIndex;
+ continue;
+ }
+
+ assertTrue("Unexpected entry: " + entryName, true);
+ }
+ assertEquals("Validate amount of entries", toscaEntryIndexToPass, toscaEntryIndex);
+ assertEquals("Validate amount of generated AAI artifacts", generatorEntryIndexToPass, generatorEntryIndex);
+ assertEquals("Validate amount of generated Deployment artifacts", deploymentArtifactIndexToPass,
+ deploymentArtifactIndex);
+
+ ins.close();
+ zip.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private void validateVFCsar(Component certifiedVF, byte[] resultByte, int toscaEntryIndexToPass, int ymlDeploymentArtifactIndexToPass,
+ int xmlDeploymentArtifactIndexToPass, int heatEnvDeploymentArtifactIndexToPass) {
+
+ // TODO Test to validate everything is right (comment out after testing)
+ /*try {
+ FileUtils.writeByteArrayToFile(new File("c:/TestCSAR/" + fetchedService.getName() + ".zip"), resultByte);
+ } catch (IOException e) {
+ // Auto-generated catch block
+ e.printStackTrace();
+ }*/
+
+ try (ByteArrayInputStream ins = new ByteArrayInputStream(resultByte);
+ ZipInputStream zip = new ZipInputStream(ins);) {
+
+ String resourceYaml = null;
+ byte[] buffer = new byte[1024];
+ ZipEntry nextEntry = zip.getNextEntry();
+ StringBuffer sb = new StringBuffer();
+ int len;
+
+ while ((len = zip.read(buffer)) > 0) {
+ sb.append(new String(buffer, 0, len));
+ }
+
+ assertTrue(nextEntry.getName().equals("TOSCA-Metadata/TOSCA.meta"));
+
+ YamlToObjectConverter yamlToObjectConverter = new YamlToObjectConverter();
+
+ int toscaEntryIndex = 0;
+ int ymlEntryIndex = 0;
+ int xmlArtifactsIndex = 0;
+ int heatEnvDeploymentArtifactIndex = 0;
+ String fileName = null;
+ ArtifactDefinition artifactDefinition;
+ Component componentToValidate = null;
+
+ artifactDefinition = certifiedVF.getToscaArtifacts().get(ASSET_TOSCA_TEMPLATE);
+ String vfFileName = artifactDefinition.getArtifactName();
+
+ while ((nextEntry = zip.getNextEntry()) != null) {
+ sb.setLength(0);
+
+ while ((len = zip.read(buffer)) > 0) {
+ sb.append(new String(buffer, 0, len));
+ }
+
+ String entryName = nextEntry.getName();
+
+ resourceYaml = sb.toString();
+ if (entryName.contains(vfFileName)) {
+ componentToValidate = certifiedVF;
+ fileName = "Definitions/" + vfFileName;
+
+ assertEquals("Validate entry Name", (fileName), nextEntry.getName());
+ assertTrue(yamlToObjectConverter.isValidYaml(resourceYaml.getBytes()));
+ validateContent(resourceYaml, componentToValidate);
+ ++toscaEntryIndex;
+ continue;
+ }
+
+ if (entryName.contains(".xml") && entryName.startsWith("Artifacts/")) {
+ ++xmlArtifactsIndex;
+ continue;
+ }
+
+ if (entryName.contains(".sh") && entryName.startsWith("Artifacts/")) {
+ ++heatEnvDeploymentArtifactIndex;
+ continue;
+ }
+
+ if (entryName.contains(".yml") && entryName.startsWith("Artifacts/")) {
+ ++ymlEntryIndex;
+ continue;
+ }
+
+ assertTrue("Unexpected entry: " + entryName, false);
+ }
+ assertEquals("Validate amount of entries", toscaEntryIndexToPass, toscaEntryIndex);
+ assertEquals("Validate amount of YAML artifacts", ymlDeploymentArtifactIndexToPass, ymlEntryIndex);
+ assertEquals("Validate amount of generated XML artifacts", xmlDeploymentArtifactIndexToPass,
+ xmlArtifactsIndex);
+ assertEquals("Validate amount of generated HEAT ENV artifacts", heatEnvDeploymentArtifactIndexToPass,
+ heatEnvDeploymentArtifactIndex);
+
+ ins.close();
+ zip.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private void validateContent(String content, Component component) {
+ Yaml yaml = new Yaml();
+
+ InputStream inputStream = new ByteArrayInputStream(content.getBytes());
+ @SuppressWarnings("unchecked")
+ Map<String, Object> load = (Map<String, Object>) yaml.load(inputStream);
+ @SuppressWarnings("unchecked")
+ Map<String, Object> metadata = (Map<String, Object>) load.get("metadata");
+ assertNotNull(metadata);
+
+ String name = (String) metadata.get("name");
+ assertNotNull(name);
+ assertEquals("Validate component name", component.getName(), name);
+
+ String invariantUUID = (String) metadata.get("invariantUUID");
+ assertNotNull(invariantUUID);
+ assertEquals("Validate component invariantUUID", component.getInvariantUUID(), invariantUUID);
+
+ String UUID = (String) metadata.get("UUID");
+ assertNotNull(UUID);
+ assertEquals("Validate component invariantUUID", component.getUUID(), UUID);
+
+ String type = (String) metadata.get("type");
+ assertNotNull(type);
+ if (component.getComponentType().equals(ComponentTypeEnum.SERVICE)) {
+ assertEquals("Validate component type", component.getComponentType().getValue(), type);
+ } else {
+ assertEquals("Validate component type", ((Resource) component).getResourceType(),
+ ResourceTypeEnum.valueOf(type));
+ }
+ }
+
+ private byte[] downloadCSAR(User sdncModifierDetails, Component createdComponent) throws Exception {
+
+ String artifactUniqeId = createdComponent.getToscaArtifacts().get("assettoscacsar").getUniqueId();
+ RestResponse getCsarResponse = null;
+
+ switch (createdComponent.getComponentType()) {
+ case RESOURCE:
+ getCsarResponse = ArtifactRestUtils.downloadResourceArtifactInternalApi(createdComponent.getUniqueId(),
+ sdncModifierDetails, artifactUniqeId);
+ break;
+ case SERVICE:
+ getCsarResponse = ArtifactRestUtils.downloadServiceArtifactInternalApi(createdComponent.getUniqueId(),
+ sdncModifierDetails, artifactUniqeId);
+ break;
+ default:
+ break;
+ }
+
+ assertNotNull(getCsarResponse);
+ BaseRestUtils.checkSuccess(getCsarResponse);
+
+ ArtifactUiDownloadData artifactUiDownloadData = ResponseParser.parseToObject(getCsarResponse.getResponse(),
+ ArtifactUiDownloadData.class);
+
+ assertNotNull(artifactUiDownloadData);
+
+ byte[] fromUiDownload = artifactUiDownloadData.getBase64Contents().getBytes();
+ byte[] decodeBase64 = Base64.decodeBase64(fromUiDownload);
+
+ return decodeBase64;
+ }
+}
diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/ExportToscaTest.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/ExportToscaTest.java
new file mode 100644
index 0000000000..163504fbb0
--- /dev/null
+++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/ExportToscaTest.java
@@ -0,0 +1,458 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * 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.openecomp.sdc.ci.tests.execute.imports;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import org.apache.commons.codec.binary.Base64;
+import org.junit.Rule;
+import org.junit.rules.TestName;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.ArtifactUiDownloadData;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstInputsMap;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentInstanceInput;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.GroupDefinition;
+import org.openecomp.sdc.be.model.InputDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
+import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
+import org.openecomp.sdc.ci.tests.datatypes.ComponentInstanceReqDetails;
+import org.openecomp.sdc.ci.tests.datatypes.ImportReqDetails;
+import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails;
+import org.openecomp.sdc.ci.tests.datatypes.enums.ArtifactTypeEnum;
+import org.openecomp.sdc.ci.tests.datatypes.enums.LifeCycleStatesEnum;
+import org.openecomp.sdc.ci.tests.datatypes.enums.ServiceCategoriesEnum;
+import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
+import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
+import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
+import org.openecomp.sdc.ci.tests.utils.rest.ArtifactRestUtils;
+import org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils;
+import org.openecomp.sdc.ci.tests.utils.rest.ComponentInstanceRestUtils;
+import org.openecomp.sdc.ci.tests.utils.rest.InputsRestUtils;
+import org.openecomp.sdc.ci.tests.utils.rest.LifecycleRestUtils;
+import org.openecomp.sdc.ci.tests.utils.rest.ResourceRestUtils;
+import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
+import org.openecomp.sdc.ci.tests.utils.rest.ServiceRestUtils;
+import org.openecomp.sdc.ci.tests.utils.validation.BaseValidationUtils;
+import org.openecomp.sdc.common.api.Constants;
+import org.testng.annotations.Test;
+import org.yaml.snakeyaml.Yaml;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonParser;
+import com.google.gson.reflect.TypeToken;
+
+public class ExportToscaTest extends ComponentBaseTest {
+ @Rule
+ public static TestName name = new TestName();
+
+ public ExportToscaTest() {
+ super(name, ExportToscaTest.class.getName());
+ }
+
+ @Test(enabled = true)
+ public void exportVfModuleTest() throws Exception {
+ User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
+
+ Resource createdResource = createVfFromCSAR(sdncModifierDetails, "VSPPackage");
+
+ Map<String, Object> load = downloadAndParseToscaTemplate(sdncModifierDetails, createdResource);
+ assertNotNull(load);
+ Map<String, Object> topology_template = (Map<String, Object>) load.get("topology_template");
+ assertNotNull(topology_template);
+ Map<String, Object> groups = (Map<String, Object>) topology_template.get("groups");
+ assertNotNull(groups);
+ List<GroupDefinition> groupsOrigin = createdResource.getGroups();
+
+ assertEquals("Validate groups size", groupsOrigin.size(), groups.size());
+ for (GroupDefinition group : groupsOrigin) {
+ Map<String, Object> groupTosca = (Map<String, Object>) groups.get(group.getName());
+ assertNotNull(groupTosca);
+
+ Map<String, Object> metadata = (Map<String, Object>) groupTosca.get("metadata");
+ assertNotNull(metadata);
+
+ String invariantUUID;
+ String name;
+ String UUID;
+ String version;
+ Map<String, Object> properties = (Map<String, Object>) groupTosca.get("properties");
+
+ if (group.getType().equals(Constants.DEFAULT_GROUP_VF_MODULE)) {
+ invariantUUID = (String) metadata.get("vfModuleModelInvariantUUID");
+ name = (String) metadata.get("vfModuleModelName");
+ UUID = (String) metadata.get("vfModuleModelUUID");
+ version = (String) metadata.get("vfModuleModelVersion");
+ assertNotNull(properties);
+
+ String vf_module_type = (String) properties.get("vf_module_type");
+ List<PropertyDataDefinition> props = group.getProperties();
+ for (PropertyDataDefinition prop : props) {
+ if (prop.getName().equals(Constants.IS_BASE)) {
+ String value = prop.getValue() == null ? prop.getDefaultValue() : prop.getValue();
+ boolean bvalue = Boolean.parseBoolean(value);
+ if (bvalue) {
+ assertEquals("Validate vf_module_type", "Base", vf_module_type);
+ } else {
+ assertEquals("Validate vf_module_type", "Expansion", vf_module_type);
+ }
+ break;
+ }
+ }
+ String vf_module_description = (String) properties.get("vf_module_description");
+ assertEquals("Validate vf_module_description", group.getDescription(), vf_module_description);
+
+ Boolean volume_group = (Boolean) properties.get("volume_group");
+ boolean isVolume = false;
+ List<String> artifactsList = group.getArtifacts();
+ List<ArtifactDefinition> artifacts = new ArrayList<>();
+ if (artifactsList != null && !artifactsList.isEmpty()) {
+ ArtifactDefinition masterArtifact = findMasterArtifact(createdResource.getDeploymentArtifacts(),
+ artifacts, artifactsList);
+ if (masterArtifact.getArtifactType().equalsIgnoreCase(ArtifactTypeEnum.HEAT_VOL.getType())) {
+ isVolume = true;
+ }
+ }
+ assertEquals("Validate volume_group", isVolume, volume_group);
+
+ } else {
+ invariantUUID = (String) metadata.get("invariantUUID");
+ name = (String) metadata.get("name");
+ UUID = (String) metadata.get("UUID");
+ version = (String) metadata.get("version");
+ assertNull(properties);
+
+ }
+ assertEquals("Validate InvariantUUID", group.getInvariantUUID(), invariantUUID);
+ assertEquals("Validate name", group.getName(), name);
+ assertEquals("Validate UUID", group.getGroupUUID(), UUID);
+ assertEquals("Validate version", group.getVersion(), version);
+
+ }
+ }
+
+ @Test(enabled = true)
+ public void exportCsarInputsTest() throws Exception {
+ User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
+
+ Resource createdResource = createVfFromCSAR(sdncModifierDetails, "csar_1");
+ Map<String, Object> load = downloadAndParseToscaTemplate(sdncModifierDetails, createdResource);
+ assertNotNull(load);
+
+ Map<String, Object> topology_template = (Map<String, Object>) load.get("topology_template");
+ assertNotNull(topology_template);
+
+ Map<String, Object> inputs = (Map<String, Object>) topology_template.get("inputs");
+ assertNotNull(inputs);
+
+ List<InputDefinition> inputsFromResource = createdResource.getInputs();
+ assertEquals("validate inputs size", inputsFromResource.size(), inputs.size());
+ for (InputDefinition inputDef : inputsFromResource) {
+ Map<String, Object> inputInFile = (Map<String, Object>) inputs.get(inputDef.getName());
+ assertNotNull(inputInFile);
+ validateInput(inputDef, inputInFile);
+ }
+ List<ComponentInstance> componentInstances = createdResource.getComponentInstances();
+ Map<String, List<ComponentInstanceProperty>> componentInstancesProperties = createdResource
+ .getComponentInstancesProperties();
+ Map<String, Object> node_templates = (Map<String, Object>) topology_template.get("node_templates");
+ assertNotNull(node_templates);
+
+ JsonParser jsonParser = new JsonParser();
+
+ for (Map.Entry<String, List<ComponentInstanceProperty>> entry : componentInstancesProperties.entrySet()) {
+
+ Optional<ComponentInstance> findFirst = componentInstances.stream()
+ .filter(ci -> ci.getUniqueId().equals(entry.getKey())).findFirst();
+ assertTrue(findFirst.isPresent());
+ String resourceName = findFirst.get().getName();
+ Map<String, Object> instance = (Map<String, Object>) node_templates.get(resourceName);
+ assertNotNull(instance);
+ Map<String, Object> properties = (Map<String, Object>) instance.get("properties");
+
+ for (ComponentInstanceProperty cip : entry.getValue()) {
+ if (cip.getValueUniqueUid() != null && !cip.getValueUniqueUid().isEmpty()) {
+ assertNotNull(properties);
+ if (cip.getValue().contains("get_input")) {
+ Object prop = properties.get(cip.getName());
+ assertNotNull(prop);
+
+ Gson gson = new Gson();
+ String json = gson.toJson(prop);
+ assertEquals("validate json property", cip.getValue(), json);
+ }
+
+ }
+ }
+
+ }
+
+ }
+
+ @Test
+ public void importExportCsarWithJsonPropertyType() throws Exception {
+ User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
+ String payloadName = "jsonPropertyTypeTest.csar";
+ ImportReqDetails resourceDetails = ElementFactory.getDefaultImportResource();
+ String rootPath = System.getProperty("user.dir");
+ Path path = null;
+ byte[] data = null;
+ String payloadData = null;
+ path = Paths.get(rootPath + "/src/test/resources/CI/csars/jsonPropertyTypeTest.csar");
+ data = Files.readAllBytes(path);
+ payloadData = Base64.encodeBase64String(data);
+ resourceDetails.setPayloadData(payloadData);
+ resourceDetails.setCsarUUID(payloadName);
+ resourceDetails.setPayloadName(payloadName);
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, sdncModifierDetails);
+ BaseRestUtils.checkCreateResponse(createResource);
+ Resource resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
+ ComponentInstance pmaaServer = resource.getComponentInstances().stream()
+ .filter(p -> p.getName().equals("pmaa_server_0")).findAny().get();
+ ComponentInstanceProperty jsonProp = resource.getComponentInstancesProperties().get(pmaaServer.getUniqueId())
+ .stream().filter(p -> p.getType().equals(ToscaPropertyType.JSON.getType())).findAny().get();
+ String jsonValue = "{\"pmaa.sb_nic\":{\"address\":{\"get_input\":\"pmaa_dpu_fixed_ip\"},\"cidr\":{\"get_input\":\"pmaa_dpu_cidr\"},\"gateway\":{\"get_input\":\"pmaa_dpu_gateway\"}}}";
+ assertEquals(jsonProp.getValue(), jsonValue);
+ // download and compare
+ Map<String, Object> load = downloadAndParseToscaTemplate(sdncModifierDetails, resource);
+ assertNotNull(load);
+ Map<String, Object> topology_template = (Map<String, Object>) load.get("topology_template");
+ assertNotNull(topology_template);
+ Map<String, Object> nodes = (Map<String, Object>) topology_template.get("node_templates");
+ assertNotNull(nodes);
+ Map<String, Object> pmaaServerObj = (Map<String, Object>) nodes.get("pmaa_server_0");
+ assertNotNull(pmaaServerObj);
+ Map<String, Object> props = (Map<String, Object>) pmaaServerObj.get("properties");
+ assertNotNull(props);
+ Map<String, Object> jsonPropObj = (Map<String, Object>) props.get("metadata");
+ assertNotNull(jsonPropObj);
+ Gson gson = new Gson();
+ String json = gson.toJson(jsonPropObj);
+ assertEquals(json, jsonValue);
+ }
+
+ @Test(enabled = true)
+ public void exportServiceInputValue() throws Exception {
+ //1 create vf as certified
+ User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
+
+ Resource createdResource = createVfFromCSAR(sdncModifierDetails, "csar_1");
+ RestResponse checkinState = LifecycleRestUtils.changeComponentState(createdResource, sdncModifierDetails, LifeCycleStatesEnum.CHECKIN);
+ BaseRestUtils.checkSuccess(checkinState);
+ ServiceReqDetails serviceDetails = ElementFactory.getDefaultService("ciNewtestservice1", ServiceCategoriesEnum.MOBILITY, sdncModifierDetails.getUserId());
+
+ //2 create service
+ RestResponse createServiceResponse = ServiceRestUtils.createService(serviceDetails, sdncModifierDetails);
+ ResourceRestUtils.checkCreateResponse(createServiceResponse);
+ Service service = ResponseParser.parseToObjectUsingMapper(createServiceResponse.getResponse(), Service.class);
+
+ //3 create vf instance in service
+ ComponentInstanceReqDetails componentInstanceDetails = ElementFactory.getComponentInstance(createdResource);
+ RestResponse createComponentInstance = ComponentInstanceRestUtils.createComponentInstance(componentInstanceDetails, sdncModifierDetails, service);
+ ResourceRestUtils.checkCreateResponse(createComponentInstance);
+
+ RestResponse getService = ServiceRestUtils.getService(service.getUniqueId());
+ BaseRestUtils.checkSuccess(getService);
+ service = ResponseParser.parseToObjectUsingMapper(getService.getResponse(), Service.class);
+
+ //4 download tosca template
+ Map<String, Object> tosca = downloadAndParseToscaTemplate(sdncModifierDetails, service);
+ assertNotNull(tosca);
+ Map<String, Object> topology_template = (Map<String, Object>) tosca.get("topology_template");
+ assertNotNull(topology_template);
+
+ //5 validate no inputs in service
+ Map<String, Object> inputs = (Map<String, Object>) tosca.get("inputs");
+ assertNull(inputs);
+
+ List<ComponentInstance> componentInstances = service.getComponentInstances();
+ assertNotNull(componentInstances);
+ assertEquals(1, componentInstances.size());
+ ComponentInstance vfi = componentInstances.get(0);
+
+ //6 add instance inputs in service
+ RestResponse getComponentInstanceInputsResponse = InputsRestUtils.getComponentInstanceInputs(service, vfi);
+ BaseValidationUtils.checkSuccess(getComponentInstanceInputsResponse);
+ List<InputDefinition> instanceInputs = new Gson().fromJson(getComponentInstanceInputsResponse.getResponse(), new TypeToken<ArrayList<InputDefinition>>(){}.getType());
+ // Take only the 2 first inputs
+ List<InputDefinition> inputsToAdd = instanceInputs.stream().limit(2).collect(Collectors.toList());
+
+ //7 Build component instances input map to add to server
+ ComponentInstInputsMap buildComponentInstInputsMap = buildComponentInstInputsMap(vfi.getUniqueId(), inputsToAdd);
+ RestResponse addInputResponse = InputsRestUtils.addInput(service, buildComponentInstInputsMap, UserRoleEnum.DESIGNER);
+ BaseValidationUtils.checkSuccess(addInputResponse);
+
+ //8 validate inputs in service
+ //8.1 download tosca template
+ getService = ServiceRestUtils.getService(service.getUniqueId());
+ BaseRestUtils.checkSuccess(getService);
+ service = ResponseParser.parseToObjectUsingMapper(getService.getResponse(), Service.class);
+
+ tosca = downloadAndParseToscaTemplate(sdncModifierDetails, service);
+ assertNotNull(tosca);
+ topology_template = (Map<String, Object>) tosca.get("topology_template");
+ assertNotNull(topology_template);
+
+ //8.2 validate inputs in service
+ inputs = (Map<String, Object>) topology_template.get("inputs");
+ assertNotNull(inputs);
+ assertEquals(2, inputs.size());
+
+ //validate created inputs vs inputs in Tosca inputs section
+ final Map<String, Object> inputsFinal = inputs;
+ buildComponentInstInputsMap.getComponentInstanceInputsMap().values().forEach(listPerInstance ->{
+ listPerInstance.forEach(input ->{
+ Map<String, Object> inputInMap = (Map<String, Object>)inputsFinal.get(input.getName());
+ assertNotNull(inputInMap);
+ });
+ });
+ Map<String, List<ComponentInstanceInput>> componentInstancesInputs = service.getComponentInstancesInputs();
+
+ //validate created inputs vs inputs in Tosca instance input value
+ List<ComponentInstanceInput> vfiInputs = componentInstancesInputs.get(vfi.getUniqueId());
+ assertNotNull(vfiInputs);
+ assertEquals(2, vfiInputs.size());
+
+ Map<String, Object> node_templates = (Map<String, Object>) topology_template.get("node_templates");
+ assertNotNull(node_templates);
+
+ Map<String, Object> instance = (Map<String, Object>) node_templates.get(vfi.getName());
+ assertNotNull(instance);
+ Map<String, Object> properties = (Map<String, Object>)instance.get("properties");
+ assertNotNull(properties);
+
+ vfiInputs.forEach(vfiInput ->{
+ Map<String, Object> inputPropValueInTosca = (Map<String, Object>)properties.get(vfiInput.getName() );
+ assertNotNull(inputPropValueInTosca);
+ String instaneInputName = (String)inputPropValueInTosca.get("get_input");
+ assertNotNull(instaneInputName);
+ Map<String, Object> inputInMap = (Map<String, Object>)inputsFinal.get(instaneInputName);
+ assertNotNull(inputInMap);
+ });
+
+
+ }
+
+
+ // ----------------------------------------
+ private void validateInput(InputDefinition inputDef, Map<String, Object> inputInFile) {
+ assertEquals("validate input type", inputDef.getType(), (String) inputInFile.get("type"));
+
+ if (inputDef.getDefaultValue() == null) {
+ assertNull(inputInFile.get("default"));
+ } else {
+ assertNotNull(inputInFile.get("default"));
+ String value = inputDef.getDefaultValue().replace("\"", "");
+ value = value.replace(" ", "");
+ String expValue = inputInFile.get("default").toString().replace(" ", "");
+ assertEquals("validate input default", value, expValue);
+ }
+ assertEquals("validate input description", inputDef.getDescription(), (String) inputInFile.get("description"));
+ }
+
+ private Map<String, Object> downloadAndParseToscaTemplate(User sdncModifierDetails, Component createdComponent)
+ throws Exception {
+ String artifactUniqeId = createdComponent.getToscaArtifacts().get("assettoscatemplate").getUniqueId();
+ RestResponse toscaTemplate;
+
+ if ( createdComponent.getComponentType() == ComponentTypeEnum.RESOURCE ){
+ toscaTemplate = ArtifactRestUtils.downloadResourceArtifactInternalApi(
+ createdComponent.getUniqueId(), sdncModifierDetails, artifactUniqeId);
+
+ }else{
+ toscaTemplate = ArtifactRestUtils.downloadServiceArtifactInternalApi(
+ createdComponent.getUniqueId(), sdncModifierDetails, artifactUniqeId);
+ }
+ BaseRestUtils.checkSuccess(toscaTemplate);
+
+ ArtifactUiDownloadData artifactUiDownloadData = ResponseParser.parseToObject(toscaTemplate.getResponse(),
+ ArtifactUiDownloadData.class);
+ byte[] fromUiDownload = artifactUiDownloadData.getBase64Contents().getBytes();
+ byte[] decodeBase64 = Base64.decodeBase64(fromUiDownload);
+ Yaml yaml = new Yaml();
+
+ InputStream inputStream = new ByteArrayInputStream(decodeBase64);
+
+ Map<String, Object> load = (Map<String, Object>) yaml.load(inputStream);
+ return load;
+ }
+
+
+ public ArtifactDefinition findMasterArtifact(Map<String, ArtifactDefinition> deplymentArtifact,
+ List<ArtifactDefinition> artifacts, List<String> artifactsList) {
+ for (String artifactUid : artifactsList) {
+ for (Entry<String, ArtifactDefinition> entry : deplymentArtifact.entrySet()) {
+ ArtifactDefinition artifact = entry.getValue();
+ if (artifactUid.equalsIgnoreCase(artifact.getUniqueId())) {
+ artifacts.add(artifact);
+ }
+
+ }
+ }
+ ArtifactDefinition masterArtifact = null;
+ for (ArtifactDefinition artifactInfo : artifacts) {
+ String atrifactType = artifactInfo.getArtifactType();
+ if (atrifactType.equalsIgnoreCase(ArtifactTypeEnum.HEAT_VOL.getType())
+ || atrifactType.equalsIgnoreCase(ArtifactTypeEnum.HEAT_NET.getType())) {
+ masterArtifact = artifactInfo;
+ continue;
+ }
+ if (atrifactType.equalsIgnoreCase(ArtifactTypeEnum.HEAT.getType())) {
+ masterArtifact = artifactInfo;
+ break;
+ }
+ }
+ return masterArtifact;
+ }
+ private ComponentInstInputsMap buildComponentInstInputsMap (String addToInput, List<InputDefinition> inputs) {
+ Map<String, List<InputDefinition>> map = new HashMap<>();
+ map.put(addToInput, inputs);
+ ComponentInstInputsMap componentInstInputsMap = new ComponentInstInputsMap();
+ componentInstInputsMap.setComponentInstanceInputsMap(map);
+ return componentInstInputsMap;
+ }
+
+}
diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/ImportCsarResourceTest.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/ImportCsarResourceTest.java
new file mode 100644
index 0000000000..1b559aaaad
--- /dev/null
+++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/ImportCsarResourceTest.java
@@ -0,0 +1,1751 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * 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.openecomp.sdc.ci.tests.execute.imports;
+
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertNotNull;
+import static org.testng.AssertJUnit.assertTrue;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.lang.WordUtils;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.apache.tinkerpop.gremlin.process.traversal.P;
+import org.junit.Rule;
+import org.junit.rules.TestName;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.CapabilityDefinition;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.GroupDefinition;
+import org.openecomp.sdc.be.model.GroupProperty;
+import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
+import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
+import org.openecomp.sdc.ci.tests.api.Urls;
+import org.openecomp.sdc.ci.tests.config.Config;
+import org.openecomp.sdc.ci.tests.datatypes.ArtifactReqDetails;
+import org.openecomp.sdc.ci.tests.datatypes.ComponentInstanceReqDetails;
+import org.openecomp.sdc.ci.tests.datatypes.ImportReqDetails;
+import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
+import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails;
+import org.openecomp.sdc.ci.tests.datatypes.enums.LifeCycleStatesEnum;
+import org.openecomp.sdc.ci.tests.datatypes.enums.ServiceCategoriesEnum;
+import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
+import org.openecomp.sdc.ci.tests.datatypes.http.HttpHeaderEnum;
+import org.openecomp.sdc.ci.tests.datatypes.http.HttpRequest;
+import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
+import org.openecomp.sdc.ci.tests.utils.Utils;
+import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
+import org.openecomp.sdc.ci.tests.utils.rest.ArtifactRestUtils;
+import org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils;
+import org.openecomp.sdc.ci.tests.utils.rest.ComponentInstanceRestUtils;
+import org.openecomp.sdc.ci.tests.utils.rest.GroupRestUtils;
+import org.openecomp.sdc.ci.tests.utils.rest.ImportRestUtils;
+import org.openecomp.sdc.ci.tests.utils.rest.LifecycleRestUtils;
+import org.openecomp.sdc.ci.tests.utils.rest.ResourceRestUtils;
+import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
+import org.openecomp.sdc.ci.tests.utils.rest.ServiceRestUtils;
+import org.openecomp.sdc.ci.tests.utils.validation.ErrorValidationUtils;
+import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
+import org.openecomp.sdc.common.util.ValidationUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.Test;
+
+import com.google.gson.Gson;
+
+public class ImportCsarResourceTest extends ComponentBaseTest {
+ private static Logger log = LoggerFactory.getLogger(ImportCsarResourceTest.class.getName());
+ @Rule
+ public static TestName name = new TestName();
+
+ Gson gson = new Gson();
+
+ public ImportCsarResourceTest() {
+ super(name, ImportCsarResourceTest.class.getName());
+ }
+
+ private String buildAssertMessage(String expectedString, String actualString) {
+ return String.format("expected is : %s , actual is: %s", expectedString, actualString);
+ }
+
+ /**
+ *
+ * User Story : US640615 [BE] - Extend create VF API with Import TOSCA CSAR
+ */
+
+ @Test(enabled = true)
+ public void createResourceFromCsarHappy() throws Exception {
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setCsarUUID("AF7F231969C5463F9C968570070E8877");
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ BaseRestUtils.checkCreateResponse(createResource);
+ Resource resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
+ assertEquals(5, resource.getComponentInstances().size());
+
+ String expectedCsarUUID = resourceDetails.getCsarUUID();
+ String expectedToscaResourceName = "org.openecomp.resource.vf." + WordUtils.capitalize(resourceDetails.getName().toLowerCase());
+
+ assertTrue("csarUUID : " + buildAssertMessage(expectedCsarUUID, resource.getCsarUUID()), expectedCsarUUID.equals(resource.getCsarUUID()));
+ assertTrue("toscaResourceName : " + buildAssertMessage(expectedToscaResourceName, resource.getToscaResourceName()), expectedToscaResourceName.equals(resource.getToscaResourceName()));
+
+ RestResponse getResourceResponse = ResourceRestUtils.getResource(resource.getUniqueId());
+ Resource getResource = ResponseParser.parseToObjectUsingMapper(getResourceResponse.getResponse(), Resource.class);
+ assertTrue("csarUUID : " + buildAssertMessage(expectedCsarUUID, getResource.getCsarUUID()), expectedCsarUUID.equals(getResource.getCsarUUID()));
+ assertTrue("toscaResourceName : " + buildAssertMessage(expectedToscaResourceName, getResource.getToscaResourceName()), expectedToscaResourceName.equals(getResource.getToscaResourceName()));
+ }
+
+ @Test(enabled = true)
+ public void emptyStringInCsarUUIDFieldTest() throws Exception {
+ String emptyString = "";
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setCsarUUID(emptyString);
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ BaseRestUtils.checkCreateResponse(createResource);
+ Resource resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
+ assertEquals(null, resource.getComponentInstances());
+
+ String expectedToscaResourceName = "org.openecomp.resource.vf." + WordUtils.capitalize(resourceDetails.getName().toLowerCase());
+
+ assertTrue("csarUUID : " + buildAssertMessage(emptyString, resource.getCsarUUID()), resource.getCsarUUID() == emptyString);
+ assertTrue("toscaResourceName : " + buildAssertMessage(expectedToscaResourceName, resource.getToscaResourceName()), expectedToscaResourceName.equals(resource.getToscaResourceName()));
+
+ RestResponse getResourceResponse = ResourceRestUtils.getResource(resource.getUniqueId());
+ Resource getResource = ResponseParser.parseToObjectUsingMapper(getResourceResponse.getResponse(), Resource.class);
+ assertTrue("csarUUID : " + buildAssertMessage(emptyString, getResource.getCsarUUID()), getResource.getCsarUUID() == emptyString);
+ assertTrue("toscaResourceName : " + buildAssertMessage(expectedToscaResourceName, getResource.getToscaResourceName()), expectedToscaResourceName.equals(getResource.getToscaResourceName()));
+ }
+
+ @Test(enabled = true)
+ public void createResourceFromScratchTest() throws Exception {
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ BaseRestUtils.checkCreateResponse(createResource);
+ Resource resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
+ assertEquals(null, resource.getComponentInstances());
+
+ String expectedToscaResourceName = "org.openecomp.resource.vf." + WordUtils.capitalize(resourceDetails.getName().toLowerCase());
+
+ assertTrue("csarUUID : " + buildAssertMessage(null, resource.getCsarUUID()), resource.getCsarUUID() == null);
+ assertTrue("toscaResourceName : " + buildAssertMessage(expectedToscaResourceName, resource.getToscaResourceName()), expectedToscaResourceName.equals(resource.getToscaResourceName()));
+
+ RestResponse getResourceResponse = ResourceRestUtils.getResource(resource.getUniqueId());
+ Resource getResource = ResponseParser.parseToObjectUsingMapper(getResourceResponse.getResponse(), Resource.class);
+ assertTrue("csarUUID : " + buildAssertMessage(null, getResource.getCsarUUID()), getResource.getCsarUUID() == null);
+ assertTrue("toscaResourceName : " + buildAssertMessage(expectedToscaResourceName, getResource.getToscaResourceName()), expectedToscaResourceName.equals(getResource.getToscaResourceName()));
+ }
+
+ @Test(enabled = true)
+ public void fileNotCsarTypeTest() throws Exception {
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ resourceDetails.setCsarUUID("valid_vf_zip");
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ List<String> variables = new ArrayList<String>();
+ variables.add(resourceDetails.getCsarUUID());
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.CSAR_NOT_FOUND.name(), variables, createResource.getResponse());
+ }
+
+ @Test(enabled = true)
+ public void missingToscaMetadataFolderTest() throws Exception {
+
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ resourceDetails.setCsarUUID("toscaFolderNotExists");
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ List<String> variables = new ArrayList<String>();
+ variables.add(resourceDetails.getCsarUUID());
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.CSAR_INVALID.name(), variables, createResource.getResponse());
+ }
+
+ @Test(enabled = true)
+ public void missingToscaMetaFileTest() throws Exception {
+
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ resourceDetails.setCsarUUID("toscaMetaFileNotExists");
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ List<String> variables = new ArrayList<String>();
+ variables.add(resourceDetails.getCsarUUID());
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.CSAR_INVALID.name(), variables, createResource.getResponse());
+ }
+
+ @Test(enabled = true)
+ public void toscaMetaFileOutsideTheFolderTest() throws Exception {
+
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ resourceDetails.setCsarUUID("toscaMetaOutsideTheFolder");
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ List<String> variables = new ArrayList<String>();
+ variables.add(resourceDetails.getCsarUUID());
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.CSAR_INVALID.name(), variables, createResource.getResponse());
+ }
+
+ @Test(enabled = true)
+ public void caseSensitiveTest_1() throws Exception {
+
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ resourceDetails.setCsarUUID("caseSensitiveTest_1");
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ List<String> variables = new ArrayList<String>();
+ variables.add(resourceDetails.getCsarUUID());
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.CSAR_INVALID.name(), variables, createResource.getResponse());
+ }
+
+ @Test(enabled = true)
+ public void caseSensitiveTest_2() throws Exception {
+
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ resourceDetails.setCsarUUID("caseSensitiveTest_2");
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ List<String> variables = new ArrayList<String>();
+ variables.add(resourceDetails.getCsarUUID());
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.CSAR_INVALID.name(), variables, createResource.getResponse());
+ }
+
+ @Test(enabled = true)
+ public void missingOneLineInToscaMetaFileTest() throws Exception {
+
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ resourceDetails.setCsarUUID("missingOneLineInToscaMeta");
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ List<String> variables = new ArrayList<String>();
+ variables.add(resourceDetails.getCsarUUID());
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.CSAR_INVALID_FORMAT.name(), variables, createResource.getResponse());
+ }
+
+ @Test(enabled = true)
+ public void noCSARVersionTest() throws Exception {
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ resourceDetails.setCsarUUID("noCSARVersion");
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ List<String> variables = new ArrayList<String>();
+ variables.add(resourceDetails.getCsarUUID());
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.CSAR_INVALID_FORMAT.name(), variables, createResource.getResponse());
+ }
+
+ @Test(enabled = true)
+ public void noCreatedByValueTest() throws Exception {
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ resourceDetails.setCsarUUID("noCreatedByValue");
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ List<String> variables = new ArrayList<String>();
+ variables.add(resourceDetails.getCsarUUID());
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.CSAR_INVALID_FORMAT.name(), variables, createResource.getResponse());
+ }
+
+ @Test(enabled = true)
+ public void noEntryDefinitionsValueTest() throws Exception {
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ resourceDetails.setCsarUUID("noEntryDefinitionsValue");
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ List<String> variables = new ArrayList<String>();
+ variables.add(resourceDetails.getCsarUUID());
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.CSAR_INVALID_FORMAT.name(), variables, createResource.getResponse());
+ }
+
+ @Test(enabled = true)
+ public void noTOSCAMetaFileVersionValueTest() throws Exception {
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ resourceDetails.setCsarUUID("noTOSCAMetaFileVersionValue");
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ List<String> variables = new ArrayList<String>();
+ variables.add(resourceDetails.getCsarUUID());
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.CSAR_INVALID_FORMAT.name(), variables, createResource.getResponse());
+ }
+
+ @Test(enabled = true)
+ public void invalidCsarVersionInMetaFileTest() throws Exception {
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ resourceDetails.setCsarUUID("invalidCsarVersion");
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ List<String> variables = new ArrayList<String>();
+ variables.add(resourceDetails.getCsarUUID());
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.CSAR_INVALID_FORMAT.name(), variables, createResource.getResponse());
+
+ resourceDetails.setCsarUUID("invalidCsarVersion2");
+ createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ variables = new ArrayList<String>();
+ variables.add(resourceDetails.getCsarUUID());
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.CSAR_INVALID_FORMAT.name(), variables, createResource.getResponse());
+
+ resourceDetails.setCsarUUID("invalidCsarVersion3");
+ createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ variables = new ArrayList<String>();
+ variables.add(resourceDetails.getCsarUUID());
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.CSAR_INVALID_FORMAT.name(), variables, createResource.getResponse());
+
+ resourceDetails.setCsarUUID("invalidCsarVersion4");
+ createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ variables = new ArrayList<String>();
+ variables.add(resourceDetails.getCsarUUID());
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.CSAR_INVALID_FORMAT.name(), variables, createResource.getResponse());
+
+ resourceDetails.setCsarUUID("invalidCsarVersion5");
+ createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ variables = new ArrayList<String>();
+ variables.add(resourceDetails.getCsarUUID());
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.CSAR_INVALID_FORMAT.name(), variables, createResource.getResponse());
+
+ }
+
+ @Test(enabled = true)
+ public void validCsarVersionInMetaFileTest() throws Exception {
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ resourceDetails.setCsarUUID("validCsarVersion");
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ BaseRestUtils.checkCreateResponse(createResource);
+ Resource resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
+ assertEquals(5, resource.getComponentInstances().size());
+
+ String expectedCsarUUID = resourceDetails.getCsarUUID();
+ String expectedToscaResourceName = "org.openecomp.resource.vf." + WordUtils.capitalize(resourceDetails.getName().toLowerCase());
+
+ assertTrue("csarUUID : " + buildAssertMessage(expectedCsarUUID, resource.getCsarUUID()), expectedCsarUUID.equals(resource.getCsarUUID()));
+ assertTrue("toscaResourceName : " + buildAssertMessage(expectedToscaResourceName, resource.getToscaResourceName()), expectedToscaResourceName.equals(resource.getToscaResourceName()));
+
+ RestResponse getResourceResponse = ResourceRestUtils.getResource(resource.getUniqueId());
+ Resource getResource = ResponseParser.parseToObjectUsingMapper(getResourceResponse.getResponse(), Resource.class);
+ assertTrue("csarUUID : " + buildAssertMessage(expectedCsarUUID, getResource.getCsarUUID()), expectedCsarUUID.equals(getResource.getCsarUUID()));
+ assertTrue("toscaResourceName : " + buildAssertMessage(expectedToscaResourceName, getResource.getToscaResourceName()), expectedToscaResourceName.equals(getResource.getToscaResourceName()));
+ }
+
+ @Test(enabled = true)
+ public void underscoreInToscaMetaFileVersionNameTest() throws Exception {
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ resourceDetails.setCsarUUID("underscoreInsteadOfDash");
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ List<String> variables = new ArrayList<String>();
+ variables.add(resourceDetails.getCsarUUID());
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.CSAR_INVALID_FORMAT.name(), variables, createResource.getResponse());
+ }
+
+ @Test(enabled = true)
+ public void missingEntryDefintionInMetaFileTest() throws Exception {
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ resourceDetails.setCsarUUID("missingEntryDefintionPair");
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ List<String> variables = new ArrayList<String>();
+ variables.add(resourceDetails.getCsarUUID());
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.CSAR_INVALID_FORMAT.name(), variables, createResource.getResponse());
+ }
+
+ @Test(enabled = false)
+ public void noNewLineAfterBLock0Test() throws Exception {
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ resourceDetails.setCsarUUID("noNewLineAfterBLock0");
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ List<String> variables = new ArrayList<String>();
+ variables.add(resourceDetails.getCsarUUID());
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.CSAR_INVALID_FORMAT.name(), variables, createResource.getResponse());
+ }
+
+ @Test(enabled = true)
+ public void moreThanOneYamlFileTest() throws Exception {
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ resourceDetails.setCsarUUID("moreThenOneYamlFile");
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ BaseRestUtils.checkCreateResponse(createResource);
+ Resource resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
+ assertEquals(5, resource.getComponentInstances().size());
+
+ String expectedCsarUUID = resourceDetails.getCsarUUID();
+ String expectedToscaResourceName = "org.openecomp.resource.vf." + WordUtils.capitalize(resourceDetails.getName().toLowerCase());
+
+ assertTrue("csarUUID : " + buildAssertMessage(expectedCsarUUID, resource.getCsarUUID()), expectedCsarUUID.equals(resource.getCsarUUID()));
+ assertTrue("toscaResourceName : " + buildAssertMessage(expectedToscaResourceName, resource.getToscaResourceName()), expectedToscaResourceName.equals(resource.getToscaResourceName()));
+
+ RestResponse getResourceResponse = ResourceRestUtils.getResource(resource.getUniqueId());
+ Resource getResource = ResponseParser.parseToObjectUsingMapper(getResourceResponse.getResponse(), Resource.class);
+ assertTrue("csarUUID : " + buildAssertMessage(expectedCsarUUID, getResource.getCsarUUID()), expectedCsarUUID.equals(getResource.getCsarUUID()));
+ assertTrue("toscaResourceName : " + buildAssertMessage(expectedToscaResourceName, getResource.getToscaResourceName()), expectedToscaResourceName.equals(getResource.getToscaResourceName()));
+ }
+
+ @Test(enabled = true)
+ public void moreThanOneMetaFileTest() throws Exception {
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ resourceDetails.setCsarUUID("moreThanOneMetaFile");
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ BaseRestUtils.checkCreateResponse(createResource);
+ Resource resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
+ assertEquals(5, resource.getComponentInstances().size());
+
+ String expectedCsarUUID = resourceDetails.getCsarUUID();
+ String expectedToscaResourceName = "org.openecomp.resource.vf." + WordUtils.capitalize(resourceDetails.getName().toLowerCase());
+
+ assertTrue("csarUUID : " + buildAssertMessage(expectedCsarUUID, resource.getCsarUUID()), expectedCsarUUID.equals(resource.getCsarUUID()));
+ assertTrue("toscaResourceName : " + buildAssertMessage(expectedToscaResourceName, resource.getToscaResourceName()), expectedToscaResourceName.equals(resource.getToscaResourceName()));
+
+ RestResponse getResourceResponse = ResourceRestUtils.getResource(resource.getUniqueId());
+ Resource getResource = ResponseParser.parseToObjectUsingMapper(getResourceResponse.getResponse(), Resource.class);
+ assertTrue("csarUUID : " + buildAssertMessage(expectedCsarUUID, getResource.getCsarUUID()), expectedCsarUUID.equals(getResource.getCsarUUID()));
+ assertTrue("toscaResourceName : " + buildAssertMessage(expectedToscaResourceName, getResource.getToscaResourceName()), expectedToscaResourceName.equals(getResource.getToscaResourceName()));
+ }
+
+ @Test(enabled = true)
+ public void csarNotContainsYamlAndMetaFilesTest() throws Exception {
+
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ resourceDetails.setCsarUUID("notContainYamlAndMetaFiles");
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ List<String> variables = new ArrayList<String>();
+ variables.add(resourceDetails.getCsarUUID());
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.CSAR_INVALID.name(), variables, createResource.getResponse());
+ }
+
+ @Test(enabled = true)
+ public void csarNotContainsYamlFileTest() throws Exception {
+
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ resourceDetails.setCsarUUID("notContainYamlFile");
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ List<String> variables = new ArrayList<String>();
+ variables.add(resourceDetails.getCsarUUID());
+ variables.add("Definitions/tosca_mock_vf.yaml");
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.YAML_NOT_FOUND_IN_CSAR.name(), variables, createResource.getResponse());
+ }
+
+ @Test(enabled = true)
+ public void missingCsarFileTest() throws Exception {
+
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ resourceDetails.setCsarUUID("abc");
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ List<String> variables = new ArrayList<String>();
+ variables.add(resourceDetails.getCsarUUID());
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.CSAR_NOT_FOUND.name(), variables, createResource.getResponse());
+ }
+
+ @Test(enabled = true)
+ public void longNamesInToscaMetaFileTest_1() throws Exception {
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ resourceDetails.setCsarUUID("longNamesInToscaMetaFile1");
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ List<String> variables = new ArrayList<String>();
+ variables.add(resourceDetails.getCsarUUID());
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.CSAR_INVALID_FORMAT.name(), variables, createResource.getResponse());
+ }
+
+ @Test(enabled = true)
+ public void longNamesInToscaMetaFileTest_2() throws Exception {
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ resourceDetails.setCsarUUID("longNamesInToscaMetaFile2");
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ List<String> variables = new ArrayList<String>();
+ variables.add(resourceDetails.getCsarUUID());
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.CSAR_INVALID_FORMAT.name(), variables, createResource.getResponse());
+ }
+
+ @Test(enabled = true)
+ public void longNamesInToscaMetaFileTest_3() throws Exception {
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ resourceDetails.setCsarUUID("longNamesInToscaMetaFile3");
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ List<String> variables = new ArrayList<String>();
+ variables.add(resourceDetails.getCsarUUID());
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.CSAR_INVALID_FORMAT.name(), variables, createResource.getResponse());
+ }
+
+ @Test(enabled = true)
+ public void longNamesInToscaMetaFileTest_4() throws Exception {
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ resourceDetails.setCsarUUID("longNamesInToscaMetaFile4");
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ List<String> variables = new ArrayList<String>();
+ variables.add(resourceDetails.getCsarUUID());
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.CSAR_INVALID_FORMAT.name(), variables, createResource.getResponse());
+ }
+
+ @Test(enabled = true)
+ public void longNamesInToscaMetaFileTest_5() throws Exception {
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ resourceDetails.setCsarUUID("longNamesInToscaMetaFile5");
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ List<String> variables = new ArrayList<String>();
+ variables.add(resourceDetails.getCsarUUID());
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.CSAR_INVALID_FORMAT.name(), variables, createResource.getResponse());
+ }
+
+ // possible to have more than four lines in block 0
+ // @Test (enabled = true)
+ public void fiveLinesAsBlock0Test() throws Exception {
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ resourceDetails.setCsarUUID("fiveLinesAsBlock0");
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ List<String> variables = new ArrayList<String>();
+ variables.add(resourceDetails.getCsarUUID());
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.CSAR_INVALID_FORMAT.name(), variables, createResource.getResponse());
+ }
+
+ @Test(enabled = true)
+ public void lifecycleChangingToResourceFromCsarTest() throws Exception {
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setCsarUUID("valid_vf");
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ BaseRestUtils.checkCreateResponse(createResource);
+
+ Resource resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
+ assertTrue("0.1".equals(resource.getVersion()));
+ assertTrue(LifeCycleStatesEnum.CHECKOUT.getComponentState().equals(resource.getLifecycleState().toString()));
+
+ String designerUserId = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER).getUserId();
+ String testerUserId = ElementFactory.getDefaultUser(UserRoleEnum.TESTER).getUserId();
+ String csarUniqueId = resourceDetails.getUniqueId();
+ assertNotNull(csarUniqueId);
+
+ RestResponse lifecycleChangeResponse = LifecycleRestUtils.changeResourceState(resourceDetails, designerUserId, LifeCycleStatesEnum.CHECKIN);
+ LifecycleRestUtils.checkSuccess(lifecycleChangeResponse);
+ lifecycleChangeResponse = LifecycleRestUtils.changeResourceState(resourceDetails, designerUserId, LifeCycleStatesEnum.CHECKOUT);
+ LifecycleRestUtils.checkSuccess(lifecycleChangeResponse);
+ lifecycleChangeResponse = LifecycleRestUtils.changeResourceState(resourceDetails, designerUserId, LifeCycleStatesEnum.CHECKIN);
+ LifecycleRestUtils.checkSuccess(lifecycleChangeResponse);
+ lifecycleChangeResponse = LifecycleRestUtils.changeResourceState(resourceDetails, designerUserId, LifeCycleStatesEnum.CERTIFICATIONREQUEST);
+ LifecycleRestUtils.checkSuccess(lifecycleChangeResponse);
+ lifecycleChangeResponse = LifecycleRestUtils.changeResourceState(resourceDetails, testerUserId, LifeCycleStatesEnum.STARTCERTIFICATION);
+ LifecycleRestUtils.checkSuccess(lifecycleChangeResponse);
+ lifecycleChangeResponse = LifecycleRestUtils.changeResourceState(resourceDetails, testerUserId, LifeCycleStatesEnum.CERTIFY);
+ LifecycleRestUtils.checkSuccess(lifecycleChangeResponse);
+ lifecycleChangeResponse = LifecycleRestUtils.changeResourceState(resourceDetails, designerUserId, LifeCycleStatesEnum.CHECKOUT);
+ LifecycleRestUtils.checkSuccess(lifecycleChangeResponse);
+
+ resource = ResponseParser.parseToObjectUsingMapper(lifecycleChangeResponse.getResponse(), Resource.class);
+ Map<String, String> allVersions = resource.getAllVersions();
+ assertEquals(2, allVersions.keySet().size());
+ assertEquals(2, allVersions.values().size());
+ Set<String> keySet = allVersions.keySet();
+ assertTrue(keySet.contains("1.0"));
+ assertTrue(keySet.contains("1.1"));
+ }
+
+ @Test(enabled = true)
+ public void csarWithJsonPromEnvTest() throws Exception {
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setCsarUUID("VSPPackageJsonProp.csar");
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ BaseRestUtils.checkCreateResponse(createResource);
+
+ Resource resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
+
+ }
+
+ @Test(enabled = true)
+ public void uploadArtifactToResourceFromCsarTest() throws Exception {
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setCsarUUID("valid_vf");
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ BaseRestUtils.checkCreateResponse(createResource);
+
+ User designer = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
+ ArtifactReqDetails artifactDetails = ElementFactory.getDefaultArtifact("firstArtifact");
+ String firstArtifactLabel = artifactDetails.getArtifactLabel();
+ RestResponse addInformationalArtifactToResource = ArtifactRestUtils.addInformationalArtifactToResource(artifactDetails, designer, resourceDetails.getUniqueId());
+ ArtifactRestUtils.checkSuccess(addInformationalArtifactToResource);
+ RestResponse getResourceResponse = ResourceRestUtils.getResource(resourceDetails.getUniqueId());
+ Resource resource = ResponseParser.parseToObjectUsingMapper(getResourceResponse.getResponse(), Resource.class);
+ Map<String, ArtifactDefinition> informationalArtifacts = resource.getArtifacts();
+ assertEquals(1, informationalArtifacts.keySet().size());
+ Set<String> keySet = informationalArtifacts.keySet();
+ assertTrue(keySet.contains(firstArtifactLabel.toLowerCase()));
+ Collection<ArtifactDefinition> values = informationalArtifacts.values();
+ assertEquals(1, values.size());
+ Iterator<ArtifactDefinition> iterator = values.iterator();
+ while (iterator.hasNext()) {
+ ArtifactDefinition actualArtifact = iterator.next();
+ assertTrue(firstArtifactLabel.equals(actualArtifact.getArtifactDisplayName()));
+ }
+
+ RestResponse lifecycleChangeResponse = LifecycleRestUtils.changeResourceState(resourceDetails, designer.getUserId(), LifeCycleStatesEnum.CHECKIN);
+ LifecycleRestUtils.checkSuccess(lifecycleChangeResponse);
+ lifecycleChangeResponse = LifecycleRestUtils.changeResourceState(resourceDetails, designer.getUserId(), LifeCycleStatesEnum.CHECKOUT);
+ LifecycleRestUtils.checkSuccess(lifecycleChangeResponse);
+
+ ArtifactReqDetails artifactDetails2 = ElementFactory.getDefaultArtifact("secondArtifact");
+ artifactDetails2.setArtifactName("secondArtifact");
+ addInformationalArtifactToResource = ArtifactRestUtils.addInformationalArtifactToResource(artifactDetails2, designer, resourceDetails.getUniqueId());
+ ArtifactRestUtils.checkSuccess(addInformationalArtifactToResource);
+
+ getResourceResponse = ResourceRestUtils.getResource(resourceDetails.getUniqueId());
+ resource = ResponseParser.parseToObjectUsingMapper(getResourceResponse.getResponse(), Resource.class);
+ informationalArtifacts = resource.getArtifacts();
+ assertEquals(2, informationalArtifacts.keySet().size());
+ keySet = informationalArtifacts.keySet();
+ assertTrue(keySet.contains(firstArtifactLabel.toLowerCase()));
+ assertTrue(keySet.contains(artifactDetails2.getArtifactLabel().toLowerCase()));
+ values = informationalArtifacts.values();
+ assertEquals(2, values.size());
+ ArtifactDefinition[] actualArtifacts = values.toArray(new ArtifactDefinition[2]);
+ assertTrue(firstArtifactLabel.equals(actualArtifacts[0].getArtifactDisplayName()));
+ assertTrue(artifactDetails2.getArtifactLabel().equals(actualArtifacts[1].getArtifactDisplayName()));
+ }
+
+ /*
+ * // @Test (enabled = true) public void createUpdateImportResourceFromCsarArtifactsWereNotChangedTest() throws Exception { // User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER); // //back original scar RestResponse
+ * copyRes = copyCsarRest(sdncModifierDetails, "VF_RI2_G4_withArtifacts_a.csar", "VF_RI2_G4_withArtifacts.csar"); BaseRestUtils.checkSuccess(copyRes);
+ *
+ * // resourceDetails.setResourceType(ResourceTypeEnum.VF.name()); // RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, sdncModifierDetails); resourceDetails.setName("test5");
+ * resourceDetails.setCsarUUID("VF_RI2_G4_withArtifacts.csar"); resourceDetails.setCsarVersion("1"); // String invariantUUID = resource.getInvariantUUID(); // // RestResponse changeResourceState =
+ * LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails, LifeCycleStatesEnum.CHECKIN); // assertEquals("Check response code ", BaseRestUtils.STATUS_CODE_SUCCESS, changeResourceState.getErrorCode().intValue());
+ *
+ * // BaseRestUtils.checkSuccess(copyRes); // //change name (temporary) resourceDetails.setCsarVersion("2"); resourceDetails.setName("test6"); createResource = ResourceRestUtils.updateResource(resourceDetails, sdncModifierDetails,
+ * resourceDetails.getUniqueId()); Resource updatedResource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class); Map<String, ArtifactDefinition> updatedArtifacts = updatedResource.getDeploymentArtifacts(); for
+ * (Entry<String, ArtifactDefinition> artifactEntry : resource.getDeploymentArtifacts().entrySet()) { if (updatedArtifacts.containsKey(artifactEntry.getKey())) { ArtifactDefinition currArt = updatedArtifacts.get(artifactEntry.getKey());
+ * assertEquals(currArt.getArtifactVersion(), artifactEntry.getValue().getArtifactVersion()); assertEquals(currArt.getArtifactUUID(), artifactEntry.getValue().getArtifactUUID()); assertEquals(currArt.getArtifactChecksum(),
+ * artifactEntry.getValue().getArtifactChecksum()); } } // resourceDetails = ElementFactory.getDefaultResource(); // resourceDetails.setName("test5"); // resourceDetails.setCsarUUID("VF_RI2_G4_withArtifacts.csar"); }
+ */
+
+ @Test(enabled = true)
+ public void createImportResourceFromCsarDissotiateArtifactFromGroupTest() throws Exception {
+ User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
+ RestResponse copyRes = copyCsarRest(sdncModifierDetails, "VF_RI2_G4_withArtifacts_a.csar", "VF_RI2_G4_withArtifacts.csar");
+
+ // create new resource from Csar
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setCsarUUID("VF_RI2_G4_withArtifacts.csar");
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, sdncModifierDetails);
+ BaseRestUtils.checkCreateResponse(createResource);
+ Resource resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
+ String invariantUUID = resource.getInvariantUUID();
+
+ // add artifact from metadata (resource metadata should be updated)
+ // RestResponse addInformationalArtifactToResource =
+ // ArtifactRestUtils.addInformationalArtifactToResource(ElementFactory.getDefaultArtifact(),
+ // sdncModifierDetails, resourceDetails.getUniqueId());
+ // ArtifactRestUtils.checkSuccess(addInformationalArtifactToResource);
+ resourceDetails.setName("test4");
+ RestResponse updateResource = ResourceRestUtils.updateResource(resourceDetails, sdncModifierDetails, resourceDetails.getUniqueId());
+ BaseRestUtils.checkSuccess(updateResource);
+ resource = ResponseParser.parseToObjectUsingMapper(updateResource.getResponse(), Resource.class);
+ assertEquals(invariantUUID, resource.getInvariantUUID());
+
+ // wrong RI (without node types, resource shouldn't be updated)
+ copyRes = copyCsarRest(sdncModifierDetails, "VF_RI2_G4_withArtifacts_dissociate.csar", "VF_RI2_G4_withArtifacts.csar");
+ BaseRestUtils.checkSuccess(copyRes);
+ // change name (temporary)
+ resourceDetails.setName("test4");
+ updateResource = ResourceRestUtils.updateResource(resourceDetails, sdncModifierDetails, resourceDetails.getUniqueId());
+ BaseRestUtils.checkSuccess(updateResource);
+ resource = ResponseParser.parseToObjectUsingMapper(updateResource.getResponse(), Resource.class);
+ assertEquals(invariantUUID, resource.getInvariantUUID());
+
+ // back original scar
+ copyRes = copyCsarRest(sdncModifierDetails, "VF_RI2_G4_withArtifacts_a.csar", "VF_RI2_G4_withArtifacts.csar");
+ BaseRestUtils.checkSuccess(copyRes);
+ }
+
+ @Test(enabled = true)
+ public void createImportResourceFromCsarNewgroupTest() throws Exception {
+ User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
+ RestResponse copyRes = copyCsarRest(sdncModifierDetails, "VF_RI2_G4_withArtifacts_a.csar", "VF_RI2_G4_withArtifacts.csar");
+
+ // create new resource from Csar
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setCsarUUID("VF_RI2_G4_withArtifacts.csar");
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, sdncModifierDetails);
+ BaseRestUtils.checkCreateResponse(createResource);
+ Resource resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
+ String invariantUUID = resource.getInvariantUUID();
+
+ // update scar
+ copyRes = copyCsarRest(sdncModifierDetails, "VF_RI2_G4_withArtifacts_UpdateToscaAndArtifacts.csar", "VF_RI2_G4_withArtifacts.csar");
+ BaseRestUtils.checkSuccess(copyRes);
+
+ resourceDetails.setName("test2");
+ // change resource metaData (resource should be updated)
+ resourceDetails.setDescription("It is new description bla bla bla");
+ RestResponse updateResource = ResourceRestUtils.updateResource(resourceDetails, sdncModifierDetails, resourceDetails.getUniqueId());
+ BaseRestUtils.checkSuccess(updateResource);
+ resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
+
+ assertEquals(invariantUUID, resource.getInvariantUUID());
+
+ copyRes = copyCsarRest(sdncModifierDetails, "VF_RI2_G4_withArtifacts_a.csar", "VF_RI2_G4_withArtifacts.csar");
+ BaseRestUtils.checkSuccess(copyRes);
+ }
+
+ @Test(enabled = true)
+ public void createImportResourceFromCsarGetGroupTest() throws Exception {
+ User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
+ // RestResponse copyRes =
+ // copyCsarRest(sdncModifierDetails,"VF_RI2_G4_withArtifacts_a.csar","VF_RI2_G4_withArtifacts.csar");
+
+ // create new resource from Csar
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setCsarUUID("VSPPackage");
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, sdncModifierDetails);
+ BaseRestUtils.checkCreateResponse(createResource);
+ Resource resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
+ String invariantUUID = resource.getInvariantUUID();
+ List<GroupDefinition> groups = resource.getGroups();
+
+ GroupDefinition groupWithArtifact = groups.stream().filter(p -> p.getArtifacts() != null && !p.getArtifacts().isEmpty()).findFirst().get();
+
+ RestResponse groupRest = GroupRestUtils.getGroupById(resource, groupWithArtifact.getUniqueId(), sdncModifierDetails);
+ BaseRestUtils.checkSuccess(groupRest);
+
+ GroupDefinition groupWithoutArtifact = groups.stream().filter(p -> p.getArtifacts() == null || p.getArtifacts().isEmpty()).findFirst().get();
+
+ groupRest = GroupRestUtils.getGroupById(resource, groupWithoutArtifact.getUniqueId(), sdncModifierDetails);
+ BaseRestUtils.checkSuccess(groupRest);
+ }
+
+ @Test(enabled = true)
+ public void createImportResourceFromCsarUITest() throws Exception {
+ RestResponse getResource = null;
+ User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
+ String payloadName = "valid_vf.csar";
+ ImportReqDetails resourceDetails = ElementFactory.getDefaultImportResource();
+ String rootPath = System.getProperty("user.dir");
+ Path path = null;
+ byte[] data = null;
+ String payloadData = null;
+
+ path = Paths.get(rootPath + "/src/main/resources/ci/valid_vf.csar");
+ data = Files.readAllBytes(path);
+ payloadData = Base64.encodeBase64String(data);
+ resourceDetails.setPayloadData(payloadData);
+
+ // create new resource from Csar
+ resourceDetails.setCsarUUID(payloadName);
+ resourceDetails.setPayloadName(payloadName);
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, sdncModifierDetails);
+ BaseRestUtils.checkCreateResponse(createResource);
+ Resource resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
+ assertEquals(5, resource.getComponentInstances().size());
+
+ RestResponse changeResourceState = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails, LifeCycleStatesEnum.CHECKIN);
+ assertEquals("Check response code ", BaseRestUtils.STATUS_CODE_SUCCESS, changeResourceState.getErrorCode().intValue());
+
+ // change composition (resource should be updated)
+ path = Paths.get(rootPath + "/src/main/resources/ci/valid_vf_b.csar");
+ data = Files.readAllBytes(path);
+ payloadData = Base64.encodeBase64String(data);
+ resourceDetails.setPayloadData(payloadData);
+ // change name
+ resourceDetails.setName("test1");
+ createResource = ResourceRestUtils.createResource(resourceDetails, sdncModifierDetails);
+ BaseRestUtils.checkCreateResponse(createResource);
+ resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
+ assertEquals(2, resource.getComponentInstances().size());
+
+ changeResourceState = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails, LifeCycleStatesEnum.CHECKIN);
+ assertEquals("Check response code ", BaseRestUtils.STATUS_CODE_SUCCESS, changeResourceState.getErrorCode().intValue());
+
+ // change name
+ resourceDetails.setName("test2");
+ // change resource metaData (resource should be updated)
+ resourceDetails.setDescription("It is new description bla bla bla");
+ createResource = ResourceRestUtils.createResource(resourceDetails, sdncModifierDetails);
+ BaseRestUtils.checkCreateResponse(createResource);
+ resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
+ assertEquals(2, resource.getComponentInstances().size());
+
+ changeResourceState = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails, LifeCycleStatesEnum.CHECKIN);
+ assertEquals("Check response code ", BaseRestUtils.STATUS_CODE_SUCCESS, changeResourceState.getErrorCode().intValue());
+
+ // wrong RI (without node types, resource shouldn't be updated)
+ path = Paths.get(rootPath + "/src/main/resources/ci/valid_vf_c.csar");
+ data = Files.readAllBytes(path);
+ payloadData = Base64.encodeBase64String(data);
+ resourceDetails.setPayloadData(payloadData);
+ // change name
+ resourceDetails.setName("test3");
+ createResource = ResourceRestUtils.createResource(resourceDetails, sdncModifierDetails);
+ BaseRestUtils.checkErrorResponse(createResource, ActionStatus.INVALID_NODE_TEMPLATE, "Definitions/tosca_mock_vf.yaml", "nodejs", "tosca.nodes.Weber");
+ resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
+ assertEquals(null, resource);
+ getResource = ResourceRestUtils.getResourceByNameAndVersion(sdncModifierDetails.getUserId(), "test3", resourceDetails.getVersion());
+ BaseRestUtils.checkErrorResponse(getResource, ActionStatus.RESOURCE_NOT_FOUND, "test3");
+
+ // create new resource from other Csar
+ resourceDetails = ElementFactory.getDefaultImportResource();
+ path = Paths.get(rootPath + "/src/main/resources/ci/VF_RI2_G4_withArtifacts.csar");
+ data = Files.readAllBytes(path);
+ payloadData = Base64.encodeBase64String(data);
+ resourceDetails.setPayloadData(payloadData);
+ resourceDetails.setPayloadName("VF_RI2_G4_withArtifacts.csar");
+ resourceDetails.setName("test4");
+ resourceDetails.setCsarUUID("VF_RI2_G4_withArtifacts.csar");
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ createResource = ResourceRestUtils.createResource(resourceDetails, sdncModifierDetails);
+ BaseRestUtils.checkCreateResponse(createResource);
+
+ changeResourceState = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails, LifeCycleStatesEnum.CHECKIN);
+ assertEquals("Check response code ", BaseRestUtils.STATUS_CODE_SUCCESS, changeResourceState.getErrorCode().intValue());
+
+ // wrong RI (with node types) resource shouldn't be created
+ resourceDetails.setCsarUUID("VF_RI2_G4_withArtifacts_b.csar");
+ path = Paths.get(rootPath + "/src/main/resources/ci/VF_RI2_G4_withArtifacts_b.csar");
+ data = Files.readAllBytes(path);
+ payloadData = Base64.encodeBase64String(data);
+ resourceDetails.setPayloadData(payloadData);
+ resourceDetails.setPayloadName("VF_RI2_G4_withArtifacts_b.csar");
+ resourceDetails.setName("test5");
+ createResource = ResourceRestUtils.createResource(resourceDetails, sdncModifierDetails);
+ BaseRestUtils.checkErrorResponse(createResource, ActionStatus.INVALID_NODE_TEMPLATE, "Definitions/VF_RI2_G1.yaml", "ps04_port_0", "org.openecomp.resource.cp.nodes.heat.network.neutron.Portur");
+ }
+
+ @Test(enabled = true)
+ public void createUpdateImportResourceFromCsarUITest() throws Exception {
+ RestResponse getResource = null;
+ User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
+ String payloadName = "valid_vf.csar";
+ ImportReqDetails resourceDetails = ElementFactory.getDefaultImportResource();
+ String rootPath = System.getProperty("user.dir");
+ Path path = null;
+ byte[] data = null;
+ String payloadData = null;
+
+ path = Paths.get(rootPath + "/src/main/resources/ci/valid_vf.csar");
+ data = Files.readAllBytes(path);
+ payloadData = Base64.encodeBase64String(data);
+ resourceDetails.setPayloadData(payloadData);
+
+ // create new resource from Csar
+ resourceDetails.setPayloadName(payloadName);
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, sdncModifierDetails);
+ BaseRestUtils.checkCreateResponse(createResource);
+ Resource resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
+ assertEquals(5, resource.getComponentInstances().size());
+
+ RestResponse changeResourceState = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails, LifeCycleStatesEnum.CHECKIN);
+ assertEquals("Check response code ", BaseRestUtils.STATUS_CODE_SUCCESS, changeResourceState.getErrorCode().intValue());
+
+ // change composition and update resource
+ path = Paths.get(rootPath + "/src/main/resources/ci/valid_vf_b.csar");
+ data = Files.readAllBytes(path);
+ payloadData = Base64.encodeBase64String(data);
+ resourceDetails.setPayloadData(payloadData);
+ resourceDetails.setUniqueId(resource.getUniqueId());
+ // change name
+ RestResponse updateResource = ResourceRestUtils.updateResource(resourceDetails, sdncModifierDetails, resource.getUniqueId());
+ BaseRestUtils.checkSuccess(updateResource);
+ resource = ResponseParser.parseToObjectUsingMapper(updateResource.getResponse(), Resource.class);
+ assertEquals(2, resource.getComponentInstances().size());
+
+ changeResourceState = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails, LifeCycleStatesEnum.CHECKIN);
+ assertEquals("Check response code ", BaseRestUtils.STATUS_CODE_SUCCESS, changeResourceState.getErrorCode().intValue());
+
+ // change name
+ resourceDetails.setName("test2");
+ // change resource metaData (resource should be updated)
+ resourceDetails.setDescription("It is new description bla bla bla");
+ updateResource = ResourceRestUtils.updateResource(resourceDetails, sdncModifierDetails, resource.getUniqueId());
+ BaseRestUtils.checkSuccess(updateResource);
+ resource = ResponseParser.parseToObjectUsingMapper(updateResource.getResponse(), Resource.class);
+ assertEquals(2, resource.getComponentInstances().size());
+
+ changeResourceState = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails, LifeCycleStatesEnum.CHECKIN);
+ assertEquals("Check response code ", BaseRestUtils.STATUS_CODE_SUCCESS, changeResourceState.getErrorCode().intValue());
+
+ // try to update resource with wrong RI (without node types, resource
+ // shouldn't be updated)
+ path = Paths.get(rootPath + "/src/main/resources/ci/valid_vf_c.csar");
+ data = Files.readAllBytes(path);
+ payloadData = Base64.encodeBase64String(data);
+ resourceDetails.setPayloadData(payloadData);
+ // change name
+ resourceDetails.setName("test3");
+ updateResource = ResourceRestUtils.updateResource(resourceDetails, sdncModifierDetails, resource.getUniqueId());
+ BaseRestUtils.checkErrorResponse(updateResource, ActionStatus.INVALID_NODE_TEMPLATE, "Definitions/tosca_mock_vf.yaml", "nodejs", "tosca.nodes.Weber");
+ resource = ResponseParser.parseToObjectUsingMapper(updateResource.getResponse(), Resource.class);
+ assertEquals(null, resource);
+ getResource = ResourceRestUtils.getResourceByNameAndVersion(sdncModifierDetails.getUserId(), "test3", resourceDetails.getVersion());
+ BaseRestUtils.checkErrorResponse(getResource, ActionStatus.RESOURCE_NOT_FOUND, "test3");
+ }
+
+ @Test(enabled = true)
+ public void createUpdateImportResourceFromCsarTest() throws Exception {
+ User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
+ RestResponse copyRes = null;
+ RestResponse getResource = null;
+ ResourceReqDetails resourceDetails = null;
+ RestResponse updateResource = null;
+ RestResponse createResource = null;
+ Resource resource = null;
+ RestResponse changeResourceState = null;
+
+ // create new resource from Csar
+ copyRes = copyCsarRest(sdncModifierDetails, "valid_vf_a.csar", "valid_vf.csar");
+ resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setCsarUUID("valid_vf.csar");
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ createResource = ResourceRestUtils.createResource(resourceDetails, sdncModifierDetails);
+ BaseRestUtils.checkCreateResponse(createResource);
+ resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
+ assertEquals(5, resource.getComponentInstances().size());
+ String invariantUUID = resource.getInvariantUUID();
+
+ changeResourceState = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails, LifeCycleStatesEnum.CHECKIN);
+ assertEquals("Check response code ", BaseRestUtils.STATUS_CODE_SUCCESS, changeResourceState.getErrorCode().intValue());
+
+ // change composition and update resource
+ copyRes = copyCsarRest(sdncModifierDetails, "valid_vf_b.csar", "valid_vf.csar");
+ BaseRestUtils.checkSuccess(copyRes);
+ // change name
+ resourceDetails.setName("test1");
+ updateResource = ResourceRestUtils.updateResource(resourceDetails, sdncModifierDetails, resource.getUniqueId());
+ BaseRestUtils.checkSuccess(updateResource);
+ resource = ResponseParser.parseToObjectUsingMapper(updateResource.getResponse(), Resource.class);
+ assertEquals(2, resource.getComponentInstances().size());
+ assertEquals(invariantUUID, resource.getInvariantUUID());
+
+ changeResourceState = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails, LifeCycleStatesEnum.CHECKIN);
+ assertEquals("Check response code ", BaseRestUtils.STATUS_CODE_SUCCESS, changeResourceState.getErrorCode().intValue());
+
+ // back original scar
+ copyRes = copyCsarRest(sdncModifierDetails, "valid_vf_a.csar", "valid_vf.csar");
+ BaseRestUtils.checkSuccess(copyRes);
+
+ // change name
+ resourceDetails.setName("test2");
+ // change resource metaData and update resource
+ resourceDetails.setDescription("It is new description bla bla bla");
+ updateResource = ResourceRestUtils.updateResource(resourceDetails, sdncModifierDetails, resource.getUniqueId());
+ BaseRestUtils.checkSuccess(updateResource);
+ resource = ResponseParser.parseToObjectUsingMapper(updateResource.getResponse(), Resource.class);
+ assertEquals(5, resource.getComponentInstances().size());
+ assertEquals(invariantUUID, resource.getInvariantUUID());
+
+ changeResourceState = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails, LifeCycleStatesEnum.CHECKIN);
+ assertEquals("Check response code ", BaseRestUtils.STATUS_CODE_SUCCESS, changeResourceState.getErrorCode().intValue());
+
+ // back original scar
+ copyRes = copyCsarRest(sdncModifierDetails, "valid_vf_a.csar", "valid_vf.csar");
+ BaseRestUtils.checkSuccess(copyRes);
+
+ // try to update resource with wrong RI (without node types, resource
+ // shouldn't be updated)
+ copyRes = copyCsarRest(sdncModifierDetails, "valid_vf_c.csar", "valid_vf.csar");
+ BaseRestUtils.checkSuccess(copyRes);
+ // change name (temporary)
+ resourceDetails.setName("test3");
+ updateResource = ResourceRestUtils.updateResource(resourceDetails, sdncModifierDetails, resource.getUniqueId());
+ BaseRestUtils.checkErrorResponse(updateResource, ActionStatus.INVALID_NODE_TEMPLATE, "Definitions/tosca_mock_vf.yaml", "nodejs", "tosca.nodes.Weber");
+
+ getResource = ResourceRestUtils.getResourceByNameAndVersion(sdncModifierDetails.getUserId(), "test3", resourceDetails.getVersion());
+ BaseRestUtils.checkErrorResponse(getResource, ActionStatus.RESOURCE_NOT_FOUND, "test3");
+ getResource = ResourceRestUtils.getResourceByNameAndVersion(sdncModifierDetails.getUserId(), "test2", resourceDetails.getVersion());
+ BaseRestUtils.checkSuccess(getResource);
+
+ // back original scar
+ copyRes = copyCsarRest(sdncModifierDetails, "valid_vf_a.csar", "valid_vf.csar");
+ BaseRestUtils.checkSuccess(copyRes);
+
+ // create new resource from Csar
+ // back original scar
+ copyRes = copyCsarRest(sdncModifierDetails, "VF_RI2_G4_withArtifacts_a.csar", "VF_RI2_G4_withArtifacts.csar");
+ BaseRestUtils.checkSuccess(copyRes);
+
+ resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setName("TEST01");
+ resourceDetails.setCsarUUID("VF_RI2_G4_withArtifacts.csar");
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ createResource = ResourceRestUtils.createResource(resourceDetails, sdncModifierDetails);
+ BaseRestUtils.checkCreateResponse(createResource);
+ resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
+
+ changeResourceState = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails, LifeCycleStatesEnum.CHECKIN);
+ assertEquals("Check response code ", BaseRestUtils.STATUS_CODE_SUCCESS, changeResourceState.getErrorCode().intValue());
+
+ // scar with wrong RI
+ copyRes = copyCsarRest(sdncModifierDetails, "VF_RI2_G4_withArtifacts_b.csar", "VF_RI2_G4_withArtifacts.csar");
+ BaseRestUtils.checkSuccess(copyRes);
+ resourceDetails.setDescription("BLA BLA BLA");
+ // wrong RI (with node types) resource shouldn't be created
+ updateResource = ResourceRestUtils.updateResource(resourceDetails, sdncModifierDetails, resourceDetails.getUniqueId());
+ BaseRestUtils.checkErrorResponse(updateResource, ActionStatus.INVALID_NODE_TEMPLATE, "Definitions/VF_RI2_G1.yaml", "ps04_port_0", "org.openecomp.resource.cp.nodes.heat.network.neutron.Portur");
+ // back original scar
+ copyRes = copyCsarRest(sdncModifierDetails, "VF_RI2_G4_withArtifacts_a.csar", "VF_RI2_G4_withArtifacts.csar");
+ BaseRestUtils.checkSuccess(copyRes);
+ }
+
+ @Test(enabled = true)
+ public void createUpdateImportResourceFromCsarWithArtifactsTest() throws Exception {
+ User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
+ RestResponse copyRes = null;
+ ResourceReqDetails resourceDetails = null;
+ RestResponse updateResource = null;
+ RestResponse createResource = null;
+ Resource resource = null;
+ RestResponse changeResourceState = null;
+
+ // back original scar
+ copyRes = copyCsarRest(sdncModifierDetails, "VF_RI2_G4_withArtifacts_a.csar", "VF_RI2_G4_withArtifacts.csar");
+ BaseRestUtils.checkSuccess(copyRes);
+
+ resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setName("TEST01");
+ resourceDetails.setCsarUUID("VF_RI2_G4_withArtifacts.csar");
+ resourceDetails.setCsarVersion("1");
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ // create new resource from Csar
+ createResource = ResourceRestUtils.createResource(resourceDetails, sdncModifierDetails);
+ BaseRestUtils.checkCreateResponse(createResource);
+ resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
+
+ List<String> requiredArtifactsOld = resource.getDeploymentArtifacts().get("heat5").getRequiredArtifacts();
+ assertTrue(requiredArtifactsOld != null && !requiredArtifactsOld.isEmpty() && requiredArtifactsOld.size() == 3);
+ assertTrue(requiredArtifactsOld.contains("hot-nimbus-pcm-volumes_v1.0.yaml"));
+ assertTrue(requiredArtifactsOld.contains("nested-pcm_v1.0.yaml"));
+ assertTrue(requiredArtifactsOld.contains("hot-nimbus-oam-volumes_v1.0.yaml"));
+
+ // update scar with new artifacts
+ copyRes = copyCsarRest(sdncModifierDetails, "VF_RI2_G4_withArtifacts_updated.csar", "VF_RI2_G4_withArtifacts.csar");
+ BaseRestUtils.checkSuccess(copyRes);
+ resourceDetails.setDescription("BLA BLA BLA");
+ resourceDetails.setCsarVersion("2");
+ updateResource = ResourceRestUtils.updateResource(resourceDetails, sdncModifierDetails, resourceDetails.getUniqueId());
+ BaseRestUtils.checkSuccess(updateResource);
+ resource = ResponseParser.parseToObjectUsingMapper(updateResource.getResponse(), Resource.class);
+
+ List<String> requiredArtifactsNew = resource.getDeploymentArtifacts().get("heat5").getRequiredArtifacts();
+ assertTrue(requiredArtifactsNew != null && !requiredArtifactsNew.isEmpty() && requiredArtifactsNew.size() == 3);
+ assertTrue(requiredArtifactsNew.contains("hot-nimbus-swift-container_v1.0.yaml"));
+ assertTrue(requiredArtifactsNew.contains("hot-nimbus-oam-volumes_v1.0.yaml"));
+ assertTrue(requiredArtifactsNew.contains("nested-oam_v1.0.yaml"));
+
+ // back original scar
+ copyRes = copyCsarRest(sdncModifierDetails, "VF_RI2_G4_withArtifacts_a.csar", "VF_RI2_G4_withArtifacts.csar");
+ BaseRestUtils.checkSuccess(copyRes);
+ }
+
+ @Test(enabled = true)
+ public void createUpdateImportWithPropertiesFromCsarUITest() throws Exception {
+ User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
+ String payloadName = "valid_vf.csar";
+ ImportReqDetails resourceDetails = ElementFactory.getDefaultImportResource();
+ String rootPath = System.getProperty("user.dir");
+ Path path = null;
+ byte[] data = null;
+ String payloadData = null;
+
+ path = Paths.get(rootPath + "/src/main/resources/ci/valid_vf.csar");
+ data = Files.readAllBytes(path);
+ payloadData = Base64.encodeBase64String(data);
+ resourceDetails.setPayloadData(payloadData);
+
+ // create new resource from Csar
+ resourceDetails.setCsarUUID(payloadName);
+ resourceDetails.setPayloadName(payloadName);
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, sdncModifierDetails);
+ BaseRestUtils.checkCreateResponse(createResource);
+ Resource resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
+ assertEquals(5, resource.getComponentInstances().size());
+
+ RestResponse changeResourceState = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails, LifeCycleStatesEnum.CHECKIN);
+ assertEquals("Check response code ", BaseRestUtils.STATUS_CODE_SUCCESS, changeResourceState.getErrorCode().intValue());
+
+ // change composition (add new RI with specified property values)
+ path = Paths.get(rootPath + "/src/main/resources/ci/valid_vf_d.csar");
+ data = Files.readAllBytes(path);
+ payloadData = Base64.encodeBase64String(data);
+ resourceDetails.setPayloadData(payloadData);
+ // change name
+ resourceDetails.setName("test1");
+ createResource = ResourceRestUtils.createResource(resourceDetails, sdncModifierDetails);
+ BaseRestUtils.checkCreateResponse(createResource);
+ resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
+ assertEquals(6, resource.getComponentInstances().size());
+
+ changeResourceState = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails, LifeCycleStatesEnum.CHECKIN);
+ assertEquals("Check response code ", BaseRestUtils.STATUS_CODE_SUCCESS, changeResourceState.getErrorCode().intValue());
+
+ // change composition (add new specified property values to existing RI)
+ path = Paths.get(rootPath + "/src/main/resources/ci/valid_vf_f.csar");
+ data = Files.readAllBytes(path);
+ payloadData = Base64.encodeBase64String(data);
+ resourceDetails.setPayloadData(payloadData);
+ // change name
+ resourceDetails.setName("test2");
+ createResource = ResourceRestUtils.createResource(resourceDetails, sdncModifierDetails);
+ BaseRestUtils.checkCreateResponse(createResource);
+ resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
+ assertEquals(6, resource.getComponentInstances().size());
+
+ }
+
+ public static RestResponse copyCsarRest(User sdncModifierDetails, String sourceCsarUuid, String targetCsarUuid) throws Exception {
+
+ Config config = Utils.getConfig();
+ String url = String.format(Urls.COPY_CSAR_USING_SIMULATOR, config.getCatalogBeHost(), config.getCatalogBePort(), sourceCsarUuid, targetCsarUuid);
+ String userId = sdncModifierDetails.getUserId();
+ Map<String, String> headersMap = prepareHeadersMap(userId);
+ HttpRequest http = new HttpRequest();
+
+ RestResponse copyCsarResponse = http.httpSendPost(url, "dummy", headersMap);
+ if (copyCsarResponse.getErrorCode() != 200) {
+ return null;
+ }
+ return copyCsarResponse;
+
+ }
+
+ public static RestResponse getCsarRest(User sdncModifierDetails, String sourceCsarUuid) throws Exception {
+
+ Config config = Utils.getConfig();
+ String url = String.format(Urls.GET_CSAR_USING_SIMULATOR, config.getCatalogBeHost(), config.getCatalogBePort(), sourceCsarUuid);
+ String userId = sdncModifierDetails.getUserId();
+ Map<String, String> headersMap = prepareHeadersMap(userId);
+ HttpRequest http = new HttpRequest();
+
+ RestResponse copyCsarResponse = http.httpSendGet(url, headersMap);
+ if (copyCsarResponse.getErrorCode() != 200) {
+ return null;
+ }
+ return copyCsarResponse;
+
+ }
+
+ @Test(enabled = true)
+ public void updateResourceFromCsarHappy() throws Exception {
+ RestResponse copyRes = copyCsarRest(ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER), "valid_vf_a.csar", "valid_vf.csar");
+ BaseRestUtils.checkSuccess(copyRes);
+ // create
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setCsarUUID("valid_vf");
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ BaseRestUtils.checkCreateResponse(createResource);
+ Resource resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
+ assertEquals(5, resource.getComponentInstances().size());
+
+ String expectedCsarUUID = resourceDetails.getCsarUUID();
+ String expectedToscaResourceName = "org.openecomp.resource.vf." + WordUtils.capitalize(resourceDetails.getName().toLowerCase());
+
+ assertTrue("csarUUID : " + buildAssertMessage(expectedCsarUUID, resource.getCsarUUID()), expectedCsarUUID.equals(resource.getCsarUUID()));
+ assertTrue("toscaResourceName : " + buildAssertMessage(expectedToscaResourceName, resource.getToscaResourceName()), expectedToscaResourceName.equals(resource.getToscaResourceName()));
+
+ RestResponse getResourceResponse = ResourceRestUtils.getResource(resource.getUniqueId());
+ Resource getResource = ResponseParser.parseToObjectUsingMapper(getResourceResponse.getResponse(), Resource.class);
+ assertTrue("csarUUID : " + buildAssertMessage(expectedCsarUUID, getResource.getCsarUUID()), expectedCsarUUID.equals(getResource.getCsarUUID()));
+ assertTrue("toscaResourceName : " + buildAssertMessage(expectedToscaResourceName, getResource.getToscaResourceName()), expectedToscaResourceName.equals(getResource.getToscaResourceName()));
+
+ RestResponse updateResource = ResourceRestUtils.updateResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER), resourceDetails.getUniqueId());
+ BaseRestUtils.checkSuccess(updateResource);
+
+ }
+
+ @Test(enabled = true)
+ public void createResourceFromCsarWithGroupsHappy() throws Exception {
+
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setCsarUUID("csarWithGroups");
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ BaseRestUtils.checkCreateResponse(createResource);
+
+ Resource resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
+ assertEquals(5, resource.getComponentInstances().size());
+
+ assertEquals("verify there are 2 groups", 2, resource.getGroups().size());
+
+ Map<String, String> compNameToUniqueId = resource.getComponentInstances().stream().collect(Collectors.toMap(p -> p.getName(), p -> p.getUniqueId()));
+
+ // Verify 2 members on group1
+ // members: [ app_server, mongo_server ]
+ String[] membersNameGroup1 = { "app_server", "mongo_server" };
+ verifyMembersInResource(resource, compNameToUniqueId, "group1", membersNameGroup1);
+ // Verify 4 members on group2
+ // members: [ mongo_db, nodejs, app_server, mongo_server ]
+ String[] membersNameGroup2 = { "app_server", "mongo_server", "mongo_db", "nodejs" };
+ verifyMembersInResource(resource, compNameToUniqueId, "group2", membersNameGroup2);
+
+ // Check OUT
+ resourceDetails.setUniqueId(resource.getUniqueId());
+ RestResponse changeResourceState = LifecycleRestUtils.changeResourceState(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER), LifeCycleStatesEnum.CHECKIN);
+ assertEquals("Check response code ", BaseRestUtils.STATUS_CODE_SUCCESS, changeResourceState.getErrorCode().intValue());
+
+ changeResourceState = LifecycleRestUtils.changeResourceState(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER), LifeCycleStatesEnum.CHECKOUT);
+ assertEquals("Check response code ", BaseRestUtils.STATUS_CODE_SUCCESS, changeResourceState.getErrorCode().intValue());
+
+ Resource checkedOutResource = ResponseParser.parseToObjectUsingMapper(changeResourceState.getResponse(), Resource.class);
+ compNameToUniqueId = checkedOutResource.getComponentInstances().stream().collect(Collectors.toMap(p -> p.getName(), p -> p.getUniqueId()));
+
+ // Verify 2 members on group1
+ // members: [ app_server, mongo_server ]
+ verifyMembersInResource(checkedOutResource, compNameToUniqueId, "group1", membersNameGroup1);
+ // Verify 4 members on group2
+ // members: [ mongo_db, nodejs, app_server, mongo_server ]
+ verifyMembersInResource(checkedOutResource, compNameToUniqueId, "group2", membersNameGroup2);
+
+ }
+
+ private void verifyMembersInResource(Resource resource, Map<String, String> compNameToUniqueId, String groupName, String[] membersName) {
+ GroupDefinition groupDefinition = resource.getGroups().stream().filter(p -> p.getName().equals(groupName)).findFirst().get();
+ assertEquals("Verify number of members", membersName.length, groupDefinition.getMembers().size());
+ Map<String, String> createdMembers = groupDefinition.getMembers();
+ Arrays.asList(membersName).forEach(p -> {
+ assertTrue("check member name exist", createdMembers.containsKey(p));
+ });
+
+ verifyMembers(createdMembers, compNameToUniqueId);
+ }
+
+ @Test(enabled = true)
+ public void createResourceFromCsarWithGroupsAndPropertiesHappy() throws Exception {
+
+ RestResponse importNewGroupTypeByName = ImportRestUtils.importNewGroupTypeByName("myHeatStack1", UserRoleEnum.ADMIN);
+ // BaseRestUtils.checkCreateResponse(importNewGroupTypeByName);
+
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setCsarUUID("csarWithGroupsWithProps");
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ BaseRestUtils.checkCreateResponse(createResource);
+
+ Resource resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
+ assertEquals(5, resource.getComponentInstances().size());
+
+ assertEquals("verify there are 2 groups", 2, resource.getGroups().size());
+
+ Map<String, String> compNameToUniqueId = resource.getComponentInstances().stream().collect(Collectors.toMap(p -> p.getName(), p -> p.getUniqueId()));
+
+ // Verify 2 members on group1
+ // members: [ app_server, mongo_server ]
+ List<GroupDefinition> groupDefinition1 = resource.getGroups().stream().filter(p -> p.getName().equals("group1")).collect(Collectors.toList());
+ assertEquals("Verify number of members", 2, groupDefinition1.get(0).getMembers().size());
+ Map<String, String> createdMembers = groupDefinition1.get(0).getMembers();
+ verifyMembers(createdMembers, compNameToUniqueId);
+
+ List<PropertyDataDefinition> properties = groupDefinition1.get(0).getProperties();
+ assertEquals("Verify number of members", 2, properties.size());
+
+ PropertyDataDefinition heatFiles = properties.stream().filter(p -> p.getName().equals("heat_files")).findFirst().get();
+ assertNotNull("check heat files not empty", heatFiles);
+ List<String> heatFilesValue = new ArrayList<>();
+ heatFilesValue.add("heat1.yaml");
+ heatFilesValue.add("heat2.yaml");
+ String heatFilesJson = gson.toJson(heatFilesValue);
+ log.debug(heatFiles.getValue());
+ assertEquals("check heat files value", heatFilesJson, heatFiles.getValue());
+
+ PropertyDataDefinition urlCredential = properties.stream().filter(p -> p.getName().equals("url_credential")).findFirst().get();
+ assertNotNull("check heat files not empty", urlCredential);
+ log.debug(urlCredential.getValue());
+ assertEquals("check url credential", "{\"protocol\":\"protocol1\",\"keys\":{\"keya\":\"valuea\",\"keyb\":\"valueb\"}}", urlCredential.getValue());
+ }
+
+ @Test(enabled = true)
+ public void createResourceFromCsarWithGroupsAndPropertyInvalidValue() throws Exception {
+
+ RestResponse importNewGroupTypeByName = ImportRestUtils.importNewGroupTypeByName("myHeatStack1", UserRoleEnum.ADMIN);
+ // BaseRestUtils.checkCreateResponse(importNewGroupTypeByName);
+
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setCsarUUID("csarWithGroupsInvalidPropertyValue");
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+
+ BaseRestUtils.checkStatusCode(createResource, "Check bad request error", false, 400);
+
+ }
+
+ @Test(enabled = true)
+ public void createResourceFromCsarWithGroupsAndInvalidPropertyName() throws Exception {
+
+ RestResponse importNewGroupTypeByName = ImportRestUtils.importNewGroupTypeByName("myHeatStack1", UserRoleEnum.ADMIN);
+ // BaseRestUtils.checkCreateResponse(importNewGroupTypeByName);
+
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setCsarUUID("csarWithGroupsPropertyNotExist");
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+
+ BaseRestUtils.checkStatusCode(createResource, "Check bad request error", false, 400);
+ BaseRestUtils.checkErrorResponse(createResource, ActionStatus.GROUP_PROPERTY_NOT_FOUND, "url_credential111", "group1", "org.openecomp.groups.MyHeatStack1");
+
+ }
+
+ @Test(enabled = true)
+ public void createResourceFromCsarGroupTypeNotExist() throws Exception {
+
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setCsarUUID("csarWithGroupsInvalidGroupType");
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+
+ BaseRestUtils.checkStatusCode(createResource, "Check bad request error", false, 400);
+ BaseRestUtils.checkErrorResponse(createResource, ActionStatus.GROUP_TYPE_IS_INVALID, "org.openecomp.groups.stamGroupType");
+
+ }
+
+ @Test(enabled = true)
+ public void createResourceFromCsarMemberNotExist() throws Exception {
+
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setCsarUUID("csarWithGroupsInvalidMember");
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+
+ BaseRestUtils.checkStatusCode(createResource, "Check bad request error", false, 400);
+ BaseRestUtils.checkErrorResponse(createResource, ActionStatus.GROUP_INVALID_COMPONENT_INSTANCE, "mycomp", "mygroup", ValidationUtils.normaliseComponentName(resourceDetails.getName()), "VF");
+
+ }
+
+ @Test(enabled = true)
+ public void createResourceFromCsarMemberNotAllowed() throws Exception {
+
+ RestResponse importNewGroupTypeByName = ImportRestUtils.importNewGroupTypeByName("myHeatStack2", UserRoleEnum.ADMIN);
+
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setCsarUUID("csarWithGroupsNotAllowedMember");
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+
+ BaseRestUtils.checkStatusCode(createResource, "Check bad request error", false, 400);
+ BaseRestUtils.checkErrorResponse(createResource, ActionStatus.GROUP_INVALID_TOSCA_NAME_OF_COMPONENT_INSTANCE, "nodejs", "group1", "org.openecomp.groups.MyHeatStack2");
+
+ }
+
+ @Test(enabled = true)
+ public void getResourceFromCsarUuidHappy() throws Exception {
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setCsarUUID("tam");
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ BaseRestUtils.checkCreateResponse(createResource);
+ Resource resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
+ assertEquals(6, resource.getComponentInstances().size());
+
+ String expectedCsarUUID = resourceDetails.getCsarUUID();
+ String expectedToscaResourceName = "org.openecomp.resource.vf." + WordUtils.capitalize(resourceDetails.getName().toLowerCase());
+
+ assertTrue("csarUUID : " + buildAssertMessage(expectedCsarUUID, resource.getCsarUUID()), expectedCsarUUID.equals(resource.getCsarUUID()));
+ assertTrue("toscaResourceName : " + buildAssertMessage(expectedToscaResourceName, resource.getToscaResourceName()), expectedToscaResourceName.equals(resource.getToscaResourceName()));
+
+ RestResponse getResourceResponse = ResourceRestUtils.getLatestResourceFromCsarUuid(resource.getCsarUUID());
+ Resource getResource = ResponseParser.parseToObjectUsingMapper(getResourceResponse.getResponse(), Resource.class);
+ assertTrue("csarUUID : " + buildAssertMessage(expectedCsarUUID, getResource.getCsarUUID()), expectedCsarUUID.equals(getResource.getCsarUUID()));
+ assertTrue("toscaResourceName : " + buildAssertMessage(expectedToscaResourceName, getResource.getToscaResourceName()), expectedToscaResourceName.equals(getResource.getToscaResourceName()));
+ }
+
+ @Test(enabled = true)
+ public void getResourceFromCsarResourceNotFound() throws Exception {
+ String csarUUID = "tam";
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setCsarUUID(csarUUID);
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+
+ RestResponse resResponse = ResourceRestUtils.getLatestResourceFromCsarUuid(csarUUID);
+
+ BaseRestUtils.checkStatusCode(resResponse, "Check bad request error", false, 400);
+ BaseRestUtils.checkErrorResponse(resResponse, ActionStatus.RESOURCE_FROM_CSAR_NOT_FOUND, csarUUID);
+
+ }
+
+ @Test(enabled = true)
+ public void getResourceFromMissingCsar() throws Exception {
+ String csarUUID = "abcdefg12345";
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setCsarUUID(csarUUID);
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+
+ RestResponse resResponse = ResourceRestUtils.getLatestResourceFromCsarUuid(csarUUID);
+
+ BaseRestUtils.checkStatusCode(resResponse, "Check bad request error", false, 400);
+ BaseRestUtils.checkErrorResponse(resResponse, ActionStatus.RESOURCE_FROM_CSAR_NOT_FOUND, csarUUID);
+
+ }
+
+ @Test(enabled = true)
+ public void createUpdateCertifiedImportResourceFromCsarTest() throws Exception {
+ User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
+ RestResponse copyRes = copyCsarRest(sdncModifierDetails, "valid_vf_a.csar", "valid_vf.csar");
+ RestResponse updateResponse = null;
+ String oldName = null;
+ // create new resource from Csar
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setCsarUUID("valid_vf.csar");
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, sdncModifierDetails);
+ BaseRestUtils.checkCreateResponse(createResource);
+ Resource resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
+ assertEquals(5, resource.getComponentInstances().size());
+ String invariantUUID = resource.getInvariantUUID();
+
+ // change metadata
+ // resource name, icon, vendor name, category, template derivedFrom
+ oldName = resourceDetails.getName();
+ resourceDetails.setName("test1");
+ resourceDetails.setIcon("newicon");
+ resourceDetails.setVendorName("newname");
+ createResource = ResourceRestUtils.createResource(resourceDetails, sdncModifierDetails);
+ BaseRestUtils.checkErrorResponse(createResource, ActionStatus.VSP_ALREADY_EXISTS, "valid_vf.csar", oldName);
+
+ updateResponse = ResourceRestUtils.updateResource(resourceDetails, sdncModifierDetails, resourceDetails.getUniqueId());
+ BaseRestUtils.checkSuccess(updateResponse);
+
+ LifecycleRestUtils.certifyResource(resourceDetails);
+ // change metadata
+ // resource name, icon, vendor name, category, template derivedFrom
+ resourceDetails.setName("test2");
+ resourceDetails.setIcon("new icon1");
+ resourceDetails.setVendorName("new name1");
+ resourceDetails.setDescription("bla bla bla");
+ updateResponse = ResourceRestUtils.updateResource(resourceDetails, sdncModifierDetails, resourceDetails.getUniqueId());
+ BaseRestUtils.checkSuccess(updateResponse);
+ resource = ResponseParser.parseToObjectUsingMapper(updateResponse.getResponse(), Resource.class);
+ assertEquals(5, resource.getComponentInstances().size());
+ assertEquals(invariantUUID, resource.getInvariantUUID());
+ assertEquals(resource.getName(), "test1");
+ assertEquals(resource.getIcon(), "newicon");
+ assertEquals(resource.getVendorName(), "newname");
+ assertEquals(resource.getDescription(), "bla bla bla");
+ assertEquals(resource.getTags().contains("test2"), false);
+ }
+
+ @Test
+ public void createImportRIRelationByCapNameFromCsarUITest() throws Exception {
+ User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
+ String payloadName = "vmmc_relate_by_cap_name.csar";
+ ImportReqDetails resourceDetails = ElementFactory.getDefaultImportResource();
+ String rootPath = System.getProperty("user.dir");
+ Path path = null;
+ byte[] data = null;
+ String payloadData = null;
+
+ path = Paths.get(rootPath + "/src/test/resources/CI/csars/vmmc_relate_by_cap_name.csar");
+ data = Files.readAllBytes(path);
+ payloadData = Base64.encodeBase64String(data);
+ resourceDetails.setPayloadData(payloadData);
+
+ // create new resource from Csar
+ resourceDetails.setCsarUUID(payloadName);
+ resourceDetails.setPayloadName(payloadName);
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, sdncModifierDetails);
+ BaseRestUtils.checkCreateResponse(createResource);
+ Resource resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
+ // assert all relations created
+ assertEquals(80, resource.getComponentInstancesRelations().size());
+ }
+
+ @Test
+ public void createImportRIRelationByCapNameFromCsarUITest2() throws Exception {
+ User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
+ String payloadName = "vf_relate_by_cap_name.csar";
+ ImportReqDetails resourceDetails = ElementFactory.getDefaultImportResource();
+ String rootPath = System.getProperty("user.dir");
+ Path path = null;
+ byte[] data = null;
+ String payloadData = null;
+
+ path = Paths.get(rootPath + "/src/test/resources/CI/csars/vf_relate_by_cap_name.csar");
+ data = Files.readAllBytes(path);
+ payloadData = Base64.encodeBase64String(data);
+ resourceDetails.setPayloadData(payloadData);
+
+ // create new resource from Csar
+ resourceDetails.setCsarUUID(payloadName);
+ resourceDetails.setPayloadName(payloadName);
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, sdncModifierDetails);
+ BaseRestUtils.checkCreateResponse(createResource);
+ Resource resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
+ // assert relations created: 1.by name: virtual_linkable. 2.by name:
+ // link
+ Map<String, ComponentInstance> nodes = resource.getComponentInstances().stream().collect(Collectors.toMap(n -> n.getName(), n -> n));
+ Map<String, CapabilityDefinition> capabilities = nodes.get("elinenode").getCapabilities().get("tosca.capabilities.network.Linkable").stream().collect(Collectors.toMap(e -> e.getName(), e -> e));
+ String cp1Uid = nodes.get("cp1node").getUniqueId();
+ String cp2Uid = nodes.get("cp2node").getUniqueId();
+ Map<String, List<RequirementCapabilityRelDef>> mappedByReqOwner = resource.getComponentInstancesRelations().stream().collect(Collectors.groupingBy(e -> e.getFromNode()));
+ assertEquals(mappedByReqOwner.get(cp1Uid).get(0).getRelationships().get(0).getCapabilityUid(), capabilities.get("virtual_linkable").getUniqueId());
+ assertEquals(mappedByReqOwner.get(cp2Uid).get(0).getRelationships().get(0).getCapabilityUid(), capabilities.get("link").getUniqueId());
+ }
+
+ @Test(enabled = true)
+ public void importCsarCheckVfHeatEnv() throws Exception {
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setCsarUUID("csar_1");
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ BaseRestUtils.checkCreateResponse(createResource);
+ Resource resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
+
+
+ Map<String, ArtifactDefinition> deploymentArtifacts = resource.getDeploymentArtifacts();
+ assertNotNull(deploymentArtifacts);
+ // 2 lisence, 1 heat, 1 heatenv
+ assertEquals(4, deploymentArtifacts.size());
+
+ ArtifactDefinition artifactHeat = deploymentArtifacts.get("heat0");
+ assertNotNull(artifactHeat);
+
+ ArtifactDefinition artifactHeatEnv = deploymentArtifacts.get("heat0env");
+ assertNotNull(artifactHeatEnv);
+
+ assertEquals(artifactHeat.getUniqueId(), artifactHeatEnv.getGeneratedFromId());
+ assertEquals("VF HEAT ENV", artifactHeatEnv.getArtifactDisplayName());
+ assertEquals("HEAT_ENV", artifactHeatEnv.getArtifactType());
+ assertEquals("VF Auto-generated HEAT Environment deployment artifact", artifactHeatEnv.getDescription());
+
+ String designerUserId = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER).getUserId();
+ String testerUserId = ElementFactory.getDefaultUser(UserRoleEnum.TESTER).getUserId();
+ RestResponse lifecycleChangeResponse = LifecycleRestUtils.changeResourceState(resourceDetails, designerUserId, LifeCycleStatesEnum.CHECKIN);
+ LifecycleRestUtils.checkSuccess(lifecycleChangeResponse);
+ lifecycleChangeResponse = LifecycleRestUtils.changeResourceState(resourceDetails, designerUserId, LifeCycleStatesEnum.CHECKOUT);
+ LifecycleRestUtils.checkSuccess(lifecycleChangeResponse);
+ lifecycleChangeResponse = LifecycleRestUtils.changeResourceState(resourceDetails, designerUserId, LifeCycleStatesEnum.CHECKIN);
+ LifecycleRestUtils.checkSuccess(lifecycleChangeResponse);
+ lifecycleChangeResponse = LifecycleRestUtils.changeResourceState(resourceDetails, designerUserId, LifeCycleStatesEnum.CERTIFICATIONREQUEST);
+ LifecycleRestUtils.checkSuccess(lifecycleChangeResponse);
+ lifecycleChangeResponse = LifecycleRestUtils.changeResourceState(resourceDetails, testerUserId, LifeCycleStatesEnum.STARTCERTIFICATION);
+ LifecycleRestUtils.checkSuccess(lifecycleChangeResponse);
+ lifecycleChangeResponse = LifecycleRestUtils.changeResourceState(resourceDetails, testerUserId, LifeCycleStatesEnum.CERTIFY);
+ LifecycleRestUtils.checkSuccess(lifecycleChangeResponse);
+ Resource certifiedResource = ResponseParser.parseToObjectUsingMapper(lifecycleChangeResponse.getResponse(), Resource.class);
+
+
+ User modifier = new User();
+ modifier.setUserId(designerUserId);
+
+ ServiceReqDetails serviceDetails = ElementFactory.getDefaultService("newtestservice1", ServiceCategoriesEnum.MOBILITY, designerUserId);
+
+ RestResponse serviceRes = ServiceRestUtils.createService(serviceDetails, modifier);
+ ResourceRestUtils.checkCreateResponse(serviceRes);
+ Service service = ResponseParser.parseToObjectUsingMapper(serviceRes.getResponse(), Service.class);
+
+ ComponentInstanceReqDetails resourceInstanceReqDetails = ElementFactory.getComponentInstance(certifiedResource);
+ RestResponse createResourceInstanceResponse = ComponentInstanceRestUtils.createComponentInstance(resourceInstanceReqDetails, modifier, service.getUniqueId(), service.getComponentType());
+ BaseRestUtils.checkCreateResponse(createResourceInstanceResponse);
+ RestResponse serviceByGet = ServiceRestUtils.getService(service.getUniqueId());
+ service = ResponseParser.parseToObjectUsingMapper(serviceByGet.getResponse(), Service.class);
+
+ List<ComponentInstance> componentInstances = service.getComponentInstances();
+ assertNotNull(componentInstances);
+
+ assertEquals(1, componentInstances.size());
+ ComponentInstance ci = componentInstances.get(0);
+ Map<String, ArtifactDefinition> instDepArtifacts = ci.getDeploymentArtifacts();
+ assertNotNull(instDepArtifacts);
+ ArtifactDefinition instArtifactHeat = instDepArtifacts.get("heat0");
+ assertNotNull(instArtifactHeat);
+
+ ArtifactDefinition instArtifactHeatEnv = instDepArtifacts.get("heat0env");
+ assertNotNull(instArtifactHeatEnv);
+ assertEquals(artifactHeat.getUniqueId(), instArtifactHeatEnv.getGeneratedFromId());
+ assertEquals("HEAT ENV", instArtifactHeatEnv.getArtifactDisplayName());
+ assertEquals("HEAT_ENV", instArtifactHeatEnv.getArtifactType());
+
+ assertEquals(artifactHeat.getUniqueId(), instArtifactHeat.getUniqueId());
+ //different artifacts
+ assertTrue( !artifactHeatEnv.getUniqueId().equals(instArtifactHeat.getUniqueId()) );
+
+
+ }
+
+ @Test(enabled = true)
+ public void createAndUpdateCsarCheckVfHeatEnv() throws Exception {
+ ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setCsarUUID("orig2G_org");
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ BaseRestUtils.checkCreateResponse(createResource);
+ Resource resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
+
+
+ Map<String, ArtifactDefinition> deploymentArtifacts = resource.getDeploymentArtifacts();
+ assertNotNull(deploymentArtifacts);
+
+ assertEquals(13, deploymentArtifacts.size());
+
+ ArtifactDefinition artifactHeat = deploymentArtifacts.get("heat0");
+ assertNotNull(artifactHeat);
+
+ ArtifactDefinition artifactHeatEnv = deploymentArtifacts.get("heat0env");
+ assertNotNull(artifactHeatEnv);
+
+ assertEquals(artifactHeat.getUniqueId(), artifactHeatEnv.getGeneratedFromId());
+ assertEquals("VF HEAT ENV", artifactHeatEnv.getArtifactDisplayName());
+ assertEquals("HEAT_ENV", artifactHeatEnv.getArtifactType());
+ assertEquals("VF Auto-generated HEAT Environment deployment artifact", artifactHeatEnv.getDescription());
+
+ List<GroupDefinition> groups = resource.getGroups();
+ assertEquals(2, groups.size());
+ GroupDefinition group1 = groups.stream().filter(p -> p.getName().contains("module-0")).findAny().get();
+ GroupDefinition group2 = groups.stream().filter(p -> p.getName().contains("module-1")).findAny().get();
+ assertEquals(11, group1.getArtifacts().size());
+ assertEquals(3, group2.getArtifacts().size());
+
+ resourceDetails.setCsarUUID("orig2G_update");
+
+ RestResponse updateResource = ResourceRestUtils.updateResource(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER), resourceDetails.getUniqueId());
+ BaseRestUtils.checkSuccess(updateResource);
+
+ resource = ResponseParser.parseToObjectUsingMapper(updateResource.getResponse(), Resource.class);
+
+
+ Map<String, ArtifactDefinition> deploymentArtifactsUpd = resource.getDeploymentArtifacts();
+ assertNotNull(deploymentArtifactsUpd);
+
+ assertEquals(13, deploymentArtifactsUpd.size());
+
+ ArtifactDefinition artifactHeatUpd = deploymentArtifacts.get("heat0");
+ assertNotNull(artifactHeatUpd);
+
+ ArtifactDefinition artifactHeatEnvUpd = deploymentArtifacts.get("heat0env");
+ assertNotNull(artifactHeatEnvUpd);
+
+ groups = resource.getGroups();
+ assertEquals(2, groups.size());
+ assertEquals(7, groups.get(0).getArtifacts().size());
+ assertEquals(7, groups.get(1).getArtifacts().size());
+
+
+ }
+
+ @Test
+ public void importInnerVfcWithArtifactsSucceed() throws Exception {
+ User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
+ String rootPath = System.getProperty("user.dir");
+ ImportReqDetails resourceDetails = ElementFactory.getDefaultImportResource();
+
+ String payloadName = "ImportArtifactsToVFC.csar";
+ Path path = Paths.get(rootPath + "/src/test/resources/CI/csars/ImportArtifactsToVFC.csar");
+ byte[] data = Files.readAllBytes(path);
+ String payloadData = Base64.encodeBase64String(data);
+ resourceDetails.setPayloadData(payloadData);
+ resourceDetails.setPayloadName(payloadName);
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, sdncModifierDetails);
+ BaseRestUtils.checkCreateResponse(createResource);
+ Resource resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
+
+ List<ComponentInstance> componentInstances = resource.getComponentInstances();
+ List<ComponentInstance> reducedComponentInstances = componentInstances.stream()
+ .filter(ci->ci.getNormalizedName().contains("server_sm"))
+ .collect(Collectors.toList());
+ assertTrue(!reducedComponentInstances.isEmpty() && reducedComponentInstances.size() == 2);
+ reducedComponentInstances.stream().forEach(ci->isValidArtifacts(ci));
+
+ payloadName = "ImportArtifactsToVFC_empty.csar";
+ path = Paths.get(rootPath + "/src/test/resources/CI/csars/ImportArtifactsToVFC_empty.csar");
+ data = Files.readAllBytes(path);
+ payloadData = Base64.encodeBase64String(data);
+ resourceDetails.setName(resourceDetails.getName()+"2");
+ resourceDetails.setPayloadData(payloadData);
+ resourceDetails.setPayloadName(payloadName);
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+
+ createResource = ResourceRestUtils.createResource(resourceDetails, sdncModifierDetails);
+ BaseRestUtils.checkCreateResponse(createResource);
+ resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
+
+ componentInstances = resource.getComponentInstances();
+ reducedComponentInstances = componentInstances.stream()
+ .filter(ci->ci.getNormalizedName().contains("server_sm"))
+ .collect(Collectors.toList());
+ assertTrue(!reducedComponentInstances.isEmpty() && reducedComponentInstances.size() == 2);
+ reducedComponentInstances.stream()
+ .forEach(ci->assertTrue(
+ (ci.getDeploymentArtifacts()==null || ci.getDeploymentArtifacts().isEmpty()) &&
+ (ci.getArtifacts()==null || ci.getArtifacts().isEmpty()))
+ );
+ }
+
+ private void isValidArtifacts(ComponentInstance ci) {
+ assertTrue(!ci.getDeploymentArtifacts().isEmpty() && ci.getDeploymentArtifacts().size() == 11);
+ ci.getDeploymentArtifacts().values().stream()
+ .forEach(a->assertTrue(a.getArtifactName().startsWith("Some")));
+
+ assertTrue(!ci.getArtifacts().isEmpty() && ci.getArtifacts().size() == 1);
+ ci.getArtifacts().values().stream()
+ .forEach(a->assertTrue(a.getArtifactName().startsWith("Process")));
+ }
+
+ private void verifyMembers(Map<String, String> createdMembers, Map<String, String> compNameToUniqueId) {
+ for (Map.Entry<String, String> entry : createdMembers.entrySet()) {
+ String key = entry.getKey();
+ String value = entry.getValue();
+ String comparedValue = compNameToUniqueId.get(key);
+
+ assertEquals("compare instance ids", comparedValue, value);
+ }
+
+ }
+
+ private static Map<String, String> prepareHeadersMap(String userId) {
+ Map<String, String> headersMap = new HashMap<String, String>();
+ headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), "application/json");
+ headersMap.put(HttpHeaderEnum.ACCEPT.getValue(), "application/json");
+ if (userId != null) {
+ headersMap.put(HttpHeaderEnum.USER_ID.getValue(), userId);
+ }
+ return headersMap;
+ }
+
+}
diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/ImportGenericResourceCITest.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/ImportGenericResourceCITest.java
new file mode 100644
index 0000000000..110fa0f53c
--- /dev/null
+++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/ImportGenericResourceCITest.java
@@ -0,0 +1,600 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * 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.openecomp.sdc.ci.tests.execute.imports;
+
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertFalse;
+import static org.testng.AssertJUnit.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.FileSystems;
+import java.nio.file.Files;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.http.HttpStatus;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.mime.MultipartEntityBuilder;
+import org.apache.http.entity.mime.content.FileBody;
+import org.apache.http.entity.mime.content.StringBody;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+
+import org.junit.Rule;
+import org.junit.rules.TestName;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.category.CategoryDefinition;
+import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
+import org.openecomp.sdc.ci.tests.api.Urls;
+import org.openecomp.sdc.ci.tests.config.Config;
+import org.openecomp.sdc.ci.tests.datatypes.enums.ErrorInfo;
+import org.openecomp.sdc.ci.tests.datatypes.enums.ImportTestTypesEnum;
+import org.openecomp.sdc.ci.tests.datatypes.enums.NormativeTypesEnum;
+import org.openecomp.sdc.ci.tests.datatypes.enums.RespJsonKeysEnum;
+import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
+import org.openecomp.sdc.ci.tests.datatypes.expected.ExpectedResourceAuditJavaObject;
+import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
+import org.openecomp.sdc.ci.tests.execute.TODO.ImportCapabilityTypeCITest;
+import org.openecomp.sdc.ci.tests.utils.DbUtils;
+import org.openecomp.sdc.ci.tests.utils.Utils;
+import org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils;
+import org.openecomp.sdc.ci.tests.utils.rest.ImportRestUtils;
+import org.openecomp.sdc.ci.tests.utils.rest.ResourceRestUtils;
+import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
+import org.openecomp.sdc.ci.tests.utils.validation.AuditValidationUtils;
+import org.openecomp.sdc.ci.tests.utils.validation.ErrorValidationUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import com.google.gson.Gson;
+
+import fj.data.Either;
+
+public class ImportGenericResourceCITest extends ComponentBaseTest {
+ private static Logger log = LoggerFactory.getLogger(ImportGenericResourceCITest.class.getName());
+ private static final String FILE_NAME_MY_COMPUTE = "tosca.nodes.MyCompute";
+ private static final String RESOURCE_NAME_UPDATE_COMPUTE = "userUpdateCompute";
+ private static final String RESOURCE_NAME_MY_COMPUTE = "myCompute";
+ private static final String RESOURCE_NAME_USER_COMPUTE = "userCompute";
+ private static final String FILE_NAME_USER_COMPUTE = "tosca.nodes.userCompute";
+ @Rule
+ public static TestName name = new TestName();
+
+ public ImportGenericResourceCITest() {
+ super(name, ImportGenericResourceCITest.class.getName());
+ }
+
+ @BeforeClass
+ public static void beforeImportClass() throws IOException {
+ ImportCapabilityTypeCITest.importAllCapabilityTypes();
+ // removeAllNormativeTypeResources();
+ // importAllNormativeTypesResources(UserRoleEnum.ADMIN);
+ }
+
+ static Config config = Config.instance();
+
+ public static Map<NormativeTypesEnum, Boolean> removeAllNormativeTypeResources() throws ClientProtocolException, IOException {
+ Map<NormativeTypesEnum, Boolean> normativeExistInDB = new HashMap<>();
+
+ for (NormativeTypesEnum current : NormativeTypesEnum.values()) {
+ Boolean existedBeforeDelete = ImportRestUtils.removeNormativeTypeResource(current);
+ normativeExistInDB.put(current, existedBeforeDelete);
+ }
+ return normativeExistInDB;
+ }
+
+ public static Either<String, Boolean> getNormativeTypeResource(NormativeTypesEnum current) throws ClientProtocolException, IOException {
+ return getResource(current.getNormativeName(), "1.0");
+ }
+
+ @Test
+ public void importAllTestResources() throws Exception {
+ for (ImportTestTypesEnum currResource : ImportTestTypesEnum.values()) {
+ DbUtils.cleanAllAudits();
+
+ RestResponse importResponse = ImportRestUtils.importTestResource(currResource, UserRoleEnum.ADMIN);
+ // System.err.println("import Resource
+ // "+"<"+currResource+">"+"response:
+ // "+importResponse.getErrorCode());
+ ImportRestUtils.validateImportTestTypesResp(currResource, importResponse);
+ if (currResource.getvalidateAudit() == true) {
+ // validate audit
+ String baseVersion = "1.0";
+ ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(currResource.getActionStatus().name());
+ ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = new ExpectedResourceAuditJavaObject();
+ String auditAction = "ResourceImport";
+ expectedResourceAuditJavaObject.setAction(auditAction);
+ expectedResourceAuditJavaObject.setModifierUid(UserRoleEnum.ADMIN.getUserId());
+ expectedResourceAuditJavaObject.setModifierName(UserRoleEnum.ADMIN.getUserName());
+ expectedResourceAuditJavaObject.setResourceName(currResource.getNormativeName());
+ expectedResourceAuditJavaObject.setResourceType("Resource");
+ expectedResourceAuditJavaObject.setPrevVersion("");
+ expectedResourceAuditJavaObject.setCurrVersion(baseVersion);
+ expectedResourceAuditJavaObject.setPrevState("");
+ expectedResourceAuditJavaObject.setCurrState(LifecycleStateEnum.CERTIFIED.toString());
+ expectedResourceAuditJavaObject.setComment(null);
+ expectedResourceAuditJavaObject.setStatus(errorInfo.getCode().toString());
+ List<String> variables = (currResource.getErrorParams() != null ? currResource.getErrorParams() : new ArrayList<String>());
+ String auditDesc = AuditValidationUtils.buildAuditDescription(errorInfo, variables);
+ expectedResourceAuditJavaObject.setDesc(auditDesc);
+ AuditValidationUtils.validateAuditImport(expectedResourceAuditJavaObject, auditAction);
+ }
+ }
+ }
+
+ // -----------------------------------------------------------------------------------
+ protected void validateMyComputeCapabilities(Map<String, Object> map) {
+ assertTrue(map.containsKey("capabilities"));
+ Map<String, Object> capabilities = (Map<String, Object>) map.get("capabilities");
+ assertTrue(capabilities.containsKey("tosca.capabilities.Container"));
+ List<Object> hostCapList = (List<Object>) capabilities.get("tosca.capabilities.Container");
+ assertFalse(hostCapList.isEmpty());
+ Map<String, Object> hostCap = (Map<String, Object>) hostCapList.get(0);
+ validateField(hostCap, "type", "tosca.capabilities.Container");
+ validateField(hostCap, "name", "host");
+ validateField(hostCap, "validSourceTypes", Arrays.asList(new String[] { "tosca.nodes.SoftwareComponent" }));
+
+ assertTrue(capabilities.containsKey("tosca.capabilities.Endpoint.Admin"));
+ List<Object> endPointCapList = (List<Object>) capabilities.get("tosca.capabilities.Endpoint.Admin");
+ assertFalse(endPointCapList.isEmpty());
+ Map<String, Object> endPointCap = (Map<String, Object>) endPointCapList.get(0);
+ validateField(endPointCap, "name", "endpoint");
+ validateField(endPointCap, "type", "tosca.capabilities.Endpoint.Admin");
+
+ assertTrue(capabilities.containsKey("tosca.capabilities.OperatingSystem"));
+ List<Object> osCapList = (List<Object>) capabilities.get("tosca.capabilities.OperatingSystem");
+ assertFalse(osCapList.isEmpty());
+ Map<String, Object> osCap = (Map<String, Object>) osCapList.get(0);
+ validateField(osCap, "name", "os");
+ validateField(osCap, "type", "tosca.capabilities.OperatingSystem");
+
+ assertTrue(capabilities.containsKey("tosca.capabilities.Scalable"));
+ List<Object> scalableCapList = (List<Object>) capabilities.get("tosca.capabilities.Scalable");
+ assertFalse(scalableCapList.isEmpty());
+ Map<String, Object> scalableCap = (Map<String, Object>) scalableCapList.get(0);
+ validateField(scalableCap, "name", "scalable");
+ validateField(scalableCap, "type", "tosca.capabilities.Scalable");
+
+ assertTrue(capabilities.containsKey("tosca.capabilities.network.Bindable"));
+ List<Object> bindingCapList = (List<Object>) capabilities.get("tosca.capabilities.network.Bindable");
+ assertFalse(bindingCapList.isEmpty());
+ Map<String, Object> bindingCap = (Map<String, Object>) bindingCapList.get(0);
+ validateField(bindingCap, "name", "binding");
+ validateField(bindingCap, "type", "tosca.capabilities.network.Bindable");
+
+ }
+
+ protected void validateMyComputeResource(String resourceName, String resourceVersion, String expectedState) throws ClientProtocolException, IOException {
+ Either<String, Boolean> eitherMyCompute = getResource(resourceName, resourceVersion);
+ assertTrue(eitherMyCompute.isLeft());
+ String testComputeYml = eitherMyCompute.left().value();
+
+ Map<String, Object> map = new HashMap<String, Object>();
+ map = (Map<String, Object>) new Gson().fromJson(testComputeYml, map.getClass());
+
+ validateMyComputeBasicFields(map, resourceName, resourceVersion, expectedState);
+
+ validateMyComputeCapabilities(map);
+
+ validateMyComputeRequirements(map);
+ validateField(map, RespJsonKeysEnum.RESOURCE_VERSION.getRespJsonKeyName(), resourceVersion);
+
+ }
+
+ protected void validateMyComputeResource(String uid, String resourceName, String resourceVersion, String expectedState) throws ClientProtocolException, IOException {
+ RestResponse resourceResponse = ResourceRestUtils.getResource(uid);
+ ResourceRestUtils.checkSuccess(resourceResponse);
+ String testComputeYml = resourceResponse.getResponse();
+
+ // Either<String, Boolean> eitherMyCompute = getResource(resourceName,
+ // resourceVersion);
+ // assertTrue( eitherMyCompute.isLeft() );
+ // String testComputeYml = eitherMyCompute.left().value();
+
+ Map<String, Object> map = new HashMap<String, Object>();
+ map = (Map<String, Object>) new Gson().fromJson(testComputeYml, map.getClass());
+
+ validateMyComputeBasicFields(map, resourceName, resourceVersion, expectedState);
+
+ validateMyComputeCapabilities(map);
+
+ validateMyComputeRequirements(map);
+ validateField(map, RespJsonKeysEnum.RESOURCE_VERSION.getRespJsonKeyName(), resourceVersion);
+
+ }
+
+ protected void validateMyComputeResourceAfterUpdate(String uid, String resourceName, String resourceVersion, String expectedState) throws ClientProtocolException, IOException {
+ RestResponse resourceResponse = ResourceRestUtils.getResource(uid);
+ ResourceRestUtils.checkSuccess(resourceResponse);
+ String testComputeYml = resourceResponse.getResponse();
+
+ // Either<String, Boolean> eitherMyCompute = getResource(resourceName,
+ // resourceVersion);
+ // assertTrue( eitherMyCompute.isLeft() );
+
+ // String testComputeYml = eitherMyCompute.left().value();
+
+ Map<String, Object> map = new HashMap<String, Object>();
+ map = (Map<String, Object>) new Gson().fromJson(testComputeYml, map.getClass());
+
+ validateMyComputeBasicFields(map, resourceName, resourceVersion, expectedState);
+ validateField(map, RespJsonKeysEnum.DESCRIPTION.getRespJsonKeyName(), "Short description");
+ validateField(map, RespJsonKeysEnum.VENDOR_NAME.getRespJsonKeyName(), "UserVendor");
+ validateField(map, RespJsonKeysEnum.VENDOR_RELEASE.getRespJsonKeyName(), "1.1.2");
+
+ // validateMyComputeCapabilities(map);
+ // AssertJUnit.assertTrue(map.containsKey("capabilities"));
+ // Map<String, Object> capabilities = (Map<String, Object>)
+ // map.get("capabilities");
+ // AssertJUnit.assertTrue(capabilities.containsKey("host"));
+ // Map<String, Object> hostCap = (Map<String, Object>)
+ // capabilities.get("host");
+ // validateField(hostCap, "type", "tosca.capabilities.Container");
+ // validateField(hostCap, "validSourceTypes", Arrays.asList(new
+ // String[]{"tosca.nodes.SoftwareComponent"}));
+ //
+ // AssertJUnit.assertTrue(capabilities.containsKey("endpoint"));
+ // Map<String, Object> endPointCap = (Map<String, Object>)
+ // capabilities.get("endpoint");
+ // validateField(endPointCap, "type",
+ // "tosca.capabilities.Endpoint.Admin");
+
+ assertTrue(map.containsKey("capabilities"));
+ Map<String, Object> capabilities = (Map<String, Object>) map.get("capabilities");
+ assertTrue(capabilities.containsKey("tosca.capabilities.Container"));
+ List<Object> hostCapList = (List<Object>) capabilities.get("tosca.capabilities.Container");
+ assertFalse(hostCapList.isEmpty());
+ Map<String, Object> hostCap = (Map<String, Object>) hostCapList.get(0);
+ validateField(hostCap, "type", "tosca.capabilities.Container");
+ validateField(hostCap, "name", "host");
+ validateField(hostCap, "validSourceTypes", Arrays.asList(new String[] { "tosca.nodes.SoftwareComponent" }));
+
+ assertTrue(capabilities.containsKey("tosca.capabilities.Endpoint.Admin"));
+ List<Object> endPointCapList = (List<Object>) capabilities.get("tosca.capabilities.Endpoint.Admin");
+ assertFalse(endPointCapList.isEmpty());
+ Map<String, Object> endPointCap = (Map<String, Object>) endPointCapList.get(0);
+ validateField(endPointCap, "name", "endpoint");
+ validateField(endPointCap, "type", "tosca.capabilities.Endpoint.Admin");
+
+ validateMyComputeRequirements(map);
+ validateField(map, RespJsonKeysEnum.RESOURCE_VERSION.getRespJsonKeyName(), resourceVersion);
+
+ }
+
+ protected void validateMyComputeRequirements(Map<String, Object> map) {
+ assertTrue(map.containsKey("requirements"));
+ Map<String, Object> requirements = (Map<String, Object>) map.get("requirements");
+
+ assertTrue(requirements.containsKey("tosca.capabilities.Attachment"));
+ List<Object> localStorageReqList = (List<Object>) requirements.get("tosca.capabilities.Attachment");
+ assertFalse(localStorageReqList.isEmpty());
+ Map<String, Object> localStorageReq = (Map<String, Object>) localStorageReqList.get(0);
+ validateField(localStorageReq, "capability", "tosca.capabilities.Attachment");
+ validateField(localStorageReq, "node", "tosca.nodes.BlockStorage");
+ validateField(localStorageReq, "relationship", "tosca.relationships.AttachesTo");
+ validateField(localStorageReq, "name", "local_storage");
+ }
+
+ protected void validateMyComputeBasicFields(Map<String, Object> map, String resourceName, String resourceVersion, String expectedState) {
+ validateField(map, RespJsonKeysEnum.IS_ABSTRACT.getRespJsonKeyName(), false);
+ // validateField(map, RespJsonKeysEnum.CATEGORIES.getRespJsonKeyName(),
+ // categoryDefinition);
+ // validateField(map, RespJsonKeysEnum.UNIQUE_ID.getRespJsonKeyName(),
+ // UniqueIdBuilder.buildResourceUniqueId(resourceName,
+ // resourceVersion));
+ validateField(map, RespJsonKeysEnum.RESOURCE_NAME.getRespJsonKeyName(), resourceName);
+ validateField(map, RespJsonKeysEnum.TAGS.getRespJsonKeyName(), Arrays.asList(new String[] { resourceName }));
+ validateField(map, RespJsonKeysEnum.LIFE_CYCLE_STATE.getRespJsonKeyName(), expectedState);
+
+ validateField(map, RespJsonKeysEnum.DERIVED_FROM.getRespJsonKeyName(), Arrays.asList(new String[] { "tosca.nodes.Root" }));
+ }
+
+ protected static void validateField(Map<String, Object> map, String jsonField, Object expectedValue) {
+ if (expectedValue == null) {
+ assertTrue(!map.containsKey(jsonField));
+ } else {
+ assertTrue("map does not contain field " + jsonField, map.containsKey(jsonField));
+ Object foundValue = map.get(jsonField);
+ compareElements(expectedValue, foundValue);
+ }
+ }
+
+ protected static void compareElements(Object expectedValue, Object foundValue) {
+ if (expectedValue instanceof String) {
+ assertTrue(foundValue instanceof String);
+ assertTrue(foundValue.equals(expectedValue));
+ }
+
+ else if (expectedValue instanceof Boolean) {
+ assertTrue(foundValue instanceof Boolean);
+ assertTrue(foundValue == expectedValue);
+ } else if (expectedValue instanceof Map) {
+ assertTrue(foundValue instanceof Map);
+ Map<String, Object> foundMap = (Map<String, Object>) foundValue;
+ Map<String, Object> excpectedMap = (Map<String, Object>) expectedValue;
+ assertTrue(foundMap.size() == excpectedMap.size());
+ Iterator<String> foundkeyItr = foundMap.keySet().iterator();
+ while (foundkeyItr.hasNext()) {
+ String foundKey = foundkeyItr.next();
+ assertTrue(excpectedMap.containsKey(foundKey));
+ compareElements(excpectedMap.get(foundKey), foundMap.get(foundKey));
+ }
+
+ } else if (expectedValue instanceof List) {
+ assertTrue(foundValue instanceof List);
+ List<Object> foundList = (List<Object>) foundValue;
+ List<Object> excpectedList = (List<Object>) expectedValue;
+ assertTrue(foundList.size() == excpectedList.size());
+ for (int i = 0; i < foundList.size(); i++) {
+ compareElements(excpectedList.get(i), foundList.get(i));
+ }
+
+ } else if (expectedValue instanceof CategoryDefinition) {
+ assertTrue(foundValue instanceof Map);
+ CategoryDefinition expCat = (CategoryDefinition) expectedValue;
+ Map<String, Object> actCat = (Map<String, Object>) foundValue;
+ assertEquals(expCat.getName(), actCat.get("name"));
+
+ // assertEquals(expCat.getSubcategories().get(0).getName(),
+ // actCat.get("subcategories").getName());
+ } else {
+ assertTrue(foundValue.equals(expectedValue));
+ }
+ }
+
+ public static void restoreToOriginalState(Map<NormativeTypesEnum, Boolean> originalState, UserRoleEnum userRole) throws IOException {
+ removeAllNormativeTypeResources();
+
+ Iterator<Entry<NormativeTypesEnum, Boolean>> iterator = originalState.entrySet().iterator();
+ while (iterator.hasNext()) {
+ Entry<NormativeTypesEnum, Boolean> entry = iterator.next();
+ Boolean isExistBeforeDelete = entry.getValue();
+ if (isExistBeforeDelete) {
+ importNormativeResource(entry.getKey(), userRole);
+ }
+ }
+
+ }
+
+ public static void importAllNormativeTypesResources(UserRoleEnum userRole) throws IOException {
+ for (NormativeTypesEnum currResource : NormativeTypesEnum.values()) {
+ Either<String, Boolean> resource = getResource(currResource.getNormativeName(), "1.0");
+ if (resource.isRight()) {
+ importNormativeResource(currResource, userRole);
+ }
+ }
+
+ }
+
+ protected static Integer importNormativeResource(NormativeTypesEnum resource, UserRoleEnum userRole) throws IOException {
+ return importResource(resource.getFolderName(), userRole, true);
+ }
+
+ protected static Integer importResource(String folderName, UserRoleEnum userRole, boolean isNormative) throws IOException {
+ Config config = Utils.getConfig();
+ CloseableHttpResponse response = null;
+ MultipartEntityBuilder mpBuilder = MultipartEntityBuilder.create();
+
+ mpBuilder.addPart("resourceZip", new FileBody(getZipFile(folderName)));
+ mpBuilder.addPart("resourceMetadata", new StringBody(getJsonStringOfFile(folderName, folderName + ".json"), ContentType.APPLICATION_JSON));
+
+ String url = String.format(Urls.IMPORT_RESOURCE_NORMATIVE, config.getCatalogBeHost(), config.getCatalogBePort());
+ if (!isNormative) {
+ url = String.format(Urls.IMPORT_USER_RESOURCE, config.getCatalogBeHost(), config.getCatalogBePort());
+ }
+
+ CloseableHttpClient client = HttpClients.createDefault();
+ try {
+ HttpPost httpPost = new HttpPost(url);
+ httpPost.addHeader("USER_ID", userRole.getUserId());
+ httpPost.setEntity(mpBuilder.build());
+ response = client.execute(httpPost);
+ return response.getStatusLine().getStatusCode();
+ } finally {
+ closeResponse(response);
+ closeHttpClient(client);
+
+ }
+ }
+
+ public static void closeHttpClient(CloseableHttpClient client) {
+ try {
+ if (client != null) {
+ client.close();
+ }
+ } catch (IOException e) {
+ log.debug("failed to close client or response: ", e);
+ }
+ }
+
+ public static void closeResponse(CloseableHttpResponse response) {
+ try {
+ if (response != null) {
+ response.close();
+ }
+ } catch (IOException e) {
+ log.debug("failed to close client or response: ", e);
+ }
+ }
+
+ protected static String getJsonStringOfFile(String folderName, String fileName) throws IOException {
+ String sourceDir = config.getImportResourceConfigDir();
+ sourceDir += File.separator + "normative-types";
+
+ java.nio.file.Path filePath = FileSystems.getDefault().getPath(sourceDir + File.separator + folderName, fileName);
+ byte[] fileContent = Files.readAllBytes(filePath);
+ String content = new String(fileContent);
+ return content;
+ }
+
+ protected static File getZipFile(String elementName) throws IOException {
+ String sourceDir = config.getImportResourceConfigDir();
+ sourceDir += File.separator + "normative-types";
+
+ java.nio.file.Path filePath = FileSystems.getDefault().getPath(sourceDir + File.separator + elementName, "normative-types-new-" + elementName + ".zip");
+ return filePath.toFile();
+ }
+
+ protected static String getTestJsonStringOfFile(String folderName, String fileName) throws IOException {
+ String sourceDir = config.getImportResourceTestsConfigDir();
+ java.nio.file.Path filePath = FileSystems.getDefault().getPath(sourceDir + File.separator + folderName, fileName);
+ byte[] fileContent = Files.readAllBytes(filePath);
+ String content = new String(fileContent);
+ return content;
+ }
+
+ protected static File getTestZipFile(String elementName) throws IOException {
+ String sourceDir = config.getImportResourceTestsConfigDir();
+
+ java.nio.file.Path filePath = FileSystems.getDefault().getPath(sourceDir + File.separator + elementName, "normative-types-new-" + elementName + ".zip");
+ return filePath.toFile();
+ }
+
+ protected static Either<String, Boolean> getResource(String name, String version) throws IOException {
+ RestResponse resource = ResourceRestUtils.getResourceByNameAndVersion(UserRoleEnum.DESIGNER.getUserId(), name, version);
+ if (resource.getErrorCode() == ImportRestUtils.STATUS_CODE_GET_SUCCESS) {
+ return Either.left(resource.getResponse());
+ // return Either.right(true);
+
+ }
+ return Either.right(false);
+ }
+
+ @Test
+ public void testImportWithRequirmentsAndCapabilities() throws IOException {
+ String fileName = FILE_NAME_MY_COMPUTE;
+ RestResponse response = ImportRestUtils.importNormativeResourceByName(RESOURCE_NAME_MY_COMPUTE, UserRoleEnum.ADMIN);
+ Integer statusCode = response.getErrorCode();
+ assertTrue(statusCode == ImportRestUtils.STATUS_CODE_IMPORT_SUCCESS);
+ String uid = ResponseParser.getUniqueIdFromResponse(response);
+ validateMyComputeResource(uid, fileName, "1.0", "CERTIFIED");
+ }
+
+ @Test
+ public void testImportWithUpdateNormativeType() throws IOException {
+ String fileName = FILE_NAME_MY_COMPUTE;
+ RestResponse response = ImportRestUtils.importNormativeResourceByName(RESOURCE_NAME_MY_COMPUTE, UserRoleEnum.ADMIN);
+ Integer statusCode = response.getErrorCode();
+ assertTrue(statusCode == BaseRestUtils.STATUS_CODE_IMPORT_SUCCESS);
+ String uid = ResponseParser.getUniqueIdFromResponse(response);
+ validateMyComputeResource(uid, fileName, "1.0", "CERTIFIED");
+
+ // update
+ response = ImportRestUtils.importNormativeResourceByName(RESOURCE_NAME_MY_COMPUTE, UserRoleEnum.ADMIN);
+ statusCode = response.getErrorCode();
+ assertTrue(statusCode == ImportRestUtils.STATUS_CODE_UPDATE_SUCCESS);
+ uid = ResponseParser.getUniqueIdFromResponse(response);
+ validateMyComputeResource(uid, fileName, "2.0", "CERTIFIED");
+
+ }
+
+ @Test
+ public void testImportWithInvalidDefaultValue() throws IOException {
+ RestResponse response = ImportRestUtils.importNewResourceByName("portInvalidDefaultValue", UserRoleEnum.DESIGNER);
+ assertTrue(response.getErrorCode() == HttpStatus.SC_BAD_REQUEST);
+ }
+
+ @Test
+ public void testImportUserResource() throws IOException {
+ String fileName = FILE_NAME_USER_COMPUTE;
+ RestResponse response = ImportRestUtils.importNewResourceByName(RESOURCE_NAME_USER_COMPUTE, UserRoleEnum.DESIGNER);
+ Integer statusCode = response.getErrorCode();
+ assertTrue(statusCode == ImportRestUtils.STATUS_CODE_IMPORT_SUCCESS);
+ String uid = ResponseParser.getUniqueIdFromResponse(response);
+ validateMyComputeResource(uid, fileName, "0.1", "NOT_CERTIFIED_CHECKOUT");
+
+ }
+
+ @Test
+ public void testImportAndUpdateUserResource() throws IOException {
+ String fileName = FILE_NAME_USER_COMPUTE;
+ RestResponse response = ImportRestUtils.importNewResourceByName(RESOURCE_NAME_USER_COMPUTE, UserRoleEnum.DESIGNER);
+ Integer statusCode = response.getErrorCode();
+ assertTrue(statusCode == ImportRestUtils.STATUS_CODE_IMPORT_SUCCESS);
+ String uid = ResponseParser.getUniqueIdFromResponse(response);
+ validateMyComputeResource(uid, fileName, "0.1", "NOT_CERTIFIED_CHECKOUT");
+ response = ImportRestUtils.importNewResourceByName(RESOURCE_NAME_UPDATE_COMPUTE, UserRoleEnum.DESIGNER);
+ statusCode = response.getErrorCode();
+ assertTrue(statusCode == ImportRestUtils.STATUS_CODE_UPDATE_SUCCESS);
+ uid = ResponseParser.getUniqueIdFromResponse(response);
+ validateMyComputeResourceAfterUpdate(uid, fileName, "0.1", "NOT_CERTIFIED_CHECKOUT");
+
+ }
+
+ @Test
+ public void testImportAndUpdateChangesUserResource() throws IOException {
+ String fileName = FILE_NAME_USER_COMPUTE;
+ RestResponse response = ImportRestUtils.importNewResourceByName(RESOURCE_NAME_USER_COMPUTE, UserRoleEnum.DESIGNER);
+ Integer statusCode = response.getErrorCode();
+ assertTrue(statusCode == ImportRestUtils.STATUS_CODE_IMPORT_SUCCESS);
+ String uid = ResponseParser.getUniqueIdFromResponse(response);
+ validateMyComputeResource(uid, fileName, "0.1", "NOT_CERTIFIED_CHECKOUT");
+ // Either<String, Boolean> resource = getResource(fileName, "0.1");
+ // assertTrue(resource.isLeft());
+
+ response = ImportRestUtils.importNewResourceByName(RESOURCE_NAME_UPDATE_COMPUTE, UserRoleEnum.DESIGNER);
+ statusCode = response.getErrorCode();
+ assertTrue(statusCode == ImportRestUtils.STATUS_CODE_UPDATE_SUCCESS);
+ validateMyComputeResourceAfterUpdate(uid, fileName, "0.1", "NOT_CERTIFIED_CHECKOUT");
+
+ }
+
+ @Test
+ public void testImportCheckoutAndUpdateUserResource() throws IOException {
+ String fileName = FILE_NAME_USER_COMPUTE;
+ RestResponse response = ImportRestUtils.importNormativeResourceByName(RESOURCE_NAME_USER_COMPUTE, UserRoleEnum.ADMIN);
+ Integer statusCode = response.getErrorCode();
+ assertTrue(statusCode == ImportRestUtils.STATUS_CODE_IMPORT_SUCCESS);
+ String uid = ResponseParser.getUniqueIdFromResponse(response);
+ validateMyComputeResource(uid, fileName, "1.0", "CERTIFIED");
+
+ response = ImportRestUtils.importNewResourceByName(RESOURCE_NAME_USER_COMPUTE, UserRoleEnum.DESIGNER);
+ statusCode = response.getErrorCode();
+ assertEquals("check response code after update resource", ImportRestUtils.STATUS_CODE_UPDATE_SUCCESS, statusCode.intValue());
+ uid = ResponseParser.getUniqueIdFromResponse(response);
+ validateMyComputeResource(uid, fileName, "1.1", "NOT_CERTIFIED_CHECKOUT");
+
+ }
+
+ @Test
+ public void importNormativeTypesTesterUserRole() throws Exception {
+ Integer statusCode = ImportRestUtils.importNormativeResourceByName(RESOURCE_NAME_MY_COMPUTE, UserRoleEnum.TESTER).getErrorCode();
+ assertTrue(statusCode == ImportRestUtils.RESTRICTED_OPERATION);
+ }
+
+ @Test
+ public void importNormativeTypesDesignerUserRole() throws Exception {
+ Integer statusCode = ImportRestUtils.importNormativeResourceByName(RESOURCE_NAME_MY_COMPUTE, UserRoleEnum.DESIGNER).getErrorCode();
+ assertTrue(statusCode == 409);
+ }
+
+}
diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/ImportNewResourceCITest.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/ImportNewResourceCITest.java
new file mode 100644
index 0000000000..c069f984d2
--- /dev/null
+++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/ImportNewResourceCITest.java
@@ -0,0 +1,1529 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * 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.openecomp.sdc.ci.tests.execute.imports;
+
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertFalse;
+import static org.testng.AssertJUnit.assertNotNull;
+import static org.testng.AssertJUnit.assertTrue;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.codec.binary.Base64;
+import org.apache.http.HttpStatus;
+import org.junit.Rule;
+import org.junit.rules.TestName;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
+import org.openecomp.sdc.ci.tests.api.Urls;
+import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
+import org.openecomp.sdc.ci.tests.datatypes.ResourceRespJavaObject;
+import org.openecomp.sdc.ci.tests.datatypes.enums.ErrorInfo;
+import org.openecomp.sdc.ci.tests.datatypes.enums.ImportTestTypesEnum;
+import org.openecomp.sdc.ci.tests.datatypes.enums.LifeCycleStatesEnum;
+import org.openecomp.sdc.ci.tests.datatypes.enums.NormativeTypesEnum;
+import org.openecomp.sdc.ci.tests.datatypes.enums.ResourceCategoryEnum;
+import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
+import org.openecomp.sdc.ci.tests.datatypes.expected.ExpectedResourceAuditJavaObject;
+import org.openecomp.sdc.ci.tests.datatypes.http.HttpRequest;
+import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
+import org.openecomp.sdc.ci.tests.utils.ArtifactUtils;
+import org.openecomp.sdc.ci.tests.utils.DbUtils;
+import org.openecomp.sdc.ci.tests.utils.Utils;
+import org.openecomp.sdc.ci.tests.utils.general.Convertor;
+import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
+import org.openecomp.sdc.ci.tests.utils.rest.ArtifactRestUtils;
+import org.openecomp.sdc.ci.tests.utils.rest.ImportRestUtils;
+import org.openecomp.sdc.ci.tests.utils.rest.LifecycleRestUtils;
+import org.openecomp.sdc.ci.tests.utils.rest.ResourceRestUtils;
+import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
+import org.openecomp.sdc.ci.tests.utils.validation.AuditValidationUtils;
+import org.openecomp.sdc.ci.tests.utils.validation.ErrorValidationUtils;
+import org.openecomp.sdc.ci.tests.utils.validation.ResourceValidationUtils;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.util.GeneralUtility;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import com.google.gson.Gson;
+
+public class ImportNewResourceCITest extends ComponentBaseTest {
+
+ // public static UserUtils userUtils = new UserUtils();
+ // public ResourceUtils resourceUtils = new ResourceUtils();
+ // public AuditValidationUtils AuditValidationUtils = new
+ // AuditValidationUtils();
+ // protected ArtifactUtils artifactUtils = new ArtifactUtils();
+
+ protected String resourceVersion = null;
+ protected String auditAction = null;
+ public User sdncModifierDetails = new User();
+ protected String artifactName1 = "data_artifact1.sh";
+ protected String artifactName2 = "data_artifact2.sh";
+ protected String interfaze = "standard";
+ protected String interfaceArtifactName = "data_interface1.sh";
+
+ private String SPECIAL_CHARACTERS = "~!#@~$%^*()[];:'\"|\\/";
+
+ public ResourceReqDetails resourceDetails = new ResourceReqDetails();
+
+ public Gson gson = new Gson();
+
+ @Rule
+ public static TestName name = new TestName();
+
+ public ImportNewResourceCITest() {
+ super(name, ImportNewResourceCITest.class.getName());
+ }
+
+ @BeforeMethod
+ public void before() throws Exception {
+
+ // init user
+ sdncModifierDetails.setUserId(UserRoleEnum.ADMIN.getUserId());
+ // init resource details
+ resourceDetails = ElementFactory.getDefaultResource("importResource4test", NormativeTypesEnum.ROOT,
+ ResourceCategoryEnum.NETWORK_L2_3_ROUTERS, "jh0003");
+ }
+
+ @Test
+ public void importAllTestResources_toValidateNewAPI() throws Exception {
+
+ for (ImportTestTypesEnum currResource : ImportTestTypesEnum.values()) {
+ // clean audit
+ DbUtils.cleanAllAudits();
+
+ // import testResources trough newResource API
+ RestResponse importResponse = ImportRestUtils.importNewResourceByName(currResource.getFolderName(),
+ UserRoleEnum.ADMIN);
+ System.err.println("import Resource " + "<" + currResource.getFolderName() + ">" + "response: "
+ + importResponse.getErrorCode());
+
+ // validate response
+ ImportRestUtils.validateImportTestTypesResp(currResource, importResponse);
+ if (currResource.getvalidateAudit() == true) {
+ // validate audit
+ // String baseVersion="0.1";
+ String baseVersion = "";
+ ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(currResource.getActionStatus().name());
+ ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = new ExpectedResourceAuditJavaObject();
+ String auditAction = "ResourceImport";
+ expectedResourceAuditJavaObject.setAction(auditAction);
+ expectedResourceAuditJavaObject.setModifierUid(UserRoleEnum.ADMIN.getUserId());
+ expectedResourceAuditJavaObject.setModifierName(UserRoleEnum.ADMIN.getUserName());
+ expectedResourceAuditJavaObject.setResourceName(currResource.getNormativeName());
+ expectedResourceAuditJavaObject.setResourceType("Resource");
+ expectedResourceAuditJavaObject.setPrevVersion("");
+ expectedResourceAuditJavaObject.setCurrVersion(baseVersion);
+ expectedResourceAuditJavaObject.setPrevState("");
+ // expectedResourceAuditJavaObject.setCurrState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.toString());
+ expectedResourceAuditJavaObject.setCurrState("");
+ expectedResourceAuditJavaObject.setComment(null);
+ expectedResourceAuditJavaObject.setStatus(errorInfo.getCode().toString());
+ List<String> variables = (currResource.getErrorParams() != null ? currResource.getErrorParams()
+ : new ArrayList<String>());
+ String auditDesc = AuditValidationUtils.buildAuditDescription(errorInfo, variables);
+ expectedResourceAuditJavaObject.setDesc(auditDesc);
+ AuditValidationUtils.validateAuditImport(expectedResourceAuditJavaObject, auditAction);
+ }
+ }
+ }
+
+ protected RestResponse importNewResource(UserRoleEnum userRoleEnum) throws Exception {
+
+ // init user
+ sdncModifierDetails.setUserId(userRoleEnum.getUserId());
+ // init resource details
+ resourceDetails = ElementFactory.getDefaultResource("importResource4test", NormativeTypesEnum.ROOT,
+ ResourceCategoryEnum.NETWORK_L2_3_ROUTERS, "jh0003");
+ // clean ES DB
+ DbUtils.cleanAllAudits();
+ // import new resource (expected checkOut state)
+ RestResponse importResponse = ImportRestUtils.importNewResourceByName("importResource4test", userRoleEnum);
+ return importResponse;
+ }
+
+ @Test(enabled = false)
+ public void importUIResource() throws IOException {
+ String payload = "tosca_definitions_version: tosca_simple_yaml_1_0_0\r\n" + "node_types: \r\n"
+ + " org.openecomp.resource.importResource4test:\r\n" + " derived_from: tosca.nodes.Root\r\n"
+ + " description: someDesc";
+
+ String encodedPayload = new String(Base64.encodeBase64(payload.getBytes()));
+
+ String json = "{\r\n" + " \"resourceName\": \"importResource4test\",\r\n"
+ + " \"payloadName\": \"importResource4test.yml\",\r\n"
+ + " \"categories\": [{\"name\": \"Application L4+\",\"normalizedName\": \"application l4+\",\"uniqueId\": \"resourceNewCategory.application l4+\",\"subcategories\": [{\"name\": \"Web Server\"}]}],\r\n"
+ + " \"description\": \"ResourceDescription\",\r\n" + " \"vendorName\": \"VendorName\",\r\n"
+ + " \"vendorRelease\": \"VendorRelease\",\r\n" + " \"contactId\": \"AT1234\",\r\n"
+ + " \"icon\": \"router\",\r\n" + " \"tags\": [\r\n" + " \"importResource4test\"\r\n" + " ],\r\n"
+ + " \"payloadData\": \"" + encodedPayload + "\"\r\n" + "}";
+
+ String md5 = GeneralUtility.calculateMD5ByString(json);
+
+ Map<String, String> headers = new HashMap<String, String>();
+ headers.put(Constants.MD5_HEADER, md5);
+ headers.put(Constants.USER_ID_HEADER, UserRoleEnum.ADMIN.getUserId());
+ headers.put(Constants.CONTENT_TYPE_HEADER, "application/json");
+
+ String url = String.format(Urls.CREATE_RESOURCE, config.getCatalogBeHost(), config.getCatalogBePort());
+
+ HttpRequest httpUtil = new HttpRequest();
+ RestResponse httpSendPost = httpUtil.httpSendPost(url, json, headers);
+ Integer errorCode = httpSendPost.getErrorCode();
+ assertTrue(errorCode == HttpStatus.SC_CREATED);
+
+ }
+
+ // TODO DE171337
+ @Test(enabled = false)
+ public void importNewResource_suc() throws Exception {
+
+ RestResponse importResponse = importNewResource(UserRoleEnum.ADMIN);
+
+ assertNotNull("check response object is not null after import resource", importResponse);
+ assertNotNull("check error code exists in response after import resource", importResponse.getErrorCode());
+ assertEquals("Check response code after import resource", 201, importResponse.getErrorCode().intValue());
+
+ // validate response
+
+ resourceVersion = "0.1";
+
+ // ResourceRespJavaObject resourceRespJavaObject =
+ // Convertor.constructFieldsForRespValidation(resourceDetails,
+ // resourceVersion);
+ // resourceRespJavaObject.setLifecycleState((LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT).toString());
+ // ResourceValidationUtils.validateResp(importResponse,
+ // resourceRespJavaObject);
+ //
+ // //validate get response
+ //
+ // RestResponse resourceGetResponse =
+ // ResourceRestUtils.getResource(sdncModifierDetails, resourceVersion);
+ // ResourceValidationUtils.validateResp(resourceGetResponse,
+ // resourceRespJavaObject);
+ Resource resourceFromImport = ResponseParser.convertResourceResponseToJavaObject(importResponse.getResponse());
+ assertNotNull(resourceFromImport);
+
+ resourceDetails = ResponseParser.parseToObject(importResponse.getResponse(), ResourceReqDetails.class);
+ ResourceRespJavaObject resourceRespJavaObject = Convertor.constructFieldsForRespValidation(resourceDetails);
+ resourceRespJavaObject.setLifecycleState((LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT).toString());
+
+ // validate get response
+ RestResponse resourceGetResponse = ResourceRestUtils.getResource(sdncModifierDetails,
+ resourceRespJavaObject.getUniqueId());
+ Resource resourceFromGet = ResponseParser
+ .convertResourceResponseToJavaObject(resourceGetResponse.getResponse());
+ assertNotNull(resourceFromGet);
+
+ // validate
+ ResourceValidationUtils.validateModelObjects(resourceFromImport, resourceFromGet);
+
+ // validate audit
+ resourceDetails.setVersion(resourceDetails.getVersion());
+ ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = Convertor
+ .constructFieldsForAuditValidation(resourceDetails, resourceVersion);
+
+ auditAction = "ResourceImport";
+ expectedResourceAuditJavaObject.setAction(auditAction);
+ expectedResourceAuditJavaObject.setPrevState("");
+ expectedResourceAuditJavaObject.setPrevVersion("");
+ expectedResourceAuditJavaObject.setCurrState((LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT).toString());
+ expectedResourceAuditJavaObject.setStatus("201");
+ expectedResourceAuditJavaObject.setDesc("OK");
+ expectedResourceAuditJavaObject.setToscaNodeType(resourceFromGet.getToscaResourceName());
+ AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject, auditAction, null, false);
+
+ }
+
+ @Test
+ public void importNewResource_byTester_failed() throws Exception {
+
+ RestResponse importResponse = importNewResource(UserRoleEnum.TESTER);
+
+ assertNotNull("check response object is not null after import resource", importResponse);
+ assertNotNull("check error code exists in response after import resource", importResponse.getErrorCode());
+ assertEquals("Check response code after import resource", 409, importResponse.getErrorCode().intValue());
+
+ }
+
+ // TODO DE171337
+ @Test(enabled = false)
+ public void importNewResource_existInCheckout_updateVendorName_updateCategory() throws Exception {
+
+ // import new resource
+ RestResponse importResponse = importNewResource(UserRoleEnum.ADMIN);
+
+ assertNotNull("check response object is not null after import resource", importResponse);
+ assertNotNull("check error code exists in response after import resource", importResponse.getErrorCode());
+ assertEquals("Check response code after import resource", 201, importResponse.getErrorCode().intValue());
+
+ // clean audit
+ DbUtils.cleanAllAudits();
+
+ // import new resource while resource already exist in other state
+ importResponse = ImportRestUtils.importNewResourceByName("importResource4testUpdateVendorNameAndCategory",
+ UserRoleEnum.ADMIN);
+
+ assertNotNull("check response object is not null after import resource", importResponse);
+ assertNotNull("check error code exists in response after import resource", importResponse.getErrorCode());
+ assertEquals("Check response code after import resource", 200, importResponse.getErrorCode().intValue());
+
+ // validate response
+ Resource resourceFromImport = ResponseParser.convertResourceResponseToJavaObject(importResponse.getResponse());
+ assertNotNull(resourceFromImport);
+
+ resourceDetails = ResponseParser.parseToObject(importResponse.getResponse(), ResourceReqDetails.class);
+ ResourceRespJavaObject resourceRespJavaObject = Convertor.constructFieldsForRespValidation(resourceDetails);
+ resourceRespJavaObject.setLifecycleState((LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT).toString());
+
+ // validate get response
+ RestResponse resourceGetResponse = ResourceRestUtils.getResource(sdncModifierDetails,
+ resourceRespJavaObject.getUniqueId());
+ Resource resourceFromGet = ResponseParser
+ .convertResourceResponseToJavaObject(resourceGetResponse.getResponse());
+ assertNotNull(resourceFromGet);
+
+ // validate
+ ResourceValidationUtils.validateModelObjects(resourceFromImport, resourceFromGet);
+
+ // validate audit
+ resourceDetails.setVersion(resourceDetails.getVersion());
+ ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = Convertor
+ .constructFieldsForAuditValidation(resourceDetails);
+
+ auditAction = "ResourceImport";
+ resourceVersion = "0.1";
+ expectedResourceAuditJavaObject.setAction(auditAction);
+ expectedResourceAuditJavaObject.setPrevState((LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT).toString());
+ expectedResourceAuditJavaObject.setCurrState((LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT).toString());
+ expectedResourceAuditJavaObject.setPrevVersion(resourceVersion);
+ expectedResourceAuditJavaObject.setStatus("200");
+ expectedResourceAuditJavaObject.setDesc("OK");
+ expectedResourceAuditJavaObject.setToscaNodeType(resourceFromGet.getToscaResourceName());
+ AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject, auditAction, null, false);
+ }
+
+ @Test
+ public void importNewResource_perfromByAdmin_ownedBy_diffrentUser() throws Exception {
+
+ RestResponse importResponse = importNewResource(UserRoleEnum.DESIGNER);
+
+ assertNotNull("check response object is not null after import resource", importResponse);
+ assertNotNull("check error code exists in response after import resource", importResponse.getErrorCode());
+ assertEquals("Check response code after import resource", 201, importResponse.getErrorCode().intValue());
+
+ Resource resourceFromImport = ResponseParser.convertResourceResponseToJavaObject(importResponse.getResponse());
+ // clean audit
+ DbUtils.cleanAllAudits();
+
+ importResponse = importNewResource(UserRoleEnum.ADMIN);
+
+ assertNotNull("check response object is not null after import resource", importResponse);
+ assertNotNull("check error code exists in response after import resource", importResponse.getErrorCode());
+
+ ErrorInfo errorInfo = ErrorValidationUtils
+ .parseErrorConfigYaml(ActionStatus.COMPONENT_IN_CHECKOUT_STATE.name());
+ assertEquals("Check response code after adding artifact", errorInfo.getCode(), importResponse.getErrorCode());
+
+ String[] split = resourceFromImport.getLastUpdaterFullName().split(" ");
+ String firstName = split[0];
+ String lastName = split[1];
+ List<String> variables = Arrays.asList(resourceFromImport.getName(), "resource", firstName, lastName,
+ resourceFromImport.getLastUpdaterUserId());
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_IN_CHECKOUT_STATE.name(), variables,
+ importResponse.getResponse());
+
+ }
+
+ @Test
+ public void importNewResource_perfromByDesigner_ownedBy_diffrentUser() throws Exception {
+
+ RestResponse importResponse = importNewResource(UserRoleEnum.ADMIN);
+
+ assertNotNull("check response object is not null after import resource", importResponse);
+ assertNotNull("check error code exists in response after import resource", importResponse.getErrorCode());
+ assertEquals("Check response code after import resource", 201, importResponse.getErrorCode().intValue());
+ Resource resourceFromImport = ResponseParser.convertResourceResponseToJavaObject(importResponse.getResponse());
+ // clean audit
+ DbUtils.cleanAllAudits();
+
+ importResponse = importNewResource(UserRoleEnum.DESIGNER);
+
+ assertNotNull("check response object is not null after import resource", importResponse);
+ assertNotNull("check error code exists in response after import resource", importResponse.getErrorCode());
+
+ ErrorInfo errorInfo = ErrorValidationUtils
+ .parseErrorConfigYaml(ActionStatus.COMPONENT_IN_CHECKOUT_STATE.name());
+ assertEquals("Check response code after adding artifact", errorInfo.getCode(), importResponse.getErrorCode());
+
+ String[] split = resourceFromImport.getLastUpdaterFullName().split(" ");
+ String firstName = split[0];
+ String lastName = split[1];
+ List<String> variables = Arrays.asList(resourceFromImport.getName(), "resource", firstName, lastName,
+ resourceFromImport.getLastUpdaterUserId());
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_IN_CHECKOUT_STATE.name(), variables,
+ importResponse.getResponse());
+
+ }
+
+ @Test(enabled = false)
+ public void importNewResource_nameSpace_vf() throws Exception {
+ RestResponse importResponse = ImportRestUtils.importNewResourceByName("importResource4testVF",
+ UserRoleEnum.DESIGNER);
+ assertNotNull("check response object is not null after import resource", importResponse);
+ assertNotNull("check error code exists in response after import resource", importResponse.getErrorCode());
+ assertEquals("Check response code after import resource", 201, importResponse.getErrorCode().intValue());
+ Resource resourceRespJavaObject = ResponseParser
+ .convertResourceResponseToJavaObject(importResponse.getResponse());
+ assertTrue(resourceRespJavaObject.getResourceType().equals(ResourceTypeEnum.VF));
+
+ }
+
+ @Test
+ public void importNewResource_nameSpace_vfc() throws Exception {
+ RestResponse importResponse = ImportRestUtils.importNewResourceByName("importResource4testVFC",
+ UserRoleEnum.DESIGNER);
+ assertNotNull("check response object is not null after import resource", importResponse);
+ assertNotNull("check error code exists in response after import resource", importResponse.getErrorCode());
+ assertEquals("Check response code after import resource", 201, importResponse.getErrorCode().intValue());
+ Resource resourceRespJavaObject = ResponseParser
+ .convertResourceResponseToJavaObject(importResponse.getResponse());
+ assertTrue(resourceRespJavaObject.getResourceType().equals(ResourceTypeEnum.VFC));
+ }
+
+ @Test
+ public void importNewResource_nameSpace_vl() throws Exception {
+ RestResponse importResponse = ImportRestUtils.importNewResourceByName("importResource4testVL",
+ UserRoleEnum.DESIGNER);
+ assertNotNull("check response object is not null after import resource", importResponse);
+ assertNotNull("check error code exists in response after import resource", importResponse.getErrorCode());
+ assertEquals("Check response code after import resource", 201, importResponse.getErrorCode().intValue());
+ Resource resourceRespJavaObject = ResponseParser
+ .convertResourceResponseToJavaObject(importResponse.getResponse());
+ assertTrue(resourceRespJavaObject.getResourceType().equals(ResourceTypeEnum.VL));
+
+ }
+
+ @Test
+ public void importNewResource_nameSpace_cp() throws Exception {
+ RestResponse importResponse = ImportRestUtils.importNewResourceByName("importResource4testCP",
+ UserRoleEnum.DESIGNER);
+ assertNotNull("check response object is not null after import resource", importResponse);
+ assertNotNull("check error code exists in response after import resource", importResponse.getErrorCode());
+ assertEquals("Check response code after import resource", 201, importResponse.getErrorCode().intValue());
+
+ Resource resourceRespJavaObject = ResponseParser
+ .convertResourceResponseToJavaObject(importResponse.getResponse());
+ assertTrue(resourceRespJavaObject.getResourceType().equals(ResourceTypeEnum.CP));
+ }
+
+ @Test
+ public void importNewResource_nameSpace_unknown() throws Exception {
+ RestResponse importResponse = ImportRestUtils.importNewResourceByName("importResource4test",
+ UserRoleEnum.DESIGNER);
+ assertNotNull("check response object is not null after import resource", importResponse);
+ assertNotNull("check error code exists in response after import resource", importResponse.getErrorCode());
+ assertEquals("Check response code after import resource", 201, importResponse.getErrorCode().intValue());
+ Resource resourceRespJavaObject = ResponseParser
+ .convertResourceResponseToJavaObject(importResponse.getResponse());
+ assertTrue(resourceRespJavaObject.getResourceType().equals(ResourceTypeEnum.VFC));
+
+ }
+
+ @Test
+ public void importNewResource_MissingNameSpace() throws Exception {
+ RestResponse importResponse = ImportRestUtils.importNewResourceByName("importResource4testMissingNameSpace",
+ UserRoleEnum.DESIGNER);
+ assertNotNull("check response object is not null after import resource", importResponse);
+ assertNotNull("check error code exists in response after import resource", importResponse.getErrorCode());
+ assertEquals("Check response code after import resource", 400, importResponse.getErrorCode().intValue());
+
+ }
+
+ // TODO DE171337
+ @Test(enabled = false)
+ public void importNewResource_existInCheckOut() throws Exception {
+
+ // import new resource
+
+ RestResponse importResponse = importNewResource(UserRoleEnum.ADMIN);
+
+ assertNotNull("check response object is not null after import resource", importResponse);
+ assertNotNull("check error code exists in response after import resource", importResponse.getErrorCode());
+ assertEquals("Check response code after import resource", 201, importResponse.getErrorCode().intValue());
+
+ // clean audit
+ DbUtils.cleanAllAudits();
+
+ // import new resource while resource already exist in CHECKOUT state
+
+ importResponse = ImportRestUtils.importNewResourceByName("importResource4test", UserRoleEnum.ADMIN);
+
+ assertNotNull("check response object is not null after import resource", importResponse);
+ assertNotNull("check error code exists in response after import resource", importResponse.getErrorCode());
+ assertEquals("Check response code after import resource", 200, importResponse.getErrorCode().intValue());
+
+ // validate response
+ Resource resourceFromImport = ResponseParser.convertResourceResponseToJavaObject(importResponse.getResponse());
+ assertNotNull(resourceFromImport);
+ resourceDetails = ResponseParser.parseToObject(importResponse.getResponse(), ResourceReqDetails.class);
+ ResourceRespJavaObject resourceRespJavaObject = Convertor.constructFieldsForRespValidation(resourceDetails);
+ resourceRespJavaObject.setLifecycleState((LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT).toString());
+
+ // validate get response
+ RestResponse resourceGetResponse = ResourceRestUtils.getResource(sdncModifierDetails,
+ resourceRespJavaObject.getUniqueId());
+ Resource resourceFromGet = ResponseParser
+ .convertResourceResponseToJavaObject(resourceGetResponse.getResponse());
+ assertNotNull(resourceFromGet);
+
+ // validate
+ ResourceValidationUtils.validateModelObjects(resourceFromImport, resourceFromGet);
+
+ // validate audit
+ resourceDetails.setVersion(resourceDetails.getVersion());
+ ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = Convertor
+ .constructFieldsForAuditValidation(resourceDetails);
+
+ auditAction = "ResourceImport";
+ resourceVersion = "0.1";
+ expectedResourceAuditJavaObject.setAction(auditAction);
+ expectedResourceAuditJavaObject.setPrevState((LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT).toString());
+ expectedResourceAuditJavaObject.setCurrState((LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT).toString());
+ expectedResourceAuditJavaObject.setPrevVersion(resourceVersion);
+ expectedResourceAuditJavaObject.setStatus("200");
+ expectedResourceAuditJavaObject.setDesc("OK");
+ expectedResourceAuditJavaObject.setToscaNodeType(resourceFromGet.getToscaResourceName());
+
+ AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject, auditAction, null, false);
+ }
+
+ // TODO DE171337
+ @Test(enabled = false)
+ public void importNewResource_existIn_CheckIn_state() throws Exception {
+
+ // import new resource
+
+ RestResponse importResponse = importNewResource(UserRoleEnum.ADMIN);
+
+ assertNotNull("check response object is not null after import resource", importResponse);
+ assertNotNull("check error code exists in response after import resource", importResponse.getErrorCode());
+ assertEquals("Check response code after import resource", 201, importResponse.getErrorCode().intValue());
+ resourceDetails = ResponseParser.parseToObject(importResponse.getResponse(), ResourceReqDetails.class);
+ // checkIn resource
+
+ resourceVersion = resourceDetails.getVersion();
+ String checkinComment = "good checkin";
+ String checkinComentJson = "{\"userRemarks\": \"" + checkinComment + "\"}";
+ RestResponse checkInResponse = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails,
+ resourceVersion, LifeCycleStatesEnum.CHECKIN, checkinComentJson);
+
+ assertNotNull("check response object is not null after import resource", checkInResponse);
+ assertEquals("Check response code after checkout resource", 200, checkInResponse.getErrorCode().intValue());
+
+ // clean audit
+ DbUtils.cleanAllAudits();
+
+ // import new resource while resource already exist in CHECKIN state
+
+ importResponse = ImportRestUtils.importNewResourceByName("importResource4test", UserRoleEnum.ADMIN);
+
+ assertNotNull("check response object is not null after import resource", importResponse);
+ assertNotNull("check error code exists in response after import resource", importResponse.getErrorCode());
+ assertEquals("Check response code after import resource", 200, importResponse.getErrorCode().intValue());
+
+ // validate response
+ Resource resourceFromImport = ResponseParser.convertResourceResponseToJavaObject(importResponse.getResponse());
+ assertNotNull(resourceFromImport);
+
+ resourceDetails = ResponseParser.parseToObject(importResponse.getResponse(), ResourceReqDetails.class);
+ ResourceRespJavaObject resourceRespJavaObject = Convertor.constructFieldsForRespValidation(resourceDetails);
+ resourceRespJavaObject.setLifecycleState((LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT).toString());
+
+ // validate get response
+ RestResponse resourceGetResponse = ResourceRestUtils.getResource(sdncModifierDetails,
+ resourceRespJavaObject.getUniqueId());
+ Resource resourceFromGet = ResponseParser
+ .convertResourceResponseToJavaObject(resourceGetResponse.getResponse());
+ assertNotNull(resourceFromGet);
+
+ // validate
+ ResourceValidationUtils.validateModelObjects(resourceFromImport, resourceFromGet);
+
+ // validate audit
+ resourceDetails.setVersion(resourceDetails.getVersion());
+ ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = Convertor
+ .constructFieldsForAuditValidation(resourceDetails);
+
+ resourceVersion = "0.2";
+ auditAction = "ResourceImport";
+ expectedResourceAuditJavaObject.setAction(auditAction);
+ expectedResourceAuditJavaObject.setPrevState((LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT).toString());
+ expectedResourceAuditJavaObject.setCurrState((LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT).toString());
+ expectedResourceAuditJavaObject.setPrevVersion(resourceVersion);
+ expectedResourceAuditJavaObject.setStatus("200");
+ expectedResourceAuditJavaObject.setDesc("OK");
+ expectedResourceAuditJavaObject.setToscaNodeType(resourceFromGet.getToscaResourceName());
+ AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject, auditAction, null, false);
+ }
+
+ @Test
+ public void importNewResource_existIn_Ready4cert_state_performByTester() throws Exception {
+ // import new resource
+
+ RestResponse importResponse = importNewResource(UserRoleEnum.ADMIN);
+
+ assertNotNull("check response object is not null after import resource", importResponse);
+ assertNotNull("check error code exists in response after import resource", importResponse.getErrorCode());
+ assertEquals("Check response code after import resource", 201, importResponse.getErrorCode().intValue());
+
+ resourceDetails = ResponseParser.parseToObject(importResponse.getResponse(), ResourceReqDetails.class);
+ resourceVersion = resourceDetails.getVersion();
+ RestResponse resourceGetResponse = ResourceRestUtils.getResource(sdncModifierDetails,
+ resourceDetails.getUniqueId());
+ assertEquals("Check response code after get resource", 200, resourceGetResponse.getErrorCode().intValue());
+ Resource resourceFromGet = ResponseParser
+ .convertResourceResponseToJavaObject(resourceGetResponse.getResponse());
+ assertNotNull(resourceFromGet);
+ // add mandatory artifacts
+ // // resourceUtils.addResourceMandatoryArtifacts(sdncModifierDetails,
+ // resourceGetResponse);
+ resourceGetResponse = ResourceRestUtils.getResource(sdncModifierDetails, resourceDetails.getUniqueId());
+ assertEquals("Check response code after get resource", 200, resourceGetResponse.getErrorCode().intValue());
+ resourceFromGet = ResponseParser.convertResourceResponseToJavaObject(resourceGetResponse.getResponse());
+ assertNotNull(resourceFromGet);
+ resourceDetails = ResponseParser.parseToObject(importResponse.getResponse(), ResourceReqDetails.class);
+ resourceDetails.setVersion(resourceFromGet.getVersion());
+
+ // checkIn resource
+ resourceVersion = resourceDetails.getVersion();
+ String checkinComment = "good checkin";
+ String checkinComentJson = "{\"userRemarks\": \"" + checkinComment + "\"}";
+ RestResponse checkInResponse = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails,
+ resourceVersion, LifeCycleStatesEnum.CHECKIN, checkinComentJson);
+
+ assertNotNull("check response object is not null after import resource", checkInResponse);
+ assertEquals("Check response code after checkout resource", 200, checkInResponse.getErrorCode().intValue());
+ resourceFromGet = ResponseParser.convertResourceResponseToJavaObject(checkInResponse.getResponse());
+ assertNotNull(resourceFromGet);
+ resourceDetails = ResponseParser.parseToObject(checkInResponse.getResponse(), ResourceReqDetails.class);
+ resourceDetails.setVersion(resourceFromGet.getVersion());
+
+ // req4cert resource
+ RestResponse request4cert = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails,
+ resourceVersion, LifeCycleStatesEnum.CERTIFICATIONREQUEST);
+ assertNotNull("check response object is not null after resource request for certification", request4cert);
+ assertEquals("Check response code after checkout resource", 200, request4cert.getErrorCode().intValue());
+ resourceFromGet = ResponseParser.convertResourceResponseToJavaObject(request4cert.getResponse());
+ assertNotNull(resourceFromGet);
+ resourceDetails = ResponseParser.parseToObject(request4cert.getResponse(), ResourceReqDetails.class);
+ resourceDetails.setVersion(resourceFromGet.getVersion());
+
+ // clean audit
+ DbUtils.cleanAllAudits();
+
+ // import new resource while resource already exist in CHECKIN state
+ importResponse = ImportRestUtils.importNewResourceByName("importResource4test", UserRoleEnum.TESTER);
+
+ // validate response
+ resourceVersion = resourceDetails.getVersion();
+ ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.RESTRICTED_OPERATION.name());
+ assertNotNull("check response object is not null after create resouce", importResponse);
+ assertNotNull("check error code exists in response after create resource", importResponse.getErrorCode());
+ assertEquals("Check response code after create service", errorInfo.getCode(), importResponse.getErrorCode());
+ List<String> variables = Arrays.asList();
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.RESTRICTED_OPERATION.name(), variables,
+ importResponse.getResponse());
+
+ // validate audit
+
+ ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = Convertor
+ .constructFieldsForAuditValidation(resourceDetails, resourceVersion);
+
+ String auditAction = "ResourceImport";
+ expectedResourceAuditJavaObject.setAction(auditAction);
+ expectedResourceAuditJavaObject.setResourceName("");
+ expectedResourceAuditJavaObject.setModifierUid(UserRoleEnum.TESTER.getUserId());
+ expectedResourceAuditJavaObject.setModifierName(UserRoleEnum.TESTER.getUserName());
+ expectedResourceAuditJavaObject.setPrevState("");
+ expectedResourceAuditJavaObject.setCurrState("");
+ expectedResourceAuditJavaObject.setPrevVersion("");
+ expectedResourceAuditJavaObject.setCurrVersion("");
+ expectedResourceAuditJavaObject.setStatus(errorInfo.getCode().toString());
+ String auditDesc = AuditValidationUtils.buildAuditDescription(errorInfo, variables);
+ expectedResourceAuditJavaObject.setDesc(auditDesc);
+
+ AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject, auditAction, null, false);
+ }
+
+ // TODO DE171337
+ @Test(enabled = false)
+ public void importNewResource_existIn_Ready4cert_state_performByDesigner() throws Exception {
+ // import new resource
+
+ RestResponse importResponse = importNewResource(UserRoleEnum.ADMIN);
+
+ assertNotNull("check response object is not null after import resource", importResponse);
+ assertNotNull("check error code exists in response after import resource", importResponse.getErrorCode());
+ assertEquals("Check response code after import resource", 201, importResponse.getErrorCode().intValue());
+
+ resourceDetails = ResponseParser.parseToObject(importResponse.getResponse(), ResourceReqDetails.class);
+ resourceVersion = resourceDetails.getVersion();
+ RestResponse resourceGetResponse = ResourceRestUtils.getResource(sdncModifierDetails,
+ resourceDetails.getUniqueId());
+ assertEquals("Check response code after get resource", 200, resourceGetResponse.getErrorCode().intValue());
+ Resource resourceFromGet = ResponseParser
+ .convertResourceResponseToJavaObject(resourceGetResponse.getResponse());
+ assertNotNull(resourceFromGet);
+ // add mandatory artifacts
+ // resourceUtils.addResourceMandatoryArtifacts(sdncModifierDetails,
+ // resourceGetResponse);
+ resourceGetResponse = ResourceRestUtils.getResource(sdncModifierDetails, resourceDetails.getUniqueId());
+ assertEquals("Check response code after get resource", 200, resourceGetResponse.getErrorCode().intValue());
+ resourceFromGet = ResponseParser.convertResourceResponseToJavaObject(resourceGetResponse.getResponse());
+ assertNotNull(resourceFromGet);
+ resourceDetails = ResponseParser.parseToObject(importResponse.getResponse(), ResourceReqDetails.class);
+ resourceDetails.setVersion(resourceFromGet.getVersion());
+
+ // checkIn resource
+ resourceVersion = resourceDetails.getVersion();
+ String checkinComment = "good checkin";
+ String checkinComentJson = "{\"userRemarks\": \"" + checkinComment + "\"}";
+ RestResponse checkInResponse = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails,
+ resourceVersion, LifeCycleStatesEnum.CHECKIN, checkinComentJson);
+ assertNotNull("check response object is not null after import resource", checkInResponse);
+ assertEquals("Check response code after checkout resource", 200, checkInResponse.getErrorCode().intValue());
+
+ // req4cert resource
+ RestResponse request4cert = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails,
+ resourceVersion, LifeCycleStatesEnum.CERTIFICATIONREQUEST);
+ assertNotNull("check response object is not null after resource request for certification", request4cert);
+ assertEquals("Check response code after checkout resource", 200, request4cert.getErrorCode().intValue());
+ resourceFromGet = ResponseParser.convertResourceResponseToJavaObject(request4cert.getResponse());
+ assertNotNull(resourceFromGet);
+ resourceDetails = ResponseParser.parseToObject(request4cert.getResponse(), ResourceReqDetails.class);
+ resourceDetails.setVersion(resourceFromGet.getVersion());
+
+ // clean audit
+ DbUtils.cleanAllAudits();
+
+ // import new resource while resource already exist in other state
+ importResponse = ImportRestUtils.importNewResourceByName("importResource4test", UserRoleEnum.DESIGNER);
+
+ // validate response
+ ErrorInfo errorInfo = ErrorValidationUtils
+ .parseErrorConfigYaml(ActionStatus.COMPONENT_SENT_FOR_CERTIFICATION.name());
+ assertNotNull("check response object is not null after create resouce", importResponse);
+ assertNotNull("check error code exists in response after create resource", importResponse.getErrorCode());
+ assertEquals("Check response code after create service", errorInfo.getCode(), importResponse.getErrorCode());
+ String[] split = resourceFromGet.getLastUpdaterFullName().split(" ");
+ String firstName = split[0];
+ String lastName = split[1];
+ List<String> variables = Arrays.asList(resourceFromGet.getName(), "resource", firstName, lastName,
+ resourceFromGet.getLastUpdaterUserId());
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_SENT_FOR_CERTIFICATION.name(), variables,
+ importResponse.getResponse());
+
+ // validate audit
+ ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = Convertor
+ .constructFieldsForAuditValidation(resourceDetails, resourceVersion);
+ String auditAction = "ResourceImport";
+ expectedResourceAuditJavaObject.setAction(auditAction);
+ expectedResourceAuditJavaObject.setModifierUid(UserRoleEnum.DESIGNER.getUserId());
+ expectedResourceAuditJavaObject.setModifierName(UserRoleEnum.DESIGNER.getUserName());
+ expectedResourceAuditJavaObject.setPrevState((LifecycleStateEnum.READY_FOR_CERTIFICATION).toString());
+ // expectedResourceAuditJavaObject.setCurrState((LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT).toString());
+ expectedResourceAuditJavaObject.setCurrState("");
+ expectedResourceAuditJavaObject.setPrevVersion(resourceVersion);
+ expectedResourceAuditJavaObject.setCurrVersion("");
+ expectedResourceAuditJavaObject.setStatus(errorInfo.getCode().toString());
+ expectedResourceAuditJavaObject.setToscaNodeType(resourceFromGet.getToscaResourceName());
+ String auditDesc = AuditValidationUtils.buildAuditDescription(errorInfo, variables);
+ expectedResourceAuditJavaObject.setDesc(auditDesc);
+ AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject, auditAction, null, false);
+
+ }
+
+ // TODO DE171337
+ @Test(enabled = false)
+ public void importNewResource_existIn_Ready4cert_state_performByAdmin() throws Exception {
+
+ // import new resource
+ RestResponse importResponse = importNewResource(UserRoleEnum.ADMIN);
+ assertNotNull("check response object is not null after import resource", importResponse);
+ assertNotNull("check error code exists in response after import resource", importResponse.getErrorCode());
+ assertEquals("Check response code after import resource", 201, importResponse.getErrorCode().intValue());
+ resourceDetails = ResponseParser.parseToObject(importResponse.getResponse(), ResourceReqDetails.class);
+ resourceVersion = resourceDetails.getVersion();
+ RestResponse resourceGetResponse = ResourceRestUtils.getResource(sdncModifierDetails,
+ resourceDetails.getUniqueId());
+ assertEquals("Check response code after get resource", 200, resourceGetResponse.getErrorCode().intValue());
+ Resource resourceFromGet = ResponseParser
+ .convertResourceResponseToJavaObject(resourceGetResponse.getResponse());
+ assertNotNull(resourceFromGet);
+
+ // add mandatory artifacts
+ // resourceUtils.addResourceMandatoryArtifacts(sdncModifierDetails,
+ // resourceGetResponse);
+ resourceGetResponse = ResourceRestUtils.getResource(sdncModifierDetails, resourceDetails.getUniqueId());
+ assertEquals("Check response code after get resource", 200, resourceGetResponse.getErrorCode().intValue());
+ resourceFromGet = ResponseParser.convertResourceResponseToJavaObject(resourceGetResponse.getResponse());
+ assertNotNull(resourceFromGet);
+ resourceDetails = ResponseParser.parseToObject(importResponse.getResponse(), ResourceReqDetails.class);
+ resourceDetails.setVersion(resourceFromGet.getVersion());
+
+ // checkIn resource
+ resourceVersion = resourceDetails.getVersion();
+ String checkinComment = "good checkin";
+ String checkinComentJson = "{\"userRemarks\": \"" + checkinComment + "\"}";
+ RestResponse checkInResponse = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails,
+ resourceVersion, LifeCycleStatesEnum.CHECKIN, checkinComentJson);
+ assertNotNull("check response object is not null after import resource", checkInResponse);
+ assertEquals("Check response code after checkout resource", 200, checkInResponse.getErrorCode().intValue());
+
+ // req4cert resource
+ RestResponse request4cert = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails,
+ resourceVersion, LifeCycleStatesEnum.CERTIFICATIONREQUEST);
+ assertNotNull("check response object is not null after resource request for certification", request4cert);
+ assertEquals("Check response code after checkout resource", 200, request4cert.getErrorCode().intValue());
+ resourceFromGet = ResponseParser.convertResourceResponseToJavaObject(request4cert.getResponse());
+ assertNotNull(resourceFromGet);
+ resourceDetails = ResponseParser.parseToObject(request4cert.getResponse(), ResourceReqDetails.class);
+ resourceDetails.setVersion(resourceFromGet.getVersion());
+
+ // clean audit
+ DbUtils.cleanAllAudits();
+
+ // import new resource while resource already exist in other state
+ importResponse = ImportRestUtils.importNewResourceByName("importResource4test", UserRoleEnum.ADMIN);
+ assertNotNull("check response object is not null after import resource", importResponse);
+ assertNotNull("check error code exists in response after import resource", importResponse.getErrorCode());
+ assertEquals("Check response code after import resource", 200, importResponse.getErrorCode().intValue());
+ resourceFromGet = ResponseParser.convertResourceResponseToJavaObject(importResponse.getResponse());
+ assertNotNull(resourceFromGet);
+ resourceDetails = ResponseParser.parseToObject(request4cert.getResponse(), ResourceReqDetails.class);
+ resourceDetails.setVersion(resourceFromGet.getVersion());
+ resourceVersion = resourceDetails.getVersion();
+ // resourceVersion="0.2";
+
+ // validate response
+ Resource resourceFromImport = ResponseParser.convertResourceResponseToJavaObject(importResponse.getResponse());
+ assertNotNull(resourceFromImport);
+ resourceDetails = ResponseParser.parseToObject(importResponse.getResponse(), ResourceReqDetails.class);
+ ResourceRespJavaObject resourceRespJavaObject = Convertor.constructFieldsForRespValidation(resourceDetails);
+ resourceRespJavaObject.setLifecycleState((LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT).toString());
+
+ // validate get response
+ resourceGetResponse = ResourceRestUtils.getResource(sdncModifierDetails, resourceRespJavaObject.getUniqueId());
+ resourceFromGet = ResponseParser.convertResourceResponseToJavaObject(resourceGetResponse.getResponse());
+ assertNotNull(resourceFromGet);
+
+ // validate
+ ResourceValidationUtils.validateModelObjects(resourceFromImport, resourceFromGet);
+
+ // validate audit
+ ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = Convertor
+ .constructFieldsForAuditValidation(resourceDetails, resourceVersion);
+ auditAction = "ResourceImport";
+ expectedResourceAuditJavaObject.setAction(auditAction);
+ expectedResourceAuditJavaObject.setPrevState((LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT).toString());
+ expectedResourceAuditJavaObject.setCurrState((LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT).toString());
+ expectedResourceAuditJavaObject.setPrevVersion(resourceVersion);
+ expectedResourceAuditJavaObject.setStatus("200");
+ expectedResourceAuditJavaObject.setDesc("OK");
+ expectedResourceAuditJavaObject.setToscaNodeType(resourceFromGet.getToscaResourceName());
+ AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject, auditAction, null, false);
+ }
+
+ @Test
+ public void importNewResource_existIn_CerInProgress_state_performByTester() throws Exception {
+
+ // import new resource
+ RestResponse importResponse = importNewResource(UserRoleEnum.ADMIN);
+ assertNotNull("check response object is not null after import resource", importResponse);
+ assertNotNull("check error code exists in response after import resource", importResponse.getErrorCode());
+ assertEquals("Check response code after import resource", 201, importResponse.getErrorCode().intValue());
+ resourceDetails = ResponseParser.parseToObject(importResponse.getResponse(), ResourceReqDetails.class);
+ resourceVersion = resourceDetails.getVersion();
+ RestResponse resourceGetResponse = ResourceRestUtils.getResource(sdncModifierDetails,
+ resourceDetails.getUniqueId());
+ assertEquals("Check response code after get resource", 200, resourceGetResponse.getErrorCode().intValue());
+ Resource resourceFromGet = ResponseParser
+ .convertResourceResponseToJavaObject(resourceGetResponse.getResponse());
+ assertNotNull(resourceFromGet);
+
+ // add mandatory artifacts
+ // resourceUtils.addResourceMandatoryArtifacts(sdncModifierDetails,
+ // resourceGetResponse);
+ resourceGetResponse = ResourceRestUtils.getResource(sdncModifierDetails, resourceDetails.getUniqueId());
+ assertEquals("Check response code after get resource", 200, resourceGetResponse.getErrorCode().intValue());
+ resourceFromGet = ResponseParser.convertResourceResponseToJavaObject(resourceGetResponse.getResponse());
+ assertNotNull(resourceFromGet);
+ resourceDetails = ResponseParser.parseToObject(importResponse.getResponse(), ResourceReqDetails.class);
+ resourceDetails.setVersion(resourceFromGet.getVersion());
+
+ // checkIn resource
+ resourceVersion = resourceDetails.getVersion();
+ String checkinComment = "good checkin";
+ String checkinComentJson = "{\"userRemarks\": \"" + checkinComment + "\"}";
+ RestResponse checkInResponse = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails,
+ resourceVersion, LifeCycleStatesEnum.CHECKIN, checkinComentJson);
+ assertNotNull("check response object is not null after import resource", checkInResponse);
+ assertEquals("Check response code after checkout resource", 200, checkInResponse.getErrorCode().intValue());
+
+ // req4cert resource
+ RestResponse request4cert = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails,
+ resourceVersion, LifeCycleStatesEnum.CERTIFICATIONREQUEST);
+ assertNotNull("check response object is not null after resource request for certification", request4cert);
+ assertEquals("Check response code after checkout resource", 200, request4cert.getErrorCode().intValue());
+ resourceFromGet = ResponseParser.convertResourceResponseToJavaObject(request4cert.getResponse());
+ assertNotNull(resourceFromGet);
+ resourceDetails = ResponseParser.parseToObject(request4cert.getResponse(), ResourceReqDetails.class);
+ resourceDetails.setVersion(resourceFromGet.getVersion());
+
+ // startCert
+ RestResponse startCert = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails,
+ resourceVersion, LifeCycleStatesEnum.STARTCERTIFICATION);
+ assertNotNull("check response object is not null after resource request start certification", startCert);
+ assertEquals("Check response code after checkout resource", 200, startCert.getErrorCode().intValue());
+ resourceFromGet = ResponseParser.convertResourceResponseToJavaObject(startCert.getResponse());
+ assertNotNull(resourceFromGet);
+ resourceDetails = ResponseParser.parseToObject(startCert.getResponse(), ResourceReqDetails.class);
+ resourceDetails.setVersion(resourceFromGet.getVersion());
+
+ // clean audit
+ DbUtils.cleanAllAudits();
+
+ // import new resource while resource already exist in other state
+ importResponse = ImportRestUtils.importNewResourceByName("importResource4test", UserRoleEnum.TESTER);
+
+ // validate response
+ resourceVersion = resourceDetails.getVersion();
+ ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.RESTRICTED_OPERATION.name());
+ assertNotNull("check response object is not null after create resouce", importResponse);
+ assertNotNull("check error code exists in response after create resource", importResponse.getErrorCode());
+ assertEquals("Check response code after create service", errorInfo.getCode(), importResponse.getErrorCode());
+ List<String> variables = Arrays.asList();
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.RESTRICTED_OPERATION.name(), variables,
+ importResponse.getResponse());
+
+ // validate audit
+ ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = Convertor
+ .constructFieldsForAuditValidation(resourceDetails, resourceVersion);
+ String auditAction = "ResourceImport";
+ expectedResourceAuditJavaObject.setAction(auditAction);
+ expectedResourceAuditJavaObject.setResourceName("");
+ expectedResourceAuditJavaObject.setModifierUid(UserRoleEnum.TESTER.getUserId());
+ expectedResourceAuditJavaObject.setModifierName(UserRoleEnum.TESTER.getUserName());
+ expectedResourceAuditJavaObject.setPrevState("");
+ expectedResourceAuditJavaObject.setCurrState("");
+ expectedResourceAuditJavaObject.setPrevVersion("");
+ expectedResourceAuditJavaObject.setCurrVersion("");
+ expectedResourceAuditJavaObject.setStatus(errorInfo.getCode().toString());
+ String auditDesc = AuditValidationUtils.buildAuditDescription(errorInfo, variables);
+ expectedResourceAuditJavaObject.setDesc(auditDesc);
+ AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject, auditAction, null, false);
+ }
+
+ // TODO DE171337
+ @Test(enabled = false)
+ public void importNewResource_existIn_CerInProgress_state_performByDesigner() throws Exception {
+
+ User sdncAdminUser = ElementFactory.getDefaultUser(UserRoleEnum.ADMIN);
+ // import new resource
+ RestResponse importResponse = importNewResource(UserRoleEnum.ADMIN);
+ assertNotNull("check response object is not null after import resource", importResponse);
+ assertNotNull("check error code exists in response after import resource", importResponse.getErrorCode());
+ assertEquals("Check response code after import resource", 201, importResponse.getErrorCode().intValue());
+ resourceDetails = ResponseParser.parseToObject(importResponse.getResponse(), ResourceReqDetails.class);
+ resourceVersion = resourceDetails.getVersion();
+ RestResponse resourceGetResponse = ResourceRestUtils.getResource(sdncModifierDetails,
+ resourceDetails.getUniqueId());
+ assertEquals("Check response code after get resource", 200, resourceGetResponse.getErrorCode().intValue());
+ Resource resourceFromGet = ResponseParser
+ .convertResourceResponseToJavaObject(resourceGetResponse.getResponse());
+ assertNotNull(resourceFromGet);
+
+ // add mandatory artifacts
+ // resourceUtils.addResourceMandatoryArtifacts(sdncModifierDetails,
+ // resourceGetResponse);
+ resourceGetResponse = ResourceRestUtils.getResource(sdncModifierDetails, resourceDetails.getUniqueId());
+ assertEquals("Check response code after get resource", 200, resourceGetResponse.getErrorCode().intValue());
+ resourceFromGet = ResponseParser.convertResourceResponseToJavaObject(resourceGetResponse.getResponse());
+ assertNotNull(resourceFromGet);
+ resourceDetails = ResponseParser.parseToObject(importResponse.getResponse(), ResourceReqDetails.class);
+ resourceDetails.setVersion(resourceFromGet.getVersion());
+
+ // checkIn resource
+ resourceVersion = resourceDetails.getVersion();
+ String checkinComment = "good checkin";
+ String checkinComentJson = "{\"userRemarks\": \"" + checkinComment + "\"}";
+ RestResponse checkInResponse = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails,
+ resourceVersion, LifeCycleStatesEnum.CHECKIN, checkinComentJson);
+ assertNotNull("check response object is not null after import resource", checkInResponse);
+ assertEquals("Check response code after checkout resource", 200, checkInResponse.getErrorCode().intValue());
+
+ // req4cert resource
+ RestResponse request4cert = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails,
+ resourceVersion, LifeCycleStatesEnum.CERTIFICATIONREQUEST);
+ assertNotNull("check response object is not null after resource request for certification", request4cert);
+ assertEquals("Check response code after checkout resource", 200, request4cert.getErrorCode().intValue());
+ resourceFromGet = ResponseParser.convertResourceResponseToJavaObject(request4cert.getResponse());
+ assertNotNull(resourceFromGet);
+ resourceDetails = ResponseParser.parseToObject(request4cert.getResponse(), ResourceReqDetails.class);
+ resourceDetails.setVersion(resourceFromGet.getVersion());
+
+ // startCert
+ RestResponse startCert = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails,
+ resourceVersion, LifeCycleStatesEnum.STARTCERTIFICATION);
+ assertNotNull("check response object is not null after resource request start certification", startCert);
+ assertEquals("Check response code after checkout resource", 200, startCert.getErrorCode().intValue());
+ resourceFromGet = ResponseParser.convertResourceResponseToJavaObject(startCert.getResponse());
+ assertNotNull(resourceFromGet);
+ resourceDetails = ResponseParser.parseToObject(startCert.getResponse(), ResourceReqDetails.class);
+ resourceDetails.setVersion(resourceFromGet.getVersion());
+ resourceVersion = resourceDetails.getVersion();
+
+ // clean audit
+ DbUtils.cleanAllAudits();
+
+ // import new resource while resource already exist in other state
+ importResponse = ImportRestUtils.importNewResourceByName("importResource4test", UserRoleEnum.DESIGNER);
+ ErrorInfo errorInfo = ErrorValidationUtils
+ .parseErrorConfigYaml(ActionStatus.COMPONENT_IN_CERT_IN_PROGRESS_STATE.name());
+ assertNotNull("check response object is not null after create resouce", importResponse);
+ assertNotNull("check error code exists in response after create resource", importResponse.getErrorCode());
+ assertEquals("Check response code after create service", errorInfo.getCode(), importResponse.getErrorCode());
+ List<String> variables = Arrays.asList(resourceDetails.getName(), "resource", sdncAdminUser.getFirstName(),
+ sdncAdminUser.getLastName(), sdncAdminUser.getUserId());
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_IN_CERT_IN_PROGRESS_STATE.name(),
+ variables, importResponse.getResponse());
+
+ // validate audit
+ ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = Convertor
+ .constructFieldsForAuditValidation(resourceDetails, resourceVersion);
+ String auditAction = "ResourceImport";
+ expectedResourceAuditJavaObject.setAction(auditAction);
+ expectedResourceAuditJavaObject.setModifierUid(UserRoleEnum.DESIGNER.getUserId());
+ expectedResourceAuditJavaObject.setModifierName(UserRoleEnum.DESIGNER.getUserName());
+ expectedResourceAuditJavaObject.setPrevState((LifecycleStateEnum.CERTIFICATION_IN_PROGRESS).toString());
+ // expectedResourceAuditJavaObject.setCurrState((LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT).toString());
+ expectedResourceAuditJavaObject.setCurrState("");
+ expectedResourceAuditJavaObject.setPrevVersion(resourceVersion);
+ expectedResourceAuditJavaObject.setCurrVersion("");
+ expectedResourceAuditJavaObject.setStatus(errorInfo.getCode().toString());
+ expectedResourceAuditJavaObject.setToscaNodeType(resourceFromGet.getToscaResourceName());
+ String auditDesc = AuditValidationUtils.buildAuditDescription(errorInfo, variables);
+ expectedResourceAuditJavaObject.setDesc(auditDesc);
+ AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject, auditAction, null, false);
+
+ }
+
+ // TODO DE171337
+ @Test(enabled = false)
+ public void importNewResource_existIn_CerInProgress_state_performByAdmin() throws Exception {
+
+ User sdncAdminUser = ElementFactory.getDefaultUser(UserRoleEnum.ADMIN);
+
+ // import new resource
+ RestResponse importResponse = importNewResource(UserRoleEnum.ADMIN);
+ assertNotNull("check response object is not null after import resource", importResponse);
+ assertNotNull("check error code exists in response after import resource", importResponse.getErrorCode());
+ assertEquals("Check response code after import resource", 201, importResponse.getErrorCode().intValue());
+ resourceDetails = ResponseParser.parseToObject(importResponse.getResponse(), ResourceReqDetails.class);
+ resourceVersion = resourceDetails.getVersion();
+ RestResponse resourceGetResponse = ResourceRestUtils.getResource(sdncModifierDetails,
+ resourceDetails.getUniqueId());
+ assertEquals("Check response code after get resource", 200, resourceGetResponse.getErrorCode().intValue());
+ Resource resourceFromGet = ResponseParser
+ .convertResourceResponseToJavaObject(resourceGetResponse.getResponse());
+ assertNotNull(resourceFromGet);
+
+ // add mandatory artifacts
+ // resourceUtils.addResourceMandatoryArtifacts(sdncModifierDetails,
+ // resourceGetResponse);
+ resourceGetResponse = ResourceRestUtils.getResource(sdncModifierDetails, resourceDetails.getUniqueId());
+ assertEquals("Check response code after get resource", 200, resourceGetResponse.getErrorCode().intValue());
+ resourceFromGet = ResponseParser.convertResourceResponseToJavaObject(resourceGetResponse.getResponse());
+ assertNotNull(resourceFromGet);
+ resourceDetails = ResponseParser.parseToObject(importResponse.getResponse(), ResourceReqDetails.class);
+ resourceDetails.setVersion(resourceFromGet.getVersion());
+
+ // checkIn resource
+ resourceVersion = resourceDetails.getVersion();
+ String checkinComment = "good checkin";
+ String checkinComentJson = "{\"userRemarks\": \"" + checkinComment + "\"}";
+ RestResponse checkInResponse = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails,
+ resourceVersion, LifeCycleStatesEnum.CHECKIN, checkinComentJson);
+ assertNotNull("check response object is not null after import resource", checkInResponse);
+ assertEquals("Check response code after checkout resource", 200, checkInResponse.getErrorCode().intValue());
+
+ // req4cert resource
+ RestResponse request4cert = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails,
+ resourceVersion, LifeCycleStatesEnum.CERTIFICATIONREQUEST);
+ assertNotNull("check response object is not null after resource request for certification", request4cert);
+ assertEquals("Check response code after checkout resource", 200, request4cert.getErrorCode().intValue());
+ resourceFromGet = ResponseParser.convertResourceResponseToJavaObject(request4cert.getResponse());
+ assertNotNull(resourceFromGet);
+ resourceDetails = ResponseParser.parseToObject(request4cert.getResponse(), ResourceReqDetails.class);
+ resourceDetails.setVersion(resourceFromGet.getVersion());
+
+ // startCert
+ RestResponse startCert = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails,
+ resourceVersion, LifeCycleStatesEnum.STARTCERTIFICATION);
+ assertNotNull("check response object is not null after resource request start certification", startCert);
+ assertEquals("Check response code after checkout resource", 200, startCert.getErrorCode().intValue());
+ resourceFromGet = ResponseParser.convertResourceResponseToJavaObject(startCert.getResponse());
+ assertNotNull(resourceFromGet);
+ resourceDetails = ResponseParser.parseToObject(startCert.getResponse(), ResourceReqDetails.class);
+ resourceDetails.setVersion(resourceFromGet.getVersion());
+ resourceVersion = resourceDetails.getVersion();
+
+ // clean audit
+ DbUtils.cleanAllAudits();
+
+ // import new resource while resource already exist in other state
+ importResponse = ImportRestUtils.importNewResourceByName("importResource4test", UserRoleEnum.ADMIN);
+
+ // validate response
+ ErrorInfo errorInfo = ErrorValidationUtils
+ .parseErrorConfigYaml(ActionStatus.COMPONENT_IN_CERT_IN_PROGRESS_STATE.name());
+ assertNotNull("check response object is not null after create resouce", importResponse);
+ assertNotNull("check error code exists in response after create resource", importResponse.getErrorCode());
+ assertEquals("Check response code after create service", errorInfo.getCode(), importResponse.getErrorCode());
+ List<String> variables = Arrays.asList(resourceDetails.getName(), "resource", sdncAdminUser.getFirstName(),
+ sdncAdminUser.getLastName(), sdncAdminUser.getUserId());
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_IN_CERT_IN_PROGRESS_STATE.name(),
+ variables, importResponse.getResponse());
+
+ // validate audit
+ ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = Convertor
+ .constructFieldsForAuditValidation(resourceDetails, resourceVersion);
+ String auditAction = "ResourceImport";
+ expectedResourceAuditJavaObject.setAction(auditAction);
+ expectedResourceAuditJavaObject.setModifierUid(UserRoleEnum.ADMIN.getUserId());
+ expectedResourceAuditJavaObject.setModifierName(UserRoleEnum.ADMIN.getUserName());
+ expectedResourceAuditJavaObject.setPrevState((LifecycleStateEnum.CERTIFICATION_IN_PROGRESS).toString());
+ // expectedResourceAuditJavaObject.setCurrState((LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT).toString());
+ expectedResourceAuditJavaObject.setCurrState("");
+ expectedResourceAuditJavaObject.setPrevVersion(resourceVersion);
+ expectedResourceAuditJavaObject.setCurrVersion("");
+ expectedResourceAuditJavaObject.setStatus(errorInfo.getCode().toString());
+ expectedResourceAuditJavaObject.setToscaNodeType(resourceFromGet.getToscaResourceName());
+ String auditDesc = AuditValidationUtils.buildAuditDescription(errorInfo, variables);
+ expectedResourceAuditJavaObject.setDesc(auditDesc);
+ AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject, auditAction, null, false);
+
+ }
+
+ // TODO DE171337
+ // @Test(enabled = false)
+ // public void
+ // importNewResource_existIn_Certified_state_chnage_reqAndCap_byDesigner()
+ // throws Exception{
+ //
+ // // Andrey - set default artifact details
+ // ArtifactDefinition artifactDefinition =
+ // artifactUtils.constructDefaultArtifactInfo();
+ //
+ // // import new resource
+ // RestResponse importResponse = importNewResource(UserRoleEnum.ADMIN);
+ // assertNotNull("check response object is not null after import resource",
+ // importResponse);
+ // assertNotNull("check error code exists in response after import
+ // resource", importResponse.getErrorCode());
+ // assertEquals("Check response code after import resource", 201,
+ // importResponse.getErrorCode().intValue());
+ // String resourceId =
+ // ResponseParser.getUniqueIdFromResponse(importResponse);
+ // resourceDetails =
+ // ResponseParser.parseToObject(importResponse.getResponse(),
+ // ResourceReqDetails.class);
+ // resourceVersion = resourceDetails.getVersion();
+ // RestResponse resourceGetResponse =
+ // ResourceRestUtils.getResource(sdncModifierDetails,
+ // resourceDetails.getUniqueId());
+ // assertEquals("Check response code after get resource", 200,
+ // resourceGetResponse.getErrorCode().intValue());
+ // Resource resourceFromGet =
+ // ResponseParser.convertResourceResponseToJavaObject(resourceGetResponse.getResponse());
+ // assertNotNull(resourceFromGet);
+ //
+ // // add mandatory artifacts
+ // // resourceUtils.addResourceMandatoryArtifacts(sdncModifierDetails,
+ // resourceGetResponse);
+ // resourceGetResponse = ResourceRestUtils.getResource(sdncModifierDetails,
+ // resourceDetails.getUniqueId());
+ // assertEquals("Check response code after get resource", 200,
+ // resourceGetResponse.getErrorCode().intValue());
+ // resourceFromGet =
+ // ResponseParser.convertResourceResponseToJavaObject(resourceGetResponse.getResponse());
+ // assertNotNull(resourceFromGet);
+ // resourceDetails =
+ // ResponseParser.parseToObject(importResponse.getResponse(),
+ // ResourceReqDetails.class);
+ // resourceDetails.setVersion(resourceFromGet.getVersion());
+ //
+ // // add artifact
+ // artifactDefinition.setArtifactName(artifactName1);
+ // ArtifactRestUtils.addInformationalArtifactToResource(resourceDetails,
+ // sdncModifierDetails, resourceVersion , artifactDefinition);
+ //
+ // // add artifact
+ // artifactDefinition.setArtifactName(artifactName2);
+ // resourceUtils.add_artifact(resourceDetails, sdncModifierDetails,
+ // resourceVersion , artifactDefinition);
+ //
+ // // add interface
+ // artifactDefinition.setArtifactName(interfaceArtifactName);
+ // ResourceRestUtils.add_interface(resourceDetails, sdncModifierDetails,
+ // resourceVersion , artifactDefinition);
+ //
+ // //construct fields for validation
+ // resourceVersion="1.0";
+ //
+ // ResourceRespJavaObject resourceRespJavaObject =
+ // Convertor.constructFieldsForRespValidation(resourceDetails,
+ // resourceVersion);
+ // ArrayList<String> artifacts = new ArrayList<String>();
+ //
+ // artifacts.add(resourceId+":"+artifactName1);
+ // artifacts.add(resourceId+":"+artifactName2);
+ // resourceRespJavaObject.setArtifacts(artifacts);
+ // ArrayList<String> interfaces = new ArrayList<String>();
+ //
+ // interfaces.add(interfaze);
+ // resourceRespJavaObject.setInterfaces(interfaces);
+ //
+ // // checkIn resource
+ // resourceVersion = resourceDetails.getVersion();
+ // String checkinComment = "good checkin";
+ // String checkinComentJson = "{\"userRemarks\": \""+checkinComment+"\"}";
+ // RestResponse checkInResponse =
+ // LifecycleRestUtils.changeResourceState(resourceDetails,
+ // sdncModifierDetails, resourceVersion, LifeCycleStatesEnum.CHECKIN,
+ // checkinComentJson);
+ // assertNotNull("check response object is not null after import resource",
+ // checkInResponse);
+ // assertEquals("Check response code after checkout resource", 200,
+ // checkInResponse.getErrorCode().intValue());
+ //
+ // // req4cert resource
+ // RestResponse request4cert =
+ // LifecycleRestUtils.changeResourceState(resourceDetails,
+ // sdncModifierDetails, resourceVersion,
+ // LifeCycleStatesEnum.CERTIFICATIONREQUEST);
+ // assertNotNull("check response object is not null after resource request
+ // for certification", request4cert);
+ // assertEquals("Check response code after checkout resource", 200,
+ // request4cert.getErrorCode().intValue());
+ // resourceFromGet =
+ // ResponseParser.convertResourceResponseToJavaObject(request4cert.getResponse());
+ // assertNotNull(resourceFromGet);
+ // resourceDetails =
+ // ResponseParser.parseToObject(request4cert.getResponse(),
+ // ResourceReqDetails.class);
+ // resourceDetails.setVersion(resourceFromGet.getVersion());
+ //
+ // // startCert
+ // RestResponse startCert =
+ // LifecycleRestUtils.changeResourceState(resourceDetails,
+ // sdncModifierDetails, resourceVersion,
+ // LifeCycleStatesEnum.STARTCERTIFICATION);
+ // assertNotNull("check response object is not null after resource request
+ // start certification", startCert);
+ // assertEquals("Check response code after checkout resource", 200,
+ // startCert.getErrorCode().intValue());
+ // resourceFromGet =
+ // ResponseParser.convertResourceResponseToJavaObject(startCert.getResponse());
+ // assertNotNull(resourceFromGet);
+ // resourceDetails = ResponseParser.parseToObject(startCert.getResponse(),
+ // ResourceReqDetails.class);
+ // resourceDetails.setVersion(resourceFromGet.getVersion());
+ //
+ // // certify
+ // RestResponse certify =
+ // LifecycleRestUtils.changeResourceState(resourceDetails,
+ // sdncModifierDetails, resourceVersion, LifeCycleStatesEnum.CERTIFY);
+ // assertNotNull("check response object is not null after resource request
+ // certify", certify);
+ // assertEquals("Check response code after certify resource", 200,
+ // certify.getErrorCode().intValue());
+ // resourceFromGet =
+ // ResponseParser.convertResourceResponseToJavaObject(certify.getResponse());
+ // assertNotNull(resourceFromGet);
+ // resourceDetails = ResponseParser.parseToObject(certify.getResponse(),
+ // ResourceReqDetails.class);
+ // resourceDetails.setVersion(resourceFromGet.getVersion());
+ //
+ // // clean audit
+ // DbUtils.cleanAllAudits();
+ //
+ // // change resource details
+ //
+ // // import new resource while resource already exist in other state
+ // importResponse =
+ // ImportRestUtils.importNewResourceByName("importResource4testUpdateWithoutReqCap",
+ // UserRoleEnum.ADMIN);
+ // assertNotNull("check response object is not null after import resource",
+ // importResponse);
+ // assertNotNull("check error code exists in response after import
+ // resource", importResponse.getErrorCode());
+ // assertEquals("Check response code after import resource", 200,
+ // importResponse.getErrorCode().intValue());
+ // resourceDetails =
+ // ResponseParser.parseToObject(importResponse.getResponse(),
+ // ResourceReqDetails.class);
+ // resourceVersion = resourceDetails.getVersion();
+ // resourceGetResponse = ResourceRestUtils.getResource(sdncModifierDetails,
+ // resourceDetails.getUniqueId());
+ // assertEquals("Check response code after get resource", 200,
+ // resourceGetResponse.getErrorCode().intValue());
+ // resourceFromGet =
+ // ResponseParser.convertResourceResponseToJavaObject(resourceGetResponse.getResponse());
+ // assertNotNull(resourceFromGet);
+ //
+ // // validate response
+ // Resource resourceFromImport =
+ // ResponseParser.convertResourceResponseToJavaObject(importResponse.getResponse());
+ // assertNotNull(resourceFromImport);
+ //
+ // resourceDetails =
+ // ResponseParser.parseToObject(importResponse.getResponse(),
+ // ResourceReqDetails.class);
+ // resourceRespJavaObject =
+ // Convertor.constructFieldsForRespValidation(resourceDetails);
+ // resourceRespJavaObject.setLifecycleState((LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT).toString());
+ //
+ // // validate get response
+ // resourceGetResponse = ResourceRestUtils.getResource(sdncModifierDetails,
+ // resourceRespJavaObject.getUniqueId());
+ // resourceFromGet =
+ // ResponseParser.convertResourceResponseToJavaObject(resourceGetResponse.getResponse());
+ // assertNotNull(resourceFromGet);
+ //
+ // // validate
+ // ResourceValidationUtils.validateModelObjects(resourceFromImport,
+ // resourceFromGet);
+ //
+ // // validate audit
+ // ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject =
+ // Convertor.constructFieldsForAuditValidation(resourceDetails,
+ // resourceVersion);
+ // auditAction="ResourceImport";
+ // expectedResourceAuditJavaObject.setAction(auditAction);
+ // expectedResourceAuditJavaObject.setPrevState((LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT).toString());
+ // expectedResourceAuditJavaObject.setCurrState((LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT).toString());
+ // expectedResourceAuditJavaObject.setPrevVersion(resourceVersion);
+ // expectedResourceAuditJavaObject.setStatus("200");
+ // expectedResourceAuditJavaObject.setDesc("OK");
+ // expectedResourceAuditJavaObject.setToscaNodeType(resourceFromGet.getToscaResourceName());
+ // AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject,
+ // auditAction, null, false);
+ // }
+
+ @Test
+ public void importNewResource_uuidTest() throws Exception {
+ RestResponse importResponse = importNewResource(UserRoleEnum.ADMIN);
+
+ assertNotNull("check response object is not null after import resource", importResponse);
+ assertNotNull("check error code exists in response after import resource", importResponse.getErrorCode());
+ assertEquals("Check response code after import resource", 201, importResponse.getErrorCode().intValue());
+ String oldUuid = ResponseParser.getValueFromJsonResponse(importResponse.getResponse(), "uuid");
+
+ resourceDetails = ResponseParser.parseToObject(importResponse.getResponse(), ResourceReqDetails.class);
+ resourceVersion = resourceDetails.getVersion();
+ RestResponse resourceGetResponse = ResourceRestUtils.getResource(sdncModifierDetails,
+ resourceDetails.getUniqueId());
+ assertEquals("Check response code after get resource", 200, resourceGetResponse.getErrorCode().intValue());
+ Resource resourceFromGet = ResponseParser
+ .convertResourceResponseToJavaObject(resourceGetResponse.getResponse());
+ assertNotNull(resourceFromGet);
+ // add mandatory artifacts
+ // resourceUtils.addResourceMandatoryArtifacts(sdncModifierDetails,
+ // resourceGetResponse);
+ resourceGetResponse = ResourceRestUtils.getResource(sdncModifierDetails, resourceDetails.getUniqueId());
+ assertEquals("Check response code after get resource", 200, resourceGetResponse.getErrorCode().intValue());
+ resourceFromGet = ResponseParser.convertResourceResponseToJavaObject(resourceGetResponse.getResponse());
+ assertNotNull(resourceFromGet);
+ resourceDetails = ResponseParser.parseToObject(importResponse.getResponse(), ResourceReqDetails.class);
+ resourceDetails.setVersion(resourceFromGet.getVersion());
+
+ RestResponse checkInResponse = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails,
+ "0.1", LifeCycleStatesEnum.CHECKIN);
+ assertNotNull("check response object is not null after import resource", checkInResponse);
+ assertEquals("Check response code after checkout resource", 200, checkInResponse.getErrorCode().intValue());
+
+ String newUuid = ResponseParser.getValueFromJsonResponse(checkInResponse.getResponse(), "uuid");
+ assertTrue(ResourceValidationUtils.validateUuidAfterChangingStatus(oldUuid, newUuid));
+
+ // req4cert resource
+ RestResponse request4cert = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails,
+ resourceVersion, LifeCycleStatesEnum.CERTIFICATIONREQUEST);
+ assertNotNull("check response object is not null after resource request for certification", request4cert);
+ assertEquals("Check response code after checkout resource", 200, request4cert.getErrorCode().intValue());
+ resourceFromGet = ResponseParser.convertResourceResponseToJavaObject(request4cert.getResponse());
+ assertNotNull(resourceFromGet);
+ resourceDetails = ResponseParser.parseToObject(request4cert.getResponse(), ResourceReqDetails.class);
+ resourceDetails.setVersion(resourceFromGet.getVersion());
+
+ String newUuid2 = ResponseParser.getValueFromJsonResponse(request4cert.getResponse(), "uuid");
+ assertTrue(ResourceValidationUtils.validateUuidAfterChangingStatus(oldUuid, newUuid2));
+
+ // startCert
+ RestResponse startCert = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails,
+ resourceVersion, LifeCycleStatesEnum.STARTCERTIFICATION);
+ assertNotNull("check response object is not null after resource request start certification", startCert);
+ assertEquals("Check response code after checkout resource", 200, startCert.getErrorCode().intValue());
+ resourceFromGet = ResponseParser.convertResourceResponseToJavaObject(startCert.getResponse());
+ assertNotNull(resourceFromGet);
+ resourceDetails = ResponseParser.parseToObject(startCert.getResponse(), ResourceReqDetails.class);
+ resourceDetails.setVersion(resourceFromGet.getVersion());
+
+ String newUuid3 = ResponseParser.getValueFromJsonResponse(startCert.getResponse(), "uuid");
+ assertTrue(ResourceValidationUtils.validateUuidAfterChangingStatus(oldUuid, newUuid3));
+
+ RestResponse certify = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails, "0.1",
+ LifeCycleStatesEnum.CERTIFY);
+ assertNotNull("check response object is not null after import resource", certify);
+ assertEquals("Check response code after checkout resource", 200, certify.getErrorCode().intValue());
+
+ String newUuid4 = ResponseParser.getValueFromJsonResponse(certify.getResponse(), "uuid");
+ assertTrue(ResourceValidationUtils.validateUuidAfterChangingStatus(oldUuid, newUuid4));
+
+ RestResponse checkoutResponse = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails,
+ "1.0", LifeCycleStatesEnum.CHECKOUT);
+ assertNotNull("check response object is not null after import resource", checkInResponse);
+ assertEquals("Check response code after checkout resource", 200, checkInResponse.getErrorCode().intValue());
+
+ String newUuid5 = ResponseParser.getValueFromJsonResponse(checkoutResponse.getResponse(), "uuid");
+ assertFalse(ResourceValidationUtils.validateUuidAfterChangingStatus(oldUuid, newUuid5));
+ }
+
+ @Test
+ public void importNewResource_propertiesMapInternalUrlCredential() throws Exception {
+ String folderName = "validateProporties_typeMap_valueUrlCredential";
+ RestResponse importResponse = ImportRestUtils.importNewResourceByName(folderName, UserRoleEnum.DESIGNER);
+
+ Resource resource = ResponseParser.parseToObjectUsingMapper(importResponse.getResponse(), Resource.class);
+
+ List<PropertyDefinition> properties = resource.getProperties();
+ assertEquals("check properties size", 3, properties.size());
+
+ PropertyDefinition propertyDefinition = properties.stream().filter(p -> p.getName().equals("validation_test"))
+ .findFirst().get();
+ String defaultValue = propertyDefinition.getDefaultValue();
+
+ Map mapValue = gson.fromJson(defaultValue, Map.class);
+ assertEquals("check Map value size", 2, mapValue.size());
+ checkMapValues(mapValue, "key", 1, null);
+ checkMapValues(mapValue, "key", 2, null);
+
+ System.err.println("import Resource " + "<" + folderName + ">" + "response: " + importResponse.getErrorCode());
+
+ }
+
+ @Test
+ public void importNewResource_propertiesListInternalUrlCredential() throws Exception {
+ String folderName = "validateProporties_typeList_valueUrlCredential";
+ RestResponse importResponse = ImportRestUtils.importNewResourceByName(folderName, UserRoleEnum.DESIGNER);
+
+ Resource resource = ResponseParser.parseToObjectUsingMapper(importResponse.getResponse(), Resource.class);
+
+ List<PropertyDefinition> properties = resource.getProperties();
+ assertEquals("check properties size", 3, properties.size());
+
+ PropertyDefinition propertyDefinition = properties.stream().filter(p -> p.getName().equals("validation_test"))
+ .findFirst().get();
+ String defaultValue = propertyDefinition.getDefaultValue();
+
+ List listValue = gson.fromJson(defaultValue, List.class);
+ assertEquals("check List value size", 2, listValue.size());
+ checkListValues(listValue.get(0), 1, SPECIAL_CHARACTERS);
+ checkListValues(listValue.get(1), 2, SPECIAL_CHARACTERS);
+
+ // Verify attributes
+ List<PropertyDefinition> attributes = resource.getAttributes();
+
+ assertEquals("check properties size", 2, attributes.size());
+
+ // Verify attribute from type map
+ PropertyDefinition attributeMapDefinition = attributes.stream()
+ .filter(p -> p.getName().equals("validation_test_map")).findFirst().get();
+ String defaultMapValue = attributeMapDefinition.getDefaultValue();
+ Map attributeMapValue = gson.fromJson(defaultMapValue, Map.class);
+ assertEquals("check Map value size", 2, attributeMapValue.size());
+ checkMapValues(attributeMapValue, "key", 1, SPECIAL_CHARACTERS);
+ checkMapValues(attributeMapValue, "key", 2, SPECIAL_CHARACTERS);
+
+ // Verify attribute from type list
+ PropertyDefinition attributeListDefinition = attributes.stream()
+ .filter(p -> p.getName().equals("validation_test_list")).findFirst().get();
+ String defaultListValue = attributeListDefinition.getDefaultValue();
+
+ List attributeListValue = gson.fromJson(defaultListValue, List.class);
+ assertEquals("check List value size", 2, attributeListValue.size());
+ checkListValues(attributeListValue.get(0), 1, SPECIAL_CHARACTERS);
+ checkListValues(attributeListValue.get(1), 2, SPECIAL_CHARACTERS);
+
+ System.err.println("import Resource " + "<" + folderName + ">" + "response: " + importResponse.getErrorCode());
+
+ }
+
+ private void checkListValues(Object object, int index, String suffix) {
+
+ Map map = (Map) object;
+ assertEquals("check Map protocol value", "protocol" + index + (suffix == null ? "" : suffix),
+ map.get("protocol"));
+ assertEquals("check Map token value", "token" + index, map.get("token"));
+ }
+
+ // @Test
+ public void importNewResource_validateProporties_typeTestDataType() throws Exception {
+ String folderName = "validateProporties_typeTestDataType";
+ RestResponse importResponse = ImportRestUtils.importNewResourceByName(folderName, UserRoleEnum.DESIGNER);
+
+ Resource resource = ResponseParser.parseToObjectUsingMapper(importResponse.getResponse(), Resource.class);
+
+ }
+
+ private void checkMapValues(Map mapValue, String key, int index, String suffix) {
+
+ Map map1 = (Map) mapValue.get(key + index);
+ assertEquals("check Map protocol value", "protocol" + index + (suffix == null ? "" : suffix),
+ map1.get("protocol"));
+ assertEquals("check Map token value", "token" + index, map1.get("token"));
+
+ }
+}
diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/ImportToscaCapabilitiesWithProperties.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/ImportToscaCapabilitiesWithProperties.java
new file mode 100644
index 0000000000..3d7c81abae
--- /dev/null
+++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/ImportToscaCapabilitiesWithProperties.java
@@ -0,0 +1,416 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * 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.openecomp.sdc.ci.tests.execute.imports;
+
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertTrue;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.junit.Rule;
+import org.junit.rules.TestName;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
+import org.openecomp.sdc.be.model.CapabilityDefinition;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
+import org.openecomp.sdc.ci.tests.datatypes.ImportReqDetails;
+import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
+import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
+import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
+import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
+import org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils;
+import org.openecomp.sdc.ci.tests.utils.rest.ResourceRestUtils;
+import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
+import org.testng.annotations.Test;
+
+import com.google.gson.Gson;
+
+/**
+ * US US730518 Story [BE] - TOSCA capabilities with properties - import "As a
+ * resource designer, I would like to add my VFC capabilities with properties."
+ *
+ * @author ns019t
+ *
+ */
+public class ImportToscaCapabilitiesWithProperties extends ComponentBaseTest {
+ @Rule
+ public static TestName name = new TestName();
+
+ Gson gson = new Gson();
+
+ /**
+ * public Constructor ImportToscaCapabilitiesWithProperties
+ */
+ public ImportToscaCapabilitiesWithProperties() {
+ super(name, ImportToscaCapabilitiesWithProperties.class.getName());
+ }
+
+ /**
+ * String constants
+ */
+ public static String propertyForTestName = "propertyfortest";
+ public static String rootPath = System.getProperty("user.dir");
+ public static String scalable = "tosca.capabilities.Scalable";
+ public static String container = "tosca.capabilities.Container";
+ public static String minInstances = "min_instances";
+ public static String userDefinedNodeYaml = "mycompute.yml";
+
+ /**
+ * Capability Type - capability type on the graph should already have
+ * properties modeled on it. please verify. The import of the capability
+ * types should support adding those properties. when importing, validate
+ * name uniqueness between the capability's properties see capability
+ * tosca.capabilities.Container
+ *
+ * Acceptance Criteria: validate capability type properties (for example,
+ * compute have capability Container -> the properties of this capability
+ * should be in the Json response)
+ *
+ * @throws IOException
+ */
+ @Test
+ public void validateCapabilityTypePropertiesSucceed() throws IOException {
+ User user = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
+ RestResponse createResourceRes = ResourceRestUtils.getResourceByNameAndVersion(user.getUserId(), "Compute",
+ "1.0");
+ BaseRestUtils.checkSuccess(createResourceRes);
+ Resource resource = ResponseParser.convertResourceResponseToJavaObject(createResourceRes.getResponse());
+ Map<String, List<CapabilityDefinition>> capabilities = resource.getCapabilities();
+ assertEquals(capabilities.size(), 6);
+
+ CapabilityDefinition capability = capabilities.get(scalable).get(0);
+ List<ComponentInstanceProperty> properties = capability.getProperties();
+ assertEquals(properties.size(), 3);
+ assertTrue(!properties.stream().filter(p -> p.getName().equalsIgnoreCase(propertyForTestName)).findAny()
+ .isPresent());
+
+ ComponentInstanceProperty originalProperty = properties.stream()
+ .filter(p -> p.getName().equalsIgnoreCase(minInstances)).findAny().get();
+ assertEquals(originalProperty.getType(), "integer");
+ assertEquals(originalProperty.getDefaultValue(), "1");
+
+ capability = capabilities.get(container).get(0);
+ properties = capability.getProperties();
+ assertEquals(properties.size(), 4);
+ }
+
+ /**
+ * Capability Definition on VFC / CP / VL - properties can also be defined
+ * on the capability when the capability is declared. (property definition
+ * with default value) If the property name (case insensitive) already
+ * defined on the capability type, it overrides the capability from the
+ * capability type Import of VFC / CP /VL should support adding properties
+ * to the capability. when importing, validate name uniqueness between the
+ * capability's properties
+ *
+ * Acceptance Criteria: import node type with capability definition on it.
+ * use the attached "myCompute"
+ *
+ * @throws Exception
+ */
+ @Test
+ public void importNodeTypeWithCapabilityWithPropertiesFromYmlSucceed() throws Exception {
+ User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
+ ImportReqDetails resourceDetails = ElementFactory.getDefaultImportResource();
+ RestResponse createResource = importUserDefinedNodeType(userDefinedNodeYaml, sdncModifierDetails,
+ resourceDetails);
+ BaseRestUtils.checkCreateResponse(createResource);
+ Resource resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
+
+ Map<String, List<CapabilityDefinition>> capabilities = resource.getCapabilities();
+ assertEquals(capabilities.size(), 6);
+
+ CapabilityDefinition capability = capabilities.get(scalable).get(0);
+ List<ComponentInstanceProperty> properties = capability.getProperties();
+ assertEquals(properties.size(), 4);
+
+ ComponentInstanceProperty newProperty = properties.stream()
+ .filter(p -> p.getName().equalsIgnoreCase(propertyForTestName)).findAny().get();
+ assertEquals(newProperty.getType(), "string");
+ assertEquals(newProperty.getDescription(), "test");
+ assertEquals(newProperty.getDefaultValue(), "success");
+
+ ComponentInstanceProperty overriddenProperty = properties.stream()
+ .filter(p -> p.getName().equalsIgnoreCase(minInstances)).collect(Collectors.toList()).get(0);
+ assertEquals(overriddenProperty.getType(), "integer");
+ assertEquals(overriddenProperty.getDefaultValue(), "3");
+
+ }
+
+ /**
+ * importNodeTypeWithCapabilityWithPropertiesFromYmlFailed
+ *
+ * @throws Exception
+ */
+ @Test
+ public void importNodeTypeWithCapabilityWithPropertiesFromYmlFailed() throws Exception {
+ User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
+ ImportReqDetails resourceDetails = ElementFactory.getDefaultImportResource();
+ RestResponse createResource = importUserDefinedNodeType("mycompute_failed.yml", sdncModifierDetails,
+ resourceDetails);
+ BaseRestUtils.checkErrorMessageResponse(createResource, ActionStatus.PROPERTY_NAME_ALREADY_EXISTS);
+ }
+
+ /**
+ * Capability Assignment (on node_template / resource instance) - should
+ * support assignment of the property (property value). On the resource
+ * instance level, value can be assigned to either properties that are
+ * defined on the capability type or on the capability definition. When
+ * importing a VF - the node_template can have capability's property value.
+ * It should be imported and saved on the graph Acceptance Criteria: import
+ * a VF that assign values to property of capability that was defined on the
+ * capability type
+ *
+ * @throws Exception
+ */
+ @Test
+ public void importResourceWithCapabilityWithPropertiesOverridingCapTypePropertiesSucceed() throws Exception {
+ User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
+ String payloadName = "vf_with_cap_prop_override_cap_type_prop.csar";
+ ImportReqDetails resourceDetails = ElementFactory.getDefaultImportResource();
+ Path path = Paths.get(rootPath + "/src/test/resources/CI/csars/vf_with_cap_prop_override_cap_type_prop.csar");
+ byte[] data = Files.readAllBytes(path);
+ String payloadData = Base64.encodeBase64String(data);
+ resourceDetails.setPayloadData(payloadData);
+
+ resourceDetails.setPayloadName(payloadName);
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, sdncModifierDetails);
+ BaseRestUtils.checkCreateResponse(createResource);
+
+ List<ImmutablePair<String, String>> propertyNamesValues = new ArrayList<>();
+ propertyNamesValues.add(new ImmutablePair<String, String>("num_cpus", "2"));
+ propertyNamesValues.add(new ImmutablePair<String, String>("mem_size", "2000 MB"));
+ checkResource(createResource, 8, container, "DBMS", propertyNamesValues);
+
+ ResourceReqDetails resourceDetails2 = ElementFactory.getDefaultResource();
+ resourceDetails2.setCsarUUID("vf_with_cap_prop_override_cap_type_prop.csar");
+ resourceDetails2.setResourceType(ResourceTypeEnum.VF.name());
+ createResource = ResourceRestUtils.createResource(resourceDetails2, sdncModifierDetails);
+ BaseRestUtils.checkCreateResponse(createResource);
+
+ checkResource(createResource, 8, container, "DBMS", propertyNamesValues);
+ }
+
+ /**
+ * importResourceWithCapabilityWithPropertiesOverridingCapTypePropertiesFailed
+ *
+ * @throws Exception
+ */
+ @Test
+ public void importResourceWithCapabilityWithPropertiesOverridingCapTypePropertiesFailed() throws Exception {
+ User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
+ String payloadName = "vf_with_cap_prop_override_cap_type_prop_failed.csar";
+ ImportReqDetails resourceDetails = ElementFactory.getDefaultImportResource();
+ Path path = Paths
+ .get(rootPath + "/src/test/resources/CI/csars/vf_with_cap_prop_override_cap_type_prop_failed.csar");
+ byte[] data = Files.readAllBytes(path);
+ String payloadData = Base64.encodeBase64String(data);
+ resourceDetails.setPayloadData(payloadData);
+
+ resourceDetails.setPayloadName(payloadName);
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, sdncModifierDetails);
+ BaseRestUtils.checkErrorMessageResponse(createResource, ActionStatus.INVALID_PROPERTY);
+
+ ResourceReqDetails resourceDetails2 = ElementFactory.getDefaultResource();
+ resourceDetails2.setCsarUUID("vf_with_cap_prop_override_cap_type_prop_failed.csar");
+ resourceDetails2.setResourceType(ResourceTypeEnum.VF.name());
+ createResource = ResourceRestUtils.createResource(resourceDetails2, sdncModifierDetails);
+ BaseRestUtils.checkErrorMessageResponse(createResource, ActionStatus.INVALID_PROPERTY);
+
+ }
+
+ /**
+ * Capability Assignment (on node_template / resource instance) - should
+ * support assignment of the property (property value). On the resource
+ * instance level, value can be assigned to either properties that are
+ * defined on the capability type or on the capability definition. When
+ * importing a VF - the node_template can have capability's property value.
+ * It should be imported and saved on the graph Acceptance Criteria: import
+ * a VF that assign values to property of capability that was defined on the
+ * capability definition (on the node type)
+ *
+ * @throws Exception
+ */
+ @Test
+ public void importResourceWithCapabilityWithPropertiesOverridingNodeTypeCapPropertiesSucceed() throws Exception {
+
+ User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
+ ImportReqDetails resourceDetails = ElementFactory.getDefaultImportResource();
+ RestResponse createResource = importUserDefinedNodeType(userDefinedNodeYaml, sdncModifierDetails,
+ resourceDetails);
+ BaseRestUtils.checkCreateResponse(createResource);
+ Resource userDefinedNodeType = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(),
+ Resource.class);
+
+ String payloadName = "vf_with_cap_prop_override_cap_type_prop1.csar";
+ resourceDetails = ElementFactory.getDefaultImportResource();
+ Path path = Paths.get(rootPath + "/src/test/resources/CI/csars/vf_with_cap_prop_override_cap_type_prop1.csar");
+ byte[] data = Files.readAllBytes(path);
+ String payloadData = Base64.encodeBase64String(data);
+ resourceDetails.setPayloadData(payloadData);
+
+ resourceDetails.setPayloadName(payloadName);
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ createResource = ResourceRestUtils.createResource(resourceDetails, sdncModifierDetails);
+ BaseRestUtils.checkCreateResponse(createResource);
+
+ List<ImmutablePair<String, String>> propertyNamesValues = new ArrayList<>();
+ propertyNamesValues.add(new ImmutablePair<String, String>("num_cpus", "2"));
+ propertyNamesValues.add(new ImmutablePair<String, String>("mem_size", "2000 MB"));
+ checkResource(createResource, 8, container, "DBMS", propertyNamesValues);
+
+ List<ImmutablePair<String, String>> propertyNamesValues1 = new ArrayList<>();
+ propertyNamesValues1.add(new ImmutablePair<String, String>(propertyForTestName, "success_again"));
+ propertyNamesValues1.add(new ImmutablePair<String, String>(minInstances, "4"));
+ checkResource(createResource, 8, scalable, userDefinedNodeType.getName(), propertyNamesValues1);
+
+ ResourceReqDetails resourceDetails2 = ElementFactory.getDefaultResource();
+ resourceDetails2.setCsarUUID("vf_with_cap_prop_override_cap_type_prop1.csar");
+ resourceDetails2.setResourceType(ResourceTypeEnum.VF.name());
+ createResource = ResourceRestUtils.createResource(resourceDetails2, sdncModifierDetails);
+ BaseRestUtils.checkCreateResponse(createResource);
+
+ checkResource(createResource, 8, container, "DBMS", propertyNamesValues);
+ checkResource(createResource, 8, scalable, userDefinedNodeType.getName(), propertyNamesValues1);
+
+ }
+
+ /**
+ * importResourceWithCapabilityWithPropertiesOverridingNodeTypeCapPropertiesFailed
+ *
+ * @throws Exception
+ */
+ @Test
+ public void importResourceWithCapabilityWithPropertiesOverridingNodeTypeCapPropertiesFailed() throws Exception {
+
+ User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
+ ImportReqDetails resourceDetails = ElementFactory.getDefaultImportResource();
+ RestResponse createResource = importUserDefinedNodeType(userDefinedNodeYaml, sdncModifierDetails,
+ resourceDetails);
+ BaseRestUtils.checkCreateResponse(createResource);
+
+ String payloadName = "vf_with_cap_prop_override_cap_type_prop1_failed.csar";
+ resourceDetails = ElementFactory.getDefaultImportResource();
+ Path path = Paths
+ .get(rootPath + "/src/test/resources/CI/csars/vf_with_cap_prop_override_cap_type_prop1_failed.csar");
+ byte[] data = Files.readAllBytes(path);
+ String payloadData = Base64.encodeBase64String(data);
+ resourceDetails.setPayloadData(payloadData);
+
+ resourceDetails.setPayloadName(payloadName);
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ createResource = ResourceRestUtils.createResource(resourceDetails, sdncModifierDetails);
+ BaseRestUtils.checkErrorResponse(createResource, ActionStatus.PROPERTY_NAME_ALREADY_EXISTS,
+ propertyForTestName);
+
+ ResourceReqDetails resourceDetails2 = ElementFactory.getDefaultResource();
+ resourceDetails2.setCsarUUID("vf_with_cap_prop_override_cap_type_prop1_failed.csar");
+ resourceDetails2.setResourceType(ResourceTypeEnum.VF.name());
+ createResource = ResourceRestUtils.createResource(resourceDetails2, sdncModifierDetails);
+ BaseRestUtils.checkErrorResponse(createResource, ActionStatus.PROPERTY_NAME_ALREADY_EXISTS,
+ propertyForTestName);
+ }
+
+ private RestResponse importUserDefinedNodeType(String payloadName, User sdncModifierDetails,
+ ImportReqDetails resourceDetails) throws Exception {
+
+ Path path = Paths.get(rootPath + "/src/test/resources/CI/csars/" + payloadName);
+ byte[] data = Files.readAllBytes(path);
+ String payloadData = Base64.encodeBase64String(data);
+ resourceDetails.setPayloadData(payloadData);
+
+ resourceDetails.setPayloadName(payloadName);
+ resourceDetails.setResourceType(ResourceTypeEnum.VFC.name());
+ return ResourceRestUtils.createResource(resourceDetails, sdncModifierDetails);
+ }
+
+ // TODO Tal: Since Cashing change partial resource returned that causes null
+ // pointer exception
+ // commented out till fixing
+ private void checkResource(RestResponse createResource, int capNum, String capType, String riName,
+ List<ImmutablePair<String, String>> propertyNamesValues) {
+ Resource resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
+
+ Map<String, List<CapabilityDefinition>> capabilities = resource.getCapabilities();
+ // TODO Tal: Since Cashing change partial resource returned that causes
+ // null pointer exception
+ /* assertEquals(capabilities.size(), capNum); */
+ /*
+ * List<CapabilityDefinition> capabilitesContainer =
+ * capabilities.get(capType);
+ */
+
+ ComponentInstance resourceRI = resource.getComponentInstances().stream()
+ .filter(ri -> ri.getComponentName().equals(riName)).collect(Collectors.toList()).get(0);
+ // TODO Tal: Since Cashing change partial resource returned that causes
+ // null pointer exception
+ /*
+ * CapabilityDefinition capabilityFromContainer =
+ * capabilitesContainer.stream()
+ * .filter(cap->cap.getOwnerId().equals(resourceRI.getUniqueId())).
+ * collect(Collectors.toList()).get(0);
+ */
+
+ CapabilityDefinition capabilityFromRI = resourceRI.getCapabilities().get(capType).get(0);
+ for (ImmutablePair<String, String> propValuePair : propertyNamesValues) {
+ // TODO Tal: Since Cashing change partial resource returned that
+ // causes null pointer exception
+ /*
+ * Map<String, ComponentInstanceProperty> propertiesFromContainer =
+ * capabilityFromContainer.getProperties()
+ * .stream().filter(p->p.getName().equalsIgnoreCase(propValuePair.
+ * getLeft())) .collect(Collectors.toMap(p->p.getName(), p->p));
+ */
+
+ List<ComponentInstanceProperty> propertiesFromRI = capabilityFromRI.getProperties().stream()
+ .filter(p -> p.getName().equalsIgnoreCase(propValuePair.getLeft())).collect(Collectors.toList());
+ // TODO Tal: Since Cashing change partial resource returned that
+ // causes null pointer exception
+ /*
+ * for(ComponentInstanceProperty riProp : propertiesFromRI){
+ * assertTrue(propertiesFromContainer.containsKey(riProp.getName()))
+ * ; ComponentInstanceProperty containerProp =
+ * propertiesFromContainer.get(riProp.getName());
+ * assertEquals(riProp.getValue(), containerProp.getValue());
+ * if(riProp.getName().equals(propValuePair.getLeft()))
+ * assertEquals(riProp.getValue(), propValuePair.getRight());
+ *
+ * }
+ */
+ }
+ }
+
+}
diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/ImportToscaResourceTest.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/ImportToscaResourceTest.java
new file mode 100644
index 0000000000..8ce8dc5433
--- /dev/null
+++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/ImportToscaResourceTest.java
@@ -0,0 +1,2896 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * 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.openecomp.sdc.ci.tests.execute.imports;
+
+import static org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils.STATUS_CODE_CREATED;
+import static org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils.STATUS_CODE_INVALID_CONTENT;
+import static org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils.STATUS_CODE_SUCCESS;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertFalse;
+import static org.testng.AssertJUnit.assertNotNull;
+import static org.testng.AssertJUnit.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.http.client.ClientProtocolException;
+import org.junit.Rule;
+import org.junit.rules.TestName;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
+import org.openecomp.sdc.be.model.CapReqDef;
+import org.openecomp.sdc.be.model.CapabilityDefinition;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.RelationshipImpl;
+import org.openecomp.sdc.be.model.RequirementAndRelationshipPair;
+import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
+import org.openecomp.sdc.be.model.RequirementDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
+import org.openecomp.sdc.ci.tests.datatypes.ArtifactReqDetails;
+import org.openecomp.sdc.ci.tests.datatypes.ComponentInstanceReqDetails;
+import org.openecomp.sdc.ci.tests.datatypes.ImportReqDetails;
+import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
+import org.openecomp.sdc.ci.tests.datatypes.enums.ErrorInfo;
+import org.openecomp.sdc.ci.tests.datatypes.enums.LifeCycleStatesEnum;
+import org.openecomp.sdc.ci.tests.datatypes.enums.NormativeTypesEnum;
+import org.openecomp.sdc.ci.tests.datatypes.enums.ResourceCategoryEnum;
+import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
+import org.openecomp.sdc.ci.tests.datatypes.expected.ExpectedResourceAuditJavaObject;
+import org.openecomp.sdc.ci.tests.datatypes.http.HttpHeaderEnum;
+import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
+import org.openecomp.sdc.ci.tests.utils.DbUtils;
+import org.openecomp.sdc.ci.tests.utils.Decoder;
+import org.openecomp.sdc.ci.tests.utils.Utils;
+import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
+import org.openecomp.sdc.ci.tests.utils.general.ImportUtils;
+import org.openecomp.sdc.ci.tests.utils.rest.ArtifactRestUtils;
+import org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils;
+import org.openecomp.sdc.ci.tests.utils.rest.ComponentInstanceRestUtils;
+import org.openecomp.sdc.ci.tests.utils.rest.ComponentRestUtils;
+import org.openecomp.sdc.ci.tests.utils.rest.LifecycleRestUtils;
+import org.openecomp.sdc.ci.tests.utils.rest.ResourceRestUtils;
+import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
+import org.openecomp.sdc.ci.tests.utils.validation.AuditValidationUtils;
+import org.openecomp.sdc.ci.tests.utils.validation.ErrorValidationUtils;
+import org.openecomp.sdc.common.api.ToscaNodeTypeInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.AssertJUnit;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import aj.org.objectweb.asm.Attribute;
+
+/**
+ *
+ * @author Andrey + Pavel + Shay
+ *
+ */
+
+public class ImportToscaResourceTest extends ComponentBaseTest {
+ private static Logger logger = LoggerFactory.getLogger(ImportToscaResourceTest.class.getName());
+ protected Utils utils = new Utils();
+
+ public ImportToscaResourceTest() {
+ super(name, ImportToscaResourceTest.class.getName());
+ }
+
+ public ImportReqDetails importReqDetails;
+ protected static User sdncUserDetails;
+ protected static User testerUser;
+ protected String testResourcesPath;
+ protected ResourceReqDetails resourceDetails;
+ private HashSet<String> capabilitySources;
+ private int actualNumOfReqOrCap;
+
+ @Rule
+ public static TestName name = new TestName();
+
+ @BeforeMethod
+ public void before() throws Exception {
+ importReqDetails = ElementFactory.getDefaultImportResource();
+ sdncUserDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
+ testerUser = ElementFactory.getDefaultUser(UserRoleEnum.TESTER);
+ resourceDetails = ElementFactory.getDefaultResource();
+ String sourceDir = config.getResourceConfigDir();
+ final String workDir = "importToscaResourceByCreateUrl";
+ testResourcesPath = sourceDir + File.separator + workDir;
+ capabilitySources = new HashSet<String>();
+ actualNumOfReqOrCap = 0;
+ }
+
+ @DataProvider
+ private static final Object[][] getYmlWithInValidListProperties() throws IOException, Exception {
+ return new Object[][] { { "ListPropertyFalure02.yml", "[false,\"truee\"]", "boolean" },
+ { "ListPropertyFalure03.yml", "[false,3]", "boolean" },
+ { "ListPropertyFalure04.yml", "[false,3.56]", "boolean" },
+ { "ListPropertyFalure05.yml", "[10000,3.56]", "integer" },
+ { "ListPropertyFalure06.yml", "[10000,\"aaaa\"]", "integer" },
+ { "ListPropertyFalure07.yml", "[10000,true]", "integer" },
+ { "ListPropertyFalure08.yml", "[10.5,true]", "float" },
+ { "ListPropertyFalure09.yml", "[10.5,\"asdc\"]", "float" }, // type
+ // float
+ { "ListPropertyFalure11.yml", "[10.5,\"500.0@\"]", "float" }, // property
+ // list
+ // float
+ // type
+ // contain
+ // @
+ // in
+ // default
+ // value
+ { "ListPropertyFalure12.yml", "[10000,\"3#\"]", "integer" }, // property
+ // list
+ // integer
+ // type
+ // contain
+ // #
+ // in
+ // default
+ // value
+ { "ListPropertyFalure13.yml", "[false,\"true%\"]", "boolean" }, // property
+ // list
+ // boolean
+ // type
+ // contain
+ // %
+ // in
+ // default
+ // value
+ { "ListPropertyFalure14.yml", "[false,\"falsee\",true]", "boolean" },
+ { "ListPropertyFalure15.yml", "[10.5,\"10.6x\",20.5,30.5]", "float" } // float
+ // with
+ // value
+ // 10.6x
+ // instead
+ // 10.6f
+
+ };
+ }
+
+ @DataProvider
+ private static final Object[][] getYmlWithInValidMapProperties() throws IOException, Exception {
+ return new Object[][] { { "MapPropertyFalure02.yml", "[false,\"truee\"]", "boolean" },
+ { "MapPropertyFalure03.yml", "[false,3]", "boolean" },
+ { "MapPropertyFalure04.yml", "[false,3.56]", "boolean" },
+ { "MapPropertyFalure05.yml", "[10000,3.56]", "integer" },
+ { "MapPropertyFalure06.yml", "[10000,\"aaaa\"]", "integer" },
+ { "MapPropertyFalure07.yml", "[10000,true]", "integer" },
+ { "MapPropertyFalure08.yml", "[10.5,true]", "float" },
+ { "MapPropertyFalure09.yml", "[10.5,\"asdc\"]", "float" }, // type
+ // float
+ { "MapPropertyFalure11.yml", "[10.5,\"500.0@\"]", "float" }, // property
+ // list
+ // float
+ // type
+ // contain
+ // @
+ // in
+ // default
+ // value
+ { "MapPropertyFalure12.yml", "[10000,\"3#\"]", "integer" }, // property
+ // list
+ // integer
+ // type
+ // contain
+ // #
+ // in
+ // default
+ // value
+ { "MapPropertyFalure13.yml", "[false,\"true%\"]", "boolean" }, // property
+ // list
+ // boolean
+ // type
+ // contain
+ // %
+ // in
+ // default
+ // value
+ { "MapPropertyFalure14.yml", "[false,\"falsee\",true]", "boolean" },
+ { "MapPropertyFalure15.yml", "[10.5,\"10.6x\",20.5,30.5]", "float" } // float
+ // with
+ // value
+ // 10.6x
+ // instead
+ // 10.6f
+
+ };
+ }
+
+ @DataProvider
+ private static final Object[][] getYmlWithInValidOccurrences() throws IOException, Exception {
+ return new Object[][] { { "occurencyFalure01.yml" }, // requirements [2
+ // , 0]
+ { "occurencyFalure02.yml" }, // requirements [-1, 2]
+ { "occurencyFalure03.yml" }, // requirements [1 ,-2]
+ { "occurencyFalure05.yml" }, // requirements MAX occurrences not
+ // exist [ 1 , ]
+ { "occurencyFalure06.yml" }, // requirements [ 0 , 0 ]
+ { "occurencyFalure08.yml" }, // requirements [ 1.0 , 2.0 ]
+ { "occurencyFalure09.yml" }, // requirements [ "1" , "2" ]
+ { "occurencyFalure10.yml" }, // requirements [ ]
+ { "occurencyFalure11.yml" }, // requirements [ UNBOUNDED ,
+ // UNBOUNDED ]
+ { "occurencyFalure31.yml" }, // capability [ 2, 1]
+ { "occurencyFalure32.yml" }, // capability [-1, 2]
+ { "occurencyFalure33.yml" }, // capability [1, -2]
+ { "occurencyFalure35.yml" }, // capability MAX occurrences not
+ // exist [ 1 , ]
+ { "occurencyFalure36.yml" }, // capability [ 0 , 0 ]
+ { "occurencyFalure38.yml" }, // capability [ 1.0 , 2.0 ]
+ { "occurencyFalure39.yml" }, // capability [ "1" , "2" ]
+ { "occurencyFalure40.yml" }, // capability [ ]
+ { "occurencyFalure41.yml" } // capability [ UNBOUNDED ,
+ // UNBOUNDED ]
+ };
+ }
+
+ @DataProvider
+ private static final Object[][] getInvalidYmlWithOccurrences() throws IOException, Exception {
+ return new Object[][] { { "occurencyFalure04.yml" }, // requirements MIN
+ // occurrences
+ // not exist [ ,
+ // 1]
+ { "occurencyFalure07.yml" }, // requirements [ @ , 1 ]
+ { "occurencyFalure34.yml" }, // capability MIN occurrences not
+ // exist [ , 1]
+ { "occurencyFalure37.yml" } // capability [ 0 , # ]
+
+ };
+ }
+
+ // US656928
+ protected final String importMapPropertySuccess = "importMapPropertySuccessFlow.yml";
+ protected final String importAttributeSuccess = "importAttributeSuccessFlow.yml";
+ protected final String importSuccessFile = "myCompute.yml";
+ protected final String derivedFromMyCompute = "derivedFromMyCompute.yml";
+ protected final String importSuccessVFFile = "myComputeVF.yml";
+ protected final String importNoDerivedFromFile = "myComputeDerivedFromNotExists.yml";
+ protected final String importInvalidDefinitionVersionFile = "myComputeIncorrectDefenitionVersionValue.yml";
+ protected final String importIncorrectNameSpaceFormatFile = "myComputeIncorrectNameSpaceFormat.yml";
+ protected final String importNoDefenitionVersionFile = "myComputeNoDefenitionVersion.yml";
+ protected final String importNodeTypesTwiceFile = "myComputeWithNodeTypesTwice.yml";
+ protected final String importTopologyTemplateFile = "myComputeWithTopologyTemplate.yml";
+ protected final String importNoContentFile = "noContent.yml";
+ protected final String importWithOccurrences = "myComputeOccurencySuccess.yml";
+ protected final String importListPropertyBadDefault = "importListPropertyBadDefault.yml";
+ protected final String importListPropertyGoodDefault = "importListPropertyGoodDefault.yml";
+ protected final String importListPropertySuccess = "importListPropertySuccessFlow.yml";
+ // US631462
+ protected final String importDuplicateRequirements = "importDuplicateRequirements.yml";
+ protected final String importDuplicateCapability = "importDuplicateCapability.yml";
+ protected final String importCapabilityNameExistsOnParent = "importCapabilityNameExistsOnParent.yml";
+ protected final String importRequirementNameExistsOnParent = "importRequirementNameExistsOnParent.yml";
+ protected final String importToscaResourceReqCapDerivedFromParent = "derivedFromWebAppDerivedReqCap.yml";
+ protected final String missingCapInReqDef = "missingCapInReqDefinition.yml";
+ protected final String missingCapInCapDef = "missingCapInCapDefinition.yml";
+
+ // US558432 - Support for Capability/Requirement "occurences" Import
+ @Test(dataProvider = "getYmlWithInValidOccurrences")
+ public void importToscaResourceWithOccurrencesFailuresFlow01(String ymlFileWithInvalidCapReqOccurrences)
+ throws Exception {
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ ymlFileWithInvalidCapReqOccurrences);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ assertTrue(importResourceResponse.getErrorCode().equals(STATUS_CODE_INVALID_CONTENT));
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.INVALID_OCCURRENCES.name(), new ArrayList<String>(),
+ importResourceResponse.getResponse());
+ }
+
+ @Test(dataProvider = "getInvalidYmlWithOccurrences")
+ public void importToscaResourceWithOccurrencesFailuresFlow02(String ymlFileWithInvalidCapReqOccurrences)
+ throws Exception {
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ ymlFileWithInvalidCapReqOccurrences);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ assertTrue(importResourceResponse.getErrorCode().equals(STATUS_CODE_INVALID_CONTENT));
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.INVALID_YAML_FILE.name(), new ArrayList<String>(),
+ importResourceResponse.getResponse());
+ }
+
+ @Test
+ public void importToscaResource() throws Exception {
+
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ importSuccessFile);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ logger.debug("import tosca resource response: {}", importResourceResponse.getResponseMessage());
+ AssertJUnit.assertTrue("response code is not 201, returned :" + importResourceResponse.getErrorCode(),
+ importResourceResponse.getErrorCode() == 201);
+ ToscaNodeTypeInfo parseToscaNodeYaml = utils
+ .parseToscaNodeYaml(Decoder.decode(importReqDetails.getPayloadData()));
+ Resource resourceJavaObject = ResponseParser
+ .convertResourceResponseToJavaObject(importResourceResponse.getResponse());
+ AssertJUnit.assertTrue("validate toscaResourceName field",
+ resourceJavaObject.getToscaResourceName().equals(parseToscaNodeYaml.getNodeName()));
+ AssertJUnit.assertTrue("validate resourceType field",
+ resourceJavaObject.getResourceType().equals(ResourceTypeEnum.VFC));
+ // find derived from resource details
+ // Validate resource details after import-create resource including
+ // capabilities, interfaces from derived_from resource
+
+ // Validate audit message
+ ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = ElementFactory
+ .getDefaultImportResourceAuditMsgSuccess();
+ expectedResourceAuditJavaObject.setResourceName(importReqDetails.getName());
+ expectedResourceAuditJavaObject.setModifierName(sdncUserDetails.getFullName());
+ expectedResourceAuditJavaObject.setModifierUid(sdncUserDetails.getUserId());
+ expectedResourceAuditJavaObject.setToscaNodeType(parseToscaNodeYaml.getNodeName());
+ AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject,
+ AuditingActionEnum.IMPORT_RESOURCE.getName(), null, false);
+ }
+
+ @Test
+ public void importToscaResourceWithOccurrencesSuccessFlow() throws Exception {
+
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ importWithOccurrences);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ logger.debug("import tosca resource response: {}", importResourceResponse.getResponseMessage());
+ AssertJUnit.assertTrue("response code is not 201, returned :" + importResourceResponse.getErrorCode(),
+ importResourceResponse.getErrorCode() == 201);
+ ToscaNodeTypeInfo parseToscaNodeYaml = utils
+ .parseToscaNodeYaml(Decoder.decode(importReqDetails.getPayloadData()));
+ Resource resourceJavaObject = ResponseParser
+ .convertResourceResponseToJavaObject(importResourceResponse.getResponse());
+ AssertJUnit.assertTrue("validate toscaResourceName field",
+ resourceJavaObject.getToscaResourceName().equals(parseToscaNodeYaml.getNodeName()));
+ AssertJUnit.assertTrue("validate resourceType field",
+ resourceJavaObject.getResourceType().equals(ResourceTypeEnum.VFC));
+ String requirementsType = "tosca.capabilities.Attachment";
+ String capabilitType = "tosca.capabilities.Endpoint.Admin";
+ // Verify Occurrences of requirements and capabilities in resource
+ verifyRequirementsOccurrences(resourceJavaObject, requirementsType);
+ verifyCapabilitiesOccurrences(resourceJavaObject, capabilitType);
+ ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = ElementFactory
+ .getDefaultImportResourceAuditMsgSuccess();
+ expectedResourceAuditJavaObject.setResourceName(importReqDetails.getName());
+ expectedResourceAuditJavaObject.setModifierName(sdncUserDetails.getFullName());
+ expectedResourceAuditJavaObject.setModifierUid(sdncUserDetails.getUserId());
+ expectedResourceAuditJavaObject.setToscaNodeType(parseToscaNodeYaml.getNodeName());
+ AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject,
+ AuditingActionEnum.IMPORT_RESOURCE.getName(), null, false);
+ }
+
+ // ------------------------------Success---------------------------------
+
+ @Test(enabled = false)
+ public void importToscaResourceVFResType() throws Exception {
+
+ String resourceType = ResourceTypeEnum.VF.toString();
+
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ importSuccessVFFile);
+ // importReqDetails.setResourceType(resourceType);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ logger.debug("import tosca resource response: {}", importResourceResponse.getResponseMessage());
+ assertTrue("response code is not 201, returned :" + importResourceResponse.getErrorCode(),
+ importResourceResponse.getErrorCode() == 201);
+ ToscaNodeTypeInfo parseToscaNodeYaml = utils
+ .parseToscaNodeYaml(Decoder.decode(importReqDetails.getPayloadData()));
+ Resource resourceJavaObject = ResponseParser
+ .convertResourceResponseToJavaObject(importResourceResponse.getResponse());
+ assertTrue("validate toscaResourceName field",
+ resourceJavaObject.getToscaResourceName().equals(parseToscaNodeYaml.getNodeName()));
+ assertTrue(
+ "validate resourceType field, expected - " + resourceType + ", actual - "
+ + resourceJavaObject.getResourceType(),
+ resourceJavaObject.getResourceType().toString().equals(resourceType));
+
+ // Validate audit message
+ ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = ElementFactory
+ .getDefaultImportResourceAuditMsgSuccess();
+ expectedResourceAuditJavaObject.setResourceName(importReqDetails.getName());
+ expectedResourceAuditJavaObject.setModifierName(sdncUserDetails.getFullName());
+ expectedResourceAuditJavaObject.setModifierUid(sdncUserDetails.getUserId());
+ expectedResourceAuditJavaObject.setToscaNodeType(parseToscaNodeYaml.getNodeName());
+ AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject,
+ AuditingActionEnum.IMPORT_RESOURCE.getName(), null, false);
+ }
+
+ // ------------------------------Failure---------------------------------
+
+ @Test
+ public void importToscaResourceDerivedFromNotExist() throws Exception {
+
+ String fileName = importNoDerivedFromFile;
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ fileName);
+ // List<String> derivedFrom = new ArrayList<String>() ;
+ // derivedFrom.add("hh");
+ // importReqDetails.setDerivedFrom(derivedFrom);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ logger.debug("import tosca resource response: {}", importResourceResponse.getResponseMessage());
+
+ // Validate audit message
+ assertNotNull("check response object is not null after import tosca resource", importResourceResponse);
+ assertNotNull("check error code exists in response after import tosca resource",
+ importResourceResponse.getErrorCode());
+
+ ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.PARENT_RESOURCE_NOT_FOUND.name());
+ assertEquals("Check response code after tosca resource import", errorInfo.getCode(),
+ importResourceResponse.getErrorCode());
+ List<String> variables = Arrays.asList();
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.PARENT_RESOURCE_NOT_FOUND.name(), variables,
+ importResourceResponse.getResponse());
+
+ ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = ElementFactory
+ .getDefaultImportResourceAuditMsgFailure(errorInfo, variables);
+ expectedResourceAuditJavaObject.setResourceName(importReqDetails.getName());
+ expectedResourceAuditJavaObject.setModifierName(sdncUserDetails.getFullName());
+ expectedResourceAuditJavaObject.setModifierUid(sdncUserDetails.getUserId());
+ expectedResourceAuditJavaObject.setCurrState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name());
+ ToscaNodeTypeInfo parseToscaNodeYaml = utils
+ .parseToscaNodeYaml(Decoder.decode(importReqDetails.getPayloadData()));
+ AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject,
+ AuditingActionEnum.IMPORT_RESOURCE.getName(), null, false);
+ }
+
+ @Test
+ public void importToscaResourceIncorrectDefinitionVersion() throws Exception {
+
+ String fileName = importInvalidDefinitionVersionFile;
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ fileName);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ logger.debug("import tosca resource response: {}", importResourceResponse.getResponseMessage());
+
+ // Validate audit message
+ assertNotNull("check response object is not null after import tosca resource", importResourceResponse);
+ assertNotNull("check error code exists in response after import tosca resource",
+ importResourceResponse.getErrorCode());
+
+ ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.INVALID_TOSCA_TEMPLATE.name());
+ assertEquals("Check response code after tosca resource import", errorInfo.getCode(),
+ importResourceResponse.getErrorCode());
+ List<String> variables = Arrays.asList();
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.INVALID_TOSCA_TEMPLATE.name(), variables,
+ importResourceResponse.getResponse());
+
+ ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = ElementFactory
+ .getDefaultImportResourceAuditMsgFailure(errorInfo, variables);
+ expectedResourceAuditJavaObject.setResourceName(importReqDetails.getName());
+ expectedResourceAuditJavaObject.setModifierName(sdncUserDetails.getFullName());
+ expectedResourceAuditJavaObject.setModifierUid(sdncUserDetails.getUserId());
+ AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject,
+ AuditingActionEnum.IMPORT_RESOURCE.getName(), null, false);
+ }
+
+ @Test
+ public void importToscaResourceIncorrectSpaceNameFormat() throws Exception {
+
+ String fileName = importIncorrectNameSpaceFormatFile;
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ fileName);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ logger.debug("import tosca resource response: {}", importResourceResponse.getResponseMessage());
+
+ // Validate audit message
+ assertNotNull("check response object is not null after import tosca resource", importResourceResponse);
+ assertNotNull("check error code exists in response after import tosca resource",
+ importResourceResponse.getErrorCode());
+
+ ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.INVALID_RESOURCE_NAMESPACE.name());
+ assertEquals("Check response code after tosca resource import", errorInfo.getCode(),
+ importResourceResponse.getErrorCode());
+ List<String> variables = Arrays.asList();
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.INVALID_RESOURCE_NAMESPACE.name(), variables,
+ importResourceResponse.getResponse());
+
+ ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = ElementFactory
+ .getDefaultImportResourceAuditMsgFailure(errorInfo, variables);
+ expectedResourceAuditJavaObject.setResourceName(importReqDetails.getName());
+ expectedResourceAuditJavaObject.setModifierName(sdncUserDetails.getFullName());
+ expectedResourceAuditJavaObject.setModifierUid(sdncUserDetails.getUserId());
+ AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject,
+ AuditingActionEnum.IMPORT_RESOURCE.getName(), null, false);
+ }
+
+ @Test
+ public void importToscaResourceNoDefinitionVersion() throws Exception {
+
+ String fileName = importNoDefenitionVersionFile;
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ fileName);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ logger.debug("import tosca resource response: {}", importResourceResponse.getResponseMessage());
+
+ // Validate audit message
+ assertNotNull("check response object is not null after import tosca resource", importResourceResponse);
+ assertNotNull("check error code exists in response after import tosca resource",
+ importResourceResponse.getErrorCode());
+
+ ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.INVALID_TOSCA_TEMPLATE.name());
+ assertEquals("Check response code after tosca resource import", errorInfo.getCode(),
+ importResourceResponse.getErrorCode());
+ List<String> variables = Arrays.asList();
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.INVALID_TOSCA_TEMPLATE.name(), variables,
+ importResourceResponse.getResponse());
+
+ ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = ElementFactory
+ .getDefaultImportResourceAuditMsgFailure(errorInfo, variables);
+ expectedResourceAuditJavaObject.setResourceName(importReqDetails.getName());
+ expectedResourceAuditJavaObject.setModifierName(sdncUserDetails.getFullName());
+ expectedResourceAuditJavaObject.setModifierUid(sdncUserDetails.getUserId());
+ AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject,
+ AuditingActionEnum.IMPORT_RESOURCE.getName(), null, false);
+ }
+
+ @Test
+ public void importToscaResourceNoContent() throws Exception {
+
+ String fileName = importNoContentFile;
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ fileName);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ logger.debug("import tosca resource response: {}", importResourceResponse.getResponseMessage());
+
+ // Validate audit message
+ assertNotNull("check response object is not null after import tosca resource", importResourceResponse);
+ assertNotNull("check error code exists in response after import tosca resource",
+ importResourceResponse.getErrorCode());
+
+ ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.INVALID_RESOURCE_PAYLOAD.name());
+ assertEquals("Check response code after tosca resource import", errorInfo.getCode(),
+ importResourceResponse.getErrorCode());
+ List<String> variables = Arrays.asList();
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.INVALID_RESOURCE_PAYLOAD.name(), variables,
+ importResourceResponse.getResponse());
+
+ ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = ElementFactory
+ .getDefaultImportResourceAuditMsgFailure(errorInfo, variables);
+ expectedResourceAuditJavaObject.setResourceName(importReqDetails.getName());
+ expectedResourceAuditJavaObject.setModifierName(sdncUserDetails.getFullName());
+ expectedResourceAuditJavaObject.setModifierUid(sdncUserDetails.getUserId());
+ AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject,
+ AuditingActionEnum.IMPORT_RESOURCE.getName(), null, false);
+ }
+
+ @Test
+ public void importToscaResourceWithTopologyTemplate() throws Exception {
+
+ String fileName = importTopologyTemplateFile;
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ fileName);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ logger.debug("import tosca resource response: {}", importResourceResponse.getResponseMessage());
+
+ // Validate audit message
+ assertNotNull("check response object is not null after import tosca resource", importResourceResponse);
+ assertNotNull("check error code exists in response after import tosca resource",
+ importResourceResponse.getErrorCode());
+
+ ErrorInfo errorInfo = ErrorValidationUtils
+ .parseErrorConfigYaml(ActionStatus.NOT_RESOURCE_TOSCA_TEMPLATE.name());
+ assertEquals("Check response code after tosca resource import", errorInfo.getCode(),
+ importResourceResponse.getErrorCode());
+ List<String> variables = Arrays.asList();
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.NOT_RESOURCE_TOSCA_TEMPLATE.name(), variables,
+ importResourceResponse.getResponse());
+
+ ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = ElementFactory
+ .getDefaultImportResourceAuditMsgFailure(errorInfo, variables);
+ expectedResourceAuditJavaObject.setResourceName(importReqDetails.getName());
+ expectedResourceAuditJavaObject.setModifierName(sdncUserDetails.getFullName());
+ expectedResourceAuditJavaObject.setModifierUid(sdncUserDetails.getUserId());
+ AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject,
+ AuditingActionEnum.IMPORT_RESOURCE.getName(), null, false);
+ }
+
+ @Test
+ public void importToscaResourceWithNodeTypesTwice() throws Exception {
+
+ String fileName = importNodeTypesTwiceFile;
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ fileName);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ logger.debug("import tosca resource response: {}", importResourceResponse.getResponseMessage());
+
+ // Validate audit message
+ assertNotNull("check response object is not null after import tosca resource", importResourceResponse);
+ assertNotNull("check error code exists in response after import tosca resource",
+ importResourceResponse.getErrorCode());
+
+ ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.NOT_SINGLE_RESOURCE.name());
+ assertEquals("Check response code after tosca resource import", errorInfo.getCode(),
+ importResourceResponse.getErrorCode());
+ List<String> variables = Arrays.asList();
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.NOT_SINGLE_RESOURCE.name(), variables,
+ importResourceResponse.getResponse());
+
+ ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = ElementFactory
+ .getDefaultImportResourceAuditMsgFailure(errorInfo, variables);
+ expectedResourceAuditJavaObject.setResourceName(importReqDetails.getName());
+ expectedResourceAuditJavaObject.setModifierName(sdncUserDetails.getFullName());
+ expectedResourceAuditJavaObject.setModifierUid(sdncUserDetails.getUserId());
+ AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject,
+ AuditingActionEnum.IMPORT_RESOURCE.getName(), null, false);
+ }
+
+ // failed case - uniqueness of toscaResourceName - RESOURCE_ALREADY_EXISTS
+ @Test
+ public void importToscaResourceTwice() throws Exception {
+ String fileName = importSuccessFile;
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ fileName);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ logger.debug("import tosca resource response: {}", importResourceResponse.getResponseMessage());
+ assertTrue("response code is not 201, returned :" + importResourceResponse.getErrorCode(),
+ importResourceResponse.getErrorCode() == 201);
+ Resource resourceJavaObject = ResponseParser
+ .convertResourceResponseToJavaObject(importResourceResponse.getResponse());
+ RestResponse checkInresponse = LifecycleRestUtils.changeResourceState(importReqDetails, sdncUserDetails,
+ LifeCycleStatesEnum.CHECKIN);
+ assertTrue("checkIn resource request returned status:" + checkInresponse.getErrorCode(),
+ checkInresponse.getErrorCode() == 200);
+
+ // Validate audit message
+ ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = ElementFactory
+ .getDefaultImportResourceAuditMsgSuccess();
+ expectedResourceAuditJavaObject.setResourceName(importReqDetails.getName());
+ expectedResourceAuditJavaObject.setModifierName(sdncUserDetails.getFullName());
+ expectedResourceAuditJavaObject.setModifierUid(sdncUserDetails.getUserId());
+ ToscaNodeTypeInfo parseToscaNodeYaml = utils
+ .parseToscaNodeYaml(Decoder.decode(importReqDetails.getPayloadData()));
+ expectedResourceAuditJavaObject.setToscaNodeType(parseToscaNodeYaml.getNodeName());
+ AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject,
+ AuditingActionEnum.IMPORT_RESOURCE.getName(), null, false);
+
+ // import the same tosca resource with different resourceName
+ DbUtils.cleanAllAudits();
+
+ importReqDetails.setName("kuku");
+ List<String> tags = new ArrayList<String>();
+ tags.add(importReqDetails.getName());
+ importReqDetails.setTags(tags);
+ importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails, null);
+ logger.debug("import tosca resource response: {}", importResourceResponse.getResponseMessage());
+
+ // Validate audit message
+ assertNotNull("check response object is not null after import tosca resource", importResourceResponse);
+ assertNotNull("check error code exists in response after import tosca resource",
+ importResourceResponse.getErrorCode());
+
+ ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.RESOURCE_ALREADY_EXISTS.name());
+ assertEquals("Check response code after tosca resource import", errorInfo.getCode(),
+ importResourceResponse.getErrorCode());
+ List<String> variables = Arrays.asList();
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.RESOURCE_ALREADY_EXISTS.name(), variables,
+ importResourceResponse.getResponse());
+
+ expectedResourceAuditJavaObject = ElementFactory.getDefaultImportResourceAuditMsgFailure(errorInfo, variables);
+ expectedResourceAuditJavaObject.setResourceName(importReqDetails.getName());
+ expectedResourceAuditJavaObject.setModifierName(sdncUserDetails.getFullName());
+ expectedResourceAuditJavaObject.setModifierUid(sdncUserDetails.getUserId());
+ expectedResourceAuditJavaObject.setToscaNodeType(importReqDetails.getToscaResourceName());
+ AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject,
+ AuditingActionEnum.IMPORT_RESOURCE.getName(), null, false);
+
+ }
+
+ @Test
+ public void importToscaResourceWithTheSameNameAsCreatedResourceBefore() throws Exception {
+
+ // create resource
+ String fileName = importSuccessFile;
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ fileName);
+
+ resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setName(importReqDetails.getName());
+
+ RestResponse response = ResourceRestUtils.createResource(resourceDetails, sdncUserDetails);
+ int status = response.getErrorCode();
+ assertEquals("create request returned status:" + status, 201, status);
+ assertNotNull("resource uniqueId is null:", resourceDetails.getUniqueId());
+ Resource resourceJavaObject = ResponseParser.convertResourceResponseToJavaObject(response.getResponse());
+ // assertNull("validate toscaResourceName field",
+ // resourceJavaObject.getToscaResourceName());
+
+ // import the same tosca resource
+ DbUtils.cleanAllAudits();
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ logger.debug("import tosca resource response: {}", importResourceResponse.getResponseMessage());
+
+ // Validate audit message
+ assertNotNull("check response object is not null after import tosca resource", importResourceResponse);
+ assertNotNull("check error code exists in response after import tosca resource",
+ importResourceResponse.getErrorCode());
+
+ ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.RESOURCE_ALREADY_EXISTS.name());
+ assertEquals("Check response code after tosca resource import", errorInfo.getCode(),
+ importResourceResponse.getErrorCode());
+ List<String> variables = Arrays.asList();
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.RESOURCE_ALREADY_EXISTS.name(), variables,
+ importResourceResponse.getResponse());
+
+ ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = ElementFactory
+ .getDefaultImportResourceAuditMsgFailure(errorInfo, variables);
+ expectedResourceAuditJavaObject.setResourceName(importReqDetails.getName());
+ expectedResourceAuditJavaObject.setModifierName(sdncUserDetails.getFullName());
+ expectedResourceAuditJavaObject.setModifierUid(sdncUserDetails.getUserId());
+ AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject,
+ AuditingActionEnum.IMPORT_RESOURCE.getName(), null, false);
+
+ }
+
+ @Test
+ public void importToscaResourceInvalidChecksum() throws Exception {
+ String fileName = importSuccessFile;
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ fileName);
+ Map<String, String> headersMap = new HashMap<String, String>();
+ headersMap.put(HttpHeaderEnum.Content_MD5.getValue(), "invalidMd5Sum");
+
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ headersMap);
+ logger.debug("import tosca resource response: {}", importResourceResponse.getResponseMessage());
+
+ // Validate audit message
+ assertNotNull("check response object is not null after import tosca resource", importResourceResponse);
+ assertNotNull("check error code exists in response after import tosca resource",
+ importResourceResponse.getErrorCode());
+
+ ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.INVALID_RESOURCE_CHECKSUM.name());
+ assertEquals("Check response code after tosca resource import", errorInfo.getCode(),
+ importResourceResponse.getErrorCode());
+ List<String> variables = Arrays.asList();
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.INVALID_RESOURCE_CHECKSUM.name(), variables,
+ importResourceResponse.getResponse());
+
+ ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = ElementFactory
+ .getDefaultImportResourceAuditMsgFailure(errorInfo, variables);
+ expectedResourceAuditJavaObject.setResourceName(importReqDetails.getName());
+ expectedResourceAuditJavaObject.setModifierName(sdncUserDetails.getFullName());
+ expectedResourceAuditJavaObject.setModifierUid(sdncUserDetails.getUserId());
+ AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject,
+ AuditingActionEnum.IMPORT_RESOURCE.getName(), null, false);
+ }
+
+ @Test
+ public void importToscaResourceInvalidResType() throws Exception {
+
+ String resourceType = "invalidResourceType";
+
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ importSuccessFile);
+ importReqDetails.setResourceType(resourceType);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+
+ ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.INVALID_CONTENT.name());
+ assertNotNull("check response object is not null after import resouce", importResourceResponse);
+ assertNotNull("check error code exists in response after import resource",
+ importResourceResponse.getErrorCode());
+ assertEquals("Check response code after import resource", errorInfo.getCode(),
+ importResourceResponse.getErrorCode());
+
+ List<String> variables = new ArrayList<>();
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.INVALID_CONTENT.name(), variables,
+ importResourceResponse.getResponse());
+
+ // Validate audit message
+ ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = ElementFactory
+ .getDefaultImportResourceAuditMsgFailure(errorInfo, variables);
+ expectedResourceAuditJavaObject.setResourceName(importReqDetails.getName());
+ expectedResourceAuditJavaObject.setModifierName(sdncUserDetails.getFullName());
+ expectedResourceAuditJavaObject.setModifierUid(sdncUserDetails.getUserId());
+ AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject,
+ AuditingActionEnum.IMPORT_RESOURCE.getName(), null, false);
+ }
+
+ @Test
+ public void derivedTemplateImportedSecondResourceAsFirstImportedNodeType() throws Exception {
+
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ importSuccessFile);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ logger.debug("import tosca resource response: {}", importResourceResponse.getResponseMessage());
+ assertTrue("response code is not 201, returned :" + importResourceResponse.getErrorCode(),
+ importResourceResponse.getErrorCode() == 201);
+ ToscaNodeTypeInfo parseToscaNodeYaml = utils
+ .parseToscaNodeYaml(Decoder.decode(importReqDetails.getPayloadData()));
+ Resource resourceJavaObject = ResponseParser
+ .convertResourceResponseToJavaObject(importResourceResponse.getResponse());
+ assertTrue("validate toscaResourceName field",
+ resourceJavaObject.getToscaResourceName().equals(parseToscaNodeYaml.getNodeName()));
+ assertTrue(
+ "validate resourceType field, expected - " + importReqDetails.getResourceType() + ", actual - "
+ + resourceJavaObject.getResourceType(),
+ resourceJavaObject.getResourceType().toString().equals(importReqDetails.getResourceType()));
+
+ // Validate audit message
+ ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = ElementFactory
+ .getDefaultImportResourceAuditMsgSuccess();
+ expectedResourceAuditJavaObject.setResourceName(importReqDetails.getName());
+ expectedResourceAuditJavaObject.setModifierName(sdncUserDetails.getFullName());
+ expectedResourceAuditJavaObject.setModifierUid(sdncUserDetails.getUserId());
+ expectedResourceAuditJavaObject.setToscaNodeType(parseToscaNodeYaml.getNodeName());
+ AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject,
+ AuditingActionEnum.IMPORT_RESOURCE.getName(), null, false);
+
+ RestResponse certifyResource = LifecycleRestUtils.certifyResource(importReqDetails);
+ assertTrue("certify resource request returned status:" + certifyResource.getErrorCode(),
+ certifyResource.getErrorCode() == 200);
+
+ // import second resource template derived from first resource
+ DbUtils.cleanAllAudits();
+ importReqDetails.setName("kuku");
+ List<String> tags = new ArrayList<String>();
+ tags.add(importReqDetails.getName());
+ importReqDetails.setTags(tags);
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ derivedFromMyCompute);
+ importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails, null);
+ logger.debug("import tosca resource response: {}", importResourceResponse.getResponseMessage());
+
+ assertTrue("response code is not 201, returned :" + importResourceResponse.getErrorCode(),
+ importResourceResponse.getErrorCode() == 201);
+ parseToscaNodeYaml = utils.parseToscaNodeYaml(Decoder.decode(importReqDetails.getPayloadData()));
+ Resource resourceJavaObject2 = ResponseParser
+ .convertResourceResponseToJavaObject(importResourceResponse.getResponse());
+ assertTrue("validate toscaResourceName field",
+ resourceJavaObject2.getToscaResourceName().equals(parseToscaNodeYaml.getNodeName()));
+ assertTrue(
+ "validate resourceType field, expected - " + importReqDetails.getResourceType() + ", actual - "
+ + resourceJavaObject2.getResourceType(),
+ resourceJavaObject2.getResourceType().toString().equals(importReqDetails.getResourceType()));
+
+ // Validate audit message
+ ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject2 = ElementFactory
+ .getDefaultImportResourceAuditMsgSuccess();
+ expectedResourceAuditJavaObject2.setResourceName(importReqDetails.getName());
+ expectedResourceAuditJavaObject2.setModifierName(sdncUserDetails.getFullName());
+ expectedResourceAuditJavaObject2.setModifierUid(sdncUserDetails.getUserId());
+ expectedResourceAuditJavaObject2.setToscaNodeType(parseToscaNodeYaml.getNodeName());
+ AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject2,
+ AuditingActionEnum.IMPORT_RESOURCE.getName(), null, false);
+
+ }
+
+ @Test
+ public void importToscaResourceListPropertyGoodDefault() throws Exception {
+
+ String fileName = importListPropertyGoodDefault;
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ fileName);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ logger.debug("import tosca resource response: {}", importResourceResponse.getResponseMessage());
+
+ assertTrue("response code is not 201, returned :" + importResourceResponse.getErrorCode(),
+ importResourceResponse.getErrorCode() == 201);
+
+ Resource resourceJavaObject = ResponseParser
+ .convertResourceResponseToJavaObject(importResourceResponse.getResponse());
+ assertTrue("Properties size : " + resourceJavaObject.getProperties().size(),
+ resourceJavaObject.getProperties().size() == 1);
+ assertTrue("Property type : " + resourceJavaObject.getProperties().get(0).getType(),
+ resourceJavaObject.getProperties().get(0).getType().equals(ToscaPropertyType.LIST.getType()));
+ assertTrue(
+ "actual Default values : " + resourceJavaObject.getProperties().get(0).getDefaultValue()
+ + " , expected : " + "[false, true]",
+ resourceJavaObject.getProperties().get(0).getDefaultValue().equals("[\"false\",\"true\"]"));
+
+ }
+
+ @Test
+ public void importToscaResourceListPropertyBadDefault() throws Exception {
+
+ String fileName = importListPropertyBadDefault;
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ fileName);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ logger.debug("import tosca resource response: {}", importResourceResponse.getResponseMessage());
+
+ ErrorInfo errorInfo = ErrorValidationUtils
+ .parseErrorConfigYaml(ActionStatus.INVALID_COMPLEX_DEFAULT_VALUE.name());
+ assertEquals("Check response code after tosca resource import", errorInfo.getCode(),
+ importResourceResponse.getErrorCode());
+ ArrayList<String> variables = new ArrayList<>();
+ variables.add("my_prop");
+ variables.add("list");
+ variables.add("boolean");
+ variables.add("[12,true]");
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.INVALID_COMPLEX_DEFAULT_VALUE.name(), variables,
+ importResourceResponse.getResponse());
+
+ }
+
+ // Benny US580744 - Add support for TOSCA "list" type - import
+
+ @Test
+ public void importToscaResourceListPropertySuccessFlow() throws Exception {
+ String fileName = importListPropertySuccess;
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ fileName);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ ResourceRestUtils.checkCreateResponse(importResourceResponse);
+ Resource resourceJavaObject = ResponseParser
+ .convertResourceResponseToJavaObject(importResourceResponse.getResponse());
+ ToscaNodeTypeInfo parseToscaNodeYaml = utils
+ .parseToscaNodeYaml(Decoder.decode(importReqDetails.getPayloadData()));
+ // Verify Properties List in resource
+ verifyResourcePropertiesList(resourceJavaObject);
+ ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = ElementFactory
+ .getDefaultImportResourceAuditMsgSuccess();
+ expectedResourceAuditJavaObject.setResourceName(importReqDetails.getName());
+ expectedResourceAuditJavaObject.setModifierName(sdncUserDetails.getFullName());
+ expectedResourceAuditJavaObject.setModifierUid(sdncUserDetails.getUserId());
+ expectedResourceAuditJavaObject.setToscaNodeType(parseToscaNodeYaml.getNodeName());
+ AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject,
+ AuditingActionEnum.IMPORT_RESOURCE.getName(), null, false);
+ }
+
+ // DE198534
+ @Test(dataProvider = "getYmlWithInValidListProperties") // invalid default
+ // values
+ public void importToscaResourceListPropertyFailureFlows(String ymlFileWithInvalidPropertyDefualtValues,
+ String defualtValues, String enterySchemaType) throws Exception {
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ ymlFileWithInvalidPropertyDefualtValues);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ assertTrue(importResourceResponse.getErrorCode().equals(STATUS_CODE_INVALID_CONTENT));
+ ArrayList<String> variables = new ArrayList<>();
+ variables.add("my_property");
+ variables.add("list");
+ variables.add(enterySchemaType);
+ variables.add(defualtValues);
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.INVALID_COMPLEX_DEFAULT_VALUE.name(), variables,
+ importResourceResponse.getResponse());
+ }
+
+ // BUG DE198650
+ @Test
+ public void importToscaResourceListPropertyNonSupportEntrySchemaType() throws Exception {
+ String ymlFile = "ListPropertyFalure01.yml";
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ ymlFile);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ assertTrue(importResourceResponse.getErrorCode().equals(STATUS_CODE_INVALID_CONTENT));
+ ArrayList<String> variables = new ArrayList<>();
+ variables.add("booolean"); // property entry_schema data type
+ variables.add("my_boolean");
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.INVALID_PROPERTY_INNER_TYPE.name(), variables,
+ importResourceResponse.getResponse());
+ }
+
+ // BUG DE198676
+ @Test // (enabled=false)
+ public void importToscaResourceListPropertyNonSupportedPropertyType() throws Exception { // Not
+ // "list"
+ // type
+ String ymlFile = "ListPropertyFalure16.yml";
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ ymlFile);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ assertTrue(importResourceResponse.getErrorCode().equals(STATUS_CODE_INVALID_CONTENT));
+ ArrayList<String> variables = new ArrayList<>();
+ variables.add("koko"); // property data type (koko instead list)
+ variables.add("my_boolean");
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.INVALID_PROPERTY_TYPE.name(), variables,
+ importResourceResponse.getResponse());
+ }
+
+ /// US656928 - [BE] - Add support for TOSCA "map" type - Phase 1 import
+ @Test
+ public void importToscaResourceMapPropertySuccessFlow() throws Exception {
+ String fileName = importMapPropertySuccess;
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ fileName);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ ResourceRestUtils.checkCreateResponse(importResourceResponse);
+ Resource resourceJavaObject = ResponseParser
+ .convertResourceResponseToJavaObject(importResourceResponse.getResponse());
+ ToscaNodeTypeInfo parseToscaNodeYaml = utils
+ .parseToscaNodeYaml(Decoder.decode(importReqDetails.getPayloadData()));
+ // Verify Properties MAP in resource
+ verifyResourcePropertiesMap(resourceJavaObject);
+ ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = ElementFactory
+ .getDefaultImportResourceAuditMsgSuccess();
+ expectedResourceAuditJavaObject.setResourceName(importReqDetails.getName());
+ expectedResourceAuditJavaObject.setModifierName(sdncUserDetails.getFullName());
+ expectedResourceAuditJavaObject.setModifierUid(sdncUserDetails.getUserId());
+ expectedResourceAuditJavaObject.setToscaNodeType(parseToscaNodeYaml.getNodeName());
+ AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject,
+ AuditingActionEnum.IMPORT_RESOURCE.getName(), null, false);
+ }
+
+ @Test(dataProvider = "getYmlWithInValidMapProperties") // invalid default
+ // values
+ public void importToscaResourceMapPropertyFailureFlows(String ymlFileWithInvalidPropertyDefualtValues,
+ String defualtValues, String enterySchemaType) throws Exception {
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ ymlFileWithInvalidPropertyDefualtValues);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ assertTrue(importResourceResponse.getErrorCode().equals(STATUS_CODE_INVALID_CONTENT));
+ ArrayList<String> variables = new ArrayList<>();
+ variables.add("my_property");
+ variables.add("map");
+ variables.add(enterySchemaType);
+ variables.add(defualtValues);
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.INVALID_COMPLEX_DEFAULT_VALUE.name(), variables,
+ importResourceResponse.getResponse());
+ }
+
+ @Test
+ public void importToscaResourceMaptPropertyNonSupportedPropertyType() throws Exception { // Not
+ // "Map"
+ // type
+ String ymlFile = "MapPropertyFalure16.yml";
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ ymlFile);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ assertTrue(importResourceResponse.getErrorCode().equals(STATUS_CODE_INVALID_CONTENT));
+ ArrayList<String> variables = new ArrayList<>();
+ variables.add("koko"); // property data type (koko instead list)
+ variables.add("my_boolean");
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.INVALID_PROPERTY_TYPE.name(), variables,
+ importResourceResponse.getResponse());
+ }
+
+ @Test
+ public void importToscaResourceMissingCapabilityInReqDefinition() throws Exception {
+
+ String fileName = missingCapInReqDef;
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ fileName);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ logger.debug("import tosca resource response: {}", importResourceResponse.getResponseMessage());
+
+ // Validate audit message
+ ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.MISSING_CAPABILITY_TYPE.name());
+ String missingCapName = "org.openecomp.capabilities.networkInterfaceNotFound";
+ BaseRestUtils.checkErrorResponse(importResourceResponse, ActionStatus.MISSING_CAPABILITY_TYPE, missingCapName);
+
+ ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = ElementFactory
+ .getDefaultImportResourceAuditMsgFailure(errorInfo, Arrays.asList(missingCapName));
+ expectedResourceAuditJavaObject.setResourceName(importReqDetails.getName());
+ expectedResourceAuditJavaObject.setModifierName(sdncUserDetails.getFullName());
+ expectedResourceAuditJavaObject.setModifierUid(sdncUserDetails.getUserId());
+ expectedResourceAuditJavaObject.setToscaNodeType("org.openecomp.resource.vSCP-03-16");
+ AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject,
+ AuditingActionEnum.IMPORT_RESOURCE.getName(), null, false);
+ }
+
+ @Test
+ public void importToscaResourceMissingCapabilityInCapDefinition() throws Exception {
+
+ String fileName = missingCapInCapDef;
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ fileName);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ logger.debug("import tosca resource response: {}", importResourceResponse.getResponseMessage());
+
+ // Validate audit message
+ ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.MISSING_CAPABILITY_TYPE.name());
+ String missingCapName = "org.openecomp.capabilities.networkInterfaceNotFound";
+ BaseRestUtils.checkErrorResponse(importResourceResponse, ActionStatus.MISSING_CAPABILITY_TYPE, missingCapName);
+
+ ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = ElementFactory
+ .getDefaultImportResourceAuditMsgFailure(errorInfo, Arrays.asList(missingCapName));
+ expectedResourceAuditJavaObject.setResourceName(importReqDetails.getName());
+ expectedResourceAuditJavaObject.setModifierName(sdncUserDetails.getFullName());
+ expectedResourceAuditJavaObject.setModifierUid(sdncUserDetails.getUserId());
+ expectedResourceAuditJavaObject.setToscaNodeType("org.openecomp.resource.vSCP-03-16");
+ AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject,
+ AuditingActionEnum.IMPORT_RESOURCE.getName(), null, false);
+ }
+
+ @Test
+ public void importToscaResourceDuplicateRequirements() throws Exception {
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ importDuplicateRequirements);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ assertTrue(importResourceResponse.getErrorCode().equals(STATUS_CODE_INVALID_CONTENT));
+ ArrayList<String> variables = new ArrayList<>();
+ variables.add("requirement");
+ variables.add("local_storage");
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.IMPORT_DUPLICATE_REQ_CAP_NAME.name(), variables,
+ importResourceResponse.getResponse());
+ ErrorInfo errorInfo = ErrorValidationUtils
+ .parseErrorConfigYaml(ActionStatus.IMPORT_DUPLICATE_REQ_CAP_NAME.name());
+ ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = ElementFactory
+ .getDefaultImportResourceAuditMsgFailure(errorInfo, variables);
+ expectedResourceAuditJavaObject.setResourceName(importReqDetails.getName());
+ expectedResourceAuditJavaObject.setModifierName(sdncUserDetails.getFullName());
+ expectedResourceAuditJavaObject.setModifierUid(sdncUserDetails.getUserId());
+ expectedResourceAuditJavaObject.setCurrState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name());
+ AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject,
+ AuditingActionEnum.IMPORT_RESOURCE.getName(), null, false);
+ }
+
+ @Test
+ public void importToscaResourceDuplicateCapabilities() throws Exception {
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ importDuplicateCapability);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ assertTrue(importResourceResponse.getErrorCode().equals(STATUS_CODE_INVALID_CONTENT));
+ ArrayList<String> variables = new ArrayList<>();
+ variables.add("capability");
+ variables.add("scalable");
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.IMPORT_DUPLICATE_REQ_CAP_NAME.name(), variables,
+ importResourceResponse.getResponse());
+ ErrorInfo errorInfo = ErrorValidationUtils
+ .parseErrorConfigYaml(ActionStatus.IMPORT_DUPLICATE_REQ_CAP_NAME.name());
+ ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = ElementFactory
+ .getDefaultImportResourceAuditMsgFailure(errorInfo, variables);
+ expectedResourceAuditJavaObject.setResourceName(importReqDetails.getName());
+ expectedResourceAuditJavaObject.setModifierName(sdncUserDetails.getFullName());
+ expectedResourceAuditJavaObject.setModifierUid(sdncUserDetails.getUserId());
+ expectedResourceAuditJavaObject.setCurrState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name());
+ AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject,
+ AuditingActionEnum.IMPORT_RESOURCE.getName(), null, false);
+ }
+
+ @Test
+ public void importToscaResourceRequirementNameExistsOnParent() throws Exception {
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ importRequirementNameExistsOnParent);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ assertTrue(importResourceResponse.getErrorCode().equals(STATUS_CODE_INVALID_CONTENT));
+ ArrayList<String> variables = new ArrayList<>();
+ variables.add("requirement");
+ variables.add("local_storage");
+ variables.add("Compute");
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.IMPORT_REQ_CAP_NAME_EXISTS_IN_DERIVED.name(),
+ variables, importResourceResponse.getResponse());
+ ErrorInfo errorInfo = ErrorValidationUtils
+ .parseErrorConfigYaml(ActionStatus.IMPORT_REQ_CAP_NAME_EXISTS_IN_DERIVED.name());
+ ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = ElementFactory
+ .getDefaultImportResourceAuditMsgFailure(errorInfo, variables);
+ expectedResourceAuditJavaObject.setResourceName(importReqDetails.getName());
+ expectedResourceAuditJavaObject.setModifierName(sdncUserDetails.getFullName());
+ expectedResourceAuditJavaObject.setModifierUid(sdncUserDetails.getUserId());
+ expectedResourceAuditJavaObject.setCurrState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name());
+ AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject,
+ AuditingActionEnum.IMPORT_RESOURCE.getName(), null, false);
+ }
+
+ @Test
+ public void importToscaResourceCapabilityNameExistsOnParent() throws Exception {
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ importCapabilityNameExistsOnParent);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ assertTrue(importResourceResponse.getErrorCode().equals(STATUS_CODE_INVALID_CONTENT));
+ ArrayList<String> variables = new ArrayList<>();
+ variables.add("capability");
+ variables.add("binding");
+ variables.add("Compute");
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.IMPORT_REQ_CAP_NAME_EXISTS_IN_DERIVED.name(),
+ variables, importResourceResponse.getResponse());
+ ErrorInfo errorInfo = ErrorValidationUtils
+ .parseErrorConfigYaml(ActionStatus.IMPORT_REQ_CAP_NAME_EXISTS_IN_DERIVED.name());
+ ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = ElementFactory
+ .getDefaultImportResourceAuditMsgFailure(errorInfo, variables);
+ expectedResourceAuditJavaObject.setResourceName(importReqDetails.getName());
+ expectedResourceAuditJavaObject.setModifierName(sdncUserDetails.getFullName());
+ expectedResourceAuditJavaObject.setModifierUid(sdncUserDetails.getUserId());
+ expectedResourceAuditJavaObject.setCurrState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name());
+ AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject,
+ AuditingActionEnum.IMPORT_RESOURCE.getName(), null, false);
+ }
+
+ @Test
+ public void importToscaResourceReqCapDerivedFromParent() throws Exception {
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ importToscaResourceReqCapDerivedFromParent);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ BaseRestUtils.checkCreateResponse(importResourceResponse);
+ ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = ElementFactory
+ .getDefaultImportResourceAuditMsgSuccess();
+ expectedResourceAuditJavaObject.setResourceName(importReqDetails.getName());
+ expectedResourceAuditJavaObject.setModifierName(sdncUserDetails.getFullName());
+ expectedResourceAuditJavaObject.setModifierUid(sdncUserDetails.getUserId());
+ expectedResourceAuditJavaObject.setToscaNodeType("org.openecomp.resource.MyWebApp");
+ AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject,
+ AuditingActionEnum.IMPORT_RESOURCE.getName(), null, false);
+ }
+
+ /************************ Shay ************************/
+
+ @Test
+ public void caseRequirementInsensitiveTest() throws Exception {
+ String fileName = "CaseInsensitiveReqTest_1.yml";
+ int expectedNumOfRequirements = 2;
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ fileName);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ assertEquals(STATUS_CODE_CREATED, importResourceResponse.getErrorCode().intValue());
+ importReqDetails.setRequirements(testResourcesPath, fileName, sdncUserDetails, null);
+ Map<String, Object> requirements = importReqDetails.getRequirements();
+ Map<String, Object> requirementsFromResponse = parseReqOrCapFromResponse("requirements", importReqDetails,
+ expectedNumOfRequirements);
+ assertEquals(requirements.keySet().size(), requirementsFromResponse.keySet().size());
+ importReqDetails.compareRequirementsOrCapabilities(requirements, requirementsFromResponse);
+
+ RestResponse changeResourceState1 = LifecycleRestUtils.changeResourceState(importReqDetails, sdncUserDetails,
+ LifeCycleStatesEnum.CERTIFICATIONREQUEST);
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState1.getErrorCode().intValue());
+ RestResponse changeResourceState2 = LifecycleRestUtils.changeResourceState(importReqDetails,
+ ElementFactory.getDefaultUser(UserRoleEnum.TESTER), LifeCycleStatesEnum.STARTCERTIFICATION);
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState2.getErrorCode().intValue());
+ RestResponse changeResourceState3 = LifecycleRestUtils.changeResourceState(importReqDetails,
+ ElementFactory.getDefaultUser(UserRoleEnum.TESTER), LifeCycleStatesEnum.CERTIFY);
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState3.getErrorCode().intValue());
+
+ String fileName2 = "CaseInsensitiveReqTest_2.yml";
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ fileName2);
+ importReqDetails.setName("secondImportedResource");
+ importReqDetails.setTags(Arrays.asList(importReqDetails.getName()));
+ importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails, null);
+ assertEquals(STATUS_CODE_CREATED, importResourceResponse.getErrorCode().intValue());
+ importReqDetails.setRequirements(testResourcesPath, importReqDetails.getPayloadName(), sdncUserDetails, null);
+ requirements = importReqDetails.getRequirements();
+ requirementsFromResponse = parseReqOrCapFromResponse("requirements", importReqDetails,
+ expectedNumOfRequirements);
+ assertEquals(requirements.keySet().size(), requirementsFromResponse.keySet().size());
+ importReqDetails.compareRequirementsOrCapabilities(requirements, requirementsFromResponse);
+
+ checkImportedAssetAssociated(importReqDetails);
+
+ }
+
+ private void checkImportedAssetAssociated(ImportReqDetails importDetails) throws IOException, Exception {
+ RestResponse importResourceResponse;
+ ImportReqDetails importReqDetails2 = ElementFactory.getDefaultImportResource();
+ importReqDetails2 = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails2, testResourcesPath,
+ "BindingAsset.yml");
+ importReqDetails2.setName("bindingAsset");
+ importReqDetails2.setTags(Arrays.asList(importReqDetails2.getName()));
+ importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails2, sdncUserDetails, null);
+ assertEquals(STATUS_CODE_CREATED, importResourceResponse.getErrorCode().intValue());
+
+ ResourceReqDetails vf = ElementFactory.getDefaultResourceByType("VF100", NormativeTypesEnum.ROOT,
+ ResourceCategoryEnum.GENERIC_INFRASTRUCTURE, sdncUserDetails.getUserId(),
+ ResourceTypeEnum.VF.toString());
+ RestResponse createResourceResponse = ResourceRestUtils.createResource(vf, sdncUserDetails);
+ ResourceRestUtils.checkCreateResponse(createResourceResponse);
+
+ LifecycleRestUtils.changeResourceState(importDetails, sdncUserDetails,
+ LifeCycleStatesEnum.CERTIFICATIONREQUEST);
+ LifecycleRestUtils.changeResourceState(importReqDetails2, sdncUserDetails,
+ LifeCycleStatesEnum.CERTIFICATIONREQUEST);
+
+ RestResponse response = ResourceRestUtils.createResourceInstance(importDetails, sdncUserDetails,
+ vf.getUniqueId());
+ ResourceRestUtils.checkCreateResponse(response);
+ ComponentInstance riCap = ResponseParser.parseToObject(response.getResponse(), ComponentInstance.class);
+
+ response = ResourceRestUtils.createResourceInstance(importReqDetails2, sdncUserDetails, vf.getUniqueId());
+ ResourceRestUtils.checkCreateResponse(response);
+ ComponentInstance riReq = ResponseParser.parseToObject(response.getResponse(), ComponentInstance.class);
+
+ RestResponse getResourceBeforeAssociate = ComponentRestUtils
+ .getComponentRequirmentsCapabilities(sdncUserDetails, vf);
+ CapReqDef capReqDef = ResponseParser.parseToObject(getResourceBeforeAssociate.getResponse(), CapReqDef.class);
+
+ String capbilityUid = capReqDef.getCapabilities().get("tosca.capabilities.network.Bindable").get(0)
+ .getUniqueId();
+ String requirementUid = capReqDef.getRequirements().get("tosca.capabilities.network.Bindable").get(0)
+ .getUniqueId();
+
+ RequirementCapabilityRelDef requirementDef = new RequirementCapabilityRelDef();
+ requirementDef.setFromNode(riReq.getUniqueId());
+ requirementDef.setToNode(riCap.getUniqueId());
+
+ RequirementAndRelationshipPair pair = new RequirementAndRelationshipPair();
+ pair.setRequirementOwnerId(riReq.getUniqueId());
+ pair.setCapabilityOwnerId(riCap.getUniqueId());
+ pair.setRequirement("VirtualBinding");
+ RelationshipImpl relationship = new RelationshipImpl();
+ relationship.setType("tosca.capabilities.network.Bindable");
+ pair.setRelationships(relationship);
+ pair.setCapabilityUid(capbilityUid);
+ pair.setRequirementUid(requirementUid);
+ List<RequirementAndRelationshipPair> relationships = new ArrayList<>();
+ relationships.add(pair);
+ requirementDef.setRelationships(relationships);
+
+ RestResponse associateInstances = ComponentInstanceRestUtils.associateInstances(requirementDef, sdncUserDetails,
+ vf.getUniqueId(), ComponentTypeEnum.RESOURCE);
+ assertEquals("Check response code ", STATUS_CODE_SUCCESS, associateInstances.getErrorCode().intValue());
+ }
+
+ @Test
+ public void caseCapabilitiesInsensitiveTest() throws Exception {
+ String fileName = "CaseInsensitiveCapTest_1.yml";
+ int expectedNumOfCapabilities = 6;
+
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ fileName);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ assertEquals(STATUS_CODE_CREATED, importResourceResponse.getErrorCode().intValue());
+
+ importReqDetails.setCapabilities(testResourcesPath, fileName, sdncUserDetails, null);
+ Map<String, Object> capabilities = importReqDetails.getCapabilities();
+ Map<String, Object> capabilitiesFromResponse = parseReqOrCapFromResponse("capabilities", importReqDetails,
+ expectedNumOfCapabilities);
+ assertEquals(capabilities.keySet().size(), capabilitiesFromResponse.keySet().size());
+ importReqDetails.compareRequirementsOrCapabilities(capabilities, capabilitiesFromResponse);
+
+ RestResponse changeResourceState1 = LifecycleRestUtils.changeResourceState(importReqDetails, sdncUserDetails,
+ LifeCycleStatesEnum.CERTIFICATIONREQUEST);
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState1.getErrorCode().intValue());
+ RestResponse changeResourceState2 = LifecycleRestUtils.changeResourceState(importReqDetails,
+ ElementFactory.getDefaultUser(UserRoleEnum.TESTER), LifeCycleStatesEnum.STARTCERTIFICATION);
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState2.getErrorCode().intValue());
+ RestResponse changeResourceState3 = LifecycleRestUtils.changeResourceState(importReqDetails,
+ ElementFactory.getDefaultUser(UserRoleEnum.TESTER), LifeCycleStatesEnum.CERTIFY);
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState3.getErrorCode().intValue());
+
+ String fileName2 = "CaseInsensitiveCapTest_2.yml";
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ fileName2);
+ importReqDetails.setName("secondImportedResource");
+ importReqDetails.setTags(Arrays.asList(importReqDetails.getName()));
+ importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails, null);
+ assertEquals(STATUS_CODE_CREATED, importResourceResponse.getErrorCode().intValue());
+
+ importReqDetails.setCapabilities(testResourcesPath, fileName2, sdncUserDetails, null);
+ capabilities = importReqDetails.getCapabilities();
+ capabilitiesFromResponse = parseReqOrCapFromResponse("capabilities", importReqDetails,
+ expectedNumOfCapabilities);
+ assertEquals(capabilities.keySet().size(), capabilitiesFromResponse.keySet().size());
+ importReqDetails.compareRequirementsOrCapabilities(capabilities, capabilitiesFromResponse);
+
+ }
+
+ @Test
+ public void fatherAndChildHaveDifferentRequirementsTest() throws Exception {
+ String fileName = "DifferentReqFromCompute.yml";
+ int expectedNumOfRequirements = 3;
+
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ fileName);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ assertEquals(STATUS_CODE_CREATED, importResourceResponse.getErrorCode().intValue());
+
+ importReqDetails.setRequirements(testResourcesPath, fileName, sdncUserDetails, "Compute");
+ Map<String, Object> requirements = importReqDetails.getRequirements();
+ Map<String, Object> requirementsFromResponse = parseReqOrCapFromResponse("requirements", importReqDetails,
+ expectedNumOfRequirements);
+ assertEquals(requirements.keySet().size(), requirementsFromResponse.keySet().size());
+ importReqDetails.compareRequirementsOrCapabilities(requirements, requirementsFromResponse);
+
+ checkImportedAssetAssociated(importReqDetails);
+ }
+
+ @Test
+ public void fatherHasNoRequirementsTest() throws Exception {
+ String fatherFileName = "CPHasNoReqCap.yml";
+ String childFileName = "DerivedFromCPWithOwnReq.yml";
+ int expectedNumOfRequirements = 3;
+
+ importReqDetails.setName("father");
+ importReqDetails.setTags(Arrays.asList(importReqDetails.getName()));
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ fatherFileName);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ assertEquals(STATUS_CODE_CREATED, importResourceResponse.getErrorCode().intValue());
+
+ RestResponse changeResourceState1 = LifecycleRestUtils.changeResourceState(importReqDetails, sdncUserDetails,
+ LifeCycleStatesEnum.CERTIFICATIONREQUEST);
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState1.getErrorCode().intValue());
+ RestResponse changeResourceState2 = LifecycleRestUtils.changeResourceState(importReqDetails,
+ ElementFactory.getDefaultUser(UserRoleEnum.TESTER), LifeCycleStatesEnum.STARTCERTIFICATION);
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState2.getErrorCode().intValue());
+ RestResponse changeResourceState3 = LifecycleRestUtils.changeResourceState(importReqDetails,
+ ElementFactory.getDefaultUser(UserRoleEnum.TESTER), LifeCycleStatesEnum.CERTIFY);
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState3.getErrorCode().intValue());
+
+ String derivedFromResourceName = importReqDetails.getName();
+ importReqDetails = ElementFactory.getDefaultImportResource();
+ importReqDetails.setName("child");
+ importReqDetails.setTags(Arrays.asList(importReqDetails.getName()));
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ childFileName);
+ importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails, null);
+ assertEquals(STATUS_CODE_CREATED, importResourceResponse.getErrorCode().intValue());
+
+ importReqDetails.setRequirements(testResourcesPath, importReqDetails.getPayloadName(), sdncUserDetails,
+ derivedFromResourceName);
+ Map<String, Object> requirements = importReqDetails.getRequirements();
+ Map<String, Object> requirementsFromResponse = parseReqOrCapFromResponse("requirements", importReqDetails,
+ expectedNumOfRequirements);
+ assertEquals(requirements.keySet().size(), requirementsFromResponse.keySet().size());
+ importReqDetails.compareRequirementsOrCapabilities(requirements, requirementsFromResponse);
+
+ }
+
+ @Test
+ public void childHasSameReqNameAndTypeLikeFatherTest() throws Exception {
+ String childFileName = "SameReqAsCompute.yml";
+ int expectedNumOfRequirements = 2;
+
+ importReqDetails.setName("child");
+ importReqDetails.setTags(Arrays.asList(importReqDetails.getName()));
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ childFileName);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ assertEquals(STATUS_CODE_CREATED, importResourceResponse.getErrorCode().intValue());
+
+ importReqDetails.setRequirements(testResourcesPath, importReqDetails.getPayloadName(), sdncUserDetails, null);
+ Map<String, Object> requirements = importReqDetails.getRequirements();
+ Map<String, Object> requirementsFromResponse = parseReqOrCapFromResponse("requirements", importReqDetails,
+ expectedNumOfRequirements);
+ assertEquals(requirements.keySet().size(), requirementsFromResponse.keySet().size());
+ importReqDetails.compareRequirementsOrCapabilities(requirements, requirementsFromResponse);
+ }
+
+ @Test
+ public void childHasSameCapNameAndTypeLikeFatherTest() throws Exception {
+ String childFileName = "SameCapAsCompute.yml";
+ int expectedNumOfCapabilities = 6;
+
+ importReqDetails.setName("child");
+ importReqDetails.setTags(Arrays.asList(importReqDetails.getName()));
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ childFileName);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ assertEquals(STATUS_CODE_CREATED, importResourceResponse.getErrorCode().intValue());
+
+ importReqDetails.setCapabilities(testResourcesPath, importReqDetails.getPayloadName(), sdncUserDetails,
+ "Compute");
+ Map<String, Object> capabilities = importReqDetails.getCapabilities();
+ Map<String, Object> capabilitiesFromResponse = parseReqOrCapFromResponse("capabilities", importReqDetails,
+ expectedNumOfCapabilities);
+ assertEquals(capabilities.keySet().size(), capabilitiesFromResponse.keySet().size());
+ importReqDetails.compareRequirementsOrCapabilities(capabilities, capabilitiesFromResponse);
+ }
+
+ @Test
+ public void childGetsAllRequirementsOfFatherAndGrandfatherTest() throws Exception {
+ int expectedNumOfRequirements = 4;
+
+ String fatherFileName = "DifferentReqFromCompute.yml";
+ importReqDetails.setName("father");
+ importReqDetails.setTags(Arrays.asList(importReqDetails.getName()));
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ fatherFileName);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ assertEquals(STATUS_CODE_CREATED, importResourceResponse.getErrorCode().intValue());
+
+ RestResponse changeResourceState1 = LifecycleRestUtils.changeResourceState(importReqDetails, sdncUserDetails,
+ LifeCycleStatesEnum.CERTIFICATIONREQUEST);
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState1.getErrorCode().intValue());
+ RestResponse changeResourceState2 = LifecycleRestUtils.changeResourceState(importReqDetails,
+ ElementFactory.getDefaultUser(UserRoleEnum.TESTER), LifeCycleStatesEnum.STARTCERTIFICATION);
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState2.getErrorCode().intValue());
+ RestResponse changeResourceState3 = LifecycleRestUtils.changeResourceState(importReqDetails,
+ ElementFactory.getDefaultUser(UserRoleEnum.TESTER), LifeCycleStatesEnum.CERTIFY);
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState3.getErrorCode().intValue());
+
+ String derivedFromName = importReqDetails.getName();
+ String childFileName = "DifferentReqCapFromCompute1.yml";
+ importReqDetails = ElementFactory.getDefaultImportResource();
+ importReqDetails.setName("child");
+ importReqDetails.setTags(Arrays.asList(importReqDetails.getName()));
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ childFileName);
+ importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails, null);
+ assertEquals(STATUS_CODE_CREATED, importResourceResponse.getErrorCode().intValue());
+
+ importReqDetails.setRequirements(testResourcesPath, importReqDetails.getPayloadName(), sdncUserDetails,
+ derivedFromName);
+ Map<String, Object> requirements = importReqDetails.getRequirements();
+ Map<String, Object> requirementsFromResponse = parseReqOrCapFromResponse("requirements", importReqDetails,
+ expectedNumOfRequirements);
+ assertEquals(requirements.keySet().size(), requirementsFromResponse.keySet().size());
+ importReqDetails.compareRequirementsOrCapabilities(requirements, requirementsFromResponse);
+
+ }
+
+ @Test
+ public void childOverridesGrandfatherRequirementsTest() throws Exception {
+ int expectedNumOfRequirements = 3;
+
+ String fatherFileName = "DifferentReqFromCompute.yml";
+ importReqDetails.setName("father");
+ importReqDetails.setTags(Arrays.asList(importReqDetails.getName()));
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ fatherFileName);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ assertEquals(STATUS_CODE_CREATED, importResourceResponse.getErrorCode().intValue());
+
+ RestResponse changeResourceState1 = LifecycleRestUtils.changeResourceState(importReqDetails, sdncUserDetails,
+ LifeCycleStatesEnum.CERTIFICATIONREQUEST);
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState1.getErrorCode().intValue());
+ RestResponse changeResourceState2 = LifecycleRestUtils.changeResourceState(importReqDetails,
+ ElementFactory.getDefaultUser(UserRoleEnum.TESTER), LifeCycleStatesEnum.STARTCERTIFICATION);
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState2.getErrorCode().intValue());
+ RestResponse changeResourceState3 = LifecycleRestUtils.changeResourceState(importReqDetails,
+ ElementFactory.getDefaultUser(UserRoleEnum.TESTER), LifeCycleStatesEnum.CERTIFY);
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState3.getErrorCode().intValue());
+
+ String derivedFromName = importReqDetails.getName();
+ String childFileName = "SameReqAsCompute_DerivedFromMyCompute1.yml";
+ importReqDetails = ElementFactory.getDefaultImportResource();
+ importReqDetails.setName("child");
+ importReqDetails.setTags(Arrays.asList(importReqDetails.getName()));
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ childFileName);
+ importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails, null);
+ assertEquals(STATUS_CODE_CREATED, importResourceResponse.getErrorCode().intValue());
+
+ importReqDetails.setRequirements(testResourcesPath, importReqDetails.getPayloadName(), sdncUserDetails,
+ derivedFromName);
+ Map<String, Object> requirements = importReqDetails.getRequirements();
+ Map<String, Object> requirementsFromResponse = parseReqOrCapFromResponse("requirements", importReqDetails,
+ expectedNumOfRequirements);
+ assertEquals(requirements.keySet().size(), requirementsFromResponse.keySet().size());
+ importReqDetails.compareRequirementsOrCapabilities(requirements, requirementsFromResponse);
+ }
+
+ @Test
+ public void childAndGrandfatherHaveDifferenetReqiurementTypeTest() throws Exception {
+ int expectedNumOfRequirements = 3;
+ int expectedNumOfCapabilities = 6;
+
+ String fatherName = "father";
+ String fatherFileName = "DifferentReqFromCompute.yml";
+ importReqDetails.setName(fatherName);
+ importReqDetails.setTags(Arrays.asList(importReqDetails.getName()));
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ fatherFileName);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ assertEquals(STATUS_CODE_CREATED, importResourceResponse.getErrorCode().intValue());
+
+ RestResponse changeResourceState1 = LifecycleRestUtils.changeResourceState(importReqDetails, sdncUserDetails,
+ LifeCycleStatesEnum.CERTIFICATIONREQUEST);
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState1.getErrorCode().intValue());
+ RestResponse changeResourceState2 = LifecycleRestUtils.changeResourceState(importReqDetails,
+ ElementFactory.getDefaultUser(UserRoleEnum.TESTER), LifeCycleStatesEnum.STARTCERTIFICATION);
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState2.getErrorCode().intValue());
+ RestResponse changeResourceState3 = LifecycleRestUtils.changeResourceState(importReqDetails,
+ ElementFactory.getDefaultUser(UserRoleEnum.TESTER), LifeCycleStatesEnum.CERTIFY);
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState3.getErrorCode().intValue());
+
+ String fatherUniqueId = importReqDetails.getUniqueId();
+ ImportReqDetails importReqDetailsFather = importReqDetails;
+
+ String childFileName = "importRequirementNameExistsOnParent_DerivedFromMyCompute1.yml";
+ importReqDetails = ElementFactory.getDefaultImportResource();
+ importReqDetails.setName("child");
+ importReqDetails.setTags(Arrays.asList(importReqDetails.getName()));
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ childFileName);
+ importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails, null);
+ assertEquals(STATUS_CODE_INVALID_CONTENT, importResourceResponse.getErrorCode().intValue());
+ ArrayList<String> variables = new ArrayList<>();
+ variables.add("requirement");
+ variables.add("local_storage");
+ variables.add(fatherName);
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.IMPORT_REQ_CAP_NAME_EXISTS_IN_DERIVED.name(),
+ variables, importResourceResponse.getResponse());
+
+ importReqDetails.setUniqueId(fatherUniqueId);
+
+ importReqDetailsFather.setRequirements(testResourcesPath, fatherFileName, sdncUserDetails, "Compute");
+ Map<String, Object> requirements = importReqDetailsFather.getRequirements();
+ Map<String, Object> requirementsFromResponse = parseReqOrCapFromResponse("requirements", importReqDetailsFather,
+ expectedNumOfRequirements);
+ assertEquals(requirements.keySet().size(), requirementsFromResponse.keySet().size());
+ importReqDetailsFather.compareRequirementsOrCapabilities(requirements, requirementsFromResponse);
+
+ importReqDetailsFather.setCapabilities(testResourcesPath, fatherFileName, sdncUserDetails, "Compute");
+ Map<String, Object> capabilities = importReqDetailsFather.getCapabilities();
+ Map<String, Object> capabilitiesFromResponse = parseReqOrCapFromResponse("capabilities", importReqDetailsFather,
+ expectedNumOfCapabilities);
+ assertEquals(capabilities.keySet().size(), capabilitiesFromResponse.keySet().size());
+ importReqDetailsFather.compareRequirementsOrCapabilities(capabilities, capabilitiesFromResponse);
+ }
+
+ @Test
+ public void childHasNoReqCapTest() throws Exception {
+ int expectedNumOfRequirements = 3;
+ int expectedNumOfCapabilities = 6;
+
+ String fatherFileName = "DifferentReqFromCompute.yml";
+ importReqDetails.setName("father");
+ importReqDetails.setTags(Arrays.asList(importReqDetails.getName()));
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ fatherFileName);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ assertEquals(STATUS_CODE_CREATED, importResourceResponse.getErrorCode().intValue());
+
+ RestResponse changeResourceState1 = LifecycleRestUtils.changeResourceState(importReqDetails, sdncUserDetails,
+ LifeCycleStatesEnum.CERTIFICATIONREQUEST);
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState1.getErrorCode().intValue());
+ RestResponse changeResourceState2 = LifecycleRestUtils.changeResourceState(importReqDetails,
+ ElementFactory.getDefaultUser(UserRoleEnum.TESTER), LifeCycleStatesEnum.STARTCERTIFICATION);
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState2.getErrorCode().intValue());
+ RestResponse changeResourceState3 = LifecycleRestUtils.changeResourceState(importReqDetails,
+ ElementFactory.getDefaultUser(UserRoleEnum.TESTER), LifeCycleStatesEnum.CERTIFY);
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState3.getErrorCode().intValue());
+
+ String derivedFromName = importReqDetails.getName();
+ String childFileName = "CPHasNoReqCap_DerivedFromMyCompute1.yml";
+ importReqDetails = ElementFactory.getDefaultImportResource();
+ importReqDetails.setName("child");
+ importReqDetails.setTags(Arrays.asList(importReqDetails.getName()));
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ childFileName);
+ importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails, null);
+ assertEquals(STATUS_CODE_CREATED, importResourceResponse.getErrorCode().intValue());
+
+ importReqDetails.setRequirements(testResourcesPath, importReqDetails.getPayloadName(), sdncUserDetails,
+ derivedFromName);
+ Map<String, Object> requirements = importReqDetails.getRequirements();
+ Map<String, Object> requirementsFromResponse = parseReqOrCapFromResponse("requirements", importReqDetails,
+ expectedNumOfRequirements);
+ assertEquals(requirements.keySet().size(), requirementsFromResponse.keySet().size());
+ importReqDetails.compareRequirementsOrCapabilities(requirements, requirementsFromResponse);
+
+ importReqDetails.setCapabilities(testResourcesPath, importReqDetails.getPayloadName(), sdncUserDetails,
+ derivedFromName);
+ Map<String, Object> capabilities = importReqDetails.getCapabilities();
+ Map<String, Object> capabilitiesFromResponse = parseReqOrCapFromResponse("capabilities", importReqDetails,
+ expectedNumOfCapabilities);
+ assertEquals(capabilities.keySet().size(), capabilitiesFromResponse.keySet().size());
+ importReqDetails.compareRequirementsOrCapabilities(capabilities, capabilitiesFromResponse);
+ }
+
+ @Test
+ public void fatherAndChildGetReqCapFromGrandfatherTest() throws Exception {
+ int expectedNumOfRequirements = 2;
+ int expectedNumOfCapabilities = 6;
+
+ String fatherFileName = "MyFatherCompute_NoReqCap.yml";
+ importReqDetails.setName("father");
+ importReqDetails.setTags(Arrays.asList(importReqDetails.getName()));
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ fatherFileName);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ assertEquals(STATUS_CODE_CREATED, importResourceResponse.getErrorCode().intValue());
+
+ RestResponse changeResourceState1 = LifecycleRestUtils.changeResourceState(importReqDetails, sdncUserDetails,
+ LifeCycleStatesEnum.CERTIFICATIONREQUEST);
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState1.getErrorCode().intValue());
+ RestResponse changeResourceState2 = LifecycleRestUtils.changeResourceState(importReqDetails,
+ ElementFactory.getDefaultUser(UserRoleEnum.TESTER), LifeCycleStatesEnum.STARTCERTIFICATION);
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState2.getErrorCode().intValue());
+ RestResponse changeResourceState3 = LifecycleRestUtils.changeResourceState(importReqDetails,
+ ElementFactory.getDefaultUser(UserRoleEnum.TESTER), LifeCycleStatesEnum.CERTIFY);
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState3.getErrorCode().intValue());
+
+ String derivedFromName = importReqDetails.getName();
+ String childFileName = "myChildCompute_NoReqCap.yml";
+ importReqDetails = ElementFactory.getDefaultImportResource();
+ importReqDetails.setName("child");
+ importReqDetails.setTags(Arrays.asList(importReqDetails.getName()));
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ childFileName);
+ importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails, null);
+ assertEquals(STATUS_CODE_CREATED, importResourceResponse.getErrorCode().intValue());
+
+ importReqDetails.setRequirements(testResourcesPath, importReqDetails.getPayloadName(), sdncUserDetails,
+ derivedFromName);
+ Map<String, Object> requirements = importReqDetails.getRequirements();
+ Map<String, Object> requirementsFromResponse = parseReqOrCapFromResponse("requirements", importReqDetails,
+ expectedNumOfRequirements);
+ assertEquals(requirements.keySet().size(), requirementsFromResponse.keySet().size());
+ importReqDetails.compareRequirementsOrCapabilities(requirements, requirementsFromResponse);
+
+ importReqDetails.setCapabilities(testResourcesPath, importReqDetails.getPayloadName(), sdncUserDetails,
+ derivedFromName);
+ Map<String, Object> capabilities = importReqDetails.getCapabilities();
+ Map<String, Object> capabilitiesFromResponse = parseReqOrCapFromResponse("capabilities", importReqDetails,
+ expectedNumOfCapabilities);
+ assertEquals(capabilities.keySet().size(), capabilitiesFromResponse.keySet().size());
+ importReqDetails.compareRequirementsOrCapabilities(capabilities, capabilitiesFromResponse);
+ }
+
+ @Test
+ public void reverseInheritanceTest() throws Exception {
+ int expectedNumOfRequirements = 2;
+ int expectedNumOfCapabilities = 2;
+
+ String fatherName = "father";
+ String fatherFileName = "myFatherWebApp_derviedFromDocker.yml";
+ importReqDetails.setName(fatherName);
+ importReqDetails.setTags(Arrays.asList(importReqDetails.getName()));
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ fatherFileName);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ assertEquals(STATUS_CODE_CREATED, importResourceResponse.getErrorCode().intValue());
+
+ RestResponse changeResourceState1 = LifecycleRestUtils.changeResourceState(importReqDetails, sdncUserDetails,
+ LifeCycleStatesEnum.CERTIFICATIONREQUEST);
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState1.getErrorCode().intValue());
+ RestResponse changeResourceState2 = LifecycleRestUtils.changeResourceState(importReqDetails,
+ ElementFactory.getDefaultUser(UserRoleEnum.TESTER), LifeCycleStatesEnum.STARTCERTIFICATION);
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState2.getErrorCode().intValue());
+ RestResponse changeResourceState3 = LifecycleRestUtils.changeResourceState(importReqDetails,
+ ElementFactory.getDefaultUser(UserRoleEnum.TESTER), LifeCycleStatesEnum.CERTIFY);
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState3.getErrorCode().intValue());
+
+ String fatherUniqueId = importReqDetails.getUniqueId();
+ ImportReqDetails importReqDetailsFather = importReqDetails;
+ String childFileName = "myChildWebApp_DerivedFromContainer.yml";
+ importReqDetails = ElementFactory.getDefaultImportResource();
+ importReqDetails.setName("child");
+ importReqDetails.setTags(Arrays.asList(importReqDetails.getName()));
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ childFileName);
+ importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails, null);
+ assertEquals(STATUS_CODE_INVALID_CONTENT, importResourceResponse.getErrorCode().intValue());
+ ArrayList<String> variables = new ArrayList<>();
+ variables.add("requirement");
+ variables.add("host");
+ variables.add(fatherName);
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.IMPORT_REQ_CAP_NAME_EXISTS_IN_DERIVED.name(),
+ variables, importResourceResponse.getResponse());
+
+ importReqDetails.setUniqueId(fatherUniqueId);
+ importReqDetailsFather.setRequirements(testResourcesPath, fatherFileName, sdncUserDetails, "Root");
+ Map<String, Object> requirements = importReqDetailsFather.getRequirements();
+ Map<String, Object> requirementsFromResponse = parseReqOrCapFromResponse("requirements", importReqDetailsFather,
+ expectedNumOfRequirements);
+ assertEquals(requirements.keySet().size(), requirementsFromResponse.keySet().size());
+ importReqDetailsFather.compareRequirementsOrCapabilities(requirements, requirementsFromResponse);
+
+ importReqDetailsFather.setCapabilities(testResourcesPath, fatherFileName, sdncUserDetails, "Root");
+ Map<String, Object> capabilities = importReqDetailsFather.getCapabilities();
+ Map<String, Object> capabilitiesFromResponse = parseReqOrCapFromResponse("capabilities", importReqDetailsFather,
+ expectedNumOfCapabilities);
+ assertEquals(capabilities.keySet().size(), capabilitiesFromResponse.keySet().size());
+ importReqDetailsFather.compareRequirementsOrCapabilities(capabilities, capabilitiesFromResponse);
+ }
+
+ // DE202329
+ @Test(enabled = false)
+ public void requirementWithMissingTypeTest() throws Exception {
+ String fatherName = "father";
+ String fatherFileName = "DerivedFromWebApplication_HasNoReqType.yml";
+ importReqDetails.setName(fatherName);
+ importReqDetails.setTags(Arrays.asList(importReqDetails.getName()));
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ fatherFileName);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ assertEquals(STATUS_CODE_INVALID_CONTENT, importResourceResponse.getErrorCode().intValue());
+ ArrayList<String> variables = new ArrayList<>();
+ variables.add("diff");
+ ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.MISSING_CAPABILITY_TYPE.name(), variables,
+ importResourceResponse.getResponse());
+
+ }
+
+ @Test
+ public void TwinBrothersHaveSameReqCapTest() throws Exception {
+ int expectedNumOfRequirements = 4;
+ int expectedNumOfCapabilities = 7;
+
+ String derivedFromName = "father";
+ String fatherFileName = "DifferentReqFromCompute.yml";
+ importReqDetails.setName(derivedFromName);
+ importReqDetails.setTags(Arrays.asList(importReqDetails.getName()));
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ fatherFileName);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ assertEquals(STATUS_CODE_CREATED, importResourceResponse.getErrorCode().intValue());
+
+ RestResponse changeResourceState1 = LifecycleRestUtils.changeResourceState(importReqDetails, sdncUserDetails,
+ LifeCycleStatesEnum.CERTIFICATIONREQUEST);
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState1.getErrorCode().intValue());
+ RestResponse changeResourceState2 = LifecycleRestUtils.changeResourceState(importReqDetails,
+ ElementFactory.getDefaultUser(UserRoleEnum.TESTER), LifeCycleStatesEnum.STARTCERTIFICATION);
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState2.getErrorCode().intValue());
+ RestResponse changeResourceState3 = LifecycleRestUtils.changeResourceState(importReqDetails,
+ ElementFactory.getDefaultUser(UserRoleEnum.TESTER), LifeCycleStatesEnum.CERTIFY);
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState3.getErrorCode().intValue());
+
+ String childFileName = "DifferentReqCapFromCompute1.yml";
+ importReqDetails = ElementFactory.getDefaultImportResource();
+ importReqDetails.setName("child");
+ importReqDetails.setTags(Arrays.asList(importReqDetails.getName()));
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ childFileName);
+ importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails, null);
+ assertEquals(STATUS_CODE_CREATED, importResourceResponse.getErrorCode().intValue());
+
+ Map<String, Object> childRequirementsFromResponse = parseReqOrCapFromResponse("requirements", importReqDetails,
+ expectedNumOfRequirements);
+ Map<String, Object> childCapabilitiesFromResponse = parseReqOrCapFromResponse("capabilities", importReqDetails,
+ expectedNumOfCapabilities - 1);
+
+ String twinFileName = "DifferentReqCapFromCompute2.yml";
+ importReqDetails = ElementFactory.getDefaultImportResource();
+ importReqDetails.setName("twin");
+ importReqDetails.setTags(Arrays.asList(importReqDetails.getName()));
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ twinFileName);
+ importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails, null);
+ assertEquals(STATUS_CODE_CREATED, importResourceResponse.getErrorCode().intValue());
+
+ importReqDetails.setRequirements(testResourcesPath, importReqDetails.getPayloadName(), sdncUserDetails,
+ derivedFromName);
+ Map<String, Object> requirements = importReqDetails.getRequirements();
+ Map<String, Object> twinRequirementsFromResponse = parseReqOrCapFromResponse("requirements", importReqDetails,
+ expectedNumOfRequirements);
+ assertEquals(requirements.keySet().size(), twinRequirementsFromResponse.keySet().size());
+ importReqDetails.compareRequirementsOrCapabilities(requirements, twinRequirementsFromResponse);
+
+ importReqDetails.setCapabilities(testResourcesPath, importReqDetails.getPayloadName(), sdncUserDetails,
+ derivedFromName);
+ Map<String, Object> capabilities = importReqDetails.getCapabilities();
+ Map<String, Object> twinCapabilitiesFromResponse = parseReqOrCapFromResponse("capabilities", importReqDetails,
+ expectedNumOfCapabilities);
+ assertEquals(capabilities.keySet().size(), twinCapabilitiesFromResponse.keySet().size());
+ importReqDetails.compareRequirementsOrCapabilities(capabilities, twinCapabilitiesFromResponse);
+
+ assertEquals(childRequirementsFromResponse.keySet().size(), twinRequirementsFromResponse.keySet().size());
+ assertEquals(childCapabilitiesFromResponse.keySet().size(), twinCapabilitiesFromResponse.keySet().size());
+ }
+
+ /*
+ * invariantUUID - US672129
+ */
+
+ private void checkInvariantUuidIsImmutableInDifferentAction(ImportReqDetails importReqDetails) throws Exception {
+ // create resource
+ importReqDetails.setName("import");
+ String invariantUuidDefinedByUser = "abcd1234";
+ RestResponse importResourceResponse = importResourceWithRequestedInvariantUuid(importReqDetails,
+ invariantUuidDefinedByUser);
+ String invariantUUIDcreation = ResponseParser.getInvariantUuid(importResourceResponse);
+ assertFalse(checkInvariantUuidEqual(invariantUuidDefinedByUser, importResourceResponse));
+
+ // get resource
+ RestResponse getResource = ResourceRestUtils.getResource(importReqDetails.getUniqueId());
+ assertTrue(checkInvariantUuidEqual(invariantUUIDcreation, getResource));
+
+ // checkin resource
+ RestResponse changeResourceState = LifecycleRestUtils.changeResourceState(importReqDetails, sdncUserDetails,
+ LifeCycleStatesEnum.CHECKIN);
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState.getErrorCode().intValue());
+ assertTrue(checkInvariantUuidEqual(invariantUUIDcreation, changeResourceState));
+
+ // checkout resource
+ changeResourceState = LifecycleRestUtils.changeResourceState(importReqDetails, sdncUserDetails,
+ LifeCycleStatesEnum.CHECKOUT);
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState.getErrorCode().intValue());
+ assertTrue(checkInvariantUuidEqual(invariantUUIDcreation, changeResourceState));
+
+ // checkin resource
+ changeResourceState = LifecycleRestUtils.changeResourceState(importReqDetails, sdncUserDetails,
+ LifeCycleStatesEnum.CHECKIN);
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState.getErrorCode().intValue());
+ assertTrue(checkInvariantUuidEqual(invariantUUIDcreation, changeResourceState));
+
+ // checkout resource
+ changeResourceState = LifecycleRestUtils.changeResourceState(importReqDetails, sdncUserDetails,
+ LifeCycleStatesEnum.CHECKOUT);
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState.getErrorCode().intValue());
+ assertTrue(checkInvariantUuidEqual(invariantUUIDcreation, changeResourceState));
+
+ // checkin resource
+ changeResourceState = LifecycleRestUtils.changeResourceState(importReqDetails, sdncUserDetails,
+ LifeCycleStatesEnum.CHECKIN);
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState.getErrorCode().intValue());
+ assertTrue(checkInvariantUuidEqual(invariantUUIDcreation, changeResourceState));
+
+ // certification request
+ changeResourceState = LifecycleRestUtils.changeResourceState(importReqDetails, sdncUserDetails,
+ LifeCycleStatesEnum.CERTIFICATIONREQUEST);
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState.getErrorCode().intValue());
+ assertTrue(checkInvariantUuidEqual(invariantUUIDcreation, changeResourceState));
+
+ // start certification
+ changeResourceState = LifecycleRestUtils.changeResourceState(importReqDetails, testerUser,
+ LifeCycleStatesEnum.STARTCERTIFICATION);
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState.getErrorCode().intValue());
+ assertTrue(checkInvariantUuidEqual(invariantUUIDcreation, changeResourceState));
+
+ // certify
+ changeResourceState = LifecycleRestUtils.changeResourceState(importReqDetails, testerUser,
+ LifeCycleStatesEnum.CERTIFY);
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState.getErrorCode().intValue());
+ assertTrue(checkInvariantUuidEqual(invariantUUIDcreation, changeResourceState));
+ String certifiedUniqueId = importReqDetails.getUniqueId();
+
+ // update resource
+ changeResourceState = LifecycleRestUtils.changeResourceState(importReqDetails, sdncUserDetails,
+ LifeCycleStatesEnum.CHECKOUT);
+ ResourceReqDetails updatedResourceReqDetails = new ResourceReqDetails(importReqDetails,
+ importReqDetails.getVersion());
+ updatedResourceReqDetails.setDescription("updatedDescription");
+ updatedResourceReqDetails.setVendorRelease("1.2.3.4");
+ RestResponse updateResponse = ResourceRestUtils.updateResourceMetadata(updatedResourceReqDetails,
+ sdncUserDetails, importReqDetails.getUniqueId());
+ assertEquals(STATUS_CODE_SUCCESS, updateResponse.getErrorCode().intValue());
+ assertTrue(checkInvariantUuidEqual(invariantUUIDcreation, updateResponse));
+
+ // certification request
+ changeResourceState = LifecycleRestUtils.changeResourceState(importReqDetails, sdncUserDetails,
+ LifeCycleStatesEnum.CERTIFICATIONREQUEST);
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState.getErrorCode().intValue());
+ assertTrue(checkInvariantUuidEqual(invariantUUIDcreation, changeResourceState));
+
+ // checkout resource
+ changeResourceState = LifecycleRestUtils.changeResourceState(importReqDetails, sdncUserDetails,
+ LifeCycleStatesEnum.CHECKOUT);
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState.getErrorCode().intValue());
+ assertTrue(checkInvariantUuidEqual(invariantUUIDcreation, changeResourceState));
+
+ // certification request
+ changeResourceState = LifecycleRestUtils.changeResourceState(importReqDetails, sdncUserDetails,
+ LifeCycleStatesEnum.CERTIFICATIONREQUEST);
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState.getErrorCode().intValue());
+ assertTrue(checkInvariantUuidEqual(invariantUUIDcreation, changeResourceState));
+
+ // start certification
+ changeResourceState = LifecycleRestUtils.changeResourceState(importReqDetails, testerUser,
+ LifeCycleStatesEnum.STARTCERTIFICATION);
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState.getErrorCode().intValue());
+ assertTrue(checkInvariantUuidEqual(invariantUUIDcreation, changeResourceState));
+
+ // cancel certification
+ changeResourceState = LifecycleRestUtils.changeResourceState(importReqDetails, testerUser,
+ LifeCycleStatesEnum.CANCELCERTIFICATION);
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState.getErrorCode().intValue());
+ assertTrue(checkInvariantUuidEqual(invariantUUIDcreation, changeResourceState));
+
+ // start certification
+ changeResourceState = LifecycleRestUtils.changeResourceState(importReqDetails, testerUser,
+ LifeCycleStatesEnum.STARTCERTIFICATION);
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState.getErrorCode().intValue());
+ assertTrue(checkInvariantUuidEqual(invariantUUIDcreation, changeResourceState));
+
+ // failure
+ changeResourceState = LifecycleRestUtils.changeResourceState(importReqDetails, testerUser,
+ LifeCycleStatesEnum.FAILCERTIFICATION);
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState.getErrorCode().intValue());
+ assertTrue(checkInvariantUuidEqual(invariantUUIDcreation, changeResourceState));
+
+ // upload artifact
+ changeResourceState = LifecycleRestUtils.changeResourceState(importReqDetails, sdncUserDetails,
+ LifeCycleStatesEnum.CHECKOUT);
+ ArtifactReqDetails artifactDetails = ElementFactory.getDefaultArtifact();
+ ArtifactRestUtils.addInformationalArtifactToResource(artifactDetails, sdncUserDetails,
+ importReqDetails.getUniqueId());
+ assertEquals(STATUS_CODE_SUCCESS, changeResourceState.getErrorCode().intValue());
+ assertTrue(checkInvariantUuidEqual(invariantUUIDcreation, changeResourceState));
+
+ // create instance
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.toString());
+ ResourceRestUtils.createResource(resourceDetails, sdncUserDetails);
+ importReqDetails.setUniqueId(certifiedUniqueId);
+ ComponentInstanceReqDetails resourceInstanceReqDetails = ElementFactory
+ .getComponentResourceInstance(importReqDetails);
+ RestResponse createResourceInstanceResponse = ComponentInstanceRestUtils.createComponentInstance(
+ resourceInstanceReqDetails, sdncUserDetails, resourceDetails.getUniqueId(), ComponentTypeEnum.RESOURCE);
+ assertEquals(STATUS_CODE_CREATED, createResourceInstanceResponse.getErrorCode().intValue());
+ getResource = ResourceRestUtils.getResource(importReqDetails.getUniqueId());
+ assertTrue(checkInvariantUuidEqual(invariantUUIDcreation, getResource));
+ }
+
+ private boolean checkInvariantUuidEqual(String expectedInvariantUuid, RestResponse response) {
+ String invariantUUIDFromResponse = ResponseParser.getInvariantUuid(response);
+ return expectedInvariantUuid.equals(invariantUUIDFromResponse);
+ }
+
+ @Test
+ public void checkCPHasImmutableInvariantUuidTest() throws Exception {
+ String filename = "FatherHasNoReqCap.yml";
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ filename);
+ checkResourceHasImmutableInvariantUuidTest(importReqDetails);
+ }
+
+ @Test
+ public void checkVFCHasImmutableInvariantUuidTest() throws Exception {
+ String filename = "computeCap11.yml";
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ filename);
+ checkResourceHasImmutableInvariantUuidTest(importReqDetails);
+ }
+
+ public void checkResourceHasImmutableInvariantUuidTest(ImportReqDetails importReqDetails) throws Exception {
+ // invariantUuid is null
+ importReqDetails.setName("first");
+ RestResponse importResourceResponse = importResourceWithRequestedInvariantUuid(importReqDetails, null);
+ String invariantUUIDcreation = ResponseParser.getInvariantUuid(importResourceResponse);
+ assertNotNull(invariantUUIDcreation);
+
+ ResourceRestUtils.deleteResource(importReqDetails.getUniqueId(), sdncUserDetails.getUserId());
+
+ // invariantUuid is empty
+ importReqDetails.setName("second");
+ String invariantUuidDefinedByUser = "";
+ importResourceResponse = importResourceWithRequestedInvariantUuid(importReqDetails, invariantUuidDefinedByUser);
+ invariantUUIDcreation = ResponseParser.getInvariantUuid(importResourceResponse);
+ assertNotNull(invariantUUIDcreation);
+
+ ResourceRestUtils.deleteResource(importReqDetails.getUniqueId(), sdncUserDetails.getUserId());
+
+ checkInvariantUuidIsImmutableInDifferentAction(importReqDetails);
+ }
+
+ private static RestResponse importResourceWithRequestedInvariantUuid(ImportReqDetails importDetails,
+ String invariantUuid) throws Exception {
+ importDetails.setInvariantUUID(invariantUuid);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importDetails, sdncUserDetails,
+ null);
+ assertEquals(STATUS_CODE_CREATED, importResourceResponse.getErrorCode().intValue());
+ return importResourceResponse;
+ }
+
+ private Map<String, Object> parseReqOrCapFromResponse(String parsedFieldName, ImportReqDetails importReqDetails,
+ int expectedNumOfReqCap) throws ClientProtocolException, IOException {
+ RestResponse getResource = ResourceRestUtils.getResource(importReqDetails.getUniqueId());
+ assertTrue(getResource.getErrorCode().equals(STATUS_CODE_SUCCESS));
+ Map<String, Object> parsedFieldFromResponseToMap = ResponseParser.getJsonValueAsMap(getResource,
+ parsedFieldName);
+ Iterator<String> iterator = parsedFieldFromResponseToMap.keySet().iterator();
+ actualNumOfReqOrCap = 0;
+ while (iterator.hasNext()) {
+ String next = iterator.next();
+ List<Object> object = (List<Object>) parsedFieldFromResponseToMap.get(next);
+ actualNumOfReqOrCap += object.size();
+ }
+ assertEquals(expectedNumOfReqCap, actualNumOfReqOrCap);
+ return parsedFieldFromResponseToMap;
+ }
+
+ // ---------------------------------
+
+ private void verifyResourcePropertiesList(Resource resourceJavaObject) { // use
+ // importListPropertySuccessFlow.yml
+ boolean isPropertyAppear = false;
+ List<PropertyDefinition> propertiesList = resourceJavaObject.getProperties();
+ for (PropertyDefinition pro : propertiesList) {
+ switch (pro.getName()) {
+ case "my_boolean":
+ assertTrue("Check Property Type ", pro.getType().equals("list"));
+ assertTrue("Check Property default values ", pro.getDefaultValue().equals("[false,true]"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("boolean"));
+ isPropertyAppear = true;
+ break;
+ case "my_boolean_array":
+ assertTrue("Check Property Type ", pro.getType().equals("list"));
+ assertTrue("Check Property default values ", pro.getDefaultValue().equals("[true,false]"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("boolean"));
+ isPropertyAppear = true;
+ break;
+ case "duplicate_boolean_values":
+ assertTrue("Check Property Type ", pro.getType().equals("list"));
+ assertTrue("Check Property default values ", pro.getDefaultValue().equals("[true,false,true]"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("boolean"));
+ isPropertyAppear = true;
+ break;
+ case "boolean_values_Insensitive":
+ assertTrue("Check Property Type ", pro.getType().equals("list"));
+ assertTrue("Check Property default values ", pro.getDefaultValue().equals("[true,false,true]"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("boolean"));
+ isPropertyAppear = true;
+ break;
+ case "my_integers":
+ assertTrue("Check Property Type ", pro.getType().equals("list"));
+ assertTrue("Check Property default values ", pro.getDefaultValue().equals("[0,1000,-1000,50]"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("integer"));
+ isPropertyAppear = true;
+ break;
+ case "my_integers_array":
+ assertTrue("Check Property Type ", pro.getType().equals("list"));
+ assertTrue("Check Property default values ", pro.getDefaultValue().equals("[10,-1000,0]"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("integer"));
+ isPropertyAppear = true;
+ break;
+ case "duplicate_integers_values":
+ assertTrue("Check Property Type ", pro.getType().equals("list"));
+ assertTrue("Check Property default values ", pro.getDefaultValue().equals("[10,10,-1000,0]"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("integer"));
+ isPropertyAppear = true;
+ break;
+ case "my_string":
+ assertTrue("Check Property Type ", pro.getType().equals("list"));
+ assertTrue("Check Property default values ",
+ pro.getDefaultValue().equals("[\"asdc\",\"$?^@ecomp$!#%()_-~@+*^...;;/w#\",\"uc\"]"));
+ // assertTrue("Check Property default values ",
+ // pro.getDefaultValue().equals("[\"asdc\",\"@=~!@#$%^&*()_+=?><:-w\",\"uc\"]"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("string"));
+ isPropertyAppear = true;
+ break;
+ case "my_string_array":
+ assertTrue("Check Property Type ", pro.getType().equals("list"));
+ assertTrue("Check Property default values ",
+ pro.getDefaultValue().equals("[\"AAA\",\"~$~#bbb%^*_-\",\"qwe\",\"1.3\",\"500\",\"true\"]"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("string"));
+ isPropertyAppear = true;
+ break;
+ case "duplicate_string_values":
+ assertTrue("Check Property Type ", pro.getType().equals("list"));
+ assertTrue("Check Property default values ",
+ pro.getDefaultValue().equals("[\"asdc\",\"asdc\",\"uc\"]"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("string"));
+ isPropertyAppear = true;
+ break;
+ case "string_null_value":
+ assertTrue("Check Property Type ", pro.getType().equals("list"));
+ assertTrue("Check Property default values ", pro.getDefaultValue().equals("[\"asdc\",\"uc\"]"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("string"));
+ isPropertyAppear = true;
+ break;
+ case "string_space_value":
+ assertTrue("Check Property Type ", pro.getType().equals("list"));
+ assertTrue("Check Property default values ", pro.getDefaultValue().equals("[\"asdc\",\"uc\"]"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("string"));
+ isPropertyAppear = true;
+ break;
+ case "string_array_null_value":
+ assertTrue("Check Property Type ", pro.getType().equals("list"));
+ assertTrue("Check Property default values ",
+ pro.getDefaultValue().equals("[\"aaa\",\"bbb\",\"500\"]"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("string"));
+ isPropertyAppear = true;
+ break;
+ case "my_float":
+ assertTrue("Check Property Type ", pro.getType().equals("list"));
+ assertTrue("Check Property default values ", pro.getDefaultValue().equals("[6,1000.000001,-3.0]"));
+ assertTrue("Check entrySchema Property Type ", pro.getSchema().getProperty().getType().equals("float"));
+ isPropertyAppear = true;
+ break;
+ case "my_float_array":
+ assertTrue("Check Property Type ", pro.getType().equals("list"));
+ assertTrue("Check Property default values ", pro.getDefaultValue().equals("[0.01,-5.0,2.1]"));
+ assertTrue("Check entrySchema Property Type ", pro.getSchema().getProperty().getType().equals("float"));
+ isPropertyAppear = true;
+ break;
+ case "duplicate_float_values":
+ assertTrue("Check Property Type ", pro.getType().equals("list"));
+ assertTrue("Check Property default values ", pro.getDefaultValue().equals("[0.0,0.0,4.555555]"));
+ assertTrue("Check entrySchema Property Type ", pro.getSchema().getProperty().getType().equals("float"));
+ isPropertyAppear = true;
+ break;
+ case "float_no_default_values":
+ assertTrue("Check Property Type ", pro.getType().equals("list"));
+ assertEquals("Check Property default values ", pro.getDefaultValue(), null);
+ assertTrue("Check entrySchema Property Type ", pro.getSchema().getProperty().getType().equals("float"));
+ isPropertyAppear = true;
+ break;
+ case "integer_no_default_values":
+ assertTrue("Check Property Type ", pro.getType().equals("list"));
+ assertEquals("Check Property default values ", pro.getDefaultValue(), null);
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("integer"));
+ isPropertyAppear = true;
+ break;
+ case "string_no_default_values":
+ assertTrue("Check Property Type ", pro.getType().equals("list"));
+ assertEquals("Check Property default values ", pro.getDefaultValue(), null);
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("string"));
+ isPropertyAppear = true;
+ break;
+ case "boolean_no_default_values":
+ assertTrue("Check Property Type ", pro.getType().equals("list"));
+ assertEquals("Check Property default values ", pro.getDefaultValue(), null);
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("boolean"));
+ isPropertyAppear = true;
+ break;
+ case "integer_null_value":
+ assertTrue("Check Property Type ", pro.getType().equals("list"));
+ assertTrue("Check Property default values ", pro.getDefaultValue().equals("[1000,2000]"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("integer"));
+ isPropertyAppear = true;
+ break;
+ case "boolean_null_value":
+ assertTrue("Check Property Type ", pro.getType().equals("list"));
+ assertTrue("Check Property default values ", pro.getDefaultValue().equals("[true,false]"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("boolean"));
+ isPropertyAppear = true;
+ break;
+ case "float_null_value":
+ assertTrue("Check Property Type ", pro.getType().equals("list"));
+ assertTrue("Check Property default values ", pro.getDefaultValue().equals("[6,-3.0]"));
+ assertTrue("Check entrySchema Property Type ", pro.getSchema().getProperty().getType().equals("float"));
+ isPropertyAppear = true;
+ break;
+ case "float_space_value":
+ assertTrue("Check Property Type ", pro.getType().equals("list"));
+ assertTrue("Check Property default values ", pro.getDefaultValue().equals("[6,-3.0]"));
+ assertTrue("Check entrySchema Property Type ", pro.getSchema().getProperty().getType().equals("float"));
+ isPropertyAppear = true;
+ break;
+
+ }
+ assertTrue(isPropertyAppear);
+ isPropertyAppear = false;
+ }
+
+ }
+
+ private void verifyRequirementsOccurrences(Resource resourceJavaObject, String requirementsType) {
+ boolean isRequirementAppear = false;
+ // List<RequirementDefinition> requerments =
+ // resourceJavaObject.getRequirements().get("tosca.capabilities.Attachment");
+ List<RequirementDefinition> requerments = resourceJavaObject.getRequirements().get(requirementsType);
+
+ for (RequirementDefinition req : requerments) {
+ switch (req.getName()) {
+ case "local_storage100":
+ assertTrue("Check Min Requirement Occurrences ", req.getMinOccurrences().equals("1"));
+ assertTrue("Check Max Requirement Occurrences ", req.getMaxOccurrences().equals("UNBOUNDED"));
+ isRequirementAppear = true;
+ break;
+ case "local_storage200":
+ assertTrue("Check Min Requirement Occurrences ", req.getMinOccurrences().equals("1"));
+ assertTrue("Check Max Requirement Occurrences ", req.getMaxOccurrences().equals("1"));
+ isRequirementAppear = true;
+ break;
+ case "local_storage300":
+ assertTrue("Check Min Requirement Occurrences ", req.getMinOccurrences().equals("1"));
+ assertTrue("Check Max Requirement Occurrences ", req.getMaxOccurrences().equals("10"));
+ isRequirementAppear = true;
+ break;
+ case "local_storage400":
+ assertTrue("Check Min Requirement Occurrences ", req.getMinOccurrences().equals("1"));
+ assertTrue("Check Max Requirement Occurrences ", req.getMaxOccurrences().equals("10000000"));
+ isRequirementAppear = true;
+ break;
+ case "local_storage500":
+ assertTrue("Check Min Requirement Occurrences ", req.getMinOccurrences().equals("2"));
+ assertTrue("Check Max Requirement Occurrences ", req.getMaxOccurrences().equals("3"));
+ isRequirementAppear = true;
+ break;
+ case "local_storageNoOccurrences600":
+ assertTrue("Check Min Requirement Occurrences ", req.getMinOccurrences().equals("1"));
+ assertTrue("Check Max Requirement Occurrences ", req.getMaxOccurrences().equals("1"));
+ isRequirementAppear = true;
+ break;
+ }
+ assertTrue(isRequirementAppear);
+ isRequirementAppear = false;
+ }
+
+ }
+
+ private void verifyCapabilitiesOccurrences(Resource resourceJavaObject, String capabilitType) {
+ boolean isCapabilityAppear = false;
+ // List<CapabilityDefinition> capabilities =
+ // resourceJavaObject.getCapabilities().get("tosca.capabilities.Endpoint.Admin");
+ List<CapabilityDefinition> capabilities = resourceJavaObject.getCapabilities().get(capabilitType);
+
+ for (CapabilityDefinition cap : capabilities) {
+ switch (cap.getName()) {
+ case "endpointNoOccurrence":
+ assertTrue("Check Min capability Occurrences ", cap.getMinOccurrences().equals("1"));
+ assertTrue("Check Max capability Occurrences ", cap.getMaxOccurrences().equals("UNBOUNDED"));
+ isCapabilityAppear = true;
+ break;
+ case "endpoint200":
+ assertTrue("Check Min capability Occurrences ", cap.getMinOccurrences().equals("1"));
+ assertTrue("Check Max capability Occurrences ", cap.getMaxOccurrences().equals("2"));
+ isCapabilityAppear = true;
+ break;
+ case "endpoint300":
+ assertTrue("Check Min capability Occurrences ", cap.getMinOccurrences().equals("1"));
+ assertTrue("Check Max capability Occurrences ", cap.getMaxOccurrences().equals("1"));
+ isCapabilityAppear = true;
+ break;
+ case "endpoint400":
+ assertTrue("Check Min capability Occurrences ", cap.getMinOccurrences().equals("1"));
+ assertTrue("Check Max capability Occurrences ", cap.getMaxOccurrences().equals("10"));
+ isCapabilityAppear = true;
+ break;
+ case "endpoint500":
+ assertTrue("Check Min capability Occurrences ", cap.getMinOccurrences().equals("1"));
+ assertTrue("Check Max capability Occurrences ", cap.getMaxOccurrences().equals("10000000"));
+ isCapabilityAppear = true;
+ break;
+ case "endpoint600":
+ assertTrue("Check Min capability Occurrences ", cap.getMinOccurrences().equals("1"));
+ assertTrue("Check Max capability Occurrences ", cap.getMaxOccurrences().equals("UNBOUNDED"));
+ isCapabilityAppear = true;
+ break;
+ case "endpoint700":
+ assertTrue("Check Min capability Occurrences ", cap.getMinOccurrences().equals("2"));
+ assertTrue("Check Max capability Occurrences ", cap.getMaxOccurrences().equals("4"));
+ isCapabilityAppear = true;
+ break;
+
+ }
+ assertTrue(isCapabilityAppear);
+ isCapabilityAppear = false;
+ }
+
+ }
+
+ private void verifyResourcePropertiesMap(Resource resourceJavaObject) { // use
+ // importMapPropertySuccessFlow.yml
+ boolean isPropertyAppear = false;
+ List<PropertyDefinition> propertiesList = resourceJavaObject.getProperties();
+ for (PropertyDefinition pro : propertiesList) {
+ switch (pro.getName()) {
+ case "string_prop01":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ",
+ pro.getDefaultValue().equals("{\"keyA\":\"val1\",\"keyB\":\"val2\"}"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("string"));
+ isPropertyAppear = true;
+ break;
+ case "string_prop02":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ",
+ pro.getDefaultValue().equals("{\"keyA\":\"val1\",\"keyB\":\"val2\"}"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("string"));
+ isPropertyAppear = true;
+ break;
+ case "string_prop03":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ",
+ pro.getDefaultValue().equals("{\"keyA\":\"val1\",\"keyB\":\"val2\"}"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("string"));
+ isPropertyAppear = true;
+ break;
+ case "string_prop04":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ",
+ pro.getDefaultValue().equals("{\"keyA\":\"10\",\"keyB\":\"true\"}"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("string"));
+ isPropertyAppear = true;
+ break;
+ case "string_prop05":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ",
+ pro.getDefaultValue().equals("{\"keyA\":null,\"keyB\":\"Big\"}"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("string"));
+ isPropertyAppear = true;
+ break;
+ case "string_prop06":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ",
+ pro.getDefaultValue().equals("{\"keyA\":\"aaaA\",\"keyB\":null}"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("string"));
+ isPropertyAppear = true;
+ break;
+ case "string_prop07":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ",
+ pro.getDefaultValue().equals("{\"keyA\":null,\"keyB\":null}"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("string"));
+ isPropertyAppear = true;
+ break;
+ case "string_prop08":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ",
+ pro.getDefaultValue().equals("{\"keyA\":\"\",\"keyB\":\"abcd\"}"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("string"));
+ isPropertyAppear = true;
+ break;
+ case "string_prop09":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ",
+ pro.getDefaultValue().equals("{\"keyA\":\" \",\"keyB\":\"abcd\"}"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("string"));
+ isPropertyAppear = true;
+ break;
+ case "string_prop10":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ",
+ pro.getDefaultValue().equals("{\"keyA\":\" aaaa\",\"keyB\":\" bbbb\"}"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("string"));
+ isPropertyAppear = true;
+ break;
+ case "string_prop11":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ",
+ pro.getDefaultValue().equals("{\"keyA\":\"aaaa \",\"keyB\":\"bbbb \"}"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("string"));
+ isPropertyAppear = true;
+ break;
+ case "string_prop12":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ",
+ pro.getDefaultValue().equals("{\"keyA\":\" aaaa \",\"keyB\":\" bbbb ccccc \"}"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("string"));
+ isPropertyAppear = true;
+ break;
+ case "string_prop13":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ", pro.getDefaultValue().equals("{\"keyA\":\"aaaa\"}"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("string"));
+ isPropertyAppear = true;
+ break;
+ case "string_prop14":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ", pro.getDefaultValue().equals("{\"keyA\":\" aaaa \"}"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("string"));
+ isPropertyAppear = true;
+ break;
+ case "string_prop15":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ", pro.getDefaultValue().equals("{\"keyA\":\"AbcD\"}"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("string"));
+ isPropertyAppear = true;
+ break;
+ case "string_prop16":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ", pro.getDefaultValue().equals("{\"keyA\":\"AbcD\"}"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("string"));
+ isPropertyAppear = true;
+ break;
+ case "string_prop17":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ", pro.getDefaultValue().equals("{\"keyA\":\"AbcD\"}"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("string"));
+ isPropertyAppear = true;
+ break;
+ case "string_prop18":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ", pro.getDefaultValue().equals("{\"keyA\":\"AbcD\"}"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("string"));
+ isPropertyAppear = true;
+ break;
+ case "string_prop19":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ", pro.getDefaultValue().equals("{\"keyA\":\"AbcD\"}"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("string"));
+ isPropertyAppear = true;
+ break;
+ case "string_prop20":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ", pro.getDefaultValue()
+ .equals("{\"keyA\":\"aaaa\",\"keya\":\"aaaa\",\"Keya\":\"Aaaa\",\"KEYA\":\"nnnn\"}"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("string"));
+ isPropertyAppear = true;
+ break;
+ case "string_prop21":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ",
+ pro.getDefaultValue().equals("{\"keyA\":null,\"keyB\":null,\"keyC\":null}"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("string"));
+ isPropertyAppear = true;
+ break;
+ case "string_prop22":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertEquals("Check Property default values ", pro.getDefaultValue(), null);
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("string"));
+ isPropertyAppear = true;
+ break;
+ case "integer_prop01":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ",
+ pro.getDefaultValue().equals("{\"keyA\":1,\"keyB\":1000}"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("integer"));
+ isPropertyAppear = true;
+ break;
+ case "integer_prop02":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ",
+ pro.getDefaultValue().equals("{\"keyA\":null,\"keyB\":null,\"keyC\":null}"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("integer"));
+ isPropertyAppear = true;
+ break;
+ case "integer_prop03":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ",
+ pro.getDefaultValue().equals("{\"keyA\":800,\"keyB\":-600}"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("integer"));
+ isPropertyAppear = true;
+ break;
+ case "integer_prop04":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ",
+ pro.getDefaultValue().equals("{\"keyA\":null,\"keyB\":-600}"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("integer"));
+ isPropertyAppear = true;
+ break;
+ case "integer_prop05":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ",
+ pro.getDefaultValue().equals("{\"keyA\":100,\"keyB\":0}"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("integer"));
+ isPropertyAppear = true;
+ break;
+ case "integer_prop06":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ",
+ pro.getDefaultValue().equals("{\"keyA\":100,\"keyB\":0}"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("integer"));
+ isPropertyAppear = true;
+ break;
+ case "integer_prop07":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ",
+ pro.getDefaultValue().equals("{\"keyA\":100,\"keyB\":100}"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("integer"));
+ isPropertyAppear = true;
+ break;
+ case "integer_prop08":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ",
+ pro.getDefaultValue().equals("{\"keyA\":100,\"keyB\":200}"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("integer"));
+ isPropertyAppear = true;
+ break;
+ case "integer_prop09":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ",
+ pro.getDefaultValue().equals("{\"keyA\":100,\"keyB\":200}"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("integer"));
+ isPropertyAppear = true;
+ break;
+ case "integer_prop10":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ",
+ pro.getDefaultValue().equals("{\"keyA\":null,\"keyB\":2222}"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("integer"));
+ isPropertyAppear = true;
+ break;
+ case "integer_prop11":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ",
+ pro.getDefaultValue().equals("{\"keyA\":null,\"keyB\":null,\"keyC\":null,\"keyD\":null}"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("integer"));
+ isPropertyAppear = true;
+ break;
+ case "integer_prop12":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertEquals("Check Property default values ", pro.getDefaultValue(), null);
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("integer"));
+ isPropertyAppear = true;
+ break;
+ case "integer_prop13":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ", pro.getDefaultValue().equals("{\"keyA\":200}"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("integer"));
+ isPropertyAppear = true;
+ break;
+ case "boolean_prop01":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ",
+ pro.getDefaultValue().equals("{\"keyA\":true,\"keyB\":false,\"keyC\":false}"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("boolean"));
+ isPropertyAppear = true;
+ break;
+ case "boolean_prop02":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ",
+ pro.getDefaultValue().equals("{\"keyA\":true,\"keyB\":false,\"keyC\":false}"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("boolean"));
+ isPropertyAppear = true;
+ break;
+ case "boolean_prop03":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ",
+ pro.getDefaultValue().equals("{\"keyA\":null,\"keyB\":null,\"keyC\":null,\"keyD\":null}"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("boolean"));
+ isPropertyAppear = true;
+ break;
+ case "boolean_prop04":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ",
+ pro.getDefaultValue().equals("{\"keyA\":null,\"keyB\":null,\"keyC\":null,\"keyD\":null}"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("boolean"));
+ isPropertyAppear = true;
+ break;
+ case "boolean_prop05":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ",
+ pro.getDefaultValue().equals("{\"keyA\":true,\"keyB\":false,\"keyC\":false}"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("boolean"));
+ isPropertyAppear = true;
+ break;
+ case "boolean_prop06":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ",
+ pro.getDefaultValue().equals("{\"keyA\":true,\"keyB\":true,\"keyC\":false}"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("boolean"));
+ isPropertyAppear = true;
+ break;
+ case "boolean_prop07":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertEquals("Check Property default values ", pro.getDefaultValue(), null);
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("boolean"));
+ isPropertyAppear = true;
+ break;
+ case "boolean_prop08":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ",
+ pro.getDefaultValue().equals("{\"keyA\":true,\"keyB\":false}"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("boolean"));
+ isPropertyAppear = true;
+ break;
+ case "boolean_prop09":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ",
+ pro.getDefaultValue().equals("{\"keyA\":false,\"keyB\":true}"));
+ assertTrue("Check entrySchema Property Type ",
+ pro.getSchema().getProperty().getType().equals("boolean"));
+ isPropertyAppear = true;
+ break;
+ case "float_prop01":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ",
+ pro.getDefaultValue().equals("{\"keyA\":1.2,\"keyB\":3.56,\"keyC\":33}"));
+ assertTrue("Check entrySchema Property Type ", pro.getSchema().getProperty().getType().equals("float"));
+ isPropertyAppear = true;
+ break;
+ case "float_prop02":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ",
+ pro.getDefaultValue().equals("{\"keyA\":0.0,\"keyB\":0.0,\"keyC\":0}"));
+ assertTrue("Check entrySchema Property Type ", pro.getSchema().getProperty().getType().equals("float"));
+ isPropertyAppear = true;
+ break;
+ case "float_prop03":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ",
+ pro.getDefaultValue().equals("{\"keyA\":null,\"keyB\":null,\"keyC\":null,\"keyD\":null}"));
+ assertTrue("Check entrySchema Property Type ", pro.getSchema().getProperty().getType().equals("float"));
+ isPropertyAppear = true;
+ break;
+ case "float_prop04":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ",
+ pro.getDefaultValue().equals("{\"keyA\":1.2,\"keyB\":3.56,\"keyC\":33}"));
+ assertTrue("Check entrySchema Property Type ", pro.getSchema().getProperty().getType().equals("float"));
+ isPropertyAppear = true;
+ break;
+ case "float_prop05":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ",
+ pro.getDefaultValue().equals("{\"keyA\":33,\"keyB\":1.2,\"keyC\":3.607,\"keyD\":0}"));
+ assertTrue("Check entrySchema Property Type ", pro.getSchema().getProperty().getType().equals("float"));
+ isPropertyAppear = true;
+ break;
+ case "float_prop06":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ",
+ pro.getDefaultValue().equals("{\"keyA\":33,\"keyB\":1.2,\"keyC\":3.607}"));
+ assertTrue("Check entrySchema Property Type ", pro.getSchema().getProperty().getType().equals("float"));
+ isPropertyAppear = true;
+ break;
+ case "float_prop07":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ",
+ pro.getDefaultValue().equals("{\"keyA\":null,\"keyB\":null,\"keyC\":null,\"keyD\":null}"));
+ assertTrue("Check entrySchema Property Type ", pro.getSchema().getProperty().getType().equals("float"));
+ isPropertyAppear = true;
+ break;
+ case "float_prop08":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertEquals("Check Property default values ", pro.getDefaultValue(), null);
+ assertTrue("Check entrySchema Property Type ", pro.getSchema().getProperty().getType().equals("float"));
+ isPropertyAppear = true;
+ break;
+ case "float_prop09":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ",
+ pro.getDefaultValue().equals("{\"keyA\":0.01,\"keyB\":null}"));
+ assertTrue("Check entrySchema Property Type ", pro.getSchema().getProperty().getType().equals("float"));
+ isPropertyAppear = true;
+ break;
+ case "float_prop10":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ", pro.getDefaultValue().equals("{\"keyA\":0.00020}"));
+ assertTrue("Check entrySchema Property Type ", pro.getSchema().getProperty().getType().equals("float"));
+ isPropertyAppear = true;
+ break;
+ case "float_prop11":
+ assertTrue("Check Property Type ", pro.getType().equals("map"));
+ assertTrue("Check Property default values ",
+ pro.getDefaultValue().equals("{\"keyA\":3.56,\"keyB\":33}"));
+ assertTrue("Check entrySchema Property Type ", pro.getSchema().getProperty().getType().equals("float"));
+ isPropertyAppear = true;
+ break;
+ }
+ assertTrue(isPropertyAppear);
+ isPropertyAppear = false;
+ }
+
+ }
+
+ @Test
+ public void importToscaResourceAttributeSuccessFlow() throws Exception {
+
+ String fileName = importAttributeSuccess;
+ importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, testResourcesPath,
+ fileName);
+ RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, sdncUserDetails,
+ null);
+ ResourceRestUtils.checkCreateResponse(importResourceResponse);
+ Resource resourceJavaObject = ResponseParser
+ .convertResourceResponseToJavaObject(importResourceResponse.getResponse());
+ ToscaNodeTypeInfo parseToscaNodeYaml = utils
+ .parseToscaNodeYaml(Decoder.decode(importReqDetails.getPayloadData()));
+
+ HashMap<String, PropertyDefinition> attr = new HashMap<>();
+
+ PropertyDefinition newAttr2 = new PropertyDefinition();
+ newAttr2.setName("networks");
+ newAttr2.setType("map");
+ newAttr2.setDefaultValue("{\"keyA\" : val1 , \"keyB\" : val2}");
+ SchemaDefinition schema = new SchemaDefinition();
+ PropertyDataDefinition prop = new PropertyDataDefinition();
+ prop.setType("string");
+ schema.setProperty(prop);
+ newAttr2.setSchema(schema);
+ attr.put("networks", newAttr2);
+
+ PropertyDefinition newAttr1 = new PropertyDefinition();
+ newAttr1.setName("public_address");
+ newAttr1.setType("string");
+ attr.put("public_address", newAttr1);
+
+ PropertyDefinition newAttr3 = new PropertyDefinition();
+ newAttr3.setName("ports");
+ newAttr3.setDescription("this is my description");
+ attr.put("ports", newAttr3);
+
+ PropertyDefinition newAttr = new PropertyDefinition();
+ newAttr.setDefaultValue("myDefault");
+ newAttr.setName("private_address");
+ newAttr.setStatus("supported");
+ newAttr.setType("string");
+ attr.put("private_address", newAttr);
+
+ // verify Resource Attributes
+ validateResourceAttribute(resourceJavaObject, attr);
+
+ // TO DO
+ ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = ElementFactory
+ .getDefaultImportResourceAuditMsgSuccess();
+ expectedResourceAuditJavaObject.setResourceName(importReqDetails.getName());
+ expectedResourceAuditJavaObject.setModifierName(sdncUserDetails.getFullName());
+ expectedResourceAuditJavaObject.setModifierUid(sdncUserDetails.getUserId());
+ expectedResourceAuditJavaObject.setToscaNodeType(parseToscaNodeYaml.getNodeName());
+ AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject,
+ AuditingActionEnum.IMPORT_RESOURCE.getName(), null, false);
+ }
+
+ private void validateResourceAttribute(Resource resource, Map<String, PropertyDefinition> attr) {
+ List<PropertyDefinition> resList = resource.getAttributes();
+ int size = resList.size();
+ String attributeName;
+ for (int i = 0; i < size; i++) {
+ attributeName = resList.get(i).getName();
+ assertEquals(attr.get(attributeName).getDefaultValue(), resList.get(i).getDefaultValue());
+ assertEquals(attr.get(attributeName).getName(), resList.get(i).getName());
+ assertEquals(attr.get(attributeName).getDescription(), resList.get(i).getDescription());
+ assertEquals(attr.get(attributeName).getStatus(), resList.get(i).getStatus());
+ }
+ }
+
+}
diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/ImportUpdateResourseCsarTest.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/ImportUpdateResourseCsarTest.java
new file mode 100644
index 0000000000..464ebe12ed
--- /dev/null
+++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/ImportUpdateResourseCsarTest.java
@@ -0,0 +1,283 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * 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.openecomp.sdc.ci.tests.execute.imports;
+
+import static org.testng.AssertJUnit.assertTrue;
+import static org.testng.AssertJUnit.assertEquals;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.List;
+import java.util.regex.Pattern;
+
+import org.apache.commons.codec.binary.Base64;
+import org.junit.Rule;
+import org.junit.rules.TestName;
+import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
+import org.openecomp.sdc.be.model.GroupDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
+import org.openecomp.sdc.ci.tests.datatypes.ImportReqDetails;
+import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
+import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
+import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
+import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
+import org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils;
+import org.openecomp.sdc.ci.tests.utils.rest.LifecycleRestUtils;
+import org.openecomp.sdc.ci.tests.utils.rest.ResourceRestUtils;
+import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
+import org.openecomp.sdc.common.api.Constants;
+import org.testng.annotations.Test;
+
+import com.google.gson.Gson;
+
+public class ImportUpdateResourseCsarTest extends ComponentBaseTest {
+ @Rule
+ public static TestName name = new TestName();
+
+ Gson gson = new Gson();
+ public static String userDefinedNodeYaml = "mycompute2.yml";
+ public static String rootPath = System.getProperty("user.dir");
+ public static String csarFolderPath = "/src/test/resources/CI/csars/";
+
+ public ImportUpdateResourseCsarTest() {
+ super(name, ImportUpdateResourseCsarTest.class.getName());
+ }
+
+ @Test
+ public void createUpdateImportResourceFromCsarTest() throws Exception {
+ User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
+ ImportReqDetails resourceDetails = ElementFactory.getDefaultImportResource();
+ RestResponse updateResource = null;
+ RestResponse createResource = null;
+ Resource resource = null;
+ String payloadName = "orig2G.csar";
+ String rootPath = System.getProperty("user.dir");
+ Path path = Paths.get(rootPath + csarFolderPath + "orig2G.csar");
+ byte[] data = Files.readAllBytes(path);
+ String payloadData = Base64.encodeBase64String(data);
+ resourceDetails.setPayloadData(payloadData);
+ resourceDetails.setPayloadName(payloadName);
+ resourceDetails.setName("TEST01");
+ resourceDetails.setCsarUUID("orig2G.csar");
+ resourceDetails.setCsarVersion("1");
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ // create new resource from Csar
+ createResource = ResourceRestUtils.createResource(resourceDetails, sdncModifierDetails);
+ BaseRestUtils.checkCreateResponse(createResource);
+ resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
+ // update scar with new artifacts
+ path = Paths.get(rootPath + csarFolderPath + "orig2G_update.csar");
+ data = Files.readAllBytes(path);
+ payloadData = Base64.encodeBase64String(data);
+ resourceDetails.setDescription("update");
+ resourceDetails.setCsarVersion("2");
+ updateResource = ResourceRestUtils.updateResource(resourceDetails, sdncModifierDetails,
+ resourceDetails.getUniqueId());
+ BaseRestUtils.checkSuccess(updateResource);
+ resource = ResponseParser.parseToObjectUsingMapper(updateResource.getResponse(), Resource.class);
+ }
+
+ @Test
+ public void createUpdateImportResourceFromCsarWithArtifactsGroupNamingTest() throws Exception {
+ User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
+ RestResponse copyRes;
+ ResourceReqDetails resourceDetails;
+ RestResponse updateResource;
+ RestResponse createResource;
+ Resource resource;
+
+ // back original scar
+ copyRes = ImportCsarResourceTest.copyCsarRest(sdncModifierDetails,
+ "VF_RI2_G4_withArtifacts_group_naming_a.csar", "VF_RI2_G4_withArtifacts_group_naming.csar");
+ BaseRestUtils.checkSuccess(copyRes);
+
+ resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setName("TEST01");
+ resourceDetails.setCsarUUID("VF_RI2_G4_withArtifacts_group_naming.csar");
+ resourceDetails.setCsarVersion("1");
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ // create new resource from Csar
+ createResource = ResourceRestUtils.createResource(resourceDetails, sdncModifierDetails);
+ BaseRestUtils.checkCreateResponse(createResource);
+ resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
+ List<GroupDefinition> groups = resource.getGroups();
+ assertTrue(groups != null && groups.size() == 6);
+ assertTrue(groups.stream()
+ .filter(g -> g.getType().equals(Constants.DEFAULT_GROUP_VF_MODULE)
+ && !Pattern.compile(Constants.MODULE_NEW_NAME_PATTERN).matcher(g.getName()).matches())
+ .count() == 0);
+ // update scar
+ copyRes = ImportCsarResourceTest.copyCsarRest(sdncModifierDetails,
+ "VF_RI2_G4_withArtifacts_group_naming_delete_update.csar", "VF_RI2_G4_withArtifacts_group_naming.csar");
+ BaseRestUtils.checkSuccess(copyRes);
+ resourceDetails.setDescription("BLA BLA BLA");
+ resourceDetails.setCsarVersion("2");
+ updateResource = ResourceRestUtils.updateResource(resourceDetails, sdncModifierDetails,
+ resourceDetails.getUniqueId());
+ BaseRestUtils.checkSuccess(updateResource);
+ resource = ResponseParser.parseToObjectUsingMapper(updateResource.getResponse(), Resource.class);
+ groups = resource.getGroups();
+ assertTrue(groups != null && groups.size() == 5);
+ // back original scar
+ copyRes = ImportCsarResourceTest.copyCsarRest(sdncModifierDetails,
+ "VF_RI2_G4_withArtifacts_group_naming_a.csar", "VF_RI2_G4_withArtifacts_group_naming.csar");
+ BaseRestUtils.checkSuccess(copyRes);
+ resourceDetails.setDescription("BLA BLA BLA");
+ resourceDetails.setCsarVersion("3");
+ updateResource = ResourceRestUtils.updateResource(resourceDetails, sdncModifierDetails,
+ resourceDetails.getUniqueId());
+ BaseRestUtils.checkSuccess(updateResource);
+ resource = ResponseParser.parseToObjectUsingMapper(updateResource.getResponse(), Resource.class);
+ groups = resource.getGroups();
+ assertTrue(groups != null && groups.size() == 6);
+ assertTrue(groups.stream()
+ .filter(g -> g.getType().equals(Constants.DEFAULT_GROUP_VF_MODULE)
+ && !Pattern.compile(Constants.MODULE_NEW_NAME_PATTERN).matcher(g.getName()).matches())
+ .count() == 0);
+ }
+
+ @Test
+ public void createUpdateDeleteAllRequiredArtifactsTest() throws Exception {
+ User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
+ RestResponse copyRes;
+ ResourceReqDetails resourceDetails;
+ RestResponse updateResource;
+ RestResponse createResource;
+ Resource resource;
+ String artifactName = "heatnested7";
+
+ ImportReqDetails resourceDetails0 = ElementFactory.getDefaultImportResource();
+ createResource = importUserDefinedNodeType(userDefinedNodeYaml, sdncModifierDetails, resourceDetails0);
+ BaseRestUtils.checkCreateResponse(createResource);
+ resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
+
+ // back original scar
+ copyRes = ImportCsarResourceTest.copyCsarRest(sdncModifierDetails, "orig2GV001_a.csar", "orig2GV001.csar");
+ BaseRestUtils.checkSuccess(copyRes);
+
+ resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setName("TEST01");
+ resourceDetails.setCsarUUID("orig2GV001.csar");
+ resourceDetails.setCsarVersion("1");
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ // create new resource from Csar
+ createResource = ResourceRestUtils.createResource(resourceDetails, sdncModifierDetails);
+
+ BaseRestUtils.checkCreateResponse(createResource);
+ resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
+ assertTrue(resource.getDeploymentArtifacts().get(artifactName).getRequiredArtifacts().size() == 2);
+ List<GroupDefinition> groups = resource.getGroups();
+ // update scar
+ copyRes = ImportCsarResourceTest.copyCsarRest(sdncModifierDetails,
+ "orig2GV006-remove-all-nested-artifacts.csar", "orig2GV001.csar");
+ BaseRestUtils.checkSuccess(copyRes);
+ resourceDetails.setDescription("BLA BLA BLA");
+ resourceDetails.setCsarVersion("2");
+ updateResource = ResourceRestUtils.updateResource(resourceDetails, sdncModifierDetails,
+ resourceDetails.getUniqueId());
+ BaseRestUtils.checkSuccess(updateResource);
+ resource = ResponseParser.parseToObjectUsingMapper(updateResource.getResponse(), Resource.class);
+ assertTrue(resource.getDeploymentArtifacts().get(artifactName).getRequiredArtifacts().size() == 0);
+ groups = resource.getGroups();
+ // back original scar
+ copyRes = ImportCsarResourceTest.copyCsarRest(sdncModifierDetails, "orig2GV001_a.csar", "orig2GV001.csar");
+ BaseRestUtils.checkSuccess(copyRes);
+ }
+
+ // First create from orig2GV006-remove-all-nested-artifacts.csar (without
+ // requiredArtifact)
+ // Submit for testing
+ // Login as tester -> Certification
+ // Login as designer
+ // then update to orig2GV008-change-nested-oam-fileContent.csar (with
+ // requiredArtifact)
+ // Expected: requiredArtifact: ["hot-nimbus-psm_v1.0.yaml",
+ // "hot-nimbus-swift-container_v1.0.yaml"]
+ // Actual: no requiredArtifact
+ @Test
+ public void createUpdateAddRequiredArtifactsTest() throws Exception {
+ User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
+ RestResponse copyRes;
+ ResourceReqDetails resourceDetails;
+ RestResponse updateResource;
+ RestResponse createResource;
+ Resource resource;
+ String artifactName = "heatnested7";
+
+ ImportReqDetails resourceDetails0 = ElementFactory.getDefaultImportResource();
+ createResource = importUserDefinedNodeType(userDefinedNodeYaml, sdncModifierDetails, resourceDetails0);
+ BaseRestUtils.checkCreateResponse(createResource);
+ createResource = LifecycleRestUtils.certifyResource(resourceDetails0);
+ BaseRestUtils.checkSuccess(createResource);
+
+ // back original scar
+ copyRes = ImportCsarResourceTest.copyCsarRest(sdncModifierDetails,
+ "orig2GV006-remove-all-nested-artifacts.csar", "orig2GV001.csar");
+ BaseRestUtils.checkSuccess(copyRes);
+
+ resourceDetails = ElementFactory.getDefaultResource();
+ resourceDetails.setName("TEST01");
+ resourceDetails.setCsarUUID("orig2GV001.csar");
+ resourceDetails.setCsarVersion("1");
+ resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
+ // create new resource from Csar
+ createResource = ResourceRestUtils.createResource(resourceDetails, sdncModifierDetails);
+ BaseRestUtils.checkCreateResponse(createResource);
+ createResource = LifecycleRestUtils.certifyResource(resourceDetails);
+ BaseRestUtils.checkSuccess(createResource);
+
+ resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
+ assertTrue(resource.getDeploymentArtifacts().get(artifactName).getRequiredArtifacts().size() == 0);
+ List<GroupDefinition> groups = resource.getGroups();
+ // update scar
+ copyRes = ImportCsarResourceTest.copyCsarRest(sdncModifierDetails,
+ "orig2GV008-change-nested-oam-fileContent.csar", "orig2GV001.csar");
+ BaseRestUtils.checkSuccess(copyRes);
+ resourceDetails.setDescription("BLA BLA BLA");
+ resourceDetails.setCsarVersion("2");
+ updateResource = ResourceRestUtils.updateResource(resourceDetails, sdncModifierDetails,
+ resourceDetails.getUniqueId());
+ BaseRestUtils.checkSuccess(updateResource);
+ resource = ResponseParser.parseToObjectUsingMapper(updateResource.getResponse(), Resource.class);
+ assertTrue(resource.getDeploymentArtifacts().get(artifactName).getRequiredArtifacts().size() == 2);
+ groups = resource.getGroups();
+ // back original scar
+ copyRes = ImportCsarResourceTest.copyCsarRest(sdncModifierDetails, "orig2GV001_a.csar", "orig2GV001.csar");
+ BaseRestUtils.checkSuccess(copyRes);
+ }
+
+ private RestResponse importUserDefinedNodeType(String payloadName, User sdncModifierDetails,
+ ImportReqDetails resourceDetails) throws Exception {
+
+ Path path = Paths.get(rootPath + csarFolderPath + payloadName);
+ byte[] data = Files.readAllBytes(path);
+ String payloadData = Base64.encodeBase64String(data);
+ resourceDetails.setPayloadData(payloadData);
+
+ resourceDetails.setPayloadName(payloadName);
+ resourceDetails.setResourceType(ResourceTypeEnum.VFC.name());
+ return ResourceRestUtils.createResource(resourceDetails, sdncModifierDetails);
+ }
+
+}