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 8224f08..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.CapabilityRequirementRelationship;
-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.RelationshipInfo;
-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;
@@ -72,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 +58,10 @@ public class ElementFactory {
        private static final String RESOURCE_INSTANCE_POS_X = "20";
        private static final String RESOURCE_INSTANCE_POS_Y = "20";
        private static final String RESOURCE_INSTANCE_DESCRIPTION = "description";
+
+       private ElementFactory() {
+
+       }
        
        // *** Getters ***
        
@@ -131,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());
        }
@@ -152,12 +137,12 @@ 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";
@@ -175,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";
@@ -192,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());
        }
@@ -200,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) {
@@ -216,6 +205,25 @@ public class ElementFactory {
                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;
@@ -224,7 +232,7 @@ public class ElementFactory {
        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";
@@ -239,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";
@@ -289,35 +297,35 @@ 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());
-       }
-
-       public static ServiceReqDetails getServiceByCategory(ServiceCategoriesEnum category) {
-               return getDefaultService(CI_SERVICE, category, "al1976");
+               return getDefaultService(CI_SERVICE, ServiceCategoriesEnum.MOBILITY, user.getUserId(), ServiceInstantiationType.A_LA_CARTE.getValue());
        }
-
+       
        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;
        }
@@ -377,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;
 
@@ -385,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;
 
        }
@@ -402,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();
@@ -965,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());
@@ -1008,10 +1036,8 @@ public class ElementFactory {
        }
 
        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) {