diff options
Diffstat (limited to 'test-apis-ci/src/main/java/org')
9 files changed, 298 insertions, 7 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 d3b717e514..ba35ac3d33 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 @@ -180,6 +180,7 @@ public interface Urls { final String CHANGE_COMPONENT_LIFECYCLE_STATE = SDC_HTTP_METHOD + "://%s:%s/sdc2/rest/v1/catalog/%s/%s/lifecycleState/%s"; final String CREATE_PROPERTY = SDC_HTTP_METHOD + "://%s:%s/sdc2/rest/v1/catalog/resources/%s/properties"; + String CREATE_SERVICE_PROPERTY = SDC_HTTP_METHOD + "://%s:%s/sdc2/rest/v1/catalog/services/%s/properties"; final String DECLARE_PROPERTIES = SDC_HTTP_METHOD + "://%s:%s/sdc2/rest/v1/catalog/%s/%s/create/inputs"; final String UPDATE_INPUT = SDC_HTTP_METHOD + "://%s:%s/sdc2/rest/v1/catalog/resources/%s/update/inputs"; @@ -392,6 +393,12 @@ public interface Urls { final String GET_VSP_COMPONENT_BY_VERSION = SDC_HTTP_METHOD + "://%s:%s/onboarding-api/v1.0/vendor-software-products/%s/versions/%s"; final String GET_VLM_COMPONENT_BY_VERSION = SDC_HTTP_METHOD + "://%s:%s/onboarding-api/v1.0/vendor-license-models/%s/versions/%s"; final String ACTION_ARCHIVE_RESTORE_COMPONENT = SDC_HTTP_METHOD + "://%s:%s/onboarding-api/v1.0/%s/%s/actions"; + String CREATE_SERVICE_FILTER = SDC_HTTP_METHOD + "://%s:%s/sdc2/rest/v1/catalog/services/%s/resourceInstances/%s/nodeFilter"; + String UPDATE_SERVICE_FILTER = SDC_HTTP_METHOD + "://%s:%s/sdc2/rest/v1/catalog/services/%s" + + "/resourceInstances/%s/nodeFilter/"; + String DELETE_SERVICE_FILTER = SDC_HTTP_METHOD + "://%s:%s/sdc2/rest/v1/catalog/services/%s" + + "/resourceInstances/%s/nodeFilter/%s"; + String MARK_AS_DEPENDENT = SDC_HTTP_METHOD + "://%s:%s/sdc2/rest/v1/catalog/%s/%s/resourceInstance/%s"; // Interface Lifecycle Types final String GET_All_INTERFACE_LIFECYCLE_TYPES = SDC_HTTP_METHOD + "://%s:%s/sdc2/rest/v1/catalog/interfaceLifecycleTypes"; diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/datatypes/ComponentInstanceReqDetails.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/datatypes/ComponentInstanceReqDetails.java index d6699d32d7..b2768501d8 100644 --- a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/datatypes/ComponentInstanceReqDetails.java +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/datatypes/ComponentInstanceReqDetails.java @@ -20,6 +20,8 @@ package org.openecomp.sdc.ci.tests.datatypes; +import java.util.List; + import org.openecomp.sdc.be.model.ComponentInstance; public class ComponentInstanceReqDetails { @@ -31,6 +33,7 @@ public class ComponentInstanceReqDetails { String name; String uniqueId; String originType; + List<String> directives; public ComponentInstanceReqDetails() { super(); @@ -122,10 +125,25 @@ public class ComponentInstanceReqDetails { this.originType = originType; } - @Override - public String toString() { - return "ResourceInstanceReqDetails [resourceUid=" + componentUid + ", description=" + description + ", posX=" - + posX + ", posY=" + posY + ", name=" + name + ", uniqueId=" + uniqueId + "]"; - } - + public List<String> getDirectives() { + return directives; + } + + public void setDirectives(List<String> directives) { + this.directives = directives; + } + + @Override + public String toString() { + return "ComponentInstanceReqDetails{" + + "componentUid='" + componentUid + '\'' + + ", description='" + description + '\'' + + ", posX='" + posX + '\'' + + ", posY='" + posY + '\'' + + ", name='" + name + '\'' + + ", uniqueId='" + uniqueId + '\'' + + ", originType='" + originType + '\'' + + ", directives=" + directives + + '}'; + } } 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 208e4aa3ea..0898206002 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 @@ -135,7 +135,8 @@ public class PropertyReqDetails { public String propertyToJsonString() { String jsonString; - jsonString = "{\"" + this.getName() + "\":{" + "\"type\":\"" + this.getPropertyType() + "\"," + "\"required\":" + 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\":" diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/datatypes/ServiceFilterDetails.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/datatypes/ServiceFilterDetails.java new file mode 100644 index 0000000000..1d6740ad47 --- /dev/null +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/datatypes/ServiceFilterDetails.java @@ -0,0 +1,60 @@ +package org.openecomp.sdc.ci.tests.datatypes; + +public class ServiceFilterDetails { + private String servicePropertyName; + private String constraintOperator; + private String sourceType; + private String sourceName; + private Object value; + + public ServiceFilterDetails() {} + + public ServiceFilterDetails(String servicePropertyName, String constraintOperator, String sourceType, String sourceName, + Object value) { + this.servicePropertyName = servicePropertyName; + this.constraintOperator = constraintOperator; + this.sourceType = sourceType; + this.sourceName = sourceName; + this.value = value; + } + + public String getServicePropertyName() { + return servicePropertyName; + } + + public void setServicePropertyName(String servicePropertyName) { + this.servicePropertyName = servicePropertyName; + } + + public String getConstraintOperator() { + return constraintOperator; + } + + public void setConstraintOperator(String constraintOperator) { + this.constraintOperator = constraintOperator; + } + + public String getSourceType() { + return sourceType; + } + + public void setSourceType(String sourceType) { + this.sourceType = sourceType; + } + + public Object getValue() { + return value; + } + + public void setValue(Object value) { + this.value = value; + } + + public String getSourceName() { + return sourceName; + } + + public void setSourceName(String sourceName) { + this.sourceName = sourceName; + } +} diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/servicefilter/ServiceFilterTests.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/servicefilter/ServiceFilterTests.java new file mode 100644 index 0000000000..8be71328ea --- /dev/null +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/servicefilter/ServiceFilterTests.java @@ -0,0 +1,123 @@ +package org.openecomp.sdc.ci.tests.servicefilter; + +import java.util.Collections; + +import org.junit.Rule; +import org.junit.rules.TestName; +import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; +import org.openecomp.sdc.be.model.User; +import org.openecomp.sdc.ci.tests.api.ComponentBaseTest; +import org.openecomp.sdc.ci.tests.datatypes.ComponentInstanceReqDetails; +import org.openecomp.sdc.ci.tests.datatypes.PropertyReqDetails; +import org.openecomp.sdc.ci.tests.datatypes.ServiceFilterDetails; +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.ElementFactory; +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.LifecycleRestUtils; +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.ServiceFilterUtils; +import org.openecomp.sdc.ci.tests.utils.rest.ServiceRestUtils; +import org.testng.Assert; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + +public class ServiceFilterTests extends ComponentBaseTest { + @Rule + public static TestName name = new TestName(); + + private static ServiceReqDetails externalService; + private static ComponentInstanceReqDetails componentInstanceReqDetails; + private static User user = null; + + public ServiceFilterTests() { + super(name, ServiceFilterTests.class.getName()); + } + + @BeforeTest + public void init() throws Exception { + user = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER); + + ServiceReqDetails internalService; + //Create External Service + externalService = ElementFactory.getDefaultService(); + externalService.setName("ExternalService" + Math.random()); + ServiceRestUtils.createService(externalService, user); + + //Create Internal Service + internalService = ElementFactory.getDefaultService(); + internalService.setName("InternalService" + Math.random()); + ServiceRestUtils.createService(internalService, user); + + //Add property services + //#PropertyOne + PropertyReqDetails propertyReqDetails = ElementFactory.getDefaultStringProperty(); + propertyReqDetails.setName("StringProp1"); + String body = propertyReqDetails.propertyToJsonString(); + PropertyRestUtils.createServiceProperty(externalService.getUniqueId(), body, user); + PropertyRestUtils.createServiceProperty(internalService.getUniqueId(), body, user); + //#PropertyTwo + propertyReqDetails.setName("StringProp2"); + body = propertyReqDetails.propertyToJsonString(); + RestResponse response = PropertyRestUtils.createServiceProperty(externalService.getUniqueId(), body, user); + response = PropertyRestUtils.createServiceProperty(internalService.getUniqueId(), body, user); + + //CheckIn internal Service + response = LifecycleRestUtils.changeServiceState(internalService, user, "0.1", + LifeCycleStatesEnum.CHECKIN, + "{\"userRemarks\":\"CheckIn\"}"); + BaseRestUtils.checkSuccess(response); + if (response.getErrorCode() == BaseRestUtils.STATUS_CODE_SUCCESS) { + internalService.setUniqueId(ResponseParser.getUniqueIdFromResponse(response)); + } + //Make internal service as component instance + componentInstanceReqDetails = + ElementFactory.getDefaultComponentInstance(internalService.getUniqueId(), "ServiceProxy"); + response = ComponentInstanceRestUtils.createComponentInstance(componentInstanceReqDetails, + user, externalService.getUniqueId(), ComponentTypeEnum.SERVICE); + BaseRestUtils.checkCreateResponse(response); + if (response.getErrorCode() == BaseRestUtils.STATUS_CODE_CREATED) { + componentInstanceReqDetails.setUniqueId(ResponseParser.getUniqueIdFromResponse(response)); + componentInstanceReqDetails.setName(ResponseParser.getNameFromResponse(response)); + } + //Mark as dependent + componentInstanceReqDetails.setDirectives(Collections.singletonList("selectable")); + response = ComponentInstanceRestUtils.updateComponentInstance(componentInstanceReqDetails, + user, externalService.getUniqueId(), ComponentTypeEnum.SERVICE); + BaseRestUtils.checkSuccess(response); + } + + @Test + public void createServiceFilter() throws Exception { + //Add Service Filter + ServiceFilterDetails serviceFilterDetails = ElementFactory.getDefaultEqualOperatorFilter("StringProp1", "value"); + RestResponse restResponse = ServiceFilterUtils.createServiceFilter(externalService.getUniqueId(), + componentInstanceReqDetails.getUniqueId(), serviceFilterDetails, user); + logger.info("CreateServiceFilter Response Code:" + restResponse.getErrorCode()); + Assert.assertEquals((int) restResponse.getErrorCode(), BaseRestUtils.STATUS_CODE_SUCCESS); + } + + @Test(dependsOnMethods = "createServiceFilter") + public void updateServiceFilter() throws Exception { + //Update Service Filter + ServiceFilterDetails serviceFilterDetails = + ElementFactory.getDefaultEqualOperatorFilter("StringProp1", "updated"); + RestResponse restResponse = ServiceFilterUtils.updateServiceFilter(externalService.getUniqueId(), + componentInstanceReqDetails.getUniqueId(), Collections.singletonList(serviceFilterDetails), user); + logger.info("UpdateServiceFilter Response Code:" + restResponse.getErrorCode()); + Assert.assertEquals((int) restResponse.getErrorCode(), BaseRestUtils.STATUS_CODE_SUCCESS); + } + + // @Test(dependsOnMethods = "updateServiceFilter") + public void deleteServiceFilter() throws Exception { + //Delete Service Filter + RestResponse restResponse = ServiceFilterUtils.deleteServiceFilter(externalService.getUniqueId(), + componentInstanceReqDetails.getUniqueId(), 0, user); + logger.info("DeleteServiceFilter Response Code:" + restResponse.getErrorCode()); + Assert.assertEquals((int) restResponse.getErrorCode(), BaseRestUtils.STATUS_CODE_SUCCESS); + } +}
\ No newline at end of file diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/general/ElementFactory.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/general/ElementFactory.java index e303682a37..82954e642a 100644 --- a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/general/ElementFactory.java +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/general/ElementFactory.java @@ -391,6 +391,16 @@ public class ElementFactory { } + public static ComponentInstanceReqDetails getDefaultComponentInstance(String serviceUniqueId, String originType) { + ComponentInstanceReqDetails componentInstanceReqDetails = new ComponentInstanceReqDetails(serviceUniqueId, + RESOURCE_INSTANCE_DESCRIPTION, RESOURCE_INSTANCE_POS_X, RESOURCE_INSTANCE_POS_Y, null, originType); + + componentInstanceReqDetails.setUniqueId(serviceUniqueId + Math.random()); + + return componentInstanceReqDetails; + + } + public static ComponentInstanceReqDetails getComponentResourceInstance(ComponentReqDetails compInstOriginDetails) { String compInstName = (compInstOriginDetails.getName() != null ? compInstOriginDetails.getName() : "resourceInstanceName"); String resourceUid = compInstOriginDetails.getUniqueId(); @@ -407,6 +417,16 @@ public class ElementFactory { } + //********ServiceFilter********** + public static ServiceFilterDetails getDefaultEqualOperatorFilter(String propertyName, String valueString) { + return new ServiceFilterDetails(propertyName, "equal", "static", "static", valueString); + } + + public static ServiceFilterDetails getDefaultFilter(String propertyName, String valueString, + String operator) { + return new ServiceFilterDetails(propertyName, operator, "static", "static", valueString); + } + // ******* USER ********************** public static User getDefaultUser(UserRoleEnum userRole) { User sdncModifierDetails = new User(); 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 d5ae0a47a1..9d2cdb50e1 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 @@ -50,6 +50,14 @@ public class PropertyRestUtils extends BaseRestUtils { 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(); diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ServiceFilterUtils.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ServiceFilterUtils.java new file mode 100644 index 0000000000..cc68ef5eac --- /dev/null +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ServiceFilterUtils.java @@ -0,0 +1,53 @@ +package org.openecomp.sdc.ci.tests.utils.rest; + +import com.google.gson.Gson; + +import java.util.List; + +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.ServiceFilterDetails; +import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ServiceFilterUtils extends BaseRestUtils { + + private static Logger logger = LoggerFactory.getLogger(ServiceFilterUtils.class.getName()); + + private static Gson gson = new Gson(); + + public static RestResponse createServiceFilter(String externalServiceId, String proxyServiceId, + ServiceFilterDetails serviceFilterDetails, + User user) throws Exception{ + Config config = Config.instance(); + + String url = String.format(Urls.CREATE_SERVICE_FILTER, config.getCatalogBeHost(), config.getCatalogBePort(), + externalServiceId, proxyServiceId); + + return sendPost(url, gson.toJson(serviceFilterDetails), user.getUserId(), acceptHeaderData); + } + + public static RestResponse updateServiceFilter(String externalServiceId, String proxyServiceId, + List<ServiceFilterDetails> serviceFilterDetailsList, + User user) throws Exception{ + Config config = Config.instance(); + + String url = String.format(Urls.UPDATE_SERVICE_FILTER, config.getCatalogBeHost(), config.getCatalogBePort(), + externalServiceId, proxyServiceId); + + return sendPut(url, gson.toJson(serviceFilterDetailsList), user.getUserId(), acceptHeaderData); + } + + public static RestResponse deleteServiceFilter(String externalServiceId, String proxyServiceId, + int constraintIndex, + User user) throws Exception{ + Config config = Config.instance(); + + String url = String.format(Urls.DELETE_SERVICE_FILTER, config.getCatalogBeHost(), config.getCatalogBePort(), + externalServiceId, proxyServiceId, constraintIndex); + + return sendDelete(url, user.getUserId()); + } +} 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 88666cce11..c82a772de3 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 @@ -99,6 +99,7 @@ public class ServiceRestUtils extends BaseRestUtils { RestResponse res = sendPost(url, serviceBodyJson, user.getUserId(), acceptHeaderData); if (res.getErrorCode() == STATUS_CODE_CREATED) { service.setUniqueId(ResponseParser.getUniqueIdFromResponse(res)); + service.setName(ResponseParser.getNameFromResponse(res)); service.setVersion(ResponseParser.getVersionFromResponse(res)); service.setUUID(ResponseParser.getUuidFromResponse(res)); // Creator details never change after component is created - Ella, |