Onboard PNF software version Ui test case
[sdc.git] / test-apis-ci / src / main / java / org / openecomp / sdc / ci / tests / utils / general / ElementFactory.java
index ddca429..31b8c5b 100644 (file)
 
 package org.openecomp.sdc.ci.tests.utils.general;
 
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.UUID;
-
 import org.apache.commons.lang.StringUtils;
 import org.openecomp.sdc.be.dao.api.ActionStatus;
 import org.openecomp.sdc.be.datatypes.elements.ConsumerDataDefinition;
 import org.openecomp.sdc.be.datatypes.enums.AssetTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
-import org.openecomp.sdc.be.model.ArtifactDefinition;
-import org.openecomp.sdc.be.model.CapabilityDefinition;
-import org.openecomp.sdc.be.model.Component;
-import org.openecomp.sdc.be.model.LifecycleStateEnum;
-import org.openecomp.sdc.be.model.RelationshipImpl;
-import org.openecomp.sdc.be.model.RequirementAndRelationshipPair;
-import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
-import org.openecomp.sdc.be.model.RequirementDefinition;
-import org.openecomp.sdc.be.model.Resource;
-import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.*;
 import org.openecomp.sdc.be.model.category.CategoryDefinition;
 import org.openecomp.sdc.be.model.category.GroupingDefinition;
 import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
-import org.openecomp.sdc.ci.tests.datatypes.ArtifactReqDetails;
-import org.openecomp.sdc.ci.tests.datatypes.ComponentInstanceReqDetails;
-import org.openecomp.sdc.ci.tests.datatypes.ComponentReqDetails;
-import org.openecomp.sdc.ci.tests.datatypes.ImportReqDetails;
-import org.openecomp.sdc.ci.tests.datatypes.ProductReqDetails;
-import org.openecomp.sdc.ci.tests.datatypes.PropertyReqDetails;
-import org.openecomp.sdc.ci.tests.datatypes.ResourceExternalReqDetails;
-import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
-import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails;
-import org.openecomp.sdc.ci.tests.datatypes.enums.ArtifactTypeEnum;
-import org.openecomp.sdc.ci.tests.datatypes.enums.ErrorInfo;
-import org.openecomp.sdc.ci.tests.datatypes.enums.LifeCycleStatesEnum;
-import org.openecomp.sdc.ci.tests.datatypes.enums.NormativeTypesEnum;
-import org.openecomp.sdc.ci.tests.datatypes.enums.PropertyTypeEnum;
-import org.openecomp.sdc.ci.tests.datatypes.enums.ResourceCategoryEnum;
-import org.openecomp.sdc.ci.tests.datatypes.enums.ServiceCategoriesEnum;
-import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
+import org.openecomp.sdc.ci.tests.datatypes.*;
+import org.openecomp.sdc.ci.tests.datatypes.enums.*;
 import org.openecomp.sdc.ci.tests.datatypes.expected.ExpectedExternalAudit;
 import org.openecomp.sdc.ci.tests.datatypes.expected.ExpectedResourceAuditJavaObject;
 import org.openecomp.sdc.ci.tests.utils.rest.ArtifactRestUtils;
@@ -71,7 +43,13 @@ import org.openecomp.sdc.ci.tests.utils.validation.ErrorValidationUtils;
 import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
 import org.openecomp.sdc.common.util.ValidationUtils;
 
-public class ElementFactory {
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+public final class ElementFactory {
 
        private static final String CI_SERVICE = "ciService";
        private static final String CI_RES = "ciRes";
@@ -81,6 +59,24 @@ public class ElementFactory {
        private static final String RESOURCE_INSTANCE_POS_Y = "20";
        private static final String RESOURCE_INSTANCE_DESCRIPTION = "description";
 
+       private ElementFactory() {
+
+       }
+       
+       // *** Getters ***
+       
+       public static String getServicePrefix() {
+               return CI_SERVICE;
+       }
+
+       public static String getResourcePrefix() {
+               return CI_RES;
+       }
+
+       public static String getProductPrefix() {
+               return CI_PRODUCT;
+       }
+
        // *** RESOURCE ***
 
        public static ResourceReqDetails getDefaultResource() {
@@ -116,6 +112,10 @@ public class ElementFactory {
        }
 
        // New
+       public static ResourceReqDetails getDefaultResourceByType(ResourceTypeEnum ResourceType, String resourceName, ResourceCategoryEnum resourceCategory, String vendorName, String vendorModelNumber) {
+               return getDefaultResourceByType(resourceName, NormativeTypesEnum.ROOT, resourceCategory, "jh0003", ResourceType.toString(), vendorName, vendorModelNumber);
+       }
+
        public static ResourceReqDetails getDefaultResourceByType(ResourceTypeEnum ResourceType, String resourceName) {
                return getDefaultResourceByType(resourceName, NormativeTypesEnum.ROOT, ResourceCategoryEnum.GENERIC_INFRASTRUCTURE, "jh0003", ResourceType.toString());
        }
@@ -137,18 +137,19 @@ public class ElementFactory {
        }
 
        public static ResourceReqDetails getDefaultResource(String resourceName, NormativeTypesEnum derived, ResourceCategoryEnum category, String contactId) {
-               resourceName = (resourceName + generateUUIDforSufix());
+               resourceName = addRandomSuffixToName(resourceName);
                String description = "Represents a generic software component that can be managed and run by a Compute Node Type.";
-               ArrayList<String> resourceTags = new ArrayList<String>();
+               ArrayList<String> resourceTags = new ArrayList<>();
                resourceTags.add(resourceName);
 
-               ArrayList<String> derivedFrom = new ArrayList<String>();
+               ArrayList<String> derivedFrom = new ArrayList<>();
                derivedFrom.add(derived.normativeName);
                String vendorName = "ATT Tosca";
                String vendorRelease = "1.0.0.wd03";
                String icon = "defaulticon";
                ResourceReqDetails resourceDetails = new ResourceReqDetails(resourceName, description, resourceTags, null, derivedFrom, vendorName, vendorRelease, contactId, icon);
                resourceDetails.addCategoryChain(category.getCategory(), category.getSubCategory());
+               resourceDetails.setResourceVendorModelNumber("vendorNumber-1.5.7");
 
                return resourceDetails;
 
@@ -159,12 +160,12 @@ public class ElementFactory {
        }
 
        public static ResourceReqDetails getDefaultResource(String resourceName, Resource derived, ResourceCategoryEnum category, String contactId) {
-               resourceName = (resourceName + generateUUIDforSufix());
+               resourceName = addRandomSuffixToName(resourceName);
                String description = "Represents a generic software component that can be managed and run by a Compute Node Type.";
-               ArrayList<String> resourceTags = new ArrayList<String>();
+               ArrayList<String> resourceTags = new ArrayList<>();
                resourceTags.add(resourceName);
 
-               ArrayList<String> derivedFrom = new ArrayList<String>();
+               ArrayList<String> derivedFrom = new ArrayList<>();
                derivedFrom.add(derived.getToscaResourceName());
                String vendorName = "ATT Tosca";
                String vendorRelease = "1.0.0.wd03";
@@ -176,6 +177,10 @@ public class ElementFactory {
 
        }
 
+       public static String addRandomSuffixToName(final String name) {
+               return name + generateUUIDforSufix();
+       }
+
        public static ResourceReqDetails getDefaultResourceByType(String resourceName, NormativeTypesEnum derived, ResourceCategoryEnum category, String contactId, ResourceTypeEnum resourceType) {
                return getDefaultResourceByType(resourceName, derived, category, contactId, resourceType.toString());
        }
@@ -184,7 +189,7 @@ public class ElementFactory {
        public static ResourceReqDetails getDefaultResourceByType(String resourceName, NormativeTypesEnum derived, ResourceCategoryEnum category, String contactId, String resourceType) {
                resourceName = (resourceName + resourceType + generateUUIDforSufix());
                String description = "Represents a generic software component that can be managed and run by a Compute Node Type.";
-               ArrayList<String> resourceTags = new ArrayList<String>();
+               ArrayList<String> resourceTags = new ArrayList<>();
                resourceTags.add(resourceName);
                ArrayList<String> derivedFrom = null;
                if (derived != null) {
@@ -196,13 +201,38 @@ public class ElementFactory {
                String icon = "defaulticon";
                ResourceReqDetails resourceDetails = new ResourceReqDetails(resourceName, description, resourceTags, null, derivedFrom, vendorName, vendorRelease, contactId, icon, resourceType.toString());
                resourceDetails.addCategoryChain(category.getCategory(), category.getSubCategory());
+               resourceDetails.setResourceVendorModelNumber("vendorNumber-1.5.7");
                return resourceDetails;
        }
-       
+
+       public static ResourceReqDetails getDefaultResourceByType(String resourceName, NormativeTypesEnum derived, ResourceCategoryEnum category, String contactId, String resourceType, String vendorName, String vendorModelNumber) {
+               resourceName = (resourceName + resourceType + generateUUIDforSufix());
+
+               String description = "Represents a generic software component that can be managed and run by a Compute Node Type.";
+               ArrayList<String> resourceTags = new ArrayList<>();
+               resourceTags.add(resourceName);
+               ArrayList<String> derivedFrom = null;
+               if (derived != null) {
+                       derivedFrom = new ArrayList<>();
+                       derivedFrom.add(derived.normativeName);
+               }
+               String vendorRelease = "1.0.0.wd03";
+               String icon = "defaulticon";
+               ResourceReqDetails resourceDetails = new ResourceReqDetails(resourceName, description, resourceTags, null, derivedFrom, vendorName, vendorRelease, contactId, icon, resourceType.toString());
+               resourceDetails.addCategoryChain(category.getCategory(), category.getSubCategory());
+               resourceDetails.setResourceVendorModelNumber(vendorModelNumber);
+               return resourceDetails;
+       }
+
+       public static ResourceReqDetails getRandomCategoryResource() {
+               ResourceReqDetails resourceDetails = getDefaultResource(ResourceCategoryEnum.getRandomElement());
+               return resourceDetails;
+       }
+
        public static ResourceExternalReqDetails getDefaultResourceByType(String resourceName, ResourceCategoryEnum category, String contactId, String resourceType) {
                resourceName = (resourceName + resourceType + generateUUIDforSufix());
                String description = "Represents a generic software component that can be managed and run by a Compute Node Type.";
-               ArrayList<String> resourceTags = new ArrayList<String>();
+               ArrayList<String> resourceTags = new ArrayList<>();
                resourceTags.add(resourceName);
                String vendorName = "ATT Tosca";
                String vendorRelease = "1.0.0.wd03";
@@ -217,11 +247,11 @@ public class ElementFactory {
        public static ImportReqDetails getDefaultImportResourceByType(String resourceName, NormativeTypesEnum derived, ResourceCategoryEnum category, String contactId, String resourceType) {
                resourceName = (resourceName + resourceType + generateUUIDforSufix());
                String description = "Represents a generic software component that can be managed and run by a Compute Node Type.";
-               ArrayList<String> resourceTags = new ArrayList<String>();
+               ArrayList<String> resourceTags = new ArrayList<>();
                resourceTags.add(resourceName);
                ArrayList<String> derivedFrom = null;
                if (derived != null) {
-                       derivedFrom = new ArrayList<String>();
+                       derivedFrom = new ArrayList<>();
                        derivedFrom.add(derived.normativeName);
                }
                String vendorName = "ATT Tosca";
@@ -267,39 +297,44 @@ public class ElementFactory {
 
        // *** SERVICE ***
        public static ServiceReqDetails getDefaultService() {
-               return getDefaultService(CI_SERVICE, ServiceCategoriesEnum.MOBILITY, "al1976");
+               return getDefaultService(CI_SERVICE, ServiceCategoriesEnum.MOBILITY, "al1976", ServiceInstantiationType.A_LA_CARTE.getValue());
        }
 
        public static ServiceReqDetails getDefaultService(String contactId) {
-               return getDefaultService(CI_SERVICE, ServiceCategoriesEnum.MOBILITY, contactId);
+               return getDefaultService(CI_SERVICE, ServiceCategoriesEnum.MOBILITY, contactId, ServiceInstantiationType.A_LA_CARTE.getValue());
        }
 
        public static ServiceReqDetails getDefaultService(User user) {
-               return getDefaultService(CI_SERVICE, ServiceCategoriesEnum.MOBILITY, user.getUserId());
+               return getDefaultService(CI_SERVICE, ServiceCategoriesEnum.MOBILITY, user.getUserId(), ServiceInstantiationType.A_LA_CARTE.getValue());
        }
-
-       public static ServiceReqDetails getService(ServiceCategoriesEnum category) {
-               return getDefaultService(CI_SERVICE, category, "al1976");
-       }
-
+       
        public static ServiceReqDetails getDefaultService(ServiceCategoriesEnum category, User user) {
-               return getDefaultService(CI_SERVICE, category, user.getUserId());
+               return getDefaultService(CI_SERVICE, category, user.getUserId(), ServiceInstantiationType.A_LA_CARTE.getValue());
+       }
+       
+       public static ServiceReqDetails getServiceByCategory(ServiceCategoriesEnum category) {
+               return getDefaultService(CI_SERVICE, category, "al1976", ServiceInstantiationType.A_LA_CARTE.getValue());
        }
 
-       public static ServiceReqDetails getDefaultService(String serviceName, ServiceCategoriesEnum category, String contactId) {
+       public static ServiceReqDetails getDefaultService(String serviceName, ServiceCategoriesEnum category, String contactId, String instantiationType) {
                serviceName = (serviceName + generateUUIDforSufix());
-               ArrayList<String> tags = new ArrayList<String>();
+               ArrayList<String> tags = new ArrayList<>();
                tags.add("serviceTag");
                tags.add("serviceTag1");
                tags.add(serviceName);
                String description = "service Description";
                String icon = "defaulticon";
 
-               ServiceReqDetails serviceDetails = new ServiceReqDetails(serviceName, category.getValue(), tags, description, contactId, icon);
+               ServiceReqDetails serviceDetails = new ServiceReqDetails(serviceName, category.getValue(), tags, description, contactId, icon, instantiationType);
 
                return serviceDetails;
        }
 
+       public static ServiceReqDetails getRandomCategoryService() {
+               ServiceReqDetails serviceReqDetails = getServiceByCategory(ServiceCategoriesEnum.getRandomElement());
+               return serviceReqDetails;
+       }
+
        // ***** PROPERTY ***
 
        public static PropertyReqDetails getDefaultProperty() {
@@ -350,7 +385,7 @@ public class ElementFactory {
 
        public static ComponentInstanceReqDetails getDefaultComponentInstance(String name) {
                String resourceUid = "resourceId";
-               ComponentInstanceReqDetails resourceInstanceDetails = new ComponentInstanceReqDetails(resourceUid, RESOURCE_INSTANCE_DESCRIPTION, RESOURCE_INSTANCE_POS_X, RESOURCE_INSTANCE_POS_Y, name);
+               ComponentInstanceReqDetails resourceInstanceDetails = new ComponentInstanceReqDetails(resourceUid, RESOURCE_INSTANCE_DESCRIPTION, RESOURCE_INSTANCE_POS_X, RESOURCE_INSTANCE_POS_Y, name, null);
 
                return resourceInstanceDetails;
 
@@ -358,16 +393,26 @@ public class ElementFactory {
 
        public static ComponentInstanceReqDetails getDefaultComponentInstance(String name, ComponentReqDetails componentReqDetails) {
                String resourceUid = componentReqDetails.getUniqueId();
-               ComponentInstanceReqDetails resourceInstanceDetails = new ComponentInstanceReqDetails(resourceUid, RESOURCE_INSTANCE_DESCRIPTION, RESOURCE_INSTANCE_POS_X, RESOURCE_INSTANCE_POS_Y, name);
+               ComponentInstanceReqDetails resourceInstanceDetails = new ComponentInstanceReqDetails(resourceUid, RESOURCE_INSTANCE_DESCRIPTION, RESOURCE_INSTANCE_POS_X, RESOURCE_INSTANCE_POS_Y, name, null);
 
                return resourceInstanceDetails;
 
        }
 
+    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();
-               ComponentInstanceReqDetails resourceInstanceDetails = new ComponentInstanceReqDetails(resourceUid, RESOURCE_INSTANCE_DESCRIPTION, RESOURCE_INSTANCE_POS_X, RESOURCE_INSTANCE_POS_Y, compInstName);
+               ComponentInstanceReqDetails resourceInstanceDetails = new ComponentInstanceReqDetails(resourceUid, RESOURCE_INSTANCE_DESCRIPTION, RESOURCE_INSTANCE_POS_X, RESOURCE_INSTANCE_POS_Y, compInstName, null);
                return resourceInstanceDetails;
 
        }
@@ -375,11 +420,21 @@ public class ElementFactory {
        public static ComponentInstanceReqDetails getComponentInstance(Component compInstOriginDetails) {
                String compInstName = (compInstOriginDetails.getName() != null ? compInstOriginDetails.getName() : "componentInstanceName");
                String compInsUid = compInstOriginDetails.getUniqueId();
-               ComponentInstanceReqDetails componentInstanceDetails = new ComponentInstanceReqDetails(compInsUid, RESOURCE_INSTANCE_DESCRIPTION, RESOURCE_INSTANCE_POS_X, RESOURCE_INSTANCE_POS_Y, compInstName);
+               ComponentInstanceReqDetails componentInstanceDetails = new ComponentInstanceReqDetails(compInsUid, RESOURCE_INSTANCE_DESCRIPTION, RESOURCE_INSTANCE_POS_X, RESOURCE_INSTANCE_POS_Y, compInstName, compInstOriginDetails.getComponentType() == ComponentTypeEnum.SERVICE ? OriginTypeEnum.ServiceProxy.name() : null);
                return componentInstanceDetails;
 
        }
 
+       //********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();
@@ -851,7 +906,6 @@ public class ElementFactory {
                try {
                        errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.COMPONENT_CATEGORY_NOT_FOUND.name());
                } catch (FileNotFoundException e) {
-                       // TODO Auto-generated catch block
                        e.printStackTrace();
                }
                String desc = (errorInfo.getMessageId() + ": " + errorInfo.getMessage()).replace("%2", "category").replace("%3", category).replace("%1", "resource");
@@ -939,12 +993,12 @@ public class ElementFactory {
                ProductReqDetails product = new ProductReqDetails(productName);
                productName = (productName + generateUUIDforSufix());
                product.setName(productName);
-               ArrayList<String> tags = new ArrayList<String>();
+               ArrayList<String> tags = new ArrayList<>();
                tags.add(productName);
                product.setTags(tags);
                product.setProjectCode("12345");
                product.setIcon("myIcon");
-               ArrayList<String> contacts = new ArrayList<String>();
+               ArrayList<String> contacts = new ArrayList<>();
                // contacts.add(ElementFactory.getDefaultUser(UserRoleEnum.PRODUCT_STRATEGIST1).getUserId());
                // contacts.add(ElementFactory.getDefaultUser(UserRoleEnum.PRODUCT_STRATEGIST2).getUserId());
                contacts.add(ElementFactory.getDefaultUser(UserRoleEnum.PRODUCT_MANAGER1).getUserId());
@@ -964,26 +1018,26 @@ public class ElementFactory {
                RequirementCapabilityRelDef requirementDef = new RequirementCapabilityRelDef();
                requirementDef.setFromNode(fromCompInstId);
                requirementDef.setToNode(toCompInstId);
-               RequirementAndRelationshipPair pair = new RequirementAndRelationshipPair();
-               pair.setRequirementOwnerId(reqOwnerId);
-               pair.setCapabilityOwnerId(capOwnerId);
-               pair.setRequirement(reqCapName);
-               RelationshipImpl relationship = new RelationshipImpl();
-               relationship.setType(capType);
-               pair.setRelationships(relationship);
-               pair.setCapabilityUid(capList.get(0).getUniqueId());
-               pair.setRequirementUid(reqList.get(0).getUniqueId());
-               List<RequirementAndRelationshipPair> relationships = new ArrayList<>();
-               relationships.add(pair);
+               RelationshipInfo relationInfo = new RelationshipInfo();
+               relationInfo.setRequirementOwnerId(reqOwnerId);
+               relationInfo.setCapabilityOwnerId(capOwnerId);
+               relationInfo.setRequirement(reqCapName);
+               RelationshipImpl relationImpl = new RelationshipImpl();
+               relationImpl.setType(capType);
+               relationInfo.setRelationships(relationImpl);
+               relationInfo.setCapabilityUid(capList.get(0).getUniqueId());
+               relationInfo.setRequirementUid(reqList.get(0).getUniqueId());
+               List<CapabilityRequirementRelationship> relationships = new ArrayList<>();
+               CapabilityRequirementRelationship relationship = new CapabilityRequirementRelationship();
+               relationship.setRelation(relationInfo);
+               relationships.add(relationship);
                requirementDef.setRelationships(relationships);
                return requirementDef;
        }
 
        public static String generateUUIDforSufix() {
-
-               String uniqueSufix = UUID.randomUUID().toString();
-               String[] split = uniqueSufix.split("-");
-               return uniqueSufix = split[4];
+               final String uniqueSuffix = UUID.randomUUID().toString();
+               return uniqueSuffix.split("-")[4];
        }
 
        private static String normalizeArtifactLabel(String label) {