summaryrefslogtreecommitdiffstats
path: root/test-apis-ci
diff options
context:
space:
mode:
Diffstat (limited to 'test-apis-ci')
-rw-r--r--test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/api/Urls.java1
-rw-r--r--test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/datatypes/PropertyReqDetails.java53
-rw-r--r--test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/inputs/InputsApiTests.java230
-rw-r--r--test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/property/PropertyApisTest.java175
-rw-r--r--test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/InputsRestUtils.java71
-rw-r--r--test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/PropertyRestUtils.java681
6 files changed, 714 insertions, 497 deletions
diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/api/Urls.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/api/Urls.java
index ad699d07ae..f85f326f03 100644
--- a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/api/Urls.java
+++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/api/Urls.java
@@ -361,6 +361,7 @@ public interface Urls {
final String GET_MODULE_BY_ID = SDC_HTTP_METHOD + "://%s:%s/sdc2/rest/v1/catalog/resources/%s/groups/%s";
// inputs
+ final String UPDATE_INPUTS = SDC_HTTP_METHOD + "://%s:%s/sdc2/rest/v1/catalog/%s/%s/update/inputs";
final String ADD_INPUTS = SDC_HTTP_METHOD + "://%s:%s/sdc2/rest/v1/catalog/%s/%s/create/inputs"; //{componentType}/{componentId}/create/inputs
final String DELETE_INPUT_BY_ID = SDC_HTTP_METHOD + "://%s:%s/sdc2/rest/v1/catalog/%s/%s/delete/%s/input"; //{componentType}/{componentId}/delete/{inputId}/input
final String GET_COMPONENT_INPUTS = SDC_HTTP_METHOD + "://%s:%s/sdc2/rest/v1/catalog/services/%s/inputs"; //services/{componentId}/inputs
diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/datatypes/PropertyReqDetails.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/datatypes/PropertyReqDetails.java
index 0898206002..64086884fa 100644
--- a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/datatypes/PropertyReqDetails.java
+++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/datatypes/PropertyReqDetails.java
@@ -7,9 +7,9 @@
* 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.
@@ -23,6 +23,7 @@ package org.openecomp.sdc.ci.tests.datatypes;
import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
public class PropertyReqDetails {
+
String name;
String type;
Boolean required = false;
@@ -32,14 +33,18 @@ public class PropertyReqDetails {
String propertyRangeMax;
Boolean isPassword = false;
SchemaDefinition schema;
+ String uniqueId;
+ String parentUniqueId;
+ String value;
public PropertyReqDetails() {
super();
}
public PropertyReqDetails(String propertyName, String propertyType, Boolean propertyRequired,
- String propertyDefaultValue, String propertyDescription, String propertyRangeMin, String propertyRangeMax,
- Boolean propertyPassword) {
+ String propertyDefaultValue, String propertyDescription, String propertyRangeMin,
+ String propertyRangeMax,
+ Boolean propertyPassword) {
super();
this.name = propertyName;
this.type = propertyType;
@@ -52,7 +57,7 @@ public class PropertyReqDetails {
}
public PropertyReqDetails(String propertyName, String propertyType, String propertyDefaultValue,
- String propertyDescription, SchemaDefinition schema) {
+ String propertyDescription, SchemaDefinition schema) {
super();
this.name = propertyName;
this.type = propertyType;
@@ -133,14 +138,42 @@ public class PropertyReqDetails {
this.isPassword = propertyPassword;
}
+ public String getUniqueId() {
+ return uniqueId;
+ }
+
+ public void setUniqueId(String uniqueId) {
+ this.uniqueId = uniqueId;
+ }
+
+ public String getParentUniqueId() {
+ return parentUniqueId;
+ }
+
+ public void setParentUniqueId(String parentUniqueId) {
+ this.parentUniqueId = parentUniqueId;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
public String propertyToJsonString() {
String jsonString;
jsonString =
- "{\"" + this.getName() + "\":{" + "\"name\":\"" + this.getName() + "\"," + "\"type\":\"" + this.getPropertyType() + "\"," + "\"required\":"
- + this.getPropertyRequired() + "," + "\"defaultValue\":\"" + this.getPropertyDefaultValue() + "\","
- + "\"description\":\"" + this.getPropertyDescription() + "\"," + "\"constraints\":[{\"inRange\":[\""
- + this.getPropertyRangeMin() + "\",\"" + this.getPropertyRangeMax() + "\"]}]," + "\"isPassword\":"
- + this.getPropertyPassword() + "}}";
+ "{\"" + this.getName() + "\":{" + "\"name\":\"" + this.getName() + "\"," + "\"type\":\"" + this
+ .getPropertyType() + "\"," + "\"required\":"
+ + this.getPropertyRequired() + "," + "\"defaultValue\":\"" + this.getPropertyDefaultValue()
+ + "\","
+ + "\"description\":\"" + this.getPropertyDescription() + "\","
+ + "\"constraints\":[{\"inRange\":[\""
+ + this.getPropertyRangeMin() + "\",\"" + this.getPropertyRangeMax() + "\"]}],"
+ + "\"isPassword\":"
+ + this.getPropertyPassword() + "}}";
return jsonString;
}
}
diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/inputs/InputsApiTests.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/inputs/InputsApiTests.java
index 91cf3b0c44..714a029fd8 100644
--- a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/inputs/InputsApiTests.java
+++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/inputs/InputsApiTests.java
@@ -7,9 +7,9 @@
* 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.
@@ -20,37 +20,61 @@
package org.openecomp.sdc.ci.tests.execute.inputs;
+import static org.testng.AssertJUnit.assertTrue;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
+
+import java.io.IOException;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
import fj.data.Either;
import org.apache.commons.lang3.tuple.Pair;
import org.junit.Rule;
import org.junit.rules.TestName;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
-import org.openecomp.sdc.be.model.*;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstInputsMap;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentInstancePropInput;
+import org.openecomp.sdc.be.model.InputDefinition;
+import org.openecomp.sdc.be.model.PropertyConstraint;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
+import org.openecomp.sdc.ci.tests.datatypes.PropertyReqDetails;
import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails;
import org.openecomp.sdc.ci.tests.datatypes.enums.LifeCycleStatesEnum;
import org.openecomp.sdc.ci.tests.datatypes.enums.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.*;
+import org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils;
+import org.openecomp.sdc.ci.tests.utils.rest.ComponentInstanceRestUtils;
+import org.openecomp.sdc.ci.tests.utils.rest.InputsRestUtils;
+import org.openecomp.sdc.ci.tests.utils.rest.PropertyRestUtils;
+import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
+import org.openecomp.sdc.ci.tests.utils.rest.ServiceRestUtils;
import org.openecomp.sdc.ci.tests.utils.validation.BaseValidationUtils;
+import org.testng.AssertJUnit;
import org.testng.annotations.Test;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-
-import static org.testng.AssertJUnit.assertTrue;
-
/**
- * CI-Tests for inputs
+ * CI-Tests for inputs
* @author il0695
*
*/
@@ -59,10 +83,10 @@ public class InputsApiTests extends ComponentBaseTest {
private static String inputCsar1 = "FCGI_with_inputs.csar";
private static String inputCsar2 = "LDSA1_with_inputs.csar";
private static User sdncDesignerDetails = null;
-
+
@Rule
public static TestName name = new TestName();
-
+
/**
* Constructor
*/
@@ -70,28 +94,28 @@ public class InputsApiTests extends ComponentBaseTest {
super(name, InputsApiTests.class.getName());
sdncDesignerDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
}
-
+
/**
* Create VF with inputs from CSAR file
- *
- * @throws Exception
+ *
+ * @throws Exception
*/
@Test
public void testCreateResourceInstanceWithInputsFromCsar() throws Exception {
Resource vf = AtomicOperationUtils.importResourceFromCsar(ResourceTypeEnum.VF, UserRoleEnum.DESIGNER, inputCsar1);
assertTrue("Success creating VF from CSAR", !vf.getInputs().isEmpty());
}
-
+
/**
* Create service and add to it VF instance with inputs
- *
- * @throws Exception
+ *
+ * @throws Exception
*/
@Test
public void testAddVfInstanceWithInputsToService() throws Exception {
createServiceWithVFInstanceWithInputs();
}
-
+
/**
* General test to check most functionality of inputs
* <ul>
@@ -101,33 +125,33 @@ public class InputsApiTests extends ComponentBaseTest {
* <li>Get service inputs</li>
* <li>Delete service inputs</li>
* </ul>
- *
- * @throws Exception
+ *
+ * @throws Exception
*/
@Test
public void testInputsMainFunctionality() throws Exception {
Service service = createServiceWithVFInstanceWithInputs();
int totalInputsBeforeAdd = service.getInputs().size();
-
+
// Get component instances
RestResponse getInstancesResponse = ComponentInstanceRestUtils.getComponentInstances(ComponentTypeEnum.SERVICE, service.getUniqueId(), sdncDesignerDetails);
BaseValidationUtils.checkSuccess(getInstancesResponse);
List<ComponentInstance> serviceInstances = new Gson().fromJson(getInstancesResponse.getResponse(), new TypeToken<ArrayList<ComponentInstance>>(){}.getType());
-
+
// Get all inputs of first instance
ComponentInstance vfInstance = serviceInstances.get(0);
RestResponse getComponentInstanceInputsResponse = InputsRestUtils.getComponentInstanceInputs(service, vfInstance);
BaseValidationUtils.checkSuccess(getComponentInstanceInputsResponse);
List<ComponentInstancePropInput> instanceInputs = new Gson().fromJson(getComponentInstanceInputsResponse.getResponse(), new TypeToken<ArrayList<ComponentInstancePropInput>>(){}.getType());
-
+
// Take only the 2 first inputs
List<ComponentInstancePropInput> inputsToAdd = instanceInputs.stream().limit(2).collect(Collectors.toList());
-
+
// Build component instances input map to add to server
ComponentInstInputsMap buildComponentInstInputsMap = buildComponentInstInputsMap(vfInstance.getUniqueId(), inputsToAdd);
RestResponse addInputResponse = InputsRestUtils.addInput(service, buildComponentInstInputsMap, UserRoleEnum.DESIGNER);
BaseValidationUtils.checkSuccess(addInputResponse);
-
+
// Get service inputs count
RestResponse getComponentInputsResponse = InputsRestUtils.getComponentInputs(service);
BaseValidationUtils.checkSuccess(getComponentInputsResponse);
@@ -135,11 +159,11 @@ public class InputsApiTests extends ComponentBaseTest {
if (serviceInputsAfterAdd.size()-totalInputsBeforeAdd!=2) {
assertTrue("Error adding inputs to service (service should have 2 inputs)", false);
}
-
+
// Delete 1 input from service
RestResponse deleteInputFromComponentResponse = InputsRestUtils.deleteInputFromComponent(service, serviceInputsAfterAdd.get(0).getUniqueId());
BaseValidationUtils.checkSuccess(deleteInputFromComponentResponse);
-
+
// Get service inputs count after delete
RestResponse getComponentInputsResponseAfterDelete = InputsRestUtils.getComponentInputs(service);
BaseValidationUtils.checkSuccess(getComponentInputsResponseAfterDelete);
@@ -147,14 +171,14 @@ public class InputsApiTests extends ComponentBaseTest {
if (serviceInputsAfterDelete.size()-totalInputsBeforeAdd!=1) {
assertTrue("Error deleting inputs from service (service should have 1 input)", false);
}
-
+
assertTrue("Success testing inputs main functionality", true);
}
/**
* Private method to create service with VF instance that has inputs
* This is private method to be used by multiple tests
- *
+ *
* @return {@link org.openecomp.sdc.be.model}
* @throws Exception
* @throws IOException
@@ -166,25 +190,25 @@ public class InputsApiTests extends ComponentBaseTest {
assertTrue("Error creating default service", false);
}
Service service = createDefaultServiceEither.left().value();
-
+
// Create VF from CSAR file
Resource vfWithInputs = AtomicOperationUtils.importResourceFromCsar(ResourceTypeEnum.VF, UserRoleEnum.DESIGNER, inputCsar2);
// Certify VF
Pair<Component, RestResponse> changeComponentState = AtomicOperationUtils.changeComponentState(vfWithInputs, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true);
assertTrue("response code is BaseRestUtils.STATUS_CODE_SUCCESS, returned :" + changeComponentState.getRight().getErrorCode(), changeComponentState.getRight().getErrorCode() == BaseRestUtils.STATUS_CODE_SUCCESS);
-
+
// Add VF instance to service
Either<ComponentInstance, RestResponse> addComponentInstanceToComponentContainerEither = AtomicOperationUtils.addComponentInstanceToComponentContainer(vfWithInputs, service, UserRoleEnum.DESIGNER, true);
if (addComponentInstanceToComponentContainerEither.isRight()){
assertTrue("Error adding VF to service", false);
}
-
+
// Get service response
ServiceReqDetails serviceDetails = new ServiceReqDetails(service);
RestResponse getServiceResponse = ServiceRestUtils.getService(serviceDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
service = ResponseParser.parseToObjectUsingMapper(getServiceResponse.getResponse(), Service.class);
-
+
// Get VF instance from service
ComponentInstance vfInstance = service.getComponentInstances().get(0);
if (vfInstance!=null){
@@ -194,10 +218,10 @@ public class InputsApiTests extends ComponentBaseTest {
}
return service;
}
-
+
/**
* Return default ComponentInstInputsMap
- *
+ *
* @param addToInput
* @param inputs
* @return {@link org.openecomp.sdc.be.model.ComponentInstInputsMap}
@@ -206,8 +230,132 @@ public class InputsApiTests extends ComponentBaseTest {
Map<String, List<ComponentInstancePropInput>> map = new HashMap<>();
map.put(addToInput, inputs);
ComponentInstInputsMap componentInstInputsMap = new ComponentInstInputsMap();
- componentInstInputsMap.setComponentInstanceInputsMap(map);
+ componentInstInputsMap.setComponentInstanceInputsMap(map);
return componentInstInputsMap;
}
+
+ @Test
+ public void validateValidValueConstraintOnInputFailTest() throws Exception {
+ Either<Service, RestResponse> createDefaultServiceEither = AtomicOperationUtils.createDefaultService(UserRoleEnum.DESIGNER, true);
+ if (createDefaultServiceEither.isRight()){
+ assertTrue("Error creating default service", false);
+ }
+ Service service = createDefaultServiceEither.left().value();
+
+ String body = "{\"SubnetProp\": {\"schema\": {\"property\": {\"type\": \"\"}},\"type\": \"org.openecomp"
+ + ".datatypes.heat.network.neutron.Subnet\",\"name\": \"SubnetProp\"}}";
+ RestResponse createPropertyResponse = PropertyRestUtils.createProperty(service.getUniqueId(), body,
+ sdncDesignerDetails);
+ AssertJUnit.assertEquals("Expected result code - 200, received - " + createPropertyResponse.getErrorCode(), 200,
+ (int) createPropertyResponse.getErrorCode());
+
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
+ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ PropertyReqDetails propertyResponseObject = mapper.readValue(createPropertyResponse.getResponse(),
+ PropertyReqDetails.class);
+
+ PropertyDefinition input = new PropertyDefinition();
+ input.setName("ipv6_address_mode");
+ input.setType("string");
+ input.setUniqueId("org.openecomp.datatypes.heat.network.neutron.Subnet.datatype.ipv6_address_mode");
+
+ ComponentInstancePropInput componentInstancePropInput = new ComponentInstancePropInput();
+ componentInstancePropInput.setPropertiesName("SubnetProp#ipv6_address_mode");
+ componentInstancePropInput.setName("SubnetProp");
+ componentInstancePropInput.setParentUniqueId(service.getUniqueId());
+ componentInstancePropInput.setType("org.openecomp.datatypes.heat.network.neutron.Subnet");
+ componentInstancePropInput.setUniqueId(propertyResponseObject.getUniqueId());
+ componentInstancePropInput.setInput(input);
+
+ ComponentInstInputsMap componentInstInputsMap = new ComponentInstInputsMap();
+ componentInstInputsMap.setServiceProperties(Collections.singletonMap(service.getUniqueId(),
+ Collections.singletonList(componentInstancePropInput)));
+ RestResponse addInputResponse = InputsRestUtils.addInput(service, componentInstInputsMap,
+ UserRoleEnum.DESIGNER);
+
+ AssertJUnit.assertEquals("Expected result code - 200, received - " + addInputResponse.getErrorCode(),
+ 200, (int) addInputResponse.getErrorCode());
+
+ Type constraintType = new TypeToken<PropertyConstraint>() {}.getType();
+ Type inDefType = new TypeToken<List<InputDefinition>>() { }.getType();
+ Gson gson = new GsonBuilder().registerTypeAdapter(constraintType, new PropertyOperation.PropertyConstraintDeserialiser()).create();
+ try {
+ List<InputDefinition> inputDefinitions = gson.fromJson(addInputResponse.getResponse(),
+ inDefType);
+
+ inputDefinitions.get(0).setDefaultValue("Fail");
+
+ RestResponse updateInputResponse = InputsRestUtils.updateInput(service, mapper.writeValueAsString(inputDefinitions),
+ UserRoleEnum.DESIGNER);
+
+ AssertJUnit.assertEquals("Expected result code - 400, received - " + addInputResponse.getErrorCode(),
+ 400, (int) updateInputResponse.getErrorCode());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void validateValidValueConstraintOnInputSuccessTest() throws Exception {
+ Either<Service, RestResponse> createDefaultServiceEither = AtomicOperationUtils.createDefaultService(UserRoleEnum.DESIGNER, true);
+ if (createDefaultServiceEither.isRight()){
+ assertTrue("Error creating default service", false);
+ }
+ Service service = createDefaultServiceEither.left().value();
+
+ String body = "{\"SubnetProp\": {\"schema\": {\"property\": {\"type\": \"\"}},\"type\": \"org.openecomp"
+ + ".datatypes.heat.network.neutron.Subnet\",\"name\": \"SubnetProp\"}}";
+ RestResponse createPropertyResponse = PropertyRestUtils.createProperty(service.getUniqueId(), body,
+ sdncDesignerDetails);
+ AssertJUnit.assertEquals("Expected result code - 200, received - " + createPropertyResponse.getErrorCode(), 200,
+ (int) createPropertyResponse.getErrorCode());
+
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
+ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ PropertyReqDetails propertyResponseObject = mapper.readValue(createPropertyResponse.getResponse(),
+ PropertyReqDetails.class);
+
+ PropertyDefinition input = new PropertyDefinition();
+ input.setName("ipv6_address_mode");
+ input.setType("string");
+ input.setUniqueId("org.openecomp.datatypes.heat.network.neutron.Subnet.datatype.ipv6_address_mode");
+
+ ComponentInstancePropInput componentInstancePropInput = new ComponentInstancePropInput();
+ componentInstancePropInput.setPropertiesName("SubnetProp#ipv6_address_mode");
+ componentInstancePropInput.setName("SubnetProp");
+ componentInstancePropInput.setParentUniqueId(service.getUniqueId());
+ componentInstancePropInput.setType("org.openecomp.datatypes.heat.network.neutron.Subnet");
+ componentInstancePropInput.setUniqueId(propertyResponseObject.getUniqueId());
+ componentInstancePropInput.setInput(input);
+
+ ComponentInstInputsMap componentInstInputsMap = new ComponentInstInputsMap();
+ componentInstInputsMap.setServiceProperties(Collections.singletonMap(service.getUniqueId(),
+ Collections.singletonList(componentInstancePropInput)));
+ RestResponse addInputResponse = InputsRestUtils.addInput(service, componentInstInputsMap,
+ UserRoleEnum.DESIGNER);
+
+ AssertJUnit.assertEquals("Expected result code - 200, received - " + addInputResponse.getErrorCode(),
+ 200, (int) addInputResponse.getErrorCode());
+
+ Type constraintType = new TypeToken<PropertyConstraint>() {}.getType();
+ Type inDefType = new TypeToken<List<InputDefinition>>() { }.getType();
+ Gson gson = new GsonBuilder().registerTypeAdapter(constraintType, new PropertyOperation.PropertyConstraintDeserialiser()).create();
+ try {
+ List<InputDefinition> inputDefinitions = gson.fromJson(addInputResponse.getResponse(),
+ inDefType);
+
+ inputDefinitions.get(0).setDefaultValue("slaac");
+
+ RestResponse updateInputResponse = InputsRestUtils.updateInput(service, mapper.writeValueAsString(inputDefinitions),
+ UserRoleEnum.DESIGNER);
+
+ AssertJUnit.assertEquals("Expected result code - 200, received - " + addInputResponse.getErrorCode(),
+ 200, (int) updateInputResponse.getErrorCode());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
}
diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/property/PropertyApisTest.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/property/PropertyApisTest.java
index 21e188649d..789b118419 100644
--- a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/property/PropertyApisTest.java
+++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/property/PropertyApisTest.java
@@ -7,9 +7,9 @@
* 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.
@@ -20,6 +20,19 @@
package org.openecomp.sdc.ci.tests.execute.property;
+import static org.testng.AssertJUnit.assertTrue;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import org.junit.Rule;
@@ -47,19 +60,12 @@ import org.testng.AssertJUnit;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import java.util.*;
-
-import static org.testng.AssertJUnit.assertTrue;
-
public class PropertyApisTest extends SimpleOneRsrcOneServiceTest {
protected static final String RESOURCE_CATEGORY = "Generic/Databases";
protected Config config = Config.instance();
protected String contentTypeHeaderData = "application/json";
protected String acceptHeaderDate = "application/json";;
-
- // protected User sdncDesignerDetails;
- // protected ResourceReqDetails resourceDetails;
protected PropertyReqDetails property;
protected String body;
@@ -75,30 +81,8 @@ public class PropertyApisTest extends SimpleOneRsrcOneServiceTest {
@BeforeMethod
public void init() throws Exception {
- //
- // //Delete resource
- //
- // resourceDetails = new ResourceReqDetails();
- // resourceDetails.setResourceName("testresourceDetails");
- //
- // resourceUtils.deleteResource_allVersions(resourceDetails,
- // sdncDesignerDetails);
- //
- // //Create resource
- // resourceDetails = createResource(sdncDesignerDetails,
- // "testresourceDetails");
-
- // Create property
- // property.setPropertyName("test");
- // property.setPropertyType("integer");
- // property.setPropertySource("A&AI");
- // property.setPropertyDescription("test property");
-
- // body = gson.toJson(property);
property = ElementFactory.getDefaultProperty();
body = property.propertyToJsonString();
- // System.out.println(body);
- // HTTP (for negative tests)
headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), contentTypeHeaderData);
headersMap.put(HttpHeaderEnum.ACCEPT.getValue(), acceptHeaderDate);
headersMap.put(HttpHeaderEnum.USER_ID.getValue(), sdncDesignerDetails.getUserId());
@@ -106,10 +90,75 @@ public class PropertyApisTest extends SimpleOneRsrcOneServiceTest {
}
@Test
- public void testPropertyApis() throws Exception {
- // Create property
- // System.out.println ("---- Create Property (POST) ----");
+ public void validateValidValueConstraintFailTest() throws Exception {
+ body = "{\"SubnetProp\": {\"schema\": {\"property\": {\"type\": \"\"}},\"type\": \"org.openecomp.datatypes.heat.network.neutron.Subnet\",\"name\": \"SubnetProp\"}}";
+ RestResponse createPropertyResponse = PropertyRestUtils.createProperty(getResourceId(resourceDetails), body,
+ sdncDesignerDetails);
+ AssertJUnit.assertEquals("Expected result code - 200, received - " + createPropertyResponse.getErrorCode(), 200,
+ (int) createPropertyResponse.getErrorCode());
+
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
+ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ try {
+ PropertyReqDetails propertyResponseObject = mapper.readValue(createPropertyResponse.getResponse(),
+ PropertyReqDetails.class);
+
+ PropertyReqDetails propertyReqDetails = new PropertyReqDetails();
+ propertyReqDetails.setPropertyType("org.openecomp.datatypes.heat.network.neutron.Subnet");
+ propertyReqDetails.setName(propertyResponseObject.getName());
+ propertyReqDetails.setValue(mapper.writeValueAsString(Collections.singletonMap("ipv6_address_mode", "Fail")));
+ propertyReqDetails.setParentUniqueId(propertyResponseObject.getParentUniqueId());
+ propertyReqDetails.setUniqueId(propertyResponseObject.getUniqueId());
+
+ body = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(Collections.singletonList(propertyReqDetails));
+ body = body.replace("propertyType", "type");
+ RestResponse addValueToPropertyResponse =
+ PropertyRestUtils.addValueToProperty(getResourceId(resourceDetails), body, sdncDesignerDetails);
+
+ AssertJUnit.assertEquals("Expected result code - 400, received - " + addValueToPropertyResponse.getErrorCode(),
+ 400, (int) addValueToPropertyResponse.getErrorCode());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ @Test
+ public void validateValidValueConstraintSuccessTest() throws Exception {
+ body = "{\"SubnetProp\": {\"schema\": {\"property\": {\"type\": \"\"}},\"type\": \"org.openecomp.datatypes.heat.network.neutron.Subnet\",\"name\": \"SubnetProp\"}}";
+ RestResponse createPropertyResponse = PropertyRestUtils.createProperty(getResourceId(resourceDetails), body,
+ sdncDesignerDetails);
+ AssertJUnit.assertEquals("Expected result code - 201, received - " + createPropertyResponse.getErrorCode(), 200,
+ (int) createPropertyResponse.getErrorCode());
+
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
+ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ try {
+ PropertyReqDetails propertyResponseObject = mapper.readValue(createPropertyResponse.getResponse(),
+ PropertyReqDetails.class);
+
+ PropertyReqDetails propertyReqDetails = new PropertyReqDetails();
+ propertyReqDetails.setPropertyType("org.openecomp.datatypes.heat.network.neutron.Subnet");
+ propertyReqDetails.setName(propertyResponseObject.getName());
+ propertyReqDetails.setValue(mapper.writeValueAsString(Collections.singletonMap("ipv6_address_mode", "slaac")));
+ propertyReqDetails.setParentUniqueId(propertyResponseObject.getParentUniqueId());
+ propertyReqDetails.setUniqueId(propertyResponseObject.getUniqueId());
+
+ body = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(Collections.singletonList(propertyReqDetails));
+ body = body.replace("propertyType", "type");
+ RestResponse addValueToPropertyResponse =
+ PropertyRestUtils.addValueToProperty(getResourceId(resourceDetails), body, sdncDesignerDetails);
+
+ AssertJUnit.assertEquals("Expected result code - 200, received - " + addValueToPropertyResponse.getErrorCode(),
+ 200, (int) addValueToPropertyResponse.getErrorCode());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void testPropertyApis() throws Exception {
String propertyId = UniqueIdBuilder.buildComponentPropertyUniqueId(getResourceId(resourceDetails), property.getName());
PropertyRestUtils.deleteProperty(getResourceId(resourceDetails), propertyId, sdncDesignerDetails);
@@ -119,7 +168,6 @@ public class PropertyApisTest extends SimpleOneRsrcOneServiceTest {
createPropertyResponse.getErrorCode() == 201);
// Get property
- // System.out.println ("---- Get Property (GET) ----");
RestResponse getPropertyResponse = PropertyRestUtils.getProperty(getResourceId(resourceDetails), propertyId,
sdncDesignerDetails);
AssertJUnit.assertTrue("Expected result code - 200, received - " + getPropertyResponse.getErrorCode(),
@@ -127,19 +175,8 @@ public class PropertyApisTest extends SimpleOneRsrcOneServiceTest {
JSONObject jsonResp = (JSONObject) JSONValue.parse(getPropertyResponse.getResponse());
- // assertTrue("Wrong 'type' in the
- // response",jsonResp.get("type").equals(property.getPropertyType()));
- // assertTrue("Wrong 'source' in the
- // response",jsonResp.get("name").equals(property.getPropertyName()));
- // assertTrue("Wrong 'name' in the
- // response",jsonResp.get("source").equals(property.getPropertySource()));
- // assertTrue("Wrong 'description' in the
- // response",jsonResp.get("description").equals(property.getPropertyDescription()));
-
// Update property
- // System.out.println ("---- Update Property (UPDATE) ----");
property.setPropertyDescription("Updated description");
- // body = gson.toJson(property);
body = property.propertyToJsonString();
RestResponse updatePropertyResponse = PropertyRestUtils.updateProperty(getResourceId(resourceDetails),
@@ -148,7 +185,6 @@ public class PropertyApisTest extends SimpleOneRsrcOneServiceTest {
updatePropertyResponse.getErrorCode() == 200);
// Get property
- // System.out.println ("---- Get Property (GET) ----");
getPropertyResponse = PropertyRestUtils.getProperty(getResourceId(resourceDetails), propertyId,
sdncDesignerDetails);
AssertJUnit.assertTrue("Expected result code - 200, received - " + getPropertyResponse.getErrorCode(),
@@ -156,24 +192,13 @@ public class PropertyApisTest extends SimpleOneRsrcOneServiceTest {
jsonResp = (JSONObject) JSONValue.parse(getPropertyResponse.getResponse());
- // assertTrue("Wrong 'type' in the
- // response",jsonResp.get("type").equals(property.getPropertyType()));
- // assertTrue("Wrong 'source' in the
- // response",jsonResp.get("name").equals(property.getPropertyName()));
- // assertTrue("Wrong 'name' in the
- // response",jsonResp.get("source").equals(property.getPropertySource()));
- // assertTrue("Wrong 'description' in the
- // response",jsonResp.get("description").equals(property.getPropertyDescription()));
-
// Delete property
- // System.out.println ("---- Delete Property (DELETE) ----");
RestResponse deletePropertyResponse = PropertyRestUtils.deleteProperty(getResourceId(resourceDetails),
propertyId, sdncDesignerDetails);
AssertJUnit.assertTrue("Expected result code - 204, received - " + deletePropertyResponse.getErrorCode(),
deletePropertyResponse.getErrorCode() == 204);
// Get property - verify that the property doesn't exist.
- // System.out.println("---- GET - Property Not Found ----");
getPropertyResponse = PropertyRestUtils.getProperty(getResourceId(resourceDetails), propertyId,
sdncDesignerDetails);
List<String> variables = Arrays.asList("");
@@ -185,16 +210,10 @@ public class PropertyApisTest extends SimpleOneRsrcOneServiceTest {
// --------------------------------------------------------------------------------------
protected String getPropertyId(ResourceReqDetails resource, PropertyReqDetails property) {
- // return
- // resource.getResourceName().toLowerCase()+".0.1."+property.getPropertyName();
return UniqueIdBuilder.buildComponentPropertyUniqueId(resource.getUniqueId(), property.getName());
}
protected String getResourceId(ResourceReqDetails resource) {
- // String resourceUid =
- // UniqueIdBuilder.buildResourceUniqueId(resource.getResourceName(),
- // "0.1");
-
return resource.getUniqueId();
}
@@ -212,7 +231,6 @@ public class PropertyApisTest extends SimpleOneRsrcOneServiceTest {
String description = "description";
ArrayList<String> resourceTags = new ArrayList<String>();
resourceTags.add(resourceName);
- // String category = ResourceCategoryEnum.DATABASE.getValue();
ArrayList<String> derivedFrom = new ArrayList<String>();
derivedFrom.add("tosca.nodes.Root");
String vendorName = "Oracle";
@@ -224,7 +242,6 @@ public class PropertyApisTest extends SimpleOneRsrcOneServiceTest {
derivedFrom, vendorName, vendorRelease, contactId, icon);
resourceDetails.addCategoryChain(ResourceCategoryEnum.GENERIC_DATABASE.getCategory(),
ResourceCategoryEnum.GENERIC_DATABASE.getSubCategory());
- // deleteResource(resourceName.toLowerCase()+".0.1",sdncUserDetails.getUserId());
// TODO delete by name
// deleteResource(UniqueIdBuilder.buildResourceUniqueId(resourceName,
// "0.1"), sdncUserDetails.getUserId());
@@ -239,8 +256,6 @@ public class PropertyApisTest extends SimpleOneRsrcOneServiceTest {
@Test
public void putReqToCreateUriNotAllowed() throws Exception {
- // System.out.println("---- PUT request to Create uri - Not Allowed
- // ----");
String url = String.format(Urls.CREATE_PROPERTY, config.getCatalogBeHost(), config.getCatalogBePort(),
getResourceId(resourceDetails));
RestResponse propertyErrorResponse = httpRequest.httpSendByMethod(url, "PUT", body, headersMap);
@@ -251,8 +266,6 @@ public class PropertyApisTest extends SimpleOneRsrcOneServiceTest {
@Test
public void getReqToCreateUriNotAllowed() throws Exception {
- // System.out.println("---- GET request to Create uri - Not Allowed
- // ----");
String url = String.format(Urls.CREATE_PROPERTY, config.getCatalogBeHost(), config.getCatalogBePort(),
getResourceId(resourceDetails));
RestResponse propertyErrorResponse = httpRequest.httpSendGet(url, headersMap);
@@ -263,8 +276,6 @@ public class PropertyApisTest extends SimpleOneRsrcOneServiceTest {
@Test
public void deleteReqToCreateUriNotAllowed() throws Exception {
- // System.out.println("---- DELETE request to Create uri - Not Allowed
- // ----");
String url = String.format(Urls.CREATE_PROPERTY, config.getCatalogBeHost(), config.getCatalogBePort(),
getResourceId(resourceDetails));
RestResponse propertyErrorResponse = httpRequest.httpSendDelete(url, headersMap);
@@ -275,8 +286,6 @@ public class PropertyApisTest extends SimpleOneRsrcOneServiceTest {
@Test
public void postReqToUpdateUriNotAllowed() throws Exception {
- // System.out.println("---- POST request to Update uri - Not Allowed
- // ----");
String url = String.format(Urls.UPDATE_PROPERTY, config.getCatalogBeHost(), config.getCatalogBePort(),
getResourceId(resourceDetails), getPropertyId(resourceDetails, property));
RestResponse propertyErrorResponse = httpRequest.httpSendPost(url, body, headersMap);
@@ -287,7 +296,6 @@ public class PropertyApisTest extends SimpleOneRsrcOneServiceTest {
@Test
public void deleteReqPropertyNotFound() throws Exception {
- // System.out.println("---- DELETE - Property Not Found ----");
String unknownPropertyId = getPropertyId(resourceDetails, property) + "111";
String url = String.format(Urls.DELETE_PROPERTY, config.getCatalogBeHost(), config.getCatalogBePort(),
getResourceId(resourceDetails), unknownPropertyId);
@@ -299,7 +307,6 @@ public class PropertyApisTest extends SimpleOneRsrcOneServiceTest {
@Test
public void updateReqPropertyNotFound() throws Exception {
- // System.out.println("---- PUT - Property Not Found ----");
String unknownPropertyId = getPropertyId(resourceDetails, property) + "111";
String url = String.format(Urls.UPDATE_PROPERTY, config.getCatalogBeHost(), config.getCatalogBePort(),
getResourceId(resourceDetails), unknownPropertyId);
@@ -311,12 +318,10 @@ public class PropertyApisTest extends SimpleOneRsrcOneServiceTest {
@Test
public void modifierNotTheStateOwner() throws Exception {
- // System.out.println("---- The modifier is not the state owner -
// Operation Not Allowed ----");
User sdncUserDetails2 = createUser("tu5555", "Test", "User", "tu5555@intl.sdc.com", "DESIGNER");
headersMap.put(HttpHeaderEnum.USER_ID.getValue(), sdncUserDetails2.getUserId());
property.setPropertyDescription("new description");
- // body = gson.toJson(property);
body = property.propertyToJsonString();
String url = String.format(Urls.UPDATE_PROPERTY, config.getCatalogBeHost(), config.getCatalogBePort(),
getResourceId(resourceDetails), getPropertyId(resourceDetails, property));
@@ -329,15 +334,11 @@ public class PropertyApisTest extends SimpleOneRsrcOneServiceTest {
@Test
public void postReqInvalidContent() throws Exception {
- // System.out.println("---- POST - Invalid Content ----");
body = "invalid";
String url = String.format(Urls.CREATE_PROPERTY, config.getCatalogBeHost(), config.getCatalogBePort(),
getResourceId(resourceDetails), getPropertyId(resourceDetails, property));
RestResponse propertyErrorResponse = httpRequest.httpSendPost(url, body, headersMap);
- // System.out.println(propertyErrorResponse.getResponse()+" "+
- // propertyErrorResponse.getErrorCode());
-
List<String> variables = Arrays.asList();
ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.INVALID_CONTENT.name(), variables,
propertyErrorResponse.getResponse());
@@ -347,30 +348,20 @@ public class PropertyApisTest extends SimpleOneRsrcOneServiceTest {
public void putReqInvalidContent() throws Exception {
// Create property
- // System.out.println ("---- Create Property (POST) ----");
RestResponse createPropertyResponse = PropertyRestUtils.createProperty(getResourceId(resourceDetails), body,
sdncDesignerDetails);
assertTrue("Expected result code - 201, received - " + createPropertyResponse.getErrorCode(),
createPropertyResponse.getErrorCode() == 201);
- // System.out.println("---- PUT - Invalid Content ----");
body = "invalid";
String url = String.format(Urls.UPDATE_PROPERTY, config.getCatalogBeHost(), config.getCatalogBePort(),
getResourceId(resourceDetails), getPropertyId(resourceDetails, property));
- // System.out.println(url + "\n" + body);
-
RestResponse propertyErrorResponse = httpRequest.httpSendByMethod(url, "PUT", body, headersMap);
- // System.out.println(propertyErrorResponse.getResponse()+" "+
- // propertyErrorResponse.getErrorCode());
-
List<String> variables = Arrays.asList();
ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.INVALID_CONTENT.name(), variables,
propertyErrorResponse.getResponse());
}
-
- // --------------------------------------------------------------------------------------
-
}
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 521da28522..36fe6e3ea7 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
@@ -7,9 +7,9 @@
* 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.
@@ -21,6 +21,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;
@@ -36,34 +37,51 @@ import org.slf4j.LoggerFactory;
/**
* RestUtils for inputs
- *
- * @author il0695
*
+ * @author il0695
*/
public class InputsRestUtils extends BaseRestUtils {
@SuppressWarnings("unused")
private static Logger logger = LoggerFactory.getLogger(InputsRestUtils.class.getName());
-
+
/**
* Add inputs to service
- *
+ *
* @param component
* @param inputs
* @param userRole
* @return {@link org.openecomp.sdc.ci.tests.datatypes.http.RestResponse}
* @throws Exception
*/
- public static RestResponse addInput(Component component, ComponentInstInputsMap inputs, UserRoleEnum userRole) throws Exception {
+ public static RestResponse addInput(Component component, ComponentInstInputsMap inputs, UserRoleEnum userRole)
+ throws Exception {
Config config = Utils.getConfig();
- String url = String.format(Urls.ADD_INPUTS, config.getCatalogBeHost(), config.getCatalogBePort(), ComponentTypeEnum.findParamByType(component.getComponentType()), component.getUniqueId());
+ String url = String.format(Urls.ADD_INPUTS, config.getCatalogBeHost(), config.getCatalogBePort(),
+ ComponentTypeEnum.findParamByType(component.getComponentType()), component.getUniqueId());
String json = new Gson().toJson(inputs);
return sendPost(url, json, userRole.getUserId(), acceptHeaderData);
}
/**
+ * Update inputs to service
+ *
+ * @param component
+ * @param data
+ * @param userRole
+ * @return {@link org.openecomp.sdc.ci.tests.datatypes.http.RestResponse}
+ * @throws Exception
+ */
+ public static RestResponse updateInput(Component component, String data, UserRoleEnum userRole) throws Exception {
+ Config config = Utils.getConfig();
+ String url = String.format(Urls.UPDATE_INPUTS, config.getCatalogBeHost(), config.getCatalogBePort(),
+ ComponentTypeEnum.findParamByType(component.getComponentType()), component.getUniqueId());
+ return sendPost(url, data, userRole.getUserId(), acceptHeaderData);
+ }
+
+ /**
* Get all Component inputs
- *
+ *
* @param component
* @return {@link org.openecomp.sdc.ci.tests.datatypes.http.RestResponse}
* @throws Exception
@@ -71,51 +89,60 @@ public class InputsRestUtils extends BaseRestUtils {
public static RestResponse getComponentInputs(Component component) throws Exception {
Config config = Utils.getConfig();
//services/{componentId}/inputs
- String url = String.format(Urls.GET_COMPONENT_INPUTS, config.getCatalogBeHost(), config.getCatalogBePort(), component.getUniqueId());
+ String url = String.format(Urls.GET_COMPONENT_INPUTS, config.getCatalogBeHost(), config.getCatalogBePort(),
+ component.getUniqueId());
return sendGet(url, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER).getUserId());
}
-
+
/**
* Get all inputs of component instance
- *
+ *
* @param parentComponent
* @param componentInstance
* @return {@link org.openecomp.sdc.ci.tests.datatypes.http.RestResponse}
* @throws Exception
*/
- public static RestResponse getComponentInstanceInputs(Component parentComponent, ComponentInstance componentInstance) throws Exception {
+ public static RestResponse getComponentInstanceInputs(Component parentComponent,
+ ComponentInstance componentInstance) throws Exception {
Config config = Utils.getConfig();
- //{componentType}/{componentId}/componentInstances/{instanceId}/{originComonentUid}/inputs
- String url = String.format(Urls.GET_COMPONENT_INSTANCE_INPUTS, config.getCatalogBeHost(), config.getCatalogBePort(), ComponentTypeEnum.findParamByType(parentComponent.getComponentType()), parentComponent.getUniqueId(), componentInstance.getUniqueId(), componentInstance.getComponentUid());
+ //{componentType}/{componentId}/componentInstances/{instanceId}/{originComonentUid}/inputs
+ String url =
+ String.format(Urls.GET_COMPONENT_INSTANCE_INPUTS, config.getCatalogBeHost(), config.getCatalogBePort(),
+ ComponentTypeEnum.findParamByType(parentComponent.getComponentType()),
+ parentComponent.getUniqueId(), componentInstance.getUniqueId(),
+ componentInstance.getComponentUid());
return sendGet(url, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER).getUserId());
}
-
+
/**
* Delete input from component
- *
+ *
* @param parentComponent
* @param inputId
* @return {@link org.openecomp.sdc.ci.tests.datatypes.http.RestResponse}
* @throws Exception
*/
public static RestResponse deleteInputFromComponent(Component parentComponent, String inputId) throws Exception {
- return deleteInputFromComponent(ComponentTypeEnum.findParamByType(parentComponent.getComponentType()), parentComponent.getUniqueId(), inputId);
+ return deleteInputFromComponent(ComponentTypeEnum.findParamByType(parentComponent.getComponentType()),
+ parentComponent.getUniqueId(), inputId);
}
/**
* Delete input from component
- *
+ *
* @param componentType
* @param componentId
* @param inputUniqueId
* @return {@link org.openecomp.sdc.ci.tests.datatypes.http.RestResponse}
* @throws Exception
*/
- public static RestResponse deleteInputFromComponent(String componentType, String componentId, String inputUniqueId) throws Exception {
+ public static RestResponse deleteInputFromComponent(String componentType, String componentId, String inputUniqueId)
+ throws Exception {
Config config = Utils.getConfig();
//{componentType}/{componentId}/delete/{inputId}/input
- String url = String.format(Urls.DELETE_INPUT_BY_ID, config.getCatalogBeHost(), config.getCatalogBePort(), componentType, componentId, inputUniqueId);
+ String url = String.format(Urls.DELETE_INPUT_BY_ID, config.getCatalogBeHost(), config.getCatalogBePort(),
+ componentType, componentId, inputUniqueId);
return sendDelete(url, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER).getUserId());
}
-
+
}
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 9d2cdb50e1..34a158fe74 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
@@ -7,9 +7,9 @@
* 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.
@@ -20,9 +20,26 @@
package org.openecomp.sdc.ci.tests.utils.rest;
+import static org.testng.AssertJUnit.assertNotNull;
+import static org.testng.AssertJUnit.assertNull;
+import static org.testng.AssertJUnit.assertTrue;
+
import com.google.gson.Gson;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.openecomp.sdc.be.model.*;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentInstanceInput;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+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.Urls;
import org.openecomp.sdc.ci.tests.config.Config;
import org.openecomp.sdc.ci.tests.datatypes.PropertyObject;
@@ -33,334 +50,334 @@ import org.openecomp.sdc.common.util.GeneralUtility;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import static org.testng.AssertJUnit.*;
-
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 createServiceProperty(String resourceId, String body, User user) throws Exception {
- Config config = Config.instance();
- String url = String.format(Urls.CREATE_SERVICE_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 addValueToProperty(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 sendPut(url, body, user.getUserId(), acceptHeaderData);
+ }
+
+ public static RestResponse createServiceProperty(String resourceId, String body, User user) throws Exception {
+ Config config = Config.instance();
+ String url = String.format(Urls.CREATE_SERVICE_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 = (String) 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;
+ }
}