From cd0672f83bef9965fe3f109e43d78c65d321544b Mon Sep 17 00:00:00 2001 From: Tal Gitelman Date: Wed, 6 Jun 2018 19:15:13 +0300 Subject: new unit tests for sdc-model Change-Id: I14b1d527b18b354b8c29149135a1dbb800a454bb Issue-ID: SDC-1333 Signed-off-by: Tal Gitelman --- .../openecomp/sdc/be/model/PropertyDefinition.java | 32 +- .../java/org/openecomp/sdc/be/model/Resource.java | 6 +- .../main/java/org/openecomp/sdc/be/model/User.java | 9 +- .../sdc/be/model/ComponentInstanceTest.java | 2 + .../org/openecomp/sdc/be/model/ModelTestBase.java | 17 +- .../sdc/be/model/PolicyTargetDTOTest.java | 52 +++ .../sdc/be/model/PolicyTypeDefinitionTest.java | 5 + .../sdc/be/model/PropertyDefinitionTest.java | 55 +++- .../org/openecomp/sdc/be/model/ResourceTest.java | 34 ++ .../sdc/be/model/UploadResourceInfoTest.java | 352 ++++++++++++++++++++ .../java/org/openecomp/sdc/be/model/UserTest.java | 230 +++++++++++++ .../model/cache/ApplicationDataTypeCacheTest.java | 169 ++++++++++ .../sdc/be/model/cache/ComponentCacheTest.java | 360 +++++++++++++++++++-- .../operations/impl/ElementOperationTest.java | 6 +- 14 files changed, 1253 insertions(+), 76 deletions(-) create mode 100644 catalog-model/src/test/java/org/openecomp/sdc/be/model/PolicyTargetDTOTest.java create mode 100644 catalog-model/src/test/java/org/openecomp/sdc/be/model/UploadResourceInfoTest.java create mode 100644 catalog-model/src/test/java/org/openecomp/sdc/be/model/UserTest.java create mode 100644 catalog-model/src/test/java/org/openecomp/sdc/be/model/cache/ApplicationDataTypeCacheTest.java (limited to 'catalog-model') diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/PropertyDefinition.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/PropertyDefinition.java index 6292218837..7cd57be442 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/PropertyDefinition.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/PropertyDefinition.java @@ -45,8 +45,8 @@ public class PropertyDefinition extends PropertyDataDefinition AVAILABILTY_ZONE_COUNT("availability_zone_count", GroupInstancePropertyValueUpdateBehavior.UPDATABLE_ON_SERVICE_LEVEL), VFC_LIST("vfc_list", GroupInstancePropertyValueUpdateBehavior.UPDATABLE_ON_SERVICE_LEVEL); - private String propertyName; - private GroupInstancePropertyValueUpdateBehavior updateBehavior; + private final String propertyName; + private final GroupInstancePropertyValueUpdateBehavior updateBehavior; private PropertyNames(String propertyName,GroupInstancePropertyValueUpdateBehavior updateBehavior){ this.propertyName = propertyName; @@ -84,8 +84,8 @@ public class PropertyDefinition extends PropertyDataDefinition UPDATABLE_ON_RESOURCE_LEVEL("UPDATABLE_ON_VF_LEVEL", 0), UPDATABLE_ON_SERVICE_LEVEL("UPDATABLE_ON_SERVICE_LEVEL", 1); - String levelName; - int levelNumber; + private final String levelName; + private final int levelNumber; private GroupInstancePropertyValueUpdateBehavior(String name, int levelNumber){ this.levelName = name; @@ -141,25 +141,6 @@ public class PropertyDefinition extends PropertyDataDefinition + constraints + "]]"; } - // public void setSchema(Schema entrySchema) { - // this.schema = entrySchema; - // - // } - // - // public Schema getSchema() { - // return schema; - // } - -// public String getStatus() { -// return status; -// } -// -// public void setStatus(String status) { -// this.status = status; -// } - - - @Override public boolean isDefinition() { return false; @@ -198,11 +179,6 @@ public class PropertyDefinition extends PropertyDataDefinition return false; } else if (!getName().equals(other.getName())) return false; -// if (status == null) { -// if (other.status != null) -// return false; -// } else if (!status.equals(other.status)) -// return false; return true; } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Resource.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Resource.java index 917678380b..58efa5689e 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Resource.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Resource.java @@ -23,6 +23,7 @@ package org.openecomp.sdc.be.model; import java.io.Serializable; import java.util.List; import java.util.Map; +import java.util.Optional; import org.openecomp.sdc.be.config.ConfigurationManager; import org.openecomp.sdc.be.dao.utils.MapUtil; @@ -324,8 +325,7 @@ public class Resource extends Component implements Serializable { } private String getInstanceNameFromInstanceId(Resource resource, String instId) { - return resource.getComponentInstanceById(instId).get().getName(); + Optional componentInstanceById = resource.getComponentInstanceById(instId); + return componentInstanceById.isPresent() ? componentInstanceById.get().getName() : null; } - - } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/User.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/User.java index 129c35b708..b10214efe2 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/User.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/User.java @@ -45,9 +45,9 @@ public class User { public User() { } - public User(UserData userDate) { - this(userDate.getFirstName(), userDate.getLastName(), userDate.getUserId(), userDate.getEmail(), - userDate.getRole(), userDate.getLastLoginTime()); + public User(UserData userData) { + this(userData.getFirstName(), userData.getLastName(), userData.getUserId(), userData.getEmail(), + userData.getRole(), userData.getLastLoginTime()); } public User(String firstName, String lastName, String userId, String emailAddress, String role, @@ -62,6 +62,9 @@ public class User { } public void copyData(User other) { + if(other == null) { + return; + } this.firstName = other.getFirstName(); this.lastName = other.getLastName(); this.userId = other.getUserId(); diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/ComponentInstanceTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ComponentInstanceTest.java index fd533122d8..39eba764c9 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/ComponentInstanceTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ComponentInstanceTest.java @@ -168,5 +168,7 @@ public class ComponentInstanceTest { // default test testSubject = createTestSubject(); result = testSubject.isArtifactExists(groupType, artifactLabel); + testSubject = createTestSubject(); + result = testSubject.isArtifactExists(ArtifactGroupTypeEnum.DEPLOYMENT, artifactLabel); } } \ No newline at end of file diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/ModelTestBase.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ModelTestBase.java index b6c081afd3..04c9d5149d 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/ModelTestBase.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ModelTestBase.java @@ -31,16 +31,15 @@ public class ModelTestBase { protected static ConfigurationManager configurationManager; public static void init() { - if (ConfigurationManager.getConfigurationManager() == null) { - String appConfigDir = "src/test/resources/config"; - ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir); - configurationManager = new ConfigurationManager(configurationSource); + String appConfigDir = "src/test/resources/config"; + ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), + appConfigDir); + configurationManager = new ConfigurationManager(configurationSource); - Configuration configuration = new Configuration(); - - configuration.setTitanInMemoryGraph(true); + Configuration configuration = new Configuration(); - configurationManager.setConfiguration(configuration); - } + configuration.setTitanInMemoryGraph(true); + + configurationManager.setConfiguration(configuration); } } diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/PolicyTargetDTOTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/PolicyTargetDTOTest.java new file mode 100644 index 0000000000..9559a230ca --- /dev/null +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/PolicyTargetDTOTest.java @@ -0,0 +1,52 @@ +package org.openecomp.sdc.be.model; + +import java.util.List; + +import org.junit.Test; + +public class PolicyTargetDTOTest { + + private PolicyTargetDTO createTestSubject() { + return new PolicyTargetDTO(); + } + + @Test + public void testGetType() throws Exception { + PolicyTargetDTO testSubject; + String result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getType(); + } + + @Test + public void testSetType() throws Exception { + PolicyTargetDTO testSubject; + String type = ""; + + // default test + testSubject = createTestSubject(); + testSubject.setType(type); + } + + @Test + public void testGetUniqueIds() throws Exception { + PolicyTargetDTO testSubject; + List result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getUniqueIds(); + } + + @Test + public void testSetUniqueIds() throws Exception { + PolicyTargetDTO testSubject; + List ids = null; + + // default test + testSubject = createTestSubject(); + testSubject.setUniqueIds(ids); + } +} \ No newline at end of file diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/PolicyTypeDefinitionTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/PolicyTypeDefinitionTest.java index 2ff19c3969..3f57ecf281 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/PolicyTypeDefinitionTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/PolicyTypeDefinitionTest.java @@ -3,6 +3,7 @@ package org.openecomp.sdc.be.model; import java.util.List; import org.junit.Test; +import org.openecomp.sdc.be.datatypes.elements.PolicyTypeDataDefinition; public class PolicyTypeDefinitionTest { @@ -11,6 +12,10 @@ public class PolicyTypeDefinitionTest { return new PolicyTypeDefinition(); } + @Test + public void testCtor() throws Exception { + new PolicyTypeDefinition(new PolicyTypeDataDefinition()); + } @Test public void testGetProperties() throws Exception { diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/PropertyDefinitionTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/PropertyDefinitionTest.java index 639be3a5d7..5a8888b8b0 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/PropertyDefinitionTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/PropertyDefinitionTest.java @@ -1,8 +1,11 @@ package org.openecomp.sdc.be.model; +import java.util.LinkedList; import java.util.List; import org.junit.Test; +import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition; +import org.openecomp.sdc.be.model.PropertyDefinition.PropertyNames; public class PropertyDefinitionTest { @@ -10,7 +13,44 @@ public class PropertyDefinitionTest { private PropertyDefinition createTestSubject() { return new PropertyDefinition(); } - + + @Test + public void testCtor() throws Exception { + new PropertyDefinition(new PropertyDefinition()); + new PropertyDefinition(new PropertyDataDefinition()); + } + + @Test + public void testPropertyNames() throws Exception { + PropertyNames availabiltyZoneCount = PropertyDefinition.PropertyNames.AVAILABILTY_ZONE_COUNT; + } + + @Test + public void testPropertyNames_GetPropertyName() throws Exception { + PropertyDefinition.PropertyNames.AVAILABILTY_ZONE_COUNT.getPropertyName(); + } + + @Test + public void testPropertyNames_GetUpdateBehavior() throws Exception { + PropertyDefinition.PropertyNames.AVAILABILTY_ZONE_COUNT.getUpdateBehavior(); + } + + @Test + public void testPropertyNames_FindName() throws Exception { + PropertyDefinition.PropertyNames.findName(null); + PropertyDefinition.PropertyNames.findName(PropertyDefinition.PropertyNames.AVAILABILTY_ZONE_COUNT.getPropertyName()); + } + + @Test + public void testGroupInstancePropertyValueUpdateBehavior_GetLevelName() throws Exception { + PropertyDefinition.GroupInstancePropertyValueUpdateBehavior.NOT_RELEVANT.getLevelName(); + } + + @Test + public void testGroupInstancePropertyValueUpdateBehavior_GetLevelNumber() throws Exception { + PropertyDefinition.GroupInstancePropertyValueUpdateBehavior.NOT_RELEVANT.getLevelNumber(); + } + @Test public void testGetConstraints() throws Exception { PropertyDefinition testSubject; @@ -80,5 +120,18 @@ public class PropertyDefinitionTest { // default test testSubject = createTestSubject(); result = testSubject.equals(obj); + + result = testSubject.equals(new Object()); + result = testSubject.equals(testSubject); + PropertyDefinition testSubject2 = createTestSubject(); + result = testSubject.equals(testSubject2); + testSubject2.setConstraints(new LinkedList<>()); + result = testSubject.equals(testSubject2); + testSubject.setConstraints(new LinkedList<>()); + result = testSubject.equals(testSubject2); + testSubject2.setName("mock"); + result = testSubject.equals(testSubject2); + testSubject.setName("mock"); + result = testSubject.equals(testSubject2); } } \ No newline at end of file diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/ResourceTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ResourceTest.java index e9976834b8..77980a823d 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/ResourceTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ResourceTest.java @@ -1,14 +1,18 @@ package org.openecomp.sdc.be.model; +import java.util.LinkedList; import java.util.List; import java.util.Map; import org.junit.Assert; import org.junit.Test; +import org.openecomp.sdc.be.config.ConfigurationManager; import org.openecomp.sdc.be.datatypes.elements.InterfaceOperationDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; import org.openecomp.sdc.be.unittests.utils.ModelConfDependentTest; +import mockit.Deencapsulation; + public class ResourceTest extends ModelConfDependentTest{ private Resource createTestSubject() { @@ -394,6 +398,15 @@ public class ResourceTest extends ModelConfDependentTest{ result = testSubject.getResourceVendorModelNumber(); } + @Test + public void testFetchGenericTypeToscaNameFromConfig() throws Exception { + Resource testSubject; + String result; + + // default test + testSubject = createTestSubject(); + result = testSubject.fetchGenericTypeToscaNameFromConfig(); + } @Test public void testAssetType() throws Exception { @@ -427,6 +440,27 @@ public class ResourceTest extends ModelConfDependentTest{ result = testSubject.deriveFromGeneric(); } + @Test + public void testGroupRelationsByInstanceName() throws Exception { + Resource testSubject; + Map> result; + + // default test + testSubject = createTestSubject(); + Resource resource = new Resource(); + resource.setComponentInstancesRelations(new LinkedList()); + result = testSubject.groupRelationsByInstanceName(resource); + } + @Test + public void testGetInstanceNameFromInstanceId() throws Exception { + Resource testSubject; + Resource resource = new Resource(); + String instId = "mock"; + boolean result; + // default test + testSubject = createTestSubject(); + Deencapsulation.invoke(testSubject, "getInstanceNameFromInstanceId", resource, instId); + } } \ No newline at end of file diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/UploadResourceInfoTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/UploadResourceInfoTest.java new file mode 100644 index 0000000000..a3c2e84ce8 --- /dev/null +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/UploadResourceInfoTest.java @@ -0,0 +1,352 @@ +package org.openecomp.sdc.be.model; + +import java.util.LinkedList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.openecomp.sdc.be.model.category.CategoryDefinition; +import org.openecomp.sdc.common.api.UploadArtifactInfo; + +public class UploadResourceInfoTest { + + private UploadResourceInfo createTestSubject() { + return new UploadResourceInfo(); + } + + @Test + public void testCtor() throws Exception { + new UploadResourceInfo("mock", "mock", "mock", "mock/mock/mock", new LinkedList<>(), new LinkedList<>()); + + } + + @Test + public void testGetPayloadData() throws Exception { + UploadResourceInfo testSubject; + String result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getPayloadData(); + } + + @Test + public void testSetPayloadData() throws Exception { + UploadResourceInfo testSubject; + String payload = ""; + + // default test + testSubject = createTestSubject(); + testSubject.setPayloadData(payload); + } + + @Test + public void testGetPayloadName() throws Exception { + UploadResourceInfo testSubject; + String result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getPayloadName(); + } + + @Test + public void testSetPayloadName() throws Exception { + UploadResourceInfo testSubject; + String payloadName = ""; + + // default test + testSubject = createTestSubject(); + testSubject.setPayloadName(payloadName); + } + + @Test + public void testGetDescription() throws Exception { + UploadResourceInfo testSubject; + String result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getDescription(); + } + + @Test + public void testSetDescription() throws Exception { + UploadResourceInfo testSubject; + String description = ""; + + // default test + testSubject = createTestSubject(); + testSubject.setDescription(description); + } + + @Test + public void testGetTags() throws Exception { + UploadResourceInfo testSubject; + List result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getTags(); + } + + @Test + public void testSetTags() throws Exception { + UploadResourceInfo testSubject; + List tags = null; + + // default test + testSubject = createTestSubject(); + testSubject.setTags(tags); + } + + @Test + public void testGetArtifactList() throws Exception { + UploadResourceInfo testSubject; + List result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getArtifactList(); + } + + @Test + public void testSetArtifactList() throws Exception { + UploadResourceInfo testSubject; + List artifactsList = null; + + // default test + testSubject = createTestSubject(); + testSubject.setArtifactList(artifactsList); + } + + @Test + public void testHashCode() throws Exception { + UploadResourceInfo testSubject; + int result; + + // default test + testSubject = createTestSubject(); + result = testSubject.hashCode(); + } + + @Test + public void testEquals() throws Exception { + UploadResourceInfo testSubject; + Object obj = null; + boolean result; + + // test 1 + testSubject = createTestSubject(); + result = testSubject.equals(obj); + Assert.assertEquals(false, result); + result = testSubject.equals(new Object()); + Assert.assertEquals(false, result); + result = testSubject.equals(testSubject); + Assert.assertEquals(true, result); + result = testSubject.equals(createTestSubject()); + Assert.assertEquals(true, result); + } + + @Test + public void testGetContactId() throws Exception { + UploadResourceInfo testSubject; + String result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getContactId(); + } + + @Test + public void testSetContactId() throws Exception { + UploadResourceInfo testSubject; + String userId = ""; + + // default test + testSubject = createTestSubject(); + testSubject.setContactId(userId); + } + + @Test + public void testGetName() throws Exception { + UploadResourceInfo testSubject; + String result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getName(); + } + + @Test + public void testSetName() throws Exception { + UploadResourceInfo testSubject; + String resourceName = ""; + + // default test + testSubject = createTestSubject(); + testSubject.setName(resourceName); + } + + @Test + public void testGetResourceIconPath() throws Exception { + UploadResourceInfo testSubject; + String result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getResourceIconPath(); + } + + @Test + public void testSetResourceIconPath() throws Exception { + UploadResourceInfo testSubject; + String resourceIconPath = ""; + + // default test + testSubject = createTestSubject(); + testSubject.setResourceIconPath(resourceIconPath); + } + + @Test + public void testGetVendorName() throws Exception { + UploadResourceInfo testSubject; + String result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getVendorName(); + } + + @Test + public void testSetVendorName() throws Exception { + UploadResourceInfo testSubject; + String vendorName = ""; + + // default test + testSubject = createTestSubject(); + testSubject.setVendorName(vendorName); + } + + @Test + public void testGetVendorRelease() throws Exception { + UploadResourceInfo testSubject; + String result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getVendorRelease(); + } + + @Test + public void testSetVendorRelease() throws Exception { + UploadResourceInfo testSubject; + String vendorRelease = ""; + + // default test + testSubject = createTestSubject(); + testSubject.setVendorRelease(vendorRelease); + } + + @Test + public void testGetResourceVendorModelNumber() throws Exception { + UploadResourceInfo testSubject; + String result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getResourceVendorModelNumber(); + } + + @Test + public void testSetResourceVendorModelNumber() throws Exception { + UploadResourceInfo testSubject; + String resourceVendorModelNumber = ""; + + // default test + testSubject = createTestSubject(); + testSubject.setResourceVendorModelNumber(resourceVendorModelNumber); + } + + @Test + public void testSetIcon() throws Exception { + UploadResourceInfo testSubject; + String icon = ""; + + // default test + testSubject = createTestSubject(); + testSubject.setIcon(icon); + } + + @Test + public void testGetResourceType() throws Exception { + UploadResourceInfo testSubject; + String result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getResourceType(); + } + + @Test + public void testSetResourceType() throws Exception { + UploadResourceInfo testSubject; + String resourceType = ""; + + // default test + testSubject = createTestSubject(); + testSubject.setResourceType(resourceType); + } + + @Test + public void testGetCategories() throws Exception { + UploadResourceInfo testSubject; + List result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getCategories(); + } + + @Test + public void testSetCategories() throws Exception { + UploadResourceInfo testSubject; + List categories = null; + + // default test + testSubject = createTestSubject(); + testSubject.setCategories(categories); + } + + @Test + public void testAddSubCategory() throws Exception { + UploadResourceInfo testSubject; + String category = ""; + String subCategory = ""; + + // test 1 + testSubject = createTestSubject(); + category = null; + subCategory = null; + testSubject.addSubCategory(category, subCategory); + + // test 2 + testSubject = createTestSubject(); + category = ""; + subCategory = null; + testSubject.addSubCategory(category, subCategory); + + // test 3 + testSubject = createTestSubject(); + subCategory = ""; + category = null; + testSubject.addSubCategory(category, subCategory); + + // test 4 + testSubject = createTestSubject(); + subCategory = "mock"; + category = "mock"; + testSubject.addSubCategory(category, subCategory); + testSubject.addSubCategory(category, subCategory); + } +} \ No newline at end of file diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/UserTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/UserTest.java new file mode 100644 index 0000000000..af4add5b85 --- /dev/null +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/UserTest.java @@ -0,0 +1,230 @@ +package org.openecomp.sdc.be.model; + +import org.junit.Assert; +import org.junit.Test; +import org.openecomp.sdc.be.dao.utils.UserStatusEnum; +import org.openecomp.sdc.be.resources.data.UserData; + +public class UserTest { + + private User createTestSubject() { + return new User(); + } + + @Test + public void testCtor() throws Exception { + new User(new User()); + new User(new UserData()); + new User("mock", "mock", "mock", "mock", "mock", 0L); + } + + @Test + public void testCopyData() throws Exception { + User testSubject; + User other = null; + + // default test + testSubject = createTestSubject(); + testSubject.copyData(other); + testSubject.copyData(new User()); + } + + @Test + public void testGetFirstName() throws Exception { + User testSubject; + String result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getFirstName(); + } + + @Test + public void testSetFirstName() throws Exception { + User testSubject; + String firstName = ""; + + // default test + testSubject = createTestSubject(); + testSubject.setFirstName(firstName); + } + + @Test + public void testGetLastName() throws Exception { + User testSubject; + String result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getLastName(); + } + + @Test + public void testSetLastName() throws Exception { + User testSubject; + String lastName = ""; + + // default test + testSubject = createTestSubject(); + testSubject.setLastName(lastName); + } + + @Test + public void testGetUserId() throws Exception { + User testSubject; + String result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getUserId(); + } + + @Test + public void testSetUserId() throws Exception { + User testSubject; + String userId = ""; + + // default test + testSubject = createTestSubject(); + testSubject.setUserId(userId); + } + + @Test + public void testGetEmail() throws Exception { + User testSubject; + String result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getEmail(); + } + + @Test + public void testSetEmail() throws Exception { + User testSubject; + String email = ""; + + // default test + testSubject = createTestSubject(); + testSubject.setEmail(email); + } + + @Test + public void testGetRole() throws Exception { + User testSubject; + String result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getRole(); + } + + @Test + public void testSetRole() throws Exception { + User testSubject; + String role = ""; + + // default test + testSubject = createTestSubject(); + testSubject.setRole(role); + } + + @Test + public void testGetFullName() throws Exception { + User testSubject; + String result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getFullName(); + } + + @Test + public void testSetLastLoginTime() throws Exception { + User testSubject; + + // default test + testSubject = createTestSubject(); + testSubject.setLastLoginTime(); + } + + @Test + public void testSetLastLoginTime_1() throws Exception { + User testSubject; + Long time = null; + + // default test + testSubject = createTestSubject(); + testSubject.setLastLoginTime(time); + } + + @Test + public void testGetLastLoginTime() throws Exception { + User testSubject; + Long result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getLastLoginTime(); + } + + @Test + public void testHashCode() throws Exception { + User testSubject; + int result; + + // default test + testSubject = createTestSubject(); + result = testSubject.hashCode(); + } + + @Test + public void testEquals() throws Exception { + User testSubject; + Object obj = null; + boolean result; + + // test 1 + testSubject = createTestSubject(); + result = testSubject.equals(obj); + Assert.assertEquals(false, result); + + result = testSubject.equals(new Object()); + Assert.assertEquals(false, result); + + result = testSubject.equals(testSubject); + Assert.assertEquals(true, result); + result = testSubject.equals(createTestSubject()); + Assert.assertEquals(true, result); + } + + @Test + public void testGetStatus() throws Exception { + User testSubject; + UserStatusEnum result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getStatus(); + } + + @Test + public void testSetStatus() throws Exception { + User testSubject; + UserStatusEnum status = null; + + // default test + testSubject = createTestSubject(); + testSubject.setStatus(status); + } + + @Test + public void testToString() throws Exception { + User testSubject; + String result; + + // default test + testSubject = createTestSubject(); + result = testSubject.toString(); + } +} \ No newline at end of file diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/cache/ApplicationDataTypeCacheTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/cache/ApplicationDataTypeCacheTest.java new file mode 100644 index 0000000000..8e5cb5be73 --- /dev/null +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/cache/ApplicationDataTypeCacheTest.java @@ -0,0 +1,169 @@ +package org.openecomp.sdc.be.model.cache; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.openecomp.sdc.be.dao.titan.TitanOperationStatus; +import org.openecomp.sdc.be.model.DataTypeDefinition; +import org.openecomp.sdc.be.model.operations.impl.PropertyOperation; +import org.openecomp.sdc.be.resources.data.DataTypeData; +import org.openecomp.sdc.be.unittests.utils.ModelConfDependentTest; + +import fj.data.Either; +import mockit.Deencapsulation; + +public class ApplicationDataTypeCacheTest extends ModelConfDependentTest{ + + @InjectMocks + private ApplicationDataTypeCache testSubject; + + @Mock + PropertyOperation propertyOperation; + + @Before + public void setUpMocks() throws Exception { + MockitoAnnotations.initMocks(this); + } + + + @Test + public void testInit() throws Exception { + testSubject.init(); + } + + @Test + public void testDestroy() throws Exception { + testSubject.init(); + Deencapsulation.invoke(testSubject, "destroy"); + } + + @Test + public void testShutdownExecutor() throws Exception { + + // default test + Deencapsulation.invoke(testSubject, "shutdownExecutor"); + } + + @Test + public void testGetAllDataTypesFromGraph() throws Exception { + Either, TitanOperationStatus> result; + + // default test + result = Deencapsulation.invoke(testSubject, "getAllDataTypesFromGraph"); + } + + @Test + public void testGetAll() throws Exception { + Either, TitanOperationStatus> result; + + // default test + result = testSubject.getAll(); + } + + @Test + public void testGet() throws Exception { + String uniqueId = ""; + Either result; + + // default test + result = testSubject.get(uniqueId); + } + + @Test + public void testGet2() throws Exception { + String uniqueId = ""; + Either result; + + HashMap a = new HashMap<>(); + DataTypeDefinition value1 = new DataTypeDefinition(); + value1.setUniqueId("mock"); + a.put("mock", value1); + Either, TitanOperationStatus> value = Either.left(a); + Mockito.when(propertyOperation.getAllDataTypes()).thenReturn(value); + // default test + Deencapsulation.invoke(testSubject, "replaceAllData"); + result = testSubject.get(uniqueId); + } + + @Test + public void testRun() throws Exception { + testSubject.run(); + } + + @Test + public void testRun2() throws Exception { + Either, TitanOperationStatus> value = Either.right(TitanOperationStatus.GENERAL_ERROR); + Mockito.when(propertyOperation.getAllDataTypeNodes()).thenReturn(value); + testSubject.run(); + } + + @Test + public void testRun3() throws Exception { + LinkedList a = new LinkedList<>(); + a.add(new DataTypeData()); + Either, TitanOperationStatus> value = Either.left(a); + Mockito.when(propertyOperation.getAllDataTypeNodes()).thenReturn(value); + + HashMap a1 = new HashMap<>(); + DataTypeDefinition value1 = new DataTypeDefinition(); + value1.setUniqueId("mock"); + a1.put("mock", value1); + Either, TitanOperationStatus> value2 = Either.left(a1); + Mockito.when(propertyOperation.getAllDataTypes()).thenReturn(value2); + + Deencapsulation.invoke(testSubject, "replaceAllData"); + testSubject.run(); + } + + @Test + public void testCompareDataTypes() throws Exception { + Map> dataTypeNameToModificationTime = new HashMap<>(); + Map> currentDataTypeToModificationTime = new HashMap<>(); + boolean result; + + // default test + result = Deencapsulation.invoke(testSubject, "compareDataTypes", dataTypeNameToModificationTime, currentDataTypeToModificationTime); + } + + @Test + public void testCompareDataTypes2() throws Exception { + Map> dataTypeNameToModificationTime = new HashMap<>(); + Map> currentDataTypeToModificationTime = new HashMap<>(); + boolean result; + + currentDataTypeToModificationTime.put("mock", ImmutablePair.of(1L, 2L)); + dataTypeNameToModificationTime.put("mock", ImmutablePair.of(5L, 6L)); + + // default test + result = Deencapsulation.invoke(testSubject, "compareDataTypes", dataTypeNameToModificationTime, currentDataTypeToModificationTime); + } + + @Test + public void testReplaceAllData() throws Exception { + HashMap a = new HashMap<>(); + DataTypeDefinition value1 = new DataTypeDefinition(); + value1.setUniqueId("mock"); + a.put("mock", value1); + Either, TitanOperationStatus> value = Either.left(a); + Mockito.when(propertyOperation.getAllDataTypes()).thenReturn(value); + // default test + Deencapsulation.invoke(testSubject, "replaceAllData"); + } + + @Test + public void testReplaceAllData2() throws Exception { + Either, TitanOperationStatus> value = Either.right(TitanOperationStatus.GENERAL_ERROR); + Mockito.when(propertyOperation.getAllDataTypes()).thenReturn(value); + // default test + Deencapsulation.invoke(testSubject, "replaceAllData"); + } +} \ No newline at end of file diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/cache/ComponentCacheTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/cache/ComponentCacheTest.java index a34d2f88f6..419666b686 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/cache/ComponentCacheTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/cache/ComponentCacheTest.java @@ -1,70 +1,376 @@ package org.openecomp.sdc.be.model.cache; import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.function.Function; -import org.junit.Before; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.apache.commons.lang3.tuple.ImmutableTriple; +import org.junit.Assert; +import org.junit.Ignore; import org.junit.Test; -import org.mockito.InjectMocks; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; -import org.openecomp.sdc.be.config.Configuration; import org.openecomp.sdc.be.dao.api.ActionStatus; -import org.openecomp.sdc.be.dao.cassandra.ComponentCassandraDao; -import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade; +import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; +import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; +import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.resources.data.ComponentCacheData; -import org.slf4j.Logger; import fj.data.Either; +import mockit.Deencapsulation; +@Ignore public class ComponentCacheTest { - ComponentCassandraDao componentCassandraDao = Mockito.mock(ComponentCassandraDao.class); - - ToscaOperationFacade toscaOperationFacade = Mockito.mock(ToscaOperationFacade.class); - Configuration configuration = Mockito.mock(Configuration.class); - - Logger logger = Mockito.mock(Logger.class); - - @InjectMocks - ComponentCache componentCache = new ComponentCache(); private ComponentCache createTestSubject() { - return componentCache; + return new ComponentCache(); } - @Before - public void initMocks() { - MockitoAnnotations.initMocks(this); - } - - + @Test + public void testInit() throws Exception { + ComponentCache testSubject; + // default test + testSubject = createTestSubject(); + testSubject.init(); + } @Test public void testIsEnabled() throws Exception { + ComponentCache testSubject; boolean result; // default test - result = componentCache.isEnabled(); + testSubject = createTestSubject(); + result = testSubject.isEnabled(); } @Test public void testSetEnabled() throws Exception { + ComponentCache testSubject; boolean enabled = false; // default test - componentCache.setEnabled(enabled); + testSubject = createTestSubject(); + testSubject.setEnabled(enabled); } + @Test + public void testGetComponent() throws Exception { + ComponentCache testSubject; + String componentUid = ""; + Long lastModificationTime = null; + Function filterFieldsFunc = null; + Either result; + // default test + testSubject = createTestSubject(); + result = testSubject.getComponent(componentUid, lastModificationTime, filterFieldsFunc); + } @Test public void testGetAllComponentIdTimeAndType() throws Exception { + ComponentCache testSubject; Either, ActionStatus> result; // default test - result = componentCache.getAllComponentIdTimeAndType(); + testSubject = createTestSubject(); + result = testSubject.getAllComponentIdTimeAndType(); } + @Test + public void testGetComponentsForCatalog() throws Exception { + ComponentCache testSubject; + Set components = null; + ComponentTypeEnum componentTypeEnum = null; + Either, List, Set>, ActionStatus> result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getComponentsForCatalog(components, componentTypeEnum); + } + + @Test + public void testUpdateCatalogInMemoryCacheWithCertified() throws Exception { + ComponentCache testSubject; + List foundComponents = null; + ComponentTypeEnum componentTypeEnum = null; + + // default test + testSubject = createTestSubject(); + Deencapsulation.invoke(testSubject, "updateCatalogInMemoryCacheWithCertified", List.class, + ComponentTypeEnum.class); + } + + @Test + public void testGetDataFromInMemoryCache() throws Exception { + ComponentCache testSubject; + Set components = null; + ComponentTypeEnum componentTypeEnum = null; + List result; + + // default test + testSubject = createTestSubject(); + result = Deencapsulation.invoke(testSubject, "getDataFromInMemoryCache", Set.class, ComponentTypeEnum.class); + } + + @Test + public void testGetComponents() throws Exception { + ComponentCache testSubject; + Set components = null; + Function, List> filterFieldsFunc = null; + Either, List, Set>, ActionStatus> result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getComponents(components, filterFieldsFunc); + } + + @Test + public void testGetComponentsForLeftPanel() throws Exception { + ComponentCache testSubject; + ComponentTypeEnum componentTypeEnum = null; + String internalComponentType = ""; + Set filteredResources = null; + Either, List, Set>, ActionStatus> result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getComponentsForLeftPanel(componentTypeEnum, internalComponentType, filteredResources); + } + + @Test + public void testFilterForLeftPanel() throws Exception { + ComponentCache testSubject; + List components = null; + List result; + + // test 1 + testSubject = createTestSubject(); + components = null; + result = Deencapsulation.invoke(testSubject, "filterForLeftPanel", List.class); + Assert.assertEquals(null, result); + } + + @Test + public void testFilterForCatalog() throws Exception { + ComponentCache testSubject; + List components = null; + List result; + + // test 1 + testSubject = createTestSubject(); + components = null; + result = Deencapsulation.invoke(testSubject, "filterForCatalog", List.class); + Assert.assertEquals(null, result); + } + + @Test + public void testFilterFieldsForLeftPanel() throws Exception { + ComponentCache testSubject; + Component component = null; + Component result; + + // default test + testSubject = createTestSubject(); + result = Deencapsulation.invoke(testSubject, "filterFieldsForLeftPanel", new Object[] { Component.class }); + } + + @Test + public void testFilterFieldsForCatalog() throws Exception { + ComponentCache testSubject; + Component component = null; + Component result; + + // default test + testSubject = createTestSubject(); + result = Deencapsulation.invoke(testSubject, "filterFieldsForCatalog", new Object[] { Component.class }); + } + + @Test + public void testCopyFieldsForLeftPanel() throws Exception { + ComponentCache testSubject; + Component component = null; + Component filteredComponent = null; + + // default test + testSubject = createTestSubject(); + Deencapsulation.invoke(testSubject, "copyFieldsForLeftPanel", + new Object[] { Component.class, Component.class }); + } + + @Test + public void testCopyFieldsForCatalog() throws Exception { + ComponentCache testSubject; + Component component = null; + Component filteredComponent = null; + + // default test + testSubject = createTestSubject(); + Deencapsulation.invoke(testSubject, "copyFieldsForCatalog", new Object[] { Component.class, Component.class }); + } + + @Test + public void testGetComponentsFull() throws Exception { + ComponentCache testSubject; + Set filteredResources = null; + Either, List, Set>, ActionStatus> result; + + // default test + testSubject = createTestSubject(); + result = Deencapsulation.invoke(testSubject, "getComponentsFull", Set.class); + } + + @Test + public void testConvertComponentCacheToComponent() throws Exception { + ComponentCache testSubject; + ComponentCacheData componentCacheData = null; + Either result; + + // default test + testSubject = createTestSubject(); + result = Deencapsulation.invoke(testSubject, "convertComponentCacheToComponent", + new Object[] { ComponentCacheData.class }); + } + + @Test + public void testDeserializeComponent() throws Exception { + ComponentCache testSubject; + ComponentCacheData componentCacheData = null; + byte[] dataAsArray = new byte[] { ' ' }; + Either result; + + // default test + testSubject = createTestSubject(); + result = Deencapsulation.invoke(testSubject, "deserializeComponent", + new Object[] { ComponentCacheData.class, dataAsArray }); + } + + @Test + public void testGetComponent_1() throws Exception { + ComponentCache testSubject; + String componentUid = ""; + Either result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getComponent(componentUid); + } + + @Test + public void testGetComponent_2() throws Exception { + ComponentCache testSubject; + String componentUid = ""; + Long lastModificationTime = null; + Either result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getComponent(componentUid, lastModificationTime); + } + + @Test + public void testSetComponent() throws Exception { + ComponentCache testSubject; + String componentUid = ""; + Long lastModificationTime = null; + NodeTypeEnum nodeTypeEnum = null; + boolean result; + + // default test + testSubject = createTestSubject(); + result = testSubject.setComponent(componentUid, lastModificationTime, nodeTypeEnum); + } + + @Test + public void testSaveComponent() throws Exception { + ComponentCache testSubject; + String componentUid = ""; + Long lastModificationTime = null; + NodeTypeEnum nodeTypeEnum = null; + Component component = null; + boolean result; + + // default test + testSubject = createTestSubject(); + result = Deencapsulation.invoke(testSubject, "saveComponent", componentUid, Long.class, NodeTypeEnum.class, + Component.class); + } + + @Test + public void testSetComponent_1() throws Exception { + ComponentCache testSubject; + Component component = null; + NodeTypeEnum nodeTypeEnum = null; + boolean result; + + // default test + testSubject = createTestSubject(); + result = testSubject.setComponent(component, nodeTypeEnum); + } + + @Test + public void testGetComponentsFull_1() throws Exception { + ComponentCache testSubject;Map filteredResources = null; + Either,Set>,ActionStatus> result; + + // default test + testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "getComponentsFull", Map.class); + } + + @Test + public void testGetComponentsForCatalog_1() throws Exception { + ComponentCache testSubject; + Map components = null; + ComponentTypeEnum componentTypeEnum = null; + Either, Set>, ActionStatus> result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getComponentsForCatalog(components, componentTypeEnum); + } + + @Test + public void testGetComponents_1() throws Exception { + ComponentCache testSubject; + Map components = null; + Function, List> filterFieldsFunc = null; + Either, Set>, ActionStatus> result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getComponents(components, filterFieldsFunc); + } + + @Test + public void testGetComponentAndTime() throws Exception { + ComponentCache testSubject; + String componentUid = ""; + Function filterFieldsFunc = null; + Either, ActionStatus> result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getComponentAndTime(componentUid, filterFieldsFunc); + } + + @Test + public void testGetComponentFromCache() throws Exception { + ComponentCache testSubject;String componentUid = ""; + Long lastModificationTime = null; + Function filterFieldsFunc = null; + Either,ActionStatus> result; + + // test 1 + testSubject=createTestSubject();lastModificationTime = null; + result=Deencapsulation.invoke(testSubject, "getComponentFromCache", new Object[]{componentUid, Long.class, Function.class}); + Assert.assertEquals(null, result); + + // test 2 + testSubject=createTestSubject();filterFieldsFunc = null; + result=Deencapsulation.invoke(testSubject, "getComponentFromCache", new Object[]{componentUid, Long.class, Function.class}); + Assert.assertEquals(null, result); + } @Test public void testDeleteComponentFromCache() throws Exception { diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ElementOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ElementOperationTest.java index 1e493a74f4..b28641cba5 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ElementOperationTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ElementOperationTest.java @@ -20,7 +20,6 @@ package org.openecomp.sdc.be.model.operations.impl; -import static org.junit.Assert.*; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -28,6 +27,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import org.apache.tinkerpop.gremlin.structure.T; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -49,10 +49,6 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import fj.data.Either; -import java.util.*; - -import org.apache.tinkerpop.gremlin.structure.T; -import org.junit.Assert; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:application-context-test.xml") -- cgit 1.2.3-korg