diff options
Diffstat (limited to 'test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest')
20 files changed, 643 insertions, 550 deletions
diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ArtifactRestUtils.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ArtifactRestUtils.java index 448442e112..7daf1bd414 100644 --- a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ArtifactRestUtils.java +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ArtifactRestUtils.java @@ -20,23 +20,12 @@ package org.openecomp.sdc.ci.tests.utils.rest; -import static org.testng.AssertJUnit.assertNotNull; -import static org.testng.AssertJUnit.assertTrue; - -import java.io.IOException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - +import com.google.gson.Gson; import org.apache.commons.codec.binary.Base64; import org.json.simple.JSONObject; import org.json.simple.JSONValue; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; -import org.openecomp.sdc.be.model.ArtifactDefinition; -import org.openecomp.sdc.be.model.Component; -import org.openecomp.sdc.be.model.ComponentInstance; -import org.openecomp.sdc.be.model.Resource; -import org.openecomp.sdc.be.model.User; +import org.openecomp.sdc.be.model.*; import org.openecomp.sdc.ci.tests.api.Urls; import org.openecomp.sdc.ci.tests.config.Config; import org.openecomp.sdc.ci.tests.datatypes.ArtifactReqDetails; @@ -55,7 +44,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testng.AssertJUnit; -import com.google.gson.Gson; +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.testng.AssertJUnit.assertNotNull; +import static org.testng.AssertJUnit.assertTrue; public class ArtifactRestUtils extends BaseRestUtils { private static Logger logger = LoggerFactory.getLogger(ArtifactRestUtils.class.getName()); @@ -344,10 +339,10 @@ public class ArtifactRestUtils extends BaseRestUtils { - public static RestResponse downloadResourceInstanceArtifact(String serviceUniqueId,String resourceInstanceId, User user, String artifactUniqeId) throws Exception + public static RestResponse downloadResourceInstanceArtifact(String serviceUniqueId,String resourceInstanceId, User user, String artifactUniqueId) throws Exception { Config config = Utils.getConfig(); - String url = String.format(Urls.DOWNLOAD_COMPONENT_INSTANCE_ARTIFACT, config.getCatalogBeHost(),config.getCatalogBePort(), serviceUniqueId, resourceInstanceId, artifactUniqeId); + String url = String.format(Urls.DOWNLOAD_COMPONENT_INSTANCE_ARTIFACT, config.getCatalogBeHost(),config.getCatalogBePort(), serviceUniqueId, resourceInstanceId, artifactUniqueId); RestResponse res = sendGet(url, user.getUserId(), null); return res; } @@ -906,4 +901,18 @@ public class ArtifactRestUtils extends BaseRestUtils { } + /** + * @param restResponse restResponse object + * @return readable content(converted from base64) + * @throws IOException ioexception + */ + public static String getDecodedArtifactPayloadFromResponse(RestResponse restResponse) throws IOException { + Gson gson = new Gson(); + Map<String, String> fromJson = gson.fromJson(restResponse.getResponse(), Map.class); + String payloadData = fromJson.get("base64Contents").toString(); + String decodedPaypload = org.openecomp.sdc.ci.tests.utils.Decoder.decode(payloadData); + return decodedPaypload; + } + + } diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/AssetRestUtils.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/AssetRestUtils.java index 13cfb8fb63..ad70c34628 100644 --- a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/AssetRestUtils.java +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/AssetRestUtils.java @@ -20,42 +20,21 @@ package org.openecomp.sdc.ci.tests.utils.rest; -import static org.testng.AssertJUnit.assertNotNull; -import static org.testng.AssertJUnit.assertTrue; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.gson.*; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; -import com.fasterxml.jackson.databind.ObjectMapper; import org.openecomp.sdc.be.datatypes.enums.AssetTypeEnum; 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.Component; -import org.openecomp.sdc.be.model.ComponentInstance; -import org.openecomp.sdc.be.model.Resource; -import org.openecomp.sdc.be.model.Service; +import org.openecomp.sdc.be.model.*; import org.openecomp.sdc.ci.tests.api.Urls; import org.openecomp.sdc.ci.tests.config.Config; -import org.openecomp.sdc.ci.tests.datatypes.ArtifactAssetStructure; -import org.openecomp.sdc.ci.tests.datatypes.AssetStructure; -import org.openecomp.sdc.ci.tests.datatypes.ResourceAssetStructure; -import org.openecomp.sdc.ci.tests.datatypes.ResourceDetailedAssetStructure; -import org.openecomp.sdc.ci.tests.datatypes.ResourceInstanceAssetStructure; -import org.openecomp.sdc.ci.tests.datatypes.ServiceAssetStructure; -import org.openecomp.sdc.ci.tests.datatypes.ServiceDetailedAssetStructure; +import org.openecomp.sdc.ci.tests.datatypes.*; 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; @@ -66,11 +45,17 @@ import org.openecomp.sdc.ci.tests.utils.general.FileHandling; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.gson.Gson; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import static org.testng.AssertJUnit.assertNotNull; +import static org.testng.AssertJUnit.assertTrue; public class AssetRestUtils extends BaseRestUtils { static Gson gson = new Gson(); diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/AutomationUtils.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/AutomationUtils.java index 65ab6c920a..8d39bd1c99 100644 --- a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/AutomationUtils.java +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/AutomationUtils.java @@ -20,15 +20,15 @@ package org.openecomp.sdc.ci.tests.utils.rest; +import org.openecomp.sdc.ci.tests.config.Config; +import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse; +import org.openecomp.sdc.ci.tests.utils.Utils; + import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; -import org.openecomp.sdc.ci.tests.config.Config; -import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse; -import org.openecomp.sdc.ci.tests.utils.Utils; - public class AutomationUtils extends BaseRestUtils { @@ -63,24 +63,24 @@ public class AutomationUtils extends BaseRestUtils { public static void createVersionsInfoFile(String filepath, String onboardVersion, String osVersion, String envData, String suiteName) throws IOException { File myFoo = new File(filepath); - FileOutputStream fooStream = new FileOutputStream(myFoo, false); // true to append - String versions = ("onboardVersion=\""+ onboardVersion+ "\"\n" + "osVersion=\"" + osVersion + "\"\n" + "env=\""+ envData + "\"\n" + "suiteName=\""+ suiteName+ "\"\n"); - byte[] myBytes = versions.getBytes(); - fooStream.write(myBytes); - fooStream.close(); + try (FileOutputStream fooStream = new FileOutputStream(myFoo, false)) { + String versions = ("onboardVersion=\"" + onboardVersion + "\"\n" + "osVersion=\"" + osVersion + "\"\n" + "env=\"" + envData + "\"\n" + "suiteName=\"" + suiteName + "\"\n"); + byte[] myBytes = versions.getBytes(); + fooStream.write(myBytes); + } } public static void createVersionsInfoFile(String filepath, String onboardVersion, String osVersion, String envData, String suiteName, String reportStartTime) throws IOException { File myFoo = new File(filepath); - FileOutputStream fooStream = new FileOutputStream(myFoo, false); // true to append - String versions = ("onboardVersion=\""+ onboardVersion+ "\"\n" + "osVersion=\"" + osVersion + "\"\n" + "env=\""+ envData + "\"\n" + "suiteName=\""+ suiteName+ "\"\n" + "reportStartTime=\""+ reportStartTime+ "\"\n"); - byte[] myBytes = versions.getBytes(); - fooStream.write(myBytes); - fooStream.close(); + try (FileOutputStream fooStream = new FileOutputStream(myFoo, false)) { + String versions = ("onboardVersion=\"" + onboardVersion + "\"\n" + "osVersion=\"" + osVersion + "\"\n" + "env=\"" + envData + "\"\n" + "suiteName=\"" + suiteName + "\"\n" + "reportStartTime=\"" + reportStartTime + "\"\n"); + byte[] myBytes = versions.getBytes(); + fooStream.write(myBytes); + } } public static void createVersionsInfoFile(String filepath, String onboardVersion, String osVersion, String envData) - throws FileNotFoundException, IOException { + throws IOException { createVersionsInfoFile(filepath, onboardVersion, osVersion, envData, null); } diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/BaseRestUtils.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/BaseRestUtils.java index 4ec0353abd..56859ff56a 100644 --- a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/BaseRestUtils.java +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/BaseRestUtils.java @@ -20,13 +20,6 @@ package org.openecomp.sdc.ci.tests.utils.rest; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - import org.apache.commons.codec.binary.Base64; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; @@ -40,6 +33,13 @@ import org.openecomp.sdc.ci.tests.utils.validation.BaseValidationUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + public class BaseRestUtils extends BaseValidationUtils { public static final String contentTypeHeaderData = "application/json"; public static final String acceptHeaderData = "application/json"; @@ -84,7 +84,7 @@ public class BaseRestUtils extends BaseValidationUtils { // ************* PRIVATE METHODS ************************ - protected static Map<String, String> prepareHeadersMap(String userId) { + public static Map<String, String> prepareHeadersMap(String userId) { return prepareHeadersMap(userId, acceptHeaderData); } diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/CatalogRestUtils.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/CatalogRestUtils.java index b09ba10df1..304df86199 100644 --- a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/CatalogRestUtils.java +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/CatalogRestUtils.java @@ -20,10 +20,6 @@ package org.openecomp.sdc.ci.tests.utils.rest; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - import org.openecomp.sdc.ci.tests.api.Urls; import org.openecomp.sdc.ci.tests.config.Config; import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum; @@ -31,6 +27,10 @@ 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.Utils; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + public class CatalogRestUtils extends BaseRestUtils { public static RestResponse getAbstractResources() throws IOException { diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/CategoryRestUtils.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/CategoryRestUtils.java index 460518b35f..3e1413a226 100644 --- a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/CategoryRestUtils.java +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/CategoryRestUtils.java @@ -20,10 +20,8 @@ package org.openecomp.sdc.ci.tests.utils.rest; -import java.io.IOException; -import java.util.List; -import java.util.Map; - +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; import org.apache.http.entity.mime.MultipartEntityBuilder; import org.openecomp.sdc.be.model.User; import org.openecomp.sdc.be.model.category.CategoryDefinition; @@ -35,8 +33,9 @@ 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 com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; +import java.io.IOException; +import java.util.List; +import java.util.Map; public class CategoryRestUtils extends BaseRestUtils { diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ComponentInstanceRestUtils.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ComponentInstanceRestUtils.java index 64b576e3e2..e59c13bf11 100644 --- a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ComponentInstanceRestUtils.java +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ComponentInstanceRestUtils.java @@ -20,19 +20,9 @@ package org.openecomp.sdc.ci.tests.utils.rest; -import static org.testng.Assert.assertTrue; - -import java.io.IOException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - +import com.google.gson.Gson; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; -import org.openecomp.sdc.be.model.Component; -import org.openecomp.sdc.be.model.ComponentInstance; -import org.openecomp.sdc.be.model.ComponentInstanceProperty; -import org.openecomp.sdc.be.model.RequirementCapabilityRelDef; -import org.openecomp.sdc.be.model.User; +import org.openecomp.sdc.be.model.*; import org.openecomp.sdc.ci.tests.api.Urls; import org.openecomp.sdc.ci.tests.config.Config; import org.openecomp.sdc.ci.tests.datatypes.ComponentInstanceReqDetails; @@ -40,7 +30,12 @@ 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.Utils; -import com.google.gson.Gson; +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.testng.Assert.assertTrue; public class ComponentInstanceRestUtils extends BaseRestUtils { // public static String acceptHeaderDate = "application/json"; @@ -272,5 +267,15 @@ public class ComponentInstanceRestUtils extends BaseRestUtils { return changeResourceInstanceVersion; } + public static CapReqDef getInstancesCapabilitiesRequirements(Component component, String userId) throws Exception { + + String url = String.format(Urls.GET_INSTANCE_REQUIRMENTS_CAPABILITIES, + Utils.getConfig().getCatalogBeHost(), Utils.getConfig().getCatalogBePort(), + ComponentTypeEnum.findParamByType(component.getComponentType()), component.getUniqueId()); + + RestResponse getComponentReqCap = sendGet(url, userId); + assertTrue(getComponentReqCap.getErrorCode() == STATUS_CODE_GET_SUCCESS); + return ResponseParser.parseToObject(getComponentReqCap.getResponse(), CapReqDef.class); + } } diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ComponentRestUtils.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ComponentRestUtils.java index dcebe4afa8..8fcc67925a 100644 --- a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ComponentRestUtils.java +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ComponentRestUtils.java @@ -20,8 +20,6 @@ package org.openecomp.sdc.ci.tests.utils.rest; -import java.io.IOException; - import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.model.CapReqDef; import org.openecomp.sdc.be.model.User; @@ -34,6 +32,8 @@ import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails; import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse; import org.openecomp.sdc.ci.tests.utils.Utils; +import java.io.IOException; + public class ComponentRestUtils extends BaseRestUtils { public static RestResponse getComponentRequirmentsCapabilities(User sdncModifierDetails, ComponentReqDetails componentReqDetails) throws IOException { diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/EcompUserRestUtils.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/EcompUserRestUtils.java index 9fdab02bb1..949ab68961 100644 --- a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/EcompUserRestUtils.java +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/EcompUserRestUtils.java @@ -20,11 +20,7 @@ package org.openecomp.sdc.ci.tests.utils.rest; -import java.io.IOException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - +import com.google.gson.Gson; import org.openecomp.portalsdk.core.restful.domain.EcompRole; import org.openecomp.portalsdk.core.restful.domain.EcompUser; import org.openecomp.sdc.ci.tests.api.Urls; @@ -37,7 +33,10 @@ import org.openecomp.sdc.ci.tests.utils.Utils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.gson.Gson; +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; public class EcompUserRestUtils extends BaseRestUtils { diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/GroupRestUtils.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/GroupRestUtils.java index f55cdbd035..e491b3bd17 100644 --- a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/GroupRestUtils.java +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/GroupRestUtils.java @@ -20,10 +20,7 @@ package org.openecomp.sdc.ci.tests.utils.rest; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - +import com.google.gson.Gson; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.User; @@ -33,7 +30,9 @@ 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.Utils; -import com.google.gson.Gson; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; public class GroupRestUtils extends BaseRestUtils { static Config config = Config.instance(); diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ImportRestUtils.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ImportRestUtils.java index 40dc060993..0edc294693 100644 --- a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ImportRestUtils.java +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ImportRestUtils.java @@ -20,22 +20,6 @@ package org.openecomp.sdc.ci.tests.utils.rest; -import static org.testng.AssertJUnit.assertEquals; -import static org.testng.AssertJUnit.assertNotNull; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.io.StringWriter; -import java.nio.file.FileSystems; -import java.nio.file.Files; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; - import org.apache.commons.io.IOUtils; import org.apache.http.HttpEntity; import org.apache.http.client.ClientProtocolException; @@ -64,6 +48,14 @@ import org.openecomp.sdc.common.http.client.api.HttpResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.*; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.util.*; + +import static org.testng.AssertJUnit.assertEquals; +import static org.testng.AssertJUnit.assertNotNull; + public class ImportRestUtils extends BaseRestUtils { private static Logger log = LoggerFactory.getLogger(ImportRestUtils.class.getName()); diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/InputsRestUtils.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/InputsRestUtils.java index de7be077d1..521da28522 100644 --- a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/InputsRestUtils.java +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/InputsRestUtils.java @@ -20,6 +20,7 @@ package org.openecomp.sdc.ci.tests.utils.rest; +import com.google.gson.Gson; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.ComponentInstInputsMap; @@ -33,8 +34,6 @@ import org.openecomp.sdc.ci.tests.utils.general.ElementFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.gson.Gson; - /** * RestUtils for inputs * diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/LifecycleRestUtils.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/LifecycleRestUtils.java index 9c0b7a89e0..44e7b56426 100644 --- a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/LifecycleRestUtils.java +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/LifecycleRestUtils.java @@ -20,19 +20,10 @@ package org.openecomp.sdc.ci.tests.utils.rest; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - import org.json.simple.JSONObject; import org.openecomp.sdc.be.datatypes.enums.AssetTypeEnum; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; -import org.openecomp.sdc.be.model.Component; -import org.openecomp.sdc.be.model.DistributionStatusEnum; -import org.openecomp.sdc.be.model.LifecycleStateEnum; -import org.openecomp.sdc.be.model.Product; -import org.openecomp.sdc.be.model.User; +import org.openecomp.sdc.be.model.*; import org.openecomp.sdc.ci.tests.api.Urls; import org.openecomp.sdc.ci.tests.config.Config; import org.openecomp.sdc.ci.tests.datatypes.ProductReqDetails; @@ -48,6 +39,11 @@ import org.openecomp.sdc.ci.tests.utils.general.ElementFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + public class LifecycleRestUtils extends BaseRestUtils { private static Logger logger = LoggerFactory.getLogger(LifecycleRestUtils.class.getName()); public static final String COMMENT = "comment"; @@ -78,10 +74,10 @@ public class LifecycleRestUtils extends BaseRestUtils { return changeLifeCycleOfAsset(serviceUUID, AssetTypeEnum.SERVICES, LifeCycleStatesEnum.CERTIFICATIONREQUEST, sdncModifierDetails, comment); } - public static RestResponse certificationRequestResource(String resourceUUID, User sdncModifierDetails) throws IOException { + /*public static RestResponse certificationRequestResource(String resourceUUID, User sdncModifierDetails) throws IOException { String comment = "Certification request resource: " + resourceUUID; return changeLifeCycleOfAsset(resourceUUID, AssetTypeEnum.RESOURCES, LifeCycleStatesEnum.CERTIFICATIONREQUEST, sdncModifierDetails, comment); - } + }*/ public static RestResponse startTestingService(String serviceUUID, User sdncModifierDetails) throws IOException { String comment = "Start testing request service: " + serviceUUID; @@ -277,10 +273,12 @@ public class LifecycleRestUtils extends BaseRestUtils { } public static RestResponse certifyResource(ResourceReqDetails resourceDetails) throws Exception { + + User designer = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER); RestResponse restResponseResource = LifecycleRestUtils.changeResourceState(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER), LifeCycleStatesEnum.CHECKIN); // if (restResponseResource.getErrorCode() == 200){ - restResponseResource = LifecycleRestUtils.changeResourceState(resourceDetails, +/* restResponseResource = LifecycleRestUtils.changeResourceState(resourceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER), LifeCycleStatesEnum.CERTIFICATIONREQUEST); // }else // return restResponseResource; @@ -289,16 +287,16 @@ public class LifecycleRestUtils extends BaseRestUtils { restResponseResource = LifecycleRestUtils.changeResourceState(resourceDetails, testerDetails, LifeCycleStatesEnum.STARTCERTIFICATION); } else - return restResponseResource; + return restResponseResource;*/ if (restResponseResource.getErrorCode() == 200) { - restResponseResource = LifecycleRestUtils.changeResourceState(resourceDetails, testerDetails, + restResponseResource = LifecycleRestUtils.changeResourceState(resourceDetails, designer, LifeCycleStatesEnum.CERTIFY); if (restResponseResource.getErrorCode() == 200) { String newVersion = ResponseParser.getVersionFromResponse(restResponseResource); resourceDetails.setVersion(newVersion); resourceDetails.setLifecycleState(LifecycleStateEnum.CERTIFIED); - resourceDetails.setLastUpdaterUserId(testerDetails.getUserId()); - resourceDetails.setLastUpdaterFullName(testerDetails.getFullName()); + resourceDetails.setLastUpdaterUserId(designer.getUserId()); + resourceDetails.setLastUpdaterFullName(designer.getFullName()); String uniqueIdFromRresponse = ResponseParser.getUniqueIdFromResponse(restResponseResource); resourceDetails.setUniqueId(uniqueIdFromRresponse); } diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ProductRestUtils.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ProductRestUtils.java index 65bc2f5d92..1a59a31ddf 100644 --- a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ProductRestUtils.java +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ProductRestUtils.java @@ -20,8 +20,7 @@ package org.openecomp.sdc.ci.tests.utils.rest; -import java.io.IOException; - +import com.google.gson.Gson; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.model.LifecycleStateEnum; import org.openecomp.sdc.be.model.Product; @@ -37,7 +36,7 @@ import org.openecomp.sdc.ci.tests.utils.general.ElementFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.gson.Gson; +import java.io.IOException; public class ProductRestUtils extends BaseRestUtils { private static Gson gson = new Gson(); diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/PropertyRestUtils.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/PropertyRestUtils.java index d507c2cb23..d5ae0a47a1 100644 --- a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/PropertyRestUtils.java +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/PropertyRestUtils.java @@ -27,14 +27,11 @@ import org.openecomp.sdc.ci.tests.api.Urls; import org.openecomp.sdc.ci.tests.config.Config; import org.openecomp.sdc.ci.tests.datatypes.PropertyObject; import org.openecomp.sdc.ci.tests.datatypes.http.HttpHeaderEnum; -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.HttpRequest; import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse; import org.openecomp.sdc.common.util.GeneralUtility; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.openecomp.sdc.ci.tests.datatypes.PropertyObject; import java.util.ArrayList; import java.util.HashMap; @@ -43,322 +40,319 @@ import java.util.Map; import static org.testng.AssertJUnit.*; -import com.google.gson.Gson; - public class PropertyRestUtils extends BaseRestUtils { - private static Logger logger = LoggerFactory.getLogger(PropertyRestUtils.class.getName()); - - public static RestResponse createProperty(String resourceId, String body, User user) throws Exception { - Config config = Config.instance(); - String url = String.format(Urls.CREATE_PROPERTY, config.getCatalogBeHost(), config.getCatalogBePort(), - resourceId); - - return sendPost(url, body, user.getUserId(), acceptHeaderData); - } - - public static RestResponse updateProperty(String resourceId, String propertyId, String body, User user) - throws Exception { - Config config = Config.instance(); - - String url = String.format(Urls.UPDATE_PROPERTY, config.getCatalogBeHost(), config.getCatalogBePort(), - resourceId, propertyId); - return sendPut(url, body, user.getUserId(), acceptHeaderData); - } - - public static RestResponse updateGroupProperty(Component component, String groupId, String body, User user) - throws Exception { - Config config = Config.instance(); - - String url = String.format(Urls.RESOURCE_GROUP_PROPERTY, config.getCatalogBeHost(), config.getCatalogBePort(), component.getUniqueId(), groupId); - return sendPut(url, body, user.getUserId(), acceptHeaderData); - } - - public static RestResponse getProperty(String resourceId, String propertyId, User user) throws Exception { - Config config = Config.instance(); - String url = String.format(Urls.GET_PROPERTY, config.getCatalogBeHost(), config.getCatalogBePort(), resourceId, - propertyId); - return sendGet(url, user.getUserId()); - } - - public static RestResponse deleteProperty(String resourceId, String propertyId, User user) throws Exception { - Config config = Config.instance(); - String url = String.format(Urls.DELETE_PROPERTY, config.getCatalogBeHost(), config.getCatalogBePort(), - resourceId, propertyId); - - return sendDelete(url, user.getUserId()); - } - - public static ComponentInstanceProperty getPropFromListByPropNameAndType(List<ComponentInstanceProperty> propList, - String propNameToUpdate, String propTypeToUpdate) { - for (ComponentInstanceProperty componentInstanceProperty : propList) { - if (componentInstanceProperty.getName().equals(propNameToUpdate) - && componentInstanceProperty.getType().equals(propTypeToUpdate)) { - return componentInstanceProperty; - } - } - return null; - } - - public static ComponentInstanceProperty getPropFromListByPropNameTypeAndPath( - List<ComponentInstanceProperty> propList, String propNameToUpdate, String propTypeToUpdate, - List<String> path) { - for (ComponentInstanceProperty componentInstanceProperty : propList) { - if (componentInstanceProperty.getPath() == null) { - return getPropFromListByPropNameAndType(propList, propNameToUpdate, propTypeToUpdate); - } - if (componentInstanceProperty.getName().equals(propNameToUpdate) - && componentInstanceProperty.getType().equals(propTypeToUpdate) - && path.containsAll(componentInstanceProperty.getPath())) { - return componentInstanceProperty; - } - } - return null; - } - - public static ComponentInstanceProperty getPropFromListByPropIdAndPath(List<ComponentInstanceProperty> propList, - String propId, List<String> path) { - - for (ComponentInstanceProperty componentInstanceProperty : propList) { - if (path != null) { - if (componentInstanceProperty.getUniqueId().equals(propId) - && componentInstanceProperty.getPath().equals(path)) { - return componentInstanceProperty; - } - } else { - if (componentInstanceProperty.getUniqueId().equals(propId)) { - return componentInstanceProperty; - } - } - } - return null; - } - - public static void comparePropertyLists(List<ComponentInstanceProperty> expectedList, - List<ComponentInstanceProperty> actualList, Boolean isUpdate) { - - assertTrue( - "list size are not equals, expected size is: " + expectedList.size() + " ,actual: " + actualList.size(), - expectedList.size() == actualList.size()); - Boolean flag = false; - for (ComponentInstanceProperty expectedcompInstProp : expectedList) { - for (ComponentInstanceProperty actualcompInstProp : actualList) { - flag = comparePropertyObjects(expectedcompInstProp, actualcompInstProp, isUpdate); - if (flag) { - break; - } - } - } - // System.out.println("expected: " + expectedList + ", actual: " + - // actualList); - logger.debug("expected: {}, actual: {}",expectedList,actualList); - assertTrue("actual lists does not contain all uniqeIds", flag); - } - - public static Boolean comparePropertyObjects(ComponentInstanceProperty expectedCompInstProp, - ComponentInstanceProperty actualCompInstProp, Boolean isUpdate) { - String uniqueId = expectedCompInstProp.getUniqueId(); - String type = expectedCompInstProp.getType(); - String defaulValue = expectedCompInstProp.getDefaultValue(); - if (actualCompInstProp.getUniqueId().equals(uniqueId) - && actualCompInstProp.getPath().equals(expectedCompInstProp.getPath())) { - assertTrue("expected type is: " + type + " ,actual: " + actualCompInstProp.getType(), - actualCompInstProp.getType().equals(type)); - if (defaulValue == null) { - assertTrue( - "expected defaulValue is: " + defaulValue + " ,actual: " + actualCompInstProp.getDefaultValue(), - actualCompInstProp.getDefaultValue() == defaulValue); - } else { - assertTrue( - "expected defaulValue is: " + defaulValue + " ,actual: " + actualCompInstProp.getDefaultValue(), - actualCompInstProp.getDefaultValue().equals(defaulValue)); - } - if (isUpdate) { - assertTrue( - "actual [Value] parameter " + actualCompInstProp.getName() - + "should equal to expected [Value]: " + actualCompInstProp.getValue() + " ,Value: " - + actualCompInstProp.getValue(), - actualCompInstProp.getValue().equals(expectedCompInstProp.getValue())); - assertNotNull("valueId is null", actualCompInstProp.getValueUniqueUid()); - } else { - if (defaulValue == null) { - assertTrue( - "actual [Value] parameter " + actualCompInstProp.getName() - + "should equal to expected [defaultValue]: " + actualCompInstProp.getValue() - + " ,defaultValue: " + actualCompInstProp.getDefaultValue(), - actualCompInstProp.getValue() == expectedCompInstProp.getDefaultValue()); - } else { - assertTrue( - "actual [Value] parameter " + actualCompInstProp.getName() - + "should equal to expected [defaultValue]: " + actualCompInstProp.getValue() - + " ,defaultValue: " + actualCompInstProp.getDefaultValue(), - actualCompInstProp.getValue().equals(expectedCompInstProp.getDefaultValue())); - } - assertNull("valueId is not null", actualCompInstProp.getValueUniqueUid()); - } - return true; - } - return false; - } - - public static List<ComponentInstanceProperty> addResourcePropertiesToList(Resource resource, - List<ComponentInstanceProperty> listToFill) { - for (PropertyDefinition prop : resource.getProperties()) { - listToFill.add(new ComponentInstanceProperty(prop, null, null)); - } - return listToFill; - } - - public static List<ComponentInstanceProperty> addComponentInstPropertiesToList(Component component, - List<ComponentInstanceProperty> listToFill, String componentId) { - - if (componentId != null) { - List<ComponentInstanceProperty> list = component.getComponentInstancesProperties().get(componentId); - for (ComponentInstanceProperty prop : list) { - ComponentInstanceProperty componentInstanceProperty = new ComponentInstanceProperty(prop, null, null); - componentInstanceProperty.setPath(prop.getPath()); - componentInstanceProperty.setValueUniqueUid(prop.getValueUniqueUid()); - componentInstanceProperty.setValue(prop.getValue()); - listToFill.add(componentInstanceProperty); - } - } else { - Map<String, List<ComponentInstanceProperty>> componentInstancesProperties = component - .getComponentInstancesProperties(); - for (Map.Entry<String, List<ComponentInstanceProperty>> componentInstanceProperties : componentInstancesProperties - .entrySet()) { - for (ComponentInstanceProperty prop : componentInstanceProperties.getValue()) { - ComponentInstanceProperty componentInstanceProperty = new ComponentInstanceProperty(prop, null, - null); - componentInstanceProperty.setPath(prop.getPath()); - componentInstanceProperty.setValueUniqueUid(prop.getValueUniqueUid()); - componentInstanceProperty.setValue(prop.getValue()); - listToFill.add(componentInstanceProperty); - } - } - } - - if (component.getComponentType().getValue().equals("Resource")) { - for (PropertyDefinition prop : ((Resource) component).getProperties()) { - listToFill.add(new ComponentInstanceProperty(prop, null, null)); - } - } - return listToFill; - } - - public static ComponentInstanceProperty getCompPropInstListByInstIdAndPropName(Component component, - ComponentInstance componentInstanceDetails, String name, String type) { - List<ComponentInstanceProperty> propList = component.getComponentInstancesProperties() - .get(componentInstanceDetails.getUniqueId()); - if (propList != null) { - return getPropFromListByPropNameAndType(propList, name, type); - } - return null; - } - - private static void updatePropertyListWithPathParameter(Resource resource, List<String> path, - List<ComponentInstanceProperty> expectedPropertyList) { - List<PropertyDefinition> propertyList = resource.getProperties(); - for (PropertyDefinition propertyDefinition : propertyList) { - ComponentInstanceProperty propDetailsToRemove = PropertyRestUtils.getPropFromListByPropNameAndType( - expectedPropertyList, propertyDefinition.getName(), propertyDefinition.getType()); - ComponentInstanceProperty propDetailsToAdd = propDetailsToRemove; - propDetailsToAdd.setPath(path); - expectedPropertyList.remove(propDetailsToRemove); - expectedPropertyList.add(propDetailsToAdd); - } - } - - private static void updatePropertyListWithPathParameterOnCompInst(Service service, List<String> path, - List<ComponentInstanceProperty> expectedPropertyList) { - List<ComponentInstanceProperty> servicePropertyList = new ArrayList<>(); - servicePropertyList = PropertyRestUtils.addComponentInstPropertiesToList(service, servicePropertyList, - path.get(0)); - - for (ComponentInstanceProperty serviceCompInstProperty : servicePropertyList) { - ComponentInstanceProperty propDetailsToRemove = PropertyRestUtils.getPropFromListByPropNameTypeAndPath( - expectedPropertyList, serviceCompInstProperty.getName(), serviceCompInstProperty.getType(), - serviceCompInstProperty.getPath()); - ComponentInstanceProperty propDetailsToAdd = propDetailsToRemove; - List<String> tempPathList = new ArrayList<String>(); - for (String tempPath : path) { - tempPathList.add(tempPath); - } - // path parameter can not contain the same service unique ID twice - if (propDetailsToAdd.getPath() != null - && !propDetailsToAdd.getPath().get(0).contains(service.getUniqueId())) { - if (!propDetailsToAdd.getPath().containsAll(tempPathList)) { - tempPathList.addAll(propDetailsToAdd.getPath()); - } - } - propDetailsToAdd.setPath(tempPathList); - expectedPropertyList.remove(propDetailsToRemove); - expectedPropertyList.add(propDetailsToAdd); - } - } - - public static void updatePropertyListWithPathOnResource(ComponentInstance componentInstDetails, Resource resource, - List<ComponentInstanceProperty> list, Component container) { - List<String> path = new ArrayList<>(); - if (container != null) { - List<ComponentInstance> componentInstances = container.getComponentInstances(); - for (ComponentInstance componentInstance : componentInstances) { - if (componentInstance.getNormalizedName().equals(componentInstDetails.getNormalizedName())) { - path.add(componentInstance.getUniqueId()); - break; - } - } - - } else { - path.add(componentInstDetails.getUniqueId()); - } - updatePropertyListWithPathParameter(resource, path, list); - } - - public static void updatePropertyListWithPathOnComponentInstance(ComponentInstance componentInstDetails, - Service service, List<ComponentInstanceProperty> list) { - List<String> path = new ArrayList<>(); - path.add(componentInstDetails.getUniqueId()); - updatePropertyListWithPathParameterOnCompInst(service, path, list); - } - - public static RestResponse declareProporties(Component componentObject, Map<String, List<ComponentInstanceInput>> componentInstancesInputs, User sdncModifierDetails) - throws Exception { - Config config = Config.instance(); - String url = String.format(Urls.DECLARE_PROPERTIES, config.getCatalogBeHost(), config.getCatalogBePort(), ComponentTypeEnum.findParamByType(componentObject.getComponentType()), componentObject.getUniqueId()); - String userId = sdncModifierDetails.getUserId(); - Map<String, String> headersMap = prepareHeadersMap(userId); - Map<String, Object> jsonBuilder = new HashMap<>(); - jsonBuilder.put("componentInstanceInputsMap", componentInstancesInputs); - Gson gson = new Gson(); - String userBodyJson = gson.toJson(jsonBuilder); - String calculateMD5 = GeneralUtility.calculateMD5Base64EncodedByString(userBodyJson); - headersMap.put(HttpHeaderEnum.Content_MD5.getValue(), calculateMD5); - HttpRequest http = new HttpRequest(); - // System.out.println(url); - // System.out.println(userBodyJson); - RestResponse declareProportiesResponse = http.httpSendPost(url, userBodyJson, headersMap); - if (declareProportiesResponse.getErrorCode() == STATUS_CODE_GET_SUCCESS) { - - } - return declareProportiesResponse; - } - - public static RestResponse updateInput(Component componentObject, PropertyObject componentInput, User sdncModifierDetails) - throws Exception { - Config config = Config.instance(); - String url = String.format(Urls.UPDATE_INPUT, config.getCatalogBeHost(), config.getCatalogBePort(), componentObject.getUniqueId()); - String userId = sdncModifierDetails.getUserId(); - Map<String, String> headersMap = prepareHeadersMap(userId); - Gson gson = new Gson(); - String userBodyJson = gson.toJson(componentInput); - String calculateMD5 = GeneralUtility.calculateMD5Base64EncodedByString(userBodyJson); - headersMap.put(HttpHeaderEnum.Content_MD5.getValue(), calculateMD5); - HttpRequest http = new HttpRequest(); - // System.out.println(url); - // System.out.println(userBodyJson); - RestResponse declareProportiesResponse = http.httpSendPost(url, userBodyJson, headersMap); - if (declareProportiesResponse.getErrorCode() == STATUS_CODE_GET_SUCCESS) { - - } - return declareProportiesResponse; - } + private static Logger logger = LoggerFactory.getLogger(PropertyRestUtils.class.getName()); + + public static RestResponse createProperty(String resourceId, String body, User user) throws Exception { + Config config = Config.instance(); + String url = String.format(Urls.CREATE_PROPERTY, config.getCatalogBeHost(), config.getCatalogBePort(), resourceId); + + return sendPost(url, body, user.getUserId(), acceptHeaderData); + } + + public static RestResponse updateProperty(String resourceId, String propertyId, String body, User user) + throws Exception { + Config config = Config.instance(); + + String url = String.format(Urls.UPDATE_PROPERTY, config.getCatalogBeHost(), config.getCatalogBePort(), + resourceId, propertyId); + return sendPut(url, body, user.getUserId(), acceptHeaderData); + } + + public static RestResponse updateGroupProperty(Component component, String groupId, String body, User user) + throws Exception { + Config config = Config.instance(); + + String url = String.format(Urls.RESOURCE_GROUP_PROPERTY, config.getCatalogBeHost(), config.getCatalogBePort(), component.getUniqueId(), groupId); + return sendPut(url, body, user.getUserId(), acceptHeaderData); + } + + public static RestResponse getProperty(String resourceId, String propertyId, User user) throws Exception { + Config config = Config.instance(); + String url = String.format(Urls.GET_PROPERTY, config.getCatalogBeHost(), config.getCatalogBePort(), resourceId, + propertyId); + return sendGet(url, user.getUserId()); + } + + public static RestResponse deleteProperty(String resourceId, String propertyId, User user) throws Exception { + Config config = Config.instance(); + String url = String.format(Urls.DELETE_PROPERTY, config.getCatalogBeHost(), config.getCatalogBePort(), + resourceId, propertyId); + + return sendDelete(url, user.getUserId()); + } + + public static ComponentInstanceProperty getPropFromListByPropNameAndType(List<ComponentInstanceProperty> propList, + String propNameToUpdate, String propTypeToUpdate) { + for (ComponentInstanceProperty componentInstanceProperty : propList) { + if (componentInstanceProperty.getName().equals(propNameToUpdate) + && componentInstanceProperty.getType().equals(propTypeToUpdate)) { + return componentInstanceProperty; + } + } + return null; + } + + public static ComponentInstanceProperty getPropFromListByPropNameTypeAndPath( + List<ComponentInstanceProperty> propList, String propNameToUpdate, String propTypeToUpdate, + List<String> path) { + for (ComponentInstanceProperty componentInstanceProperty : propList) { + if (componentInstanceProperty.getPath() == null) { + return getPropFromListByPropNameAndType(propList, propNameToUpdate, propTypeToUpdate); + } + if (componentInstanceProperty.getName().equals(propNameToUpdate) + && componentInstanceProperty.getType().equals(propTypeToUpdate) + && path.containsAll(componentInstanceProperty.getPath())) { + return componentInstanceProperty; + } + } + return null; + } + + public static ComponentInstanceProperty getPropFromListByPropIdAndPath(List<ComponentInstanceProperty> propList, + String propId, List<String> path) { + + for (ComponentInstanceProperty componentInstanceProperty : propList) { + if (path != null) { + if (componentInstanceProperty.getUniqueId().equals(propId) + && componentInstanceProperty.getPath().equals(path)) { + return componentInstanceProperty; + } + } else { + if (componentInstanceProperty.getUniqueId().equals(propId)) { + return componentInstanceProperty; + } + } + } + return null; + } + + public static void comparePropertyLists(List<ComponentInstanceProperty> expectedList, + List<ComponentInstanceProperty> actualList, Boolean isUpdate) { + + assertTrue( + "list size are not equals, expected size is: " + expectedList.size() + " ,actual: " + actualList.size(), + expectedList.size() == actualList.size()); + Boolean flag = false; + for (ComponentInstanceProperty expectedcompInstProp : expectedList) { + for (ComponentInstanceProperty actualcompInstProp : actualList) { + flag = comparePropertyObjects(expectedcompInstProp, actualcompInstProp, isUpdate); + if (flag) { + break; + } + } + } + // System.out.println("expected: " + expectedList + ", actual: " + + // actualList); + logger.debug("expected: {}, actual: {}", expectedList, actualList); + assertTrue("actual lists does not contain all uniqeIds", flag); + } + + public static Boolean comparePropertyObjects(ComponentInstanceProperty expectedCompInstProp, + ComponentInstanceProperty actualCompInstProp, Boolean isUpdate) { + String uniqueId = expectedCompInstProp.getUniqueId(); + String type = expectedCompInstProp.getType(); + String defaulValue = expectedCompInstProp.getDefaultValue(); + if (actualCompInstProp.getUniqueId().equals(uniqueId) + && actualCompInstProp.getPath().equals(expectedCompInstProp.getPath())) { + assertTrue("expected type is: " + type + " ,actual: " + actualCompInstProp.getType(), + actualCompInstProp.getType().equals(type)); + if (defaulValue == null) { + assertTrue( + "expected defaulValue is: " + defaulValue + " ,actual: " + actualCompInstProp.getDefaultValue(), + actualCompInstProp.getDefaultValue() == defaulValue); + } else { + assertTrue( + "expected defaulValue is: " + defaulValue + " ,actual: " + actualCompInstProp.getDefaultValue(), + actualCompInstProp.getDefaultValue().equals(defaulValue)); + } + if (isUpdate) { + assertTrue( + "actual [Value] parameter " + actualCompInstProp.getName() + + "should equal to expected [Value]: " + actualCompInstProp.getValue() + " ,Value: " + + actualCompInstProp.getValue(), + actualCompInstProp.getValue().equals(expectedCompInstProp.getValue())); + assertNotNull("valueId is null", actualCompInstProp.getValueUniqueUid()); + } else { + if (defaulValue == null) { + assertTrue( + "actual [Value] parameter " + actualCompInstProp.getName() + + "should equal to expected [defaultValue]: " + actualCompInstProp.getValue() + + " ,defaultValue: " + actualCompInstProp.getDefaultValue(), + actualCompInstProp.getValue() == expectedCompInstProp.getDefaultValue()); + } else { + assertTrue( + "actual [Value] parameter " + actualCompInstProp.getName() + + "should equal to expected [defaultValue]: " + actualCompInstProp.getValue() + + " ,defaultValue: " + actualCompInstProp.getDefaultValue(), + actualCompInstProp.getValue().equals(expectedCompInstProp.getDefaultValue())); + } + assertNull("valueId is not null", actualCompInstProp.getValueUniqueUid()); + } + return true; + } + return false; + } + + public static List<ComponentInstanceProperty> addResourcePropertiesToList(Resource resource, + List<ComponentInstanceProperty> listToFill) { + for (PropertyDefinition prop : resource.getProperties()) { + listToFill.add(new ComponentInstanceProperty(prop, null, null)); + } + return listToFill; + } + + public static List<ComponentInstanceProperty> addComponentInstPropertiesToList(Component component, + List<ComponentInstanceProperty> listToFill, String componentId) { + + if (componentId != null) { + List<ComponentInstanceProperty> list = component.getComponentInstancesProperties().get(componentId); + for (ComponentInstanceProperty prop : list) { + ComponentInstanceProperty componentInstanceProperty = new ComponentInstanceProperty(prop, null, null); + componentInstanceProperty.setPath(prop.getPath()); + componentInstanceProperty.setValueUniqueUid(prop.getValueUniqueUid()); + componentInstanceProperty.setValue(prop.getValue()); + listToFill.add(componentInstanceProperty); + } + } else { + Map<String, List<ComponentInstanceProperty>> componentInstancesProperties = component + .getComponentInstancesProperties(); + for (Map.Entry<String, List<ComponentInstanceProperty>> componentInstanceProperties : componentInstancesProperties + .entrySet()) { + for (ComponentInstanceProperty prop : componentInstanceProperties.getValue()) { + ComponentInstanceProperty componentInstanceProperty = new ComponentInstanceProperty(prop, null, + null); + componentInstanceProperty.setPath(prop.getPath()); + componentInstanceProperty.setValueUniqueUid(prop.getValueUniqueUid()); + componentInstanceProperty.setValue(prop.getValue()); + listToFill.add(componentInstanceProperty); + } + } + } + + if (component.getComponentType().getValue().equals("Resource")) { + for (PropertyDefinition prop : ((Resource) component).getProperties()) { + listToFill.add(new ComponentInstanceProperty(prop, null, null)); + } + } + return listToFill; + } + + public static ComponentInstanceProperty getCompPropInstListByInstIdAndPropName(Component component, + ComponentInstance componentInstanceDetails, String name, String type) { + List<ComponentInstanceProperty> propList = component.getComponentInstancesProperties() + .get(componentInstanceDetails.getUniqueId()); + if (propList != null) { + return getPropFromListByPropNameAndType(propList, name, type); + } + return null; + } + + private static void updatePropertyListWithPathParameter(Resource resource, List<String> path, + List<ComponentInstanceProperty> expectedPropertyList) { + List<PropertyDefinition> propertyList = resource.getProperties(); + for (PropertyDefinition propertyDefinition : propertyList) { + ComponentInstanceProperty propDetailsToRemove = PropertyRestUtils.getPropFromListByPropNameAndType( + expectedPropertyList, propertyDefinition.getName(), propertyDefinition.getType()); + ComponentInstanceProperty propDetailsToAdd = propDetailsToRemove; + propDetailsToAdd.setPath(path); + expectedPropertyList.remove(propDetailsToRemove); + expectedPropertyList.add(propDetailsToAdd); + } + } + + private static void updatePropertyListWithPathParameterOnCompInst(Service service, List<String> path, + List<ComponentInstanceProperty> expectedPropertyList) { + List<ComponentInstanceProperty> servicePropertyList = new ArrayList<>(); + servicePropertyList = PropertyRestUtils.addComponentInstPropertiesToList(service, servicePropertyList, + path.get(0)); + + for (ComponentInstanceProperty serviceCompInstProperty : servicePropertyList) { + ComponentInstanceProperty propDetailsToRemove = PropertyRestUtils.getPropFromListByPropNameTypeAndPath( + expectedPropertyList, serviceCompInstProperty.getName(), serviceCompInstProperty.getType(), + serviceCompInstProperty.getPath()); + ComponentInstanceProperty propDetailsToAdd = propDetailsToRemove; + List<String> tempPathList = new ArrayList<String>(); + for (String tempPath : path) { + tempPathList.add(tempPath); + } + // path parameter can not contain the same service unique ID twice + if (propDetailsToAdd.getPath() != null + && !propDetailsToAdd.getPath().get(0).contains(service.getUniqueId())) { + if (!propDetailsToAdd.getPath().containsAll(tempPathList)) { + tempPathList.addAll(propDetailsToAdd.getPath()); + } + } + propDetailsToAdd.setPath(tempPathList); + expectedPropertyList.remove(propDetailsToRemove); + expectedPropertyList.add(propDetailsToAdd); + } + } + + public static void updatePropertyListWithPathOnResource(ComponentInstance componentInstDetails, Resource resource, + List<ComponentInstanceProperty> list, Component container) { + List<String> path = new ArrayList<>(); + if (container != null) { + List<ComponentInstance> componentInstances = container.getComponentInstances(); + for (ComponentInstance componentInstance : componentInstances) { + if (componentInstance.getNormalizedName().equals(componentInstDetails.getNormalizedName())) { + path.add(componentInstance.getUniqueId()); + break; + } + } + + } else { + path.add(componentInstDetails.getUniqueId()); + } + updatePropertyListWithPathParameter(resource, path, list); + } + + public static void updatePropertyListWithPathOnComponentInstance(ComponentInstance componentInstDetails, + Service service, List<ComponentInstanceProperty> list) { + List<String> path = new ArrayList<>(); + path.add(componentInstDetails.getUniqueId()); + updatePropertyListWithPathParameterOnCompInst(service, path, list); + } + + public static RestResponse declareProporties(Component componentObject, Map<String, List<ComponentInstanceInput>> componentInstancesInputs, User sdncModifierDetails) + throws Exception { + Config config = Config.instance(); + String url = String.format(Urls.DECLARE_PROPERTIES, config.getCatalogBeHost(), config.getCatalogBePort(), ComponentTypeEnum.findParamByType(componentObject.getComponentType()), componentObject.getUniqueId()); + String userId = sdncModifierDetails.getUserId(); + Map<String, String> headersMap = prepareHeadersMap(userId); + Map<String, Object> jsonBuilder = new HashMap<>(); + jsonBuilder.put("componentInstanceInputsMap", componentInstancesInputs); + Gson gson = new Gson(); + String userBodyJson = gson.toJson(jsonBuilder); + String calculateMD5 = GeneralUtility.calculateMD5Base64EncodedByString(userBodyJson); + headersMap.put(HttpHeaderEnum.Content_MD5.getValue(), calculateMD5); + HttpRequest http = new HttpRequest(); + // System.out.println(url); + // System.out.println(userBodyJson); + RestResponse declareProportiesResponse = http.httpSendPost(url, userBodyJson, headersMap); + if (declareProportiesResponse.getErrorCode() == STATUS_CODE_GET_SUCCESS) { + + } + return declareProportiesResponse; + } + + public static RestResponse updateInput(Component componentObject, PropertyObject componentInput, User sdncModifierDetails) + throws Exception { + Config config = Config.instance(); + String url = String.format(Urls.UPDATE_INPUT, config.getCatalogBeHost(), config.getCatalogBePort(), componentObject.getUniqueId()); + String userId = sdncModifierDetails.getUserId(); + Map<String, String> headersMap = prepareHeadersMap(userId); + Gson gson = new Gson(); + String userBodyJson = gson.toJson(componentInput); + String calculateMD5 = GeneralUtility.calculateMD5Base64EncodedByString(userBodyJson); + headersMap.put(HttpHeaderEnum.Content_MD5.getValue(), calculateMD5); + HttpRequest http = new HttpRequest(); + // System.out.println(url); + // System.out.println(userBodyJson); + RestResponse declareProportiesResponse = http.httpSendPost(url, userBodyJson, headersMap); + if (declareProportiesResponse.getErrorCode() == STATUS_CODE_GET_SUCCESS) { + + } + return declareProportiesResponse; + } } diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ResourceRestUtils.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ResourceRestUtils.java index 599ce006fa..656ece54f0 100644 --- a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ResourceRestUtils.java +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ResourceRestUtils.java @@ -20,26 +20,16 @@ package org.openecomp.sdc.ci.tests.utils.rest; -import static org.testng.AssertJUnit.assertEquals; - -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonParser; import org.apache.http.client.ClientProtocolException; import org.json.JSONException; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; -import org.openecomp.sdc.be.model.CapabilityDefinition; -import org.openecomp.sdc.be.model.Component; -import org.openecomp.sdc.be.model.ComponentInstance; -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.*; import org.openecomp.sdc.be.resources.data.RelationshipInstData; import org.openecomp.sdc.ci.tests.api.Urls; import org.openecomp.sdc.ci.tests.config.Config; @@ -56,10 +46,14 @@ import org.openecomp.sdc.common.util.GeneralUtility; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.gson.Gson; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonParser; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.testng.AssertJUnit.assertEquals; public class ResourceRestUtils extends BaseRestUtils { private static Logger logger = LoggerFactory.getLogger(ResourceRestUtils.class.getName()); diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ResourceRestUtilsExternalAPI.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ResourceRestUtilsExternalAPI.java index 76d2ededfc..f09b14cc62 100644 --- a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ResourceRestUtilsExternalAPI.java +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ResourceRestUtilsExternalAPI.java @@ -20,8 +20,7 @@ package org.openecomp.sdc.ci.tests.utils.rest; -import java.util.Map; - +import com.google.gson.Gson; import org.openecomp.sdc.be.model.User; import org.openecomp.sdc.ci.tests.api.Urls; import org.openecomp.sdc.ci.tests.config.Config; @@ -32,7 +31,7 @@ import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse; import org.openecomp.sdc.ci.tests.utils.Utils; import org.openecomp.sdc.common.util.GeneralUtility; -import com.google.gson.Gson; +import java.util.Map; public class ResourceRestUtilsExternalAPI extends BaseRestUtils { diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ResponseParser.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ResponseParser.java index cbfc84d1cb..ec2121475e 100644 --- a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ResponseParser.java +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ResponseParser.java @@ -20,48 +20,66 @@ package org.openecomp.sdc.ci.tests.utils.rest; +//import com.fasterxml.jackson.databind.DeserializationFeature; +//import com.fasterxml.jackson.databind.ObjectMapper; +//import com.fasterxml.jackson.databind.module.SimpleModule; +//import com.google.gson.*; +//import org.apache.commons.codec.binary.Base64; +//import org.apache.log4j.Logger; +//import org.codehaus.jackson.JsonNode; +// +//import org.json.JSONArray; +//import org.json.JSONException; +//import org.json.simple.JSONObject; +//import org.json.simple.JSONValue; +//import org.openecomp.sdc.be.model.*; +//import org.openecomp.sdc.be.model.category.CategoryDefinition; +//import org.openecomp.sdc.be.model.operations.impl.PropertyOperation.PropertyConstraintJacksonDeserializer;; +//import org.openecomp.sdc.ci.tests.datatypes.ArtifactReqDetails; +//import org.openecomp.sdc.ci.tests.datatypes.ResourceAssetStructure; +//import org.openecomp.sdc.ci.tests.datatypes.ResourceRespJavaObject; +//import org.openecomp.sdc.ci.tests.datatypes.ServiceDistributionStatus; +//import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse; +//import org.openecomp.sdc.ci.tests.tosca.datatypes.VfModuleDefinition; +//import org.openecomp.sdc.ci.tests.utils.Utils; +//import org.yaml.snakeyaml.Yaml; +// +//import java.io.ByteArrayInputStream; +//import java.io.IOException; +//import java.io.InputStream; +//import java.text.ParseException; +//import java.util.*; + import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.exc.InvalidFormatException; import com.fasterxml.jackson.databind.module.SimpleModule; -import com.google.gson.Gson; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; +import com.google.gson.*; import org.apache.commons.codec.binary.Base64; import org.apache.log4j.Logger; import org.json.JSONArray; import org.json.JSONException; import org.json.simple.JSONObject; import org.json.simple.JSONValue; -import org.openecomp.sdc.be.model.ArtifactDefinition; -import org.openecomp.sdc.be.model.Component; -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.Product; -import org.openecomp.sdc.be.model.PropertyConstraint; -import org.openecomp.sdc.be.model.Resource; -import org.openecomp.sdc.be.model.Service; +import org.openecomp.sdc.be.model.*; import org.openecomp.sdc.be.model.category.CategoryDefinition; -import org.openecomp.sdc.be.model.operations.impl.PropertyOperation.PropertyConstraintJacksonDeserializer; +import org.openecomp.sdc.be.model.operations.impl.PropertyOperation; import org.openecomp.sdc.ci.tests.datatypes.ArtifactReqDetails; import org.openecomp.sdc.ci.tests.datatypes.ResourceAssetStructure; import org.openecomp.sdc.ci.tests.datatypes.ResourceRespJavaObject; import org.openecomp.sdc.ci.tests.datatypes.ServiceDistributionStatus; import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse; +import org.openecomp.sdc.ci.tests.tosca.datatypes.VfModuleDefinition; import org.openecomp.sdc.ci.tests.utils.Utils; +import org.yaml.snakeyaml.Yaml; +import java.io.ByteArrayInputStream; import java.io.IOException; +import java.io.InputStream; import java.text.ParseException; -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.List; -import java.util.Map; +import java.util.*; + +//import org.codehaus.jackson.JsonNode; public class ResponseParser { @@ -180,7 +198,7 @@ public class ResponseParser { private static ObjectMapper newObjectMapper() { SimpleModule module = new SimpleModule("customDeserializationModule"); - module.addDeserializer(PropertyConstraint.class, new PropertyConstraintJacksonDeserializer()); + module.addDeserializer(PropertyConstraint.class, new PropertyOperation.PropertyConstraintJacksonDeserializer()); return new ObjectMapper() .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) .registerModule(module); @@ -294,7 +312,7 @@ public class ResponseParser { return artifactReqDetails; } - public static Service convertServiceResponseToJavaObject(String response) { + /*public static Service convertServiceResponseToJavaObject(String response) { ObjectMapper mapper = newObjectMapper(); Service service = null; @@ -306,8 +324,27 @@ public class ResponseParser { } return service; + }*/ + public static Service convertServiceResponseToJavaObject(String response) { + + ObjectMapper mapper = newObjectMapper(); + Service service = null; + try { + service = mapper.readValue(response, Service.class); + logger.debug(service.toString()); + //Temporary catch until bug with distribution status fixed + } catch (InvalidFormatException e) { + System.out.println("broken service with invalid distribution status : " + response); + logger.debug("broken service with invalid distribution status : " + response); + return service; + } catch(IOException e){ + + e.printStackTrace(); } + return service; +} + public static Product convertProductResponseToJavaObject(String response) { ObjectMapper mapper = newObjectMapper(); @@ -446,6 +483,68 @@ public class ResponseParser { } } +// /*public static Map<String, List<Component>> convertCatalogResponseToJavaObject(String response) { +// +// // Map<String, ArrayList<Component>> map = new HashMap<String, +// // ArrayList<Component>>(); +// Map<String, List<Component>> map = new HashMap<>(); +// +// JsonElement jElement = new JsonParser().parse(response); +// JsonObject jObject = jElement.getAsJsonObject(); +// JsonArray jArrReousrces = jObject.getAsJsonArray("resources"); +// JsonArray jArrServices = jObject.getAsJsonArray("services"); +// //Product removed +//// JsonArray jArrProducts = jObject.getAsJsonArray("products"); +// //Product removed +// if (jArrReousrces != null && jArrServices != null /*&& jArrProducts != null*/){ +// +// +// //////// RESOURCE///////////////////////////// +// ArrayList<Component> restResponseArray = new ArrayList<>(); +// Component component = null; +// for (int i = 0; i < jArrReousrces.size(); i++) { +// String resourceString = (String) jArrReousrces.get(i).toString(); +// component = ResponseParser.convertResourceResponseToJavaObject(resourceString); +// restResponseArray.add(component); +// } +// +// map.put("resources", restResponseArray); +// +// ///////// SERVICE///////////////////////////// +// +// restResponseArray = new ArrayList<>(); +// component = null; +// for (int i = 0; i < jArrServices.size(); i++) { +// String resourceString = (String) jArrServices.get(i).toString(); +// component = ResponseParser.convertServiceResponseToJavaObject(resourceString); +// restResponseArray.add(component); +// } +// +// map.put("services", restResponseArray); +////Product removed +// ///////// PRODUCT///////////////////////////// +//// restResponseArray = new ArrayList<>(); +//// component = null; +//// for (int i = 0; i < jArrProducts.size(); i++) { +//// String resourceString = (String) jArrProducts.get(i).toString(); +//// component = ResponseParser.convertProductResponseToJavaObject(resourceString); +//// restResponseArray.add(component); +//// } +//// +//// map.put("products", restResponseArray); +//// +// } +// else { +// map.put("resources", new ArrayList<>()); +// map.put("services", new ArrayList<>()); +// //Product removed +//// map.put("products", new ArrayList<>()); +// } +// +// return map; +// +// }*/ + public static Map<String, List<Component>> convertCatalogResponseToJavaObject(String response) { // Map<String, ArrayList<Component>> map = new HashMap<String, @@ -456,57 +555,63 @@ public class ResponseParser { JsonObject jObject = jElement.getAsJsonObject(); JsonArray jArrReousrces = jObject.getAsJsonArray("resources"); JsonArray jArrServices = jObject.getAsJsonArray("services"); - JsonArray jArrProducts = jObject.getAsJsonArray("products"); - + //Product removed +// JsonArray jArrProducts = jObject.getAsJsonArray("products"); + //Product removed + if (jArrReousrces != null && jArrServices != null /*&& jArrProducts != null*/){ - //////// RESOURCE///////////////////////////// - ArrayList<Component> restResponseArray = new ArrayList<>(); - Component component = null; - if (jArrReousrces != null) { - for (int i = 0; i < jArrReousrces.size(); i++) { + //////// RESOURCE///////////////////////////// + ArrayList<Component> restResponseArray = new ArrayList<>(); + Component component = null; + for (int i = 0; i < jArrReousrces.size(); i++) { String resourceString = (String) jArrReousrces.get(i).toString(); component = ResponseParser.convertResourceResponseToJavaObject(resourceString); restResponseArray.add(component); - } - + } - } map.put("resources", restResponseArray); + map.put("resources", restResponseArray); + ///////// SERVICE///////////////////////////// - ///////// SERVICE///////////////////////////// - restResponseArray = new ArrayList<>(); - component = null; - if (jArrServices != null ) { - for (int i = 0; i < jArrServices.size(); i++) { + restResponseArray = new ArrayList<>(); + component = null; + for (int i = 0; i < jArrServices.size(); i++) { String resourceString = (String) jArrServices.get(i).toString(); component = ResponseParser.convertServiceResponseToJavaObject(resourceString); restResponseArray.add(component); - } - + } - } map.put("services", restResponseArray); + map.put("services", restResponseArray); +//Product removed + ///////// PRODUCT///////////////////////////// +// restResponseArray = new ArrayList<>(); +// component = null; +// for (int i = 0; i < jArrProducts.size(); i++) { +// String resourceString = (String) jArrProducts.get(i).toString(); +// component = ResponseParser.convertProductResponseToJavaObject(resourceString); +// restResponseArray.add(component); +// } +// - ///////// PRODUCT///////////////////////////// - restResponseArray = new ArrayList<>(); - component = null; - if ( jArrProducts != null){ - for (int i = 0; i < jArrProducts.size(); i++) { - String resourceString = (String) jArrProducts.get(i).toString(); - component = ResponseParser.convertProductResponseToJavaObject(resourceString); - restResponseArray.add(component); - } - } map.put("products", restResponseArray); +// map.put("products", restResponseArray); +// + } + else { + map.put("resources", new ArrayList<>()); + map.put("services", new ArrayList<>()); + //Product removed +// map.put("products", new ArrayList<>()); + } return map; } - public static Map<Long, ServiceDistributionStatus> convertServiceDistributionStatusToObject(String response) throws ParseException { Map<Long, ServiceDistributionStatus> serviceDistributionStatusMap = new HashMap<>(); @@ -555,5 +660,24 @@ public class ResponseParser { return null; } - + + public static Map<String, VfModuleDefinition> convertVfModuleJsonResponseToJavaObject(String response) { + + Yaml yaml = new Yaml(); + InputStream inputStream = null; + inputStream = new ByteArrayInputStream(response.getBytes()); + List<?> list = (List<?> )yaml.load(inputStream); + ObjectMapper mapper = new ObjectMapper(); + + VfModuleDefinition moduleDefinition; + Map<String, VfModuleDefinition> vfModulesMap = new HashMap<>(); + for (Object obj : list) { +// TODO Andrey L. uncomment line below in case to ignore on unknown properties, not recommended + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + moduleDefinition = mapper.convertValue(obj, VfModuleDefinition.class); + vfModulesMap.put(moduleDefinition.vfModuleModelName, moduleDefinition); + } + return vfModulesMap; + } + } diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ServiceRestUtils.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ServiceRestUtils.java index 1d8aef6f04..88666cce11 100644 --- a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ServiceRestUtils.java +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ServiceRestUtils.java @@ -20,10 +20,7 @@ package org.openecomp.sdc.ci.tests.utils.rest; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - +import com.google.gson.Gson; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.JSONValue; @@ -41,7 +38,9 @@ import org.openecomp.sdc.ci.tests.utils.general.ElementFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.gson.Gson; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; public class ServiceRestUtils extends BaseRestUtils { private static Logger logger = LoggerFactory.getLogger(ServiceRestUtils.class.getName()); diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/UserRestUtils.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/UserRestUtils.java index 5031391fe4..1a5136ef05 100644 --- a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/UserRestUtils.java +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/UserRestUtils.java @@ -20,10 +20,7 @@ package org.openecomp.sdc.ci.tests.utils.rest; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - +import com.google.gson.Gson; import org.apache.commons.lang.StringUtils; import org.openecomp.sdc.be.model.User; import org.openecomp.sdc.ci.tests.api.Urls; @@ -36,7 +33,9 @@ import org.openecomp.sdc.ci.tests.utils.Utils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.gson.Gson; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; public class UserRestUtils extends BaseRestUtils { |