diff options
Diffstat (limited to 'test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/devCI')
6 files changed, 1551 insertions, 0 deletions
diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/devCI/AndreyTest.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/devCI/AndreyTest.java new file mode 100644 index 0000000000..8a5fe91065 --- /dev/null +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/devCI/AndreyTest.java @@ -0,0 +1,104 @@ +/*- + * ============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.devCI; + +import java.io.File; +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.LinkedHashMap; +import java.util.List; + +import org.openecomp.sdc.ci.tests.datatypes.GroupHeatMetaDefinition; +import org.openecomp.sdc.ci.tests.datatypes.HeatMetaFirstLevelDefinition; +import org.openecomp.sdc.ci.tests.datatypes.TypeHeatMetaDefinition; +import org.openecomp.sdc.ci.tests.tosca.datatypes.ToscaDefinition; +import org.openecomp.sdc.ci.tests.utils.CsarParserUtils; +import org.openecomp.sdc.ci.tests.utils.ToscaParserUtils; +import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper; +import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; +import org.openecomp.sdc.tosca.parser.impl.SdcToscaParserFactory; +//import org.openecomp.sdc.toscaparser.api.Metadata; +import org.openecomp.sdc.toscaparser.api.Capability; +import org.openecomp.sdc.toscaparser.api.NodeTemplate; +import org.openecomp.sdc.toscaparser.api.common.JToscaException; +import org.testng.annotations.Test; + +public class AndreyTest { + + public static void main(String[] args) throws Exception { + ToscaDefinition toscaDefinition; + System.out.println("start " + new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date())); +// File path = new File("C:/Data/D2.0/TOSCA_Ex/Definitions/tosca_definition_version.yaml"); +// File path = new File("C:/Data/D2.0/TOSCA_Ex/resource-Vl11Vl10-template.yml"); + File path = new File("C:/Data/D2.0/TOSCA_Ex/service-Servicepxtc-template US822998.yml"); + File csarPath = new File("C:/Data/D2.0/TOSCA_Ex/Nested.csar"); + + toscaDefinition = ToscaParserUtils.parseToscaYamlToJavaObject(path); + System.out.println("listTypeHeatMetaDefinition start " + new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date())); + List<TypeHeatMetaDefinition> listTypeHeatMetaDefinition = CsarParserUtils.getListTypeHeatMetaDefinition(csarPath); + System.out.println("get service start " + new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date())); + System.out.println(listTypeHeatMetaDefinition); + for(TypeHeatMetaDefinition typeHeatMetaDefinition : listTypeHeatMetaDefinition){ + for(GroupHeatMetaDefinition groupHeatMetaDefinition : typeHeatMetaDefinition.getGroupHeatMetaDefinition()){ + List<HeatMetaFirstLevelDefinition> artifactList = groupHeatMetaDefinition.getArtifactList(); + boolean isBase = groupHeatMetaDefinition.getPropertyHeatMetaDefinition().getValue(); + } + + } + System.out.println("Finished"); + System.out.println("get service start " + new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date())); + } + + + @Test + public void distributionTest() throws SdcToscaParserException, JToscaException, IOException { + //String serviceName = import and create().getName(); + //getServiceObject(); + //parseServiceObject(); + + + + SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance(); + long startTime = System.currentTimeMillis(); + long estimatedTime = System.currentTimeMillis() - startTime; + System.out.println("Time to init factory " + estimatedTime); + String fileStr1 = "src//test//resources//CI//csars//service-ServiceFdnt-csar-0904-2.csar";//ToscaParserStubsTest.class.getClassLoader().getResource("csars/service-ServiceFdnt-csar-0904-2.csar").getFile(); + File file1 = new File(fileStr1); + String name = file1.getName(); + String absolutePath = file1.getAbsolutePath(); + ISdcCsarHelper fdntCsarHelper = factory.getSdcCsarHelper(file1.getAbsolutePath()); + + List<NodeTemplate> serviceVfList = fdntCsarHelper.getServiceVfList(); + serviceVfList.size(); + for (NodeTemplate nodeTemplate : serviceVfList) { + ArrayList<Object> requirements = nodeTemplate.getRequirements(); + requirements.size(); + LinkedHashMap<String, Capability> capabilities = nodeTemplate.getCapabilities(); + ArrayList<Object> requirements2 = nodeTemplate.getRequirements(); + + System.out.println(nodeTemplate.getName()); + } + + } + +} diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/devCI/ArtifactFromCsar.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/devCI/ArtifactFromCsar.java new file mode 100644 index 0000000000..c3346952b2 --- /dev/null +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/devCI/ArtifactFromCsar.java @@ -0,0 +1,301 @@ +/*- + * ============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.devCI; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.file.DirectoryStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.text.SimpleDateFormat; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.stream.Collectors; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; + +import org.apache.commons.codec.digest.DigestUtils; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.IOUtils; +import org.openecomp.sdc.ci.tests.datatypes.GroupHeatMetaDefinition; +import org.openecomp.sdc.ci.tests.datatypes.HeatMetaFirstLevelDefinition; +import org.openecomp.sdc.ci.tests.datatypes.TypeHeatMetaDefinition; +import org.openecomp.sdc.ci.tests.utils.CsarParserUtils; + +public class ArtifactFromCsar { + + + public static void main(String[] args) throws Exception { + // TODO Auto-generated method stub + String zipFile = "C:\\Users\\rp955r\\Documents\\InTesting\\resource-CivfonboardedFdnt2f792348-csar.csar"; + +// Map<String, Object> combinedMap = combineHeatArtifacstWithFolderArtifacsToMap(zipFile); + + Map<String, Object> vfcArtifacts = ArtifactFromCsar.getVFCArtifacts(zipFile); + + System.out.println("1234o"); + } + + public static Map<String, Object> combineHeatArtifacstWithFolderArtifacsToMap(String pathToCsar) throws Exception { + return combineHeatArtifacstWithFolderArtifacsToMap(pathToCsar, "output"); + } + + public static Map<String, Object> combineHeatArtifacstWithFolderArtifacsToMap(String pathToCsar, String outputCsar) throws Exception { + File csarFile = new File(pathToCsar); + + + File dir = new File(csarFile.getParent() + File.separator + outputCsar); + dir.mkdir(); + if(!dir.exists()) { + } + + String outputFolder = dir.getPath(); + unZip(pathToCsar, outputFolder); + File directory = new File(outputFolder + File.separator + "Artifacts" + File.separator ); + + Map<String, Object> artifactsMap = combineHeatArtifacstWithFolderArtifacsToMap(getMapArtifactFromFolderStructure(directory), getDeploymentArtifactListFromHeatMeta(csarFile, directory)); + FileUtils.cleanDirectory(new File(outputFolder)); + + return artifactsMap; + } + + public static Map<String, Object> getVFCArtifacts(String pathToCsar) throws Exception{ + String outputFolder = unzipCsarFile(pathToCsar); + File directory = new File(outputFolder + File.separator + "Artifacts" + File.separator ); + Map<String, Object> artifactsMap = getMapArtifactFromFolderStructure(directory); + cleanFolders(outputFolder); + + return artifactsMap; + } + + private static Map<String, Object> combineHeatArtifacstWithFolderArtifacsToMap(Map<String, Object> map, List<HeatMetaFirstLevelDefinition> rlist) { + if(map.get("Deployment") != null) { + rlist.addAll((Collection<? extends HeatMetaFirstLevelDefinition>) map.get("Deployment")); + } + map.put("Deployment", rlist); + return map; + } + + private static List<HeatMetaFirstLevelDefinition> getDeploymentArtifactListFromHeatMeta(File pathToCsar, File directory) throws Exception { + List<HeatMetaFirstLevelDefinition> artifactList = new LinkedList<HeatMetaFirstLevelDefinition>(); + + List<TypeHeatMetaDefinition> listTypeHeatMetaDefinition = CsarParserUtils.getListTypeHeatMetaDefinition(pathToCsar); + + for(TypeHeatMetaDefinition typeHeatMetaDefinition : listTypeHeatMetaDefinition){ + for(GroupHeatMetaDefinition groupHeatMetaDefinition : typeHeatMetaDefinition.getGroupHeatMetaDefinition()){ + artifactList.addAll(groupHeatMetaDefinition.getArtifactList()); + } + } + + List<HeatMetaFirstLevelDefinition> listArtifactWithTypesByList = getListArtifactWithTypesByList(directory, artifactList); + return listArtifactWithTypesByList; +// return artifactList; + + } + + private static Map<String, Object> getMapArtifactFromFolderStructure(File pathToArtifactFolder) throws IOException { + + Map<String, Object> map = new HashMap<String, Object>(); + + + final Path dir = Paths.get(pathToArtifactFolder.getPath()); + final DirectoryStream<Path> dirStream = Files.newDirectoryStream(dir); + + dirStream.forEach(currFile -> { + File file = currFile.toFile(); + if (file.isDirectory()) { + System.out.println(file.getName()); + if(file.getName().toLowerCase().equals("deployment") || file.getName().toLowerCase().equals("informational")) { + map.put(file.getName(), getListArtifactWithTypes(file)); + } else { + try { + map.put(file.getName(), getMapArtifactFromFolderStructure(file)); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + }); + + dirStream.close(); + + + +// +// File[] fileList = pathToArtifactFolder.listFiles(); +// for(File file: fileList) { +// if (file.isDirectory()) { +// +// System.out.println(file.getName()); +// if(file.getName().equals("Deployment") || file.getName().equals("Informational")) { +// map.put(file.getName(), getListArtifactWithTypes(file)); +// } else { +// map.put(file.getName(), getMapArtifactFromFolderStructure(file)); +// } +// } +// } + return map; + } + + + + private static List<HeatMetaFirstLevelDefinition> getListArtifactWithTypes(File folderPath) { + List<HeatMetaFirstLevelDefinition> artifactList = new LinkedList<HeatMetaFirstLevelDefinition>(); + + File[] fileList = folderPath.listFiles(); + + for(File file: fileList) { + File[] artifacts = file.listFiles(); + + for(File artifact: artifacts) { +// HeatMetaFirstLevelDefinition heatMetaFirstLevelDefinition = new HeatMetaFirstLevelDefinition(file.getName(), artifact.getName()); + HeatMetaFirstLevelDefinition heatMetaFirstLevelDefinition = new HeatMetaFirstLevelDefinition(artifact.getName(), file.getName(), crunchifyGetMd5ForFile(artifact)); + artifactList.add(heatMetaFirstLevelDefinition); + } + } + + return artifactList; + } + + private static List<HeatMetaFirstLevelDefinition> getListArtifactWithTypesByList(File folderPath, List<HeatMetaFirstLevelDefinition> artifactLogicList) { + + + File[] fileList = folderPath.listFiles(); + + + + for (HeatMetaFirstLevelDefinition heatMetaFirstLevelDefinition : artifactLogicList) { + + String fileName = heatMetaFirstLevelDefinition.getFileName(); + + for (File fileFromFolder : fileList) { + if ( fileFromFolder.getName().equals(fileName)){ + heatMetaFirstLevelDefinition.setCheckSum(crunchifyGetMd5ForFile(fileFromFolder)); + } + + } + } + + return artifactLogicList; + } + + public static String crunchifyGetMd5ForFile(File crunchifyFile) { + String crunchifyValue = null; + FileInputStream crunchifyInputStream = null; + try { + crunchifyInputStream = new FileInputStream(crunchifyFile); + + // md5Hex converts an array of bytes into an array of characters representing the hexadecimal values of each byte in order. + // The returned array will be double the length of the passed array, as it takes two characters to represent any given byte. + crunchifyValue = DigestUtils.md5Hex(IOUtils.toByteArray(crunchifyInputStream)); + } catch (IOException e) { + e.printStackTrace(); + } finally { + IOUtils.closeQuietly(crunchifyInputStream); + } + return crunchifyValue; + } + + public static void unZip(String zipFile, String outputFolder) { + byte[] buffer = new byte[1024]; + + try{ + File folder = new File(outputFolder); + + if(!folder.exists()){ + folder.mkdir(); + } + + ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFile)); + ZipEntry ze = zis.getNextEntry(); + + while(ze!=null){ + + String fileName = ze.getName(); + File newFile = new File(outputFolder + File.separator + fileName); + + if(ze.isDirectory()) { + newFile.mkdir(); + ze = zis.getNextEntry(); + continue; + } + + new File(newFile.getParent()).mkdirs(); + FileOutputStream fos = new FileOutputStream(newFile); + + int len; + while ((len = zis.read(buffer)) > 0) { + fos.write(buffer, 0, len); + } + + fos.close(); + ze = zis.getNextEntry(); + } + + zis.closeEntry(); + zis.close(); + + } catch (IOException ex) { + ex.printStackTrace(); + } + + } + + private static void cleanFolders(String outputFolder) throws IOException { + System.gc(); + FileUtils.cleanDirectory(new File(outputFolder)); + FileUtils.deleteDirectory(new File(outputFolder)); + } + + private static String unzipCsarFile(String pathToCsar) { + File csarFile = new File(pathToCsar); + + + File dir = new File(csarFile.getParent() + File.separator + "output-" + UUID.randomUUID()); + if(!dir.exists()) { + dir.mkdirs(); + } + + String outputFolder = dir.getPath(); + ArtifactFromCsar.unZip(pathToCsar, outputFolder); + return outputFolder; + } + + public static String[] getArtifactNamesFromCsar(String path, String csarFile) throws Exception { + Map<String, Object> combinedMap = combineHeatArtifacstWithFolderArtifacsToMap(path + csarFile); + LinkedList<HeatMetaFirstLevelDefinition> deploymentArtifacts = ((LinkedList<HeatMetaFirstLevelDefinition>) combinedMap.get("Deployment")); + List<String> artifactNamesList = deploymentArtifacts.stream().map(e -> e.getFileName()).collect(Collectors.toList()); + Object[] artifactNamesObjectArr = artifactNamesList.toArray(); + String[] artifactNamesFromFile = Arrays.copyOf(artifactNamesObjectArr, artifactNamesObjectArr.length, String[].class); + return artifactNamesFromFile; + } + +} diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/devCI/ImportCsarUpdate.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/devCI/ImportCsarUpdate.java new file mode 100644 index 0000000000..f66fd670f6 --- /dev/null +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/devCI/ImportCsarUpdate.java @@ -0,0 +1,362 @@ +/*- + * ============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.devCI; + +import static org.testng.AssertJUnit.assertTrue; + +import org.junit.Rule; +import org.junit.rules.TestName; +import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; +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.ResourceReqDetails; +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.NormativeTypesEnum; +import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum; +import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse; +import org.openecomp.sdc.ci.tests.execute.imports.ImportCsarResourceTest; +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.BaseRestUtils; +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.CsarValidationUtils; +import org.testng.annotations.AfterTest; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +public class ImportCsarUpdate extends ComponentBaseTest { + + @Rule + public static TestName name = new TestName(); + + public ImportCsarUpdate() { + super(name, ImportCsarUpdate.class.getName()); + } + + @DataProvider(name = "happyArts") + public Object[][] getHappyArtifacts() { + + return new Object[][] { { "happy_VF_RI2_G2_two_different_artifacts_under_heatBaseheatVolheatNet2" }, + { "happy_VF_RI2_G2_two_different_artifacts_under_heatBaseheatVolheatNet" }, + { "happy_VF_RI2_G2_two_identical_artifacts_under_heatBaseheatVolheatNet" }, + { "happy_VF_RI2_G2_two_different_artifacts_under_nested" }, + { "happy_VF_RI2_G2_two_indentical_nested_under_different_groups" }, + { "happy_VF_RI2_G2_two_different_nested_under_different_groups" }, + { "happy_VF_RI2_G2_two_different_nested_under_same_group" }, + + }; + } + + @DataProvider(name = "negativeArts") + public Object[][] getNegativeArtifacts() { + + return new Object[][] { + + { "negative_VF_RI2_G2_same_heatVol_different_groups" }, + { "negative_VF_RI2_G2_same_heatBase_different_envs" }, + { "negative_VF_RI2_G2_heatBaseHeatVolHeatNet_under_nested" }, + { "negative_VF_RI2_G2_two_indentical_artifacts_under_nested" }, + { "negative_VF_RI2_G2_nested_under_nested" }, { "negative_VF_RI2_G2_same_heatVol_different_groups" }, }; + } + + @BeforeTest + public void resumeOrigCsarBefore() throws Exception { + + User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER); + ImportCsarResourceTest.copyCsarRest(sdncModifierDetails, "orig.csar", "importCsar_2Gartifacts.csar"); + + } + + @AfterTest + public void resumeOrigCsarAfter() throws Exception { + + User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER); + ImportCsarResourceTest.copyCsarRest(sdncModifierDetails, "orig.csar", "importCsar_2Gartifacts.csar"); + + } + + @Test + public void updateVFsearchByCsarIdCheckInState() throws Exception { + + ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource(); + resourceDetails.setName("hardcodedName"); + resourceDetails.setCsarUUID("importCsar_2Gartifacts"); + resourceDetails.setResourceType(ResourceTypeEnum.VF.name()); + RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, + ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER)); + BaseRestUtils.checkCreateResponse(createResource); + Resource resourceFirstImport = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), + Resource.class); + Component resourceObject = AtomicOperationUtils + .changeComponentState(resourceFirstImport, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CHECKIN, true) + .getLeft(); + + User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER); + RestResponse copyRes = ImportCsarResourceTest.copyCsarRest(sdncModifierDetails, + "updateImportCsar_2Gartifacts_topologyChanged.csar", "importCsar_2Gartifacts.csar"); + + resourceDetails.setCsarUUID("importCsar_2Gartifacts"); + createResource = ResourceRestUtils.createResource(resourceDetails, + ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER)); + BaseRestUtils.checkCreateResponse(createResource); + Resource resourceSecondImport = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), + Resource.class); + + // Validation Part + + resourceFirstImport.getGroups().equals(resourceSecondImport.getGroups()); + + } + + @Test + public void updateVFsearchByCsarIdCheckInState_checkSum() throws Exception { + + ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource(); + resourceDetails.setName("hardcodedName"); + resourceDetails.setCsarUUID("importCsar_2Gartifacts"); + resourceDetails.setResourceType(ResourceTypeEnum.VF.name()); + RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, + ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER)); + BaseRestUtils.checkCreateResponse(createResource); + Resource resourceFirstImport = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), + Resource.class); + Component resourceObject = AtomicOperationUtils + .changeComponentState(resourceFirstImport, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CHECKIN, true) + .getLeft(); + + // User sdncModifierDetails = + // ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER); + // RestResponse copyRes = + // ImportCsarResourceTest.copyCsarRest(sdncModifierDetails,"updateImportCsar_2Gartifacts_topologyChanged.csar","importCsar_2Gartifacts.csar"); + + resourceDetails.setCsarUUID("importCsar_2Gartifacts"); + createResource = ResourceRestUtils.createResource(resourceDetails, + ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER)); + BaseRestUtils.checkCreateResponse(createResource); + Resource resourceSecondImport = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), + Resource.class); + + // Validation Part + + resourceFirstImport.getGroups().equals(resourceSecondImport.getGroups()); + + } + + @Test + public void updateVFsearchByCsarIdCheckOutState() throws Exception { + + ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource(); + resourceDetails.setName("hardcodedName"); + resourceDetails.setCsarUUID("importCsar_2Gartifacts"); + resourceDetails.setResourceType(ResourceTypeEnum.VF.name()); + RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, + ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER)); + BaseRestUtils.checkCreateResponse(createResource); + Resource resourceFirstImport = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), + Resource.class); + // Component resourceObject = + // AtomicOperationUtils.changeComponentState(resourceFirstImport, + // UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CHECKOUT, true).getLeft(); + + User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER); + RestResponse copyRes = ImportCsarResourceTest.copyCsarRest(sdncModifierDetails, + "updateImportCsar_2Gartifacts_topologyChanged.csar", "importCsar_2Gartifacts.csar"); + + resourceDetails.setCsarUUID("importCsar_2Gartifacts"); + createResource = ResourceRestUtils.createResource(resourceDetails, + ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER)); + BaseRestUtils.checkCreateResponse(createResource); + Resource resourceSecondImport = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), + Resource.class); + + // Validation Part + + resourceFirstImport.getGroups().equals(resourceSecondImport.getGroups()); + + } + + @Test + public void updateVFsearchByCsarIdCertifyStat() throws Exception { + + ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource(); + resourceDetails.setName("hardcodedName"); + resourceDetails.setCsarUUID("importCsar_2Gartifacts"); + resourceDetails.setResourceType(ResourceTypeEnum.VF.name()); + RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, + ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER)); + BaseRestUtils.checkCreateResponse(createResource); + Resource resourceFirstImport = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), + Resource.class); + Component resourceObject = AtomicOperationUtils + .changeComponentState(resourceFirstImport, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true) + .getLeft(); + + User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER); + RestResponse copyRes = ImportCsarResourceTest.copyCsarRest(sdncModifierDetails, + "updateImportCsar_2Gartifacts_topologyChanged.csar", "importCsar_2Gartifacts.csar"); + + resourceDetails.setCsarUUID("importCsar_2Gartifacts"); + createResource = ResourceRestUtils.createResource(resourceDetails, + ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER)); + BaseRestUtils.checkCreateResponse(createResource); + Resource resourceSecondImport = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), + Resource.class); + + // Validation Part + + resourceFirstImport.getGroups().equals(resourceSecondImport.getGroups()); + + } + + @Test + public void updateVFsearchByCsarStartCertifaicationState() throws Exception { + + ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource(); + resourceDetails.setName("hardcodedName"); + resourceDetails.setCsarUUID("importCsar_2Gartifacts"); + resourceDetails.setResourceType(ResourceTypeEnum.VF.name()); + RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, + ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER)); + BaseRestUtils.checkCreateResponse(createResource); + Resource resourceFirstImport = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), + Resource.class); + Component resourceObject = AtomicOperationUtils.changeComponentState(resourceFirstImport, UserRoleEnum.DESIGNER, + LifeCycleStatesEnum.CERTIFICATIONREQUEST, true).getLeft(); + + User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER); + RestResponse copyRes = ImportCsarResourceTest.copyCsarRest(sdncModifierDetails, + "updateImportCsar_2Gartifacts_topologyChanged.csar", "importCsar_2Gartifacts.csar"); + + resourceDetails.setCsarUUID("importCsar_2Gartifacts"); + createResource = ResourceRestUtils.createResource(resourceDetails, + ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER)); + BaseRestUtils.checkCreateResponse(createResource); + Resource resourceSecondImport = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), + Resource.class); + + // Validation Part + + resourceFirstImport.getGroups().equals(resourceSecondImport.getGroups()); + + } + + @Test + public void updateVFsearchBySystemNameCheckInState() throws Exception { + + ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource(); + resourceDetails.setName("hardcodedName"); + resourceDetails.setCsarUUID("importCsar_2Gartifacts"); + resourceDetails.setResourceType(ResourceTypeEnum.VF.name()); + RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, + ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER)); + BaseRestUtils.checkCreateResponse(createResource); + Resource resourceFirstImport = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), + Resource.class); + Component resourceObject = AtomicOperationUtils + .changeComponentState(resourceFirstImport, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CHECKIN, true) + .getLeft(); + + User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER); + RestResponse copyRes = ImportCsarResourceTest.copyCsarRest(sdncModifierDetails, + "updateImportCsar_2Gartifacts_topologyChanged.csar", "importCsar_2Gartifacts.csar"); + + resourceDetails.setName("hardcodedNameChanged"); + resourceDetails.setCsarUUID("importCsar_2Gartifacts"); + createResource = ResourceRestUtils.createResource(resourceDetails, + ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER)); + BaseRestUtils.checkCreateResponse(createResource); + Resource resourceSecondImport = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), + Resource.class); + + // Validation Part + + resourceFirstImport.getGroups().equals(resourceSecondImport.getGroups()); + + } + + @Test + public void updateVFsearchBySystemNameCertifyState() throws Exception { + + ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource(); + resourceDetails.setName("hardcodedName"); + resourceDetails.setCsarUUID("importCsar_2Gartifacts"); + resourceDetails.setResourceType(ResourceTypeEnum.VF.name()); + RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, + ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER)); + BaseRestUtils.checkCreateResponse(createResource); + Resource resourceFirstImport = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), + Resource.class); + Component resourceObject = AtomicOperationUtils + .changeComponentState(resourceFirstImport, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true) + .getLeft(); + + User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER); + RestResponse copyRes = ImportCsarResourceTest.copyCsarRest(sdncModifierDetails, + "updateImportCsar_2Gartifacts_topologyChanged.csar", "importCsar_2Gartifacts.csar"); + + resourceDetails.setName("hardcodedNameChanged"); + resourceDetails.setCsarUUID("importCsar_2Gartifacts"); + createResource = ResourceRestUtils.createResource(resourceDetails, + ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER)); + + } + + @Test + public void updateVFsearchBySystemNameCsarIdNotExist() throws Exception { + + ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource(); + resourceDetails.setName("hardcodedName"); + resourceDetails.setResourceType(ResourceTypeEnum.VF.name()); + RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, + ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER)); + BaseRestUtils.checkCreateResponse(createResource); + Resource resourceFirstImport = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), + Resource.class); + Component resourceObject = AtomicOperationUtils + .changeComponentState(resourceFirstImport, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CHECKIN, true) + .getLeft(); + // User sdncModifierDetails = + // ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER); + // RestResponse copyRes = + // ImportCsarResourceTest.copyCsarRest(sdncModifierDetails,"updateImportCsar_2Gartifacts_topologyChanged.csar","importCsar_2Gartifacts.csar"); + ResourceReqDetails resourceDetails2 = ElementFactory.getDefaultResource(); + resourceDetails2.setName("hardcodedName"); + resourceDetails2.setCsarUUID("importCsar_2Gartifacts"); + resourceDetails2.setResourceType(ResourceTypeEnum.VF.name()); + createResource = ResourceRestUtils.createResource(resourceDetails2, + ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER)); + BaseRestUtils.checkCreateResponse(createResource); + Resource resourceSecondImport = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), + Resource.class); + + // Validation Part + + resourceFirstImport.getGroups().equals(resourceSecondImport.getGroups()); + + } + +} diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/devCI/ImportCsarValidateArtifacts.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/devCI/ImportCsarValidateArtifacts.java new file mode 100644 index 0000000000..5ed71e53b0 --- /dev/null +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/devCI/ImportCsarValidateArtifacts.java @@ -0,0 +1,108 @@ +/*- + * ============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.devCI; + +import static org.testng.AssertJUnit.assertTrue; + +import org.junit.Rule; +import org.junit.rules.TestName; +import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; +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.ci.tests.api.ComponentBaseTest; +import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails; +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.BaseRestUtils; +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.CsarValidationUtils; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +public class ImportCsarValidateArtifacts extends ComponentBaseTest { + + @Rule + public static TestName name = new TestName(); + + public ImportCsarValidateArtifacts() { + super(name, ImportCsarValidateArtifacts.class.getName()); + } + + @DataProvider(name = "happyArts") + public Object[][] getHappyArtifacts() { + + return new Object[][] { { "happy_VF_RI2_G2_two_different_artifacts_under_heatBaseheatVolheatNet2" }, + { "happy_VF_RI2_G2_two_different_artifacts_under_heatBaseheatVolheatNet" }, + { "happy_VF_RI2_G2_two_identical_artifacts_under_heatBaseheatVolheatNet" }, + { "happy_VF_RI2_G2_two_different_artifacts_under_nested" }, + { "happy_VF_RI2_G2_two_indentical_nested_under_different_groups" }, + { "happy_VF_RI2_G2_two_different_nested_under_different_groups" }, + { "happy_VF_RI2_G2_two_different_nested_under_same_group" }, + + }; + } + + @DataProvider(name = "negativeArts") + public Object[][] getNegativeArtifacts() { + + return new Object[][] { + + { "negative_VF_RI2_G2_same_heatVol_different_groups" }, + { "negative_VF_RI2_G2_same_heatBase_different_envs" }, + { "negative_VF_RI2_G2_heatBaseHeatVolHeatNet_under_nested" }, + { "negative_VF_RI2_G2_two_indentical_artifacts_under_nested" }, + { "negative_VF_RI2_G2_nested_under_nested" }, { "negative_VF_RI2_G2_same_heatVol_different_groups" }, }; + } + + @Test(dataProvider = "happyArts") + public void createResourceFromCsarArtsHappy(String artifactName) throws Exception { + + ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource(); + resourceDetails.setCsarUUID(artifactName); + 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); + CsarValidationUtils.validateCsarVfArtifact(artifactName, resource); + + } + + @Test(dataProvider = "negativeArts") + public void createResourceFromCsarArtsNegative(String artifactName) throws Exception { + + ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource(); + resourceDetails.setCsarUUID(artifactName); + resourceDetails.setResourceType(ResourceTypeEnum.VF.name()); + RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, + ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER)); + assertTrue(createResource.getErrorCode() != 201 && createResource.getErrorCode() != 500); + + } + +} diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/devCI/ToscaGroupInsideVF.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/devCI/ToscaGroupInsideVF.java new file mode 100644 index 0000000000..64df976c09 --- /dev/null +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/devCI/ToscaGroupInsideVF.java @@ -0,0 +1,580 @@ +/*- + * ============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.devCI; + +import static org.testng.AssertJUnit.assertEquals; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.lang3.tuple.Pair; +import org.junit.Rule; +import org.junit.rules.TestName; +import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; +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.api.Urls; +import org.openecomp.sdc.ci.tests.config.Config; +import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails; +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.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.tosca.datatypes.ToscaDefinition; +import org.openecomp.sdc.ci.tests.utils.ToscaParserUtils; +import org.openecomp.sdc.ci.tests.utils.Utils; +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.BaseRestUtils; +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.CsarValidationUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.annotations.Test; + +public class ToscaGroupInsideVF extends ComponentBaseTest { + private static Logger logger = LoggerFactory.getLogger(ToscaGroupInsideVF.class.getName()); + + @Rule + public static TestName name = new TestName(); + + public ToscaGroupInsideVF() { + super(name, ToscaGroupInsideVF.class.getName()); + } + + /*@Test + public void createResourceFromCsarArts() throws Exception { + + // String csar = getCsar(); + // parseCsar(csar); + ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource(); + resourceDetails.setCsarUUID("VF_RI2_G6_withArtifacts"); + 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); + + Component resourceObject = AtomicOperationUtils + .changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft(); + Resource vfManual = AtomicOperationUtils.createResourceByType(ResourceTypeEnum.VF, UserRoleEnum.DESIGNER, true) + .left().value(); + AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.OTHER, vfManual, UserRoleEnum.DESIGNER, true, true); + AtomicOperationUtils.changeComponentState(vfManual, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true) + .getLeft(); + + Service service = AtomicOperationUtils.createDefaultService(UserRoleEnum.DESIGNER, true).left().value(); + AtomicOperationUtils + .addComponentInstanceToComponentContainer(resourceObject, service, UserRoleEnum.DESIGNER, true).left() + .value(); + AtomicOperationUtils.addComponentInstanceToComponentContainer(vfManual, service, UserRoleEnum.DESIGNER, true) + .left().value(); + AtomicOperationUtils.getServiceObject(service, UserRoleEnum.DESIGNER); + AtomicOperationUtils + .changeComponentState(service, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFICATIONREQUEST, true) + .getLeft(); + AtomicOperationUtils + .changeComponentState(service, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CANCELCERTIFICATION, true) + .getLeft(); + AtomicOperationUtils + .changeComponentState(service, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFICATIONREQUEST, true) + .getLeft(); + + } + + @Test + public void soferTest() throws Exception { + + // String csar = getCsar(); + // parseCsar(csar); + ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource(); + resourceDetails.setCsarUUID("sofer"); + 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 + public void createVFwith2VLs() throws Exception { + + // String csar = getCsar(); + // parseCsar(csar); + ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource(); + resourceDetails.setCsarUUID("VSPPackage"); + 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); + + Component resourceObject = AtomicOperationUtils + .changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft(); + Resource vfManual = AtomicOperationUtils.createResourceByType(ResourceTypeEnum.VF, UserRoleEnum.DESIGNER, true) + .left().value(); + AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.OTHER, vfManual, UserRoleEnum.DESIGNER, true, true); + AtomicOperationUtils.changeComponentState(vfManual, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true) + .getLeft(); + + Service service = AtomicOperationUtils.createDefaultService(UserRoleEnum.DESIGNER, true).left().value(); + AtomicOperationUtils + .addComponentInstanceToComponentContainer(resourceObject, service, UserRoleEnum.DESIGNER, true).left() + .value(); + AtomicOperationUtils.addComponentInstanceToComponentContainer(vfManual, service, UserRoleEnum.DESIGNER, true) + .left().value(); + AtomicOperationUtils.getServiceObject(service, UserRoleEnum.DESIGNER); + AtomicOperationUtils + .changeComponentState(service, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFICATIONREQUEST, true) + .getLeft(); + AtomicOperationUtils + .changeComponentState(service, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CANCELCERTIFICATION, true) + .getLeft(); + AtomicOperationUtils.changeComponentState(service, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true) + .getLeft(); + + } + + @Test // (enabled = false) + public void createResourceFromCsarHappy() throws Exception { + // String csarUUID = "VF_RI2_G2_withArtifacts"; + String csarUUID = "VF_RI2_G1_Invalid"; + ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource(); + resourceDetails.setCsarUUID(csarUUID); + 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); + CsarValidationUtils.validateCsarVfArtifact(csarUUID, resource); + } + + @Test // (enabled = false) + public void createResourceFromCsarWithProperty() throws Exception { + String csarUUID = "VF_RI2_G4_withArtifacts"; + ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource(); + resourceDetails.setCsarUUID(csarUUID); + 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); + CsarValidationUtils.validateCsarVfArtifact(csarUUID, resource); + } + + @Test // (enabled = false) + public void UpdateCsarWithNonExistingResourceInstanceFail() throws Exception { + + // String csarUUID = "VF_RI2_G1-RI_NotExist"; + // String csarUUID = "nested3"; + + // String csarUUID = "VF_RI2_G1_Invalid_WithArtifacts"; + User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER); + + RestResponse copyRes = copyCsarRest(sdncModifierDetails, "VF_RI2_G4_withArtifacts_a.csar", + "VF_RI2_G4_withArtifacts.csar"); + BaseRestUtils.checkSuccess(copyRes); + String csarUUID = "VF_RI2_G4_withArtifacts.csar"; + + ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource(); + resourceDetails.setCsarUUID(csarUUID); + 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); + + copyRes = copyCsarRest(sdncModifierDetails, "VF_RI2_G4_withArtifactsRI_FAIL.csar", + "VF_RI2_G4_withArtifacts.csar"); + BaseRestUtils.checkSuccess(copyRes); + + resourceDetails.setName(resource.getName()); + // resourceDetails.setVendorName("Govnuk"); + // resourceDetails.setDescription("Other"); + RestResponse createResource2 = ResourceRestUtils.createResource(resourceDetails, + ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER)); + BaseRestUtils.checkCreateResponse(createResource2); + Resource resource2 = ResponseParser.parseToObjectUsingMapper(createResource2.getResponse(), Resource.class); + + CsarValidationUtils.validateCsarVfArtifact(csarUUID, resource); + ToscaDefinition toscaDefinition = ToscaParserUtils.getToscaDefinitionObjectByCsarUuid(csarUUID); + CsarValidationUtils.validateToscaDefinitonObjectVsResource(toscaDefinition, resource); + + // CsarValidationUtils.validateCsarVfArtifact(csarUUID2, resource2); + // ToscaDefinition toscaDefinition2 = + // ToscaParserUtils.getToscaDefinitionObjectByCsarUuid(csarUUID2); + // CsarValidationUtils.validateToscaDefinitonObjectVsResource(toscaDefinition2, + // resource2); + + // Csar csar = parserTocsarObject(csarUUID); + // validateCsarVsResourceObj(csar, resource); + // csar.node_types(); + + } + + @Test // (enabled = false) + public void UpdateCsarWithSameCsarDifferentMetadata() throws Exception { + + // User sdncModifierDetails = + // ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER); + // RestResponse copyRes = + // copyCsarRest(sdncModifierDetails,"VF_RI2_G4_withArtifacts_a.csar","VF_RI2_G4_withArtifacts.csar"); + // BaseRestUtils.checkSuccess(copyRes); + String csarUUID = "VF_RI2_G4_withArtifacts.csar"; + + ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource(); + resourceDetails.setCsarUUID(csarUUID); + 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); + + resourceDetails.setName(resource.getName()); + resourceDetails.setVendorName("Govnuk"); + resourceDetails.setDescription("Other"); + RestResponse createResource2 = ResourceRestUtils.createResource(resourceDetails, + ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER)); + BaseRestUtils.checkCreateResponse(createResource2); + Resource resource2 = ResponseParser.parseToObjectUsingMapper(createResource2.getResponse(), Resource.class); + + CsarValidationUtils.validateCsarVfArtifact(csarUUID, resource); + ToscaDefinition toscaDefinition = ToscaParserUtils.getToscaDefinitionObjectByCsarUuid(csarUUID); + CsarValidationUtils.validateToscaDefinitonObjectVsResource(toscaDefinition, resource); + + // CsarValidationUtils.validateCsarVfArtifact(csarUUID2, resource2); + // ToscaDefinition toscaDefinition2 = + // ToscaParserUtils.getToscaDefinitionObjectByCsarUuid(csarUUID2); + // CsarValidationUtils.validateToscaDefinitonObjectVsResource(toscaDefinition2, + // resource2); + + // Csar csar = parserTocsarObject(csarUUID); + // validateCsarVsResourceObj(csar, resource); + // csar.node_types(); + + } + + @Test // (enabled = false) + public void UpdateCsarWithSameCsar() throws Exception { + + // User sdncModifierDetails = + // ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER); + // RestResponse copyRes = + // copyCsarRest(sdncModifierDetails,"VF_RI2_G4_withArtifacts_a.csar","VF_RI2_G4_withArtifacts.csar"); + // BaseRestUtils.checkSuccess(copyRes); + String csarUUID = "VF_RI2_G4_withArtifacts.csar"; + + ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource(); + resourceDetails.setCsarUUID(csarUUID); + 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); + + resourceDetails.setName(resource.getName()); + RestResponse createResource2 = ResourceRestUtils.createResource(resourceDetails, + ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER)); + BaseRestUtils.checkCreateResponse(createResource2); + Resource resource2 = ResponseParser.parseToObjectUsingMapper(createResource2.getResponse(), Resource.class); + + CsarValidationUtils.validateCsarVfArtifact(csarUUID, resource); + ToscaDefinition toscaDefinition = ToscaParserUtils.getToscaDefinitionObjectByCsarUuid(csarUUID); + CsarValidationUtils.validateToscaDefinitonObjectVsResource(toscaDefinition, resource); + + // CsarValidationUtils.validateCsarVfArtifact(csarUUID2, resource2); + // ToscaDefinition toscaDefinition2 = + // ToscaParserUtils.getToscaDefinitionObjectByCsarUuid(csarUUID2); + // CsarValidationUtils.validateToscaDefinitonObjectVsResource(toscaDefinition2, + // resource2); + + // Csar csar = parserTocsarObject(csarUUID); + // validateCsarVsResourceObj(csar, resource); + // csar.node_types(); + + } + + @Test // (enabled = false) + public void UpdateCsarCertifiedVfWithSameCsar() throws Exception { + + User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER); + RestResponse copyRes = copyCsarRest(sdncModifierDetails, "VF_RI2_G4_withArtifacts_a.csar", + "VF_RI2_G4_withArtifacts.csar"); + BaseRestUtils.checkSuccess(copyRes); + String csarUUID = "VF_RI2_G4_withArtifacts.csar"; + + ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource(); + resourceDetails.setCsarUUID(csarUUID); + 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); + Pair<Component, RestResponse> changeComponentState = AtomicOperationUtils.changeComponentState(resource, + UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true); + resource = (Resource) changeComponentState.getLeft(); + + resourceDetails.setName(resource.getName()); + RestResponse createResource2 = ResourceRestUtils.createResource(resourceDetails, + ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER)); + BaseRestUtils.checkCreateResponse(createResource2); + Resource resource2 = ResponseParser.parseToObjectUsingMapper(createResource2.getResponse(), Resource.class); + + CsarValidationUtils.validateCsarVfArtifact(csarUUID, resource); + ToscaDefinition toscaDefinition = ToscaParserUtils.getToscaDefinitionObjectByCsarUuid(csarUUID); + CsarValidationUtils.validateToscaDefinitonObjectVsResource(toscaDefinition, resource); + + // CsarValidationUtils.validateCsarVfArtifact(csarUUID2, resource2); + // ToscaDefinition toscaDefinition2 = + // ToscaParserUtils.getToscaDefinitionObjectByCsarUuid(csarUUID2); + // CsarValidationUtils.validateToscaDefinitonObjectVsResource(toscaDefinition2, + // resource2); + + // Csar csar = parserTocsarObject(csarUUID); + // validateCsarVsResourceObj(csar, resource); + // csar.node_types(); + + } + + @Test // (enabled = false) + public void UpdateCsarDifferentTosca() throws Exception { + + User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER); + RestResponse copyRes = copyCsarRest(sdncModifierDetails, "VF_RI2_G4_withArtifacts_a.csar", + "VF_RI2_G4_withArtifacts.csar"); + BaseRestUtils.checkSuccess(copyRes); + String csarUUID = "VF_RI2_G4_withArtifacts.csar"; + + ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource(); + resourceDetails.setCsarUUID(csarUUID); + 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); + + copyRes = copyCsarRest(sdncModifierDetails, "VF_RI2_G4_withArtifactsUpdated.csar", + "VF_RI2_G4_withArtifacts.csar"); + BaseRestUtils.checkSuccess(copyRes); + + resourceDetails.setName(resource.getName()); + RestResponse createResource2 = ResourceRestUtils.createResource(resourceDetails, + ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER)); + BaseRestUtils.checkCreateResponse(createResource2); + Resource resource2 = ResponseParser.parseToObjectUsingMapper(createResource2.getResponse(), Resource.class); + + CsarValidationUtils.validateCsarVfArtifact(csarUUID, resource); + ToscaDefinition toscaDefinition = ToscaParserUtils.getToscaDefinitionObjectByCsarUuid(csarUUID); + CsarValidationUtils.validateToscaDefinitonObjectVsResource(toscaDefinition, resource); + + // CsarValidationUtils.validateCsarVfArtifact(csarUUID2, resource2); + // ToscaDefinition toscaDefinition2 = + // ToscaParserUtils.getToscaDefinitionObjectByCsarUuid(csarUUID2); + // CsarValidationUtils.validateToscaDefinitonObjectVsResource(toscaDefinition2, + // resource2); + + // Csar csar = parserTocsarObject(csarUUID); + // validateCsarVsResourceObj(csar, resource); + // csar.node_types(); + + } + + @Test // (enabled = false) + public void UpdateCsarDifferentToscaAndArtifacts() throws Exception { + + User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER); + RestResponse copyRes = copyCsarRest(sdncModifierDetails, "VF_RI2_G4_withArtifacts_a.csar", + "VF_RI2_G4_withArtifacts.csar"); + BaseRestUtils.checkSuccess(copyRes); + String csarUUID = "VF_RI2_G4_withArtifacts.csar"; + + ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource(); + resourceDetails.setCsarUUID(csarUUID); + 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); + + copyRes = copyCsarRest(sdncModifierDetails, "VF_RI2_G4_withArtifacts_UpdateToscaAndArtifacts.csar", + "VF_RI2_G4_withArtifacts.csar"); + BaseRestUtils.checkSuccess(copyRes); + + resourceDetails.setName(resource.getName()); + RestResponse createResource2 = ResourceRestUtils.createResource(resourceDetails, + ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER)); + BaseRestUtils.checkCreateResponse(createResource2); + Resource resource2 = ResponseParser.parseToObjectUsingMapper(createResource2.getResponse(), Resource.class); + + CsarValidationUtils.validateCsarVfArtifact(csarUUID, resource); + ToscaDefinition toscaDefinition = ToscaParserUtils.getToscaDefinitionObjectByCsarUuid(csarUUID); + CsarValidationUtils.validateToscaDefinitonObjectVsResource(toscaDefinition, resource); + + // CsarValidationUtils.validateCsarVfArtifact(csarUUID2, resource2); + // ToscaDefinition toscaDefinition2 = + // ToscaParserUtils.getToscaDefinitionObjectByCsarUuid(csarUUID2); + // CsarValidationUtils.validateToscaDefinitonObjectVsResource(toscaDefinition2, + // resource2); + + // Csar csar = parserTocsarObject(csarUUID); + // validateCsarVsResourceObj(csar, resource); + // csar.node_types(); + + } + + @Test // (enabled = false) + public void migration() throws Exception { + String csarUUID = "VF_RI2_G4_withArtifacts"; + ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource(); + resourceDetails.setCsarUUID(csarUUID); + resourceDetails.setName("Resource1"); + resourceDetails.setResourceType(ResourceTypeEnum.VF.name()); + RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, + ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER)); + BaseRestUtils.checkCreateResponse(createResource); + + resourceDetails.setName("Resource2"); + resourceDetails.setResourceType(ResourceTypeEnum.VF.name()); + createResource = ResourceRestUtils.createResource(resourceDetails, + ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER)); + BaseRestUtils.checkCreateResponse(createResource); + Resource resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class); + resource = (Resource) AtomicOperationUtils + .changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft(); + resource = (Resource) AtomicOperationUtils + .changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CHECKOUT, true).getLeft(); + resource = (Resource) AtomicOperationUtils + .changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CHECKIN, true).getLeft(); + resource = (Resource) AtomicOperationUtils + .changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CHECKOUT, true).getLeft(); + + resourceDetails.setName("Resource3"); + resourceDetails.setResourceType(ResourceTypeEnum.VF.name()); + createResource = ResourceRestUtils.createResource(resourceDetails, + ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER)); + BaseRestUtils.checkCreateResponse(createResource); + resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class); + resource = (Resource) AtomicOperationUtils + .changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft(); + resource = (Resource) AtomicOperationUtils + .changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft(); + resource = (Resource) AtomicOperationUtils + .changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft(); + + resourceDetails.setName("Resource4"); + resourceDetails.setResourceType(ResourceTypeEnum.VF.name()); + createResource = ResourceRestUtils.createResource(resourceDetails, + ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER)); + BaseRestUtils.checkCreateResponse(createResource); + resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class); + resource = (Resource) AtomicOperationUtils + .changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CHECKIN, true).getLeft(); + resource = (Resource) AtomicOperationUtils + .changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CHECKOUT, true).getLeft(); + resource = (Resource) AtomicOperationUtils + .changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CHECKIN, true).getLeft(); + resource = (Resource) AtomicOperationUtils + .changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CHECKOUT, true).getLeft(); + resource = (Resource) AtomicOperationUtils + .changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CHECKIN, true).getLeft(); + + resourceDetails.setName("Resource5"); + resourceDetails.setResourceType(ResourceTypeEnum.VF.name()); + createResource = ResourceRestUtils.createResource(resourceDetails, + ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER)); + BaseRestUtils.checkCreateResponse(createResource); + resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class); + resource = (Resource) AtomicOperationUtils + .changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CHECKIN, true).getLeft(); + resource = (Resource) AtomicOperationUtils + .changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CHECKOUT, true).getLeft(); + resource = (Resource) AtomicOperationUtils + .changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CHECKIN, true).getLeft(); + resource = (Resource) AtomicOperationUtils + .changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CHECKOUT, true).getLeft(); + + resourceDetails.setName("Resource6"); + resourceDetails.setResourceType(ResourceTypeEnum.VF.name()); + createResource = ResourceRestUtils.createResource(resourceDetails, + ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER)); + BaseRestUtils.checkCreateResponse(createResource); + resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class); + resource = (Resource) AtomicOperationUtils + .changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.STARTCERTIFICATION, true) + .getLeft(); + + resourceDetails.setName("Resource7"); + resourceDetails.setResourceType(ResourceTypeEnum.VF.name()); + createResource = ResourceRestUtils.createResource(resourceDetails, + ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER)); + BaseRestUtils.checkCreateResponse(createResource); + resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class); + resource = (Resource) AtomicOperationUtils + .changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft(); + resource = (Resource) AtomicOperationUtils + .changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFICATIONREQUEST, true) + .getLeft(); + + logger.debug("7 VF resources were created"); + + } + + 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; + + } + + 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; + } + + public static void main(String[] args) throws Exception { + // String csarUUID = "VF_RI2_G4_withArtifacts"; + String csarUUID = "node_types"; + ToscaParserUtils.getToscaDefinitionObjectByCsarUuid(csarUUID); + }*/ +} diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/devCI/test1.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/devCI/test1.java new file mode 100644 index 0000000000..7acf1206e7 --- /dev/null +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/devCI/test1.java @@ -0,0 +1,96 @@ +/*- + * ============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.devCI; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import org.junit.Rule; +import org.junit.rules.TestName; +import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; +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.ci.tests.api.ComponentBaseTest; +import org.openecomp.sdc.ci.tests.config.Config; +import org.openecomp.sdc.ci.tests.datatypes.enums.ArtifactTypeEnum; +import org.openecomp.sdc.ci.tests.datatypes.enums.DistributionNotificationStatusEnum; +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.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.Utils; +import org.openecomp.sdc.ci.tests.utils.general.AtomicOperationUtils; +import org.openecomp.sdc.ci.tests.utils.validation.DistributionValidationUtils; +import org.openecomp.sdc.externalApis.CRUDExternalAPI; +import org.testng.annotations.Test; + +import fj.data.Either; + +public class test1 extends ComponentBaseTest{ + + @Rule + public static TestName name = new TestName(); + + public test1() { + super(name, CRUDExternalAPI.class.getName()); + + } + + @Test() + public void uploadArtifactOnServiceViaExternalAPI() throws Exception { + Config config = Utils.getConfig(); + + Service service = AtomicOperationUtils.createServiceByCategory(ServiceCategoriesEnum.MOBILITY, UserRoleEnum.DESIGNER, true).left().value(); + AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.MODEL_QUERY_SPEC, service, UserRoleEnum.DESIGNER, true, true); + service = (Service) AtomicOperationUtils.changeComponentState(service, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft(); + if(config.getIsDistributionClientRunning()){ + List<String> distributionStatusList = Arrays.asList(DistributionNotificationStatusEnum.DOWNLOAD_OK.toString(), DistributionNotificationStatusEnum.DEPLOY_OK.toString(), DistributionNotificationStatusEnum.NOTIFIED.toString()); + DistributionValidationUtils.validateDistributedArtifactsByAudit(service, distributionStatusList); + } + } + + + public static Map<String, String> addVNF_ModuleDeploymentArtifactToMap(Service service, Map<String, String> distributionArtifactMap){ + + + return distributionArtifactMap; + } + + public Component getComponentInTargetLifeCycleState(String componentType, UserRoleEnum creatorUser, LifeCycleStatesEnum targetLifeCycleState) throws Exception { + Component component = null; + + if(componentType.toLowerCase().equals("vf")) { + Either<Resource, RestResponse> createdResource = AtomicOperationUtils.createResourcesByTypeNormTypeAndCatregory(ResourceTypeEnum.VF, NormativeTypesEnum.ROOT, ResourceCategoryEnum.GENERIC_INFRASTRUCTURE, creatorUser, true); + component = createdResource.left().value(); + component = AtomicOperationUtils.changeComponentState(component, creatorUser, targetLifeCycleState, true).getLeft(); + } else { + Either<Service, RestResponse> createdResource = AtomicOperationUtils.createDefaultService(creatorUser, true); + component = createdResource.left().value(); + component = AtomicOperationUtils.changeComponentState(component, creatorUser, targetLifeCycleState, true).getLeft(); + } + + return component; + } +} |