Increased UT coverage -versioning-api-types 32/70132/4
authormojahidi <mojahidul.islam@amdocs.com>
Wed, 10 Oct 2018 05:28:39 +0000 (10:58 +0530)
committerVitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com>
Wed, 10 Oct 2018 09:24:45 +0000 (09:24 +0000)
Increased UT coverage openecomp-sdc-versioning-api-types

Change-Id: I28098e79848315076e75777e957a5dfe6f1eb481
Issue-ID: SDC-1673
Signed-off-by: mojahidi <mojahidul.islam@amdocs.com>
openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/types/Item.java
openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/types/UniqueValueMetadata.java
openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/types/VersionInfo.java
openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/types/VersionableEntityMetadata.java
openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/test/java/org/openecomp/sdc/versioning/VersionInfoDaoImplStub.java [new file with mode: 0644]
openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/test/java/org/openecomp/sdc/versioning/VersionableEntityImplStub.java [new file with mode: 0644]
openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/test/java/org/openecomp/sdc/versioning/VersioningUtilTest.java [new file with mode: 0644]
openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/test/java/org/openecomp/sdc/versioning/types/ItemTest.java [new file with mode: 0644]

index 161c22c..154bc40 100644 (file)
@@ -1,5 +1,24 @@
+/*
+ *
+ *  Copyright © 2017-2018 European Support Limited
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  * Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
 package org.openecomp.sdc.versioning.types;
 
+import lombok.Getter;
+import lombok.Setter;
 import org.openecomp.sdc.versioning.dao.types.VersionStatus;
 
 import java.util.Date;
@@ -7,6 +26,8 @@ import java.util.EnumMap;
 import java.util.HashMap;
 import java.util.Map;
 
+@Getter
+@Setter
 public class Item {
   private String id;
   private String type;
@@ -19,74 +40,10 @@ public class Item {
   private Date creationTime;
   private Date modificationTime;
 
-  public String getId() {
-    return id;
-  }
-
-  public void setId(String id) {
-    this.id = id;
-  }
-
-  public String getType() {
-    return type;
-  }
-
-  public void setType(String type) {
-    this.type = type;
-  }
-
-  public String getName() {
-    return name;
-  }
-
-  public void setName(String name) {
-    this.name = name;
-  }
-
-  public String getOwner() {
-    return owner;
-  }
-
-  public void setOwner(String owner) {
-    this.owner = owner;
-  }
-
-  public ItemStatus getStatus() {
-    return status;
-  }
-
-  public void setStatus(ItemStatus status) {
-    this.status = status;
-  }
-
-  public String getDescription() {
-    return description;
-  }
-
-  public void setDescription(String description) {
-    this.description = description;
-  }
-
-  public Map<String, Object> getProperties() {
-    return properties;
-  }
-
   public void addProperty(String key, Object value) {
     properties.put(key, value);
   }
 
-  public void setProperties(Map<String, Object> properties) {
-    this.properties = properties;
-  }
-
-  public Map<VersionStatus, Integer> getVersionStatusCounters() {
-    return versionStatusCounters;
-  }
-
-  public void setVersionStatusCounters(Map<VersionStatus, Integer> versionStatusCounters) {
-    this.versionStatusCounters = versionStatusCounters;
-  }
-
   public void addVersionStatus(VersionStatus versionStatus) {
     Integer counter = versionStatusCounters.get(versionStatus);
     versionStatusCounters
@@ -103,20 +60,4 @@ public class Item {
       }
     }
   }
-
-  public Date getCreationTime() {
-    return creationTime;
-  }
-
-  public void setCreationTime(Date creationTime) {
-    this.creationTime = creationTime;
-  }
-
-  public Date getModificationTime() {
-    return modificationTime;
-  }
-
-  public void setModificationTime(Date modificationTime) {
-    this.modificationTime = modificationTime;
-  }
 }
index 21d4229..e12a42e 100644 (file)
 
 package org.openecomp.sdc.versioning.types;
 
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.Setter;
 import java.util.List;
 
+@Getter
+@Setter
+@AllArgsConstructor
 public class UniqueValueMetadata {
   private String type;
   private List<String> uniqueConstraintIdentifiers;
-
-  public UniqueValueMetadata(String type, List<String> contextIdentifierNames) {
-    this.type = type;
-    this.uniqueConstraintIdentifiers = contextIdentifierNames;
-  }
-
-  public String getType() {
-    return type;
-  }
-
-  public void setType(String type) {
-    this.type = type;
-  }
-
-  public List<String> getUniqueConstraintIdentifiers() {
-    return uniqueConstraintIdentifiers;
-  }
-
-  public void setUniqueConstraintIdentifiers(List<String> uniqueConstraintIdentifiers) {
-    this.uniqueConstraintIdentifiers = uniqueConstraintIdentifiers;
-  }
 }
index 02b5aaa..a56c73d 100644 (file)
 
 package org.openecomp.sdc.versioning.types;
 
+import lombok.Getter;
+import lombok.Setter;
 import org.openecomp.sdc.versioning.dao.types.Version;
 import org.openecomp.sdc.versioning.dao.types.VersionStatus;
 
 import java.util.ArrayList;
 import java.util.List;
 
+@Getter
+@Setter
 public class VersionInfo {
   private Version activeVersion;
   private Version latestFinalVersion;
@@ -34,54 +38,6 @@ public class VersionInfo {
   private VersionStatus status;
   private String lockingUser;
 
-  public Version getActiveVersion() {
-    return activeVersion;
-  }
-
-  public void setActiveVersion(Version activeVersion) {
-    this.activeVersion = activeVersion;
-  }
-
-  public Version getLatestFinalVersion() {
-    return latestFinalVersion;
-  }
-
-  public void setLatestFinalVersion(Version latestFinalVersion) {
-    this.latestFinalVersion = latestFinalVersion;
-  }
-
-  public List<Version> getViewableVersions() {
-    return viewableVersions;
-  }
-
-  public void setViewableVersions(List<Version> viewableVersions) {
-    this.viewableVersions = viewableVersions;
-  }
-
-  public List<Version> getFinalVersions() {
-    return finalVersions;
-  }
-
-  public void setFinalVersions(List<Version> finalVersions) {
-    this.finalVersions = finalVersions;
-  }
-
-  public VersionStatus getStatus() {
-    return status;
-  }
-
-  public void setStatus(VersionStatus status) {
-    this.status = status;
-  }
-
-  public String getLockingUser() {
-    return lockingUser;
-  }
-
-  public void setLockingUser(String lockingUser) {
-    this.lockingUser = lockingUser;
-  }
-
   @Override
   public String toString() {
     final StringBuilder sb = new StringBuilder("VersionInfo{");
index 8ec54c9..fcc02af 100644 (file)
 
 package org.openecomp.sdc.versioning.types;
 
+import lombok.Getter;
+import lombok.Setter;
 import java.util.ArrayList;
 import java.util.List;
 
+@Getter
+@Setter
 public class VersionableEntityMetadata {
 
   private VersionableEntityStoreType storeType;
@@ -44,43 +48,4 @@ public class VersionableEntityMetadata {
     this.versionIdentifierName = versionIdentifierName;
   }
 
-  public VersionableEntityStoreType getStoreType() {
-    return storeType;
-  }
-
-  public void setStoreType(VersionableEntityStoreType storeType) {
-    this.storeType = storeType;
-  }
-
-  public String getName() {
-    return name;
-  }
-
-  public void setName(String name) {
-    this.name = name;
-  }
-
-  public String getIdentifierName() {
-    return identifierName;
-  }
-
-  public void setIdentifierName(String idColumnName) {
-    this.identifierName = idColumnName;
-  }
-
-  public String getVersionIdentifierName() {
-    return versionIdentifierName;
-  }
-
-  public void setVersionIdentifierName(String versionColumnName) {
-    this.versionIdentifierName = versionColumnName;
-  }
-
-  public List<UniqueValueMetadata> getUniqueValuesMetadata() {
-    return uniqueValuesMetadata;
-  }
-
-  public void setUniqueValuesMetadata(List<UniqueValueMetadata> uniqueValuesMetadata) {
-    this.uniqueValuesMetadata = uniqueValuesMetadata;
-  }
 }
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/test/java/org/openecomp/sdc/versioning/VersionInfoDaoImplStub.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/test/java/org/openecomp/sdc/versioning/VersionInfoDaoImplStub.java
new file mode 100644 (file)
index 0000000..d5799b1
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ *
+ *  Copyright © 2017-2018 European Support Limited
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  * Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.openecomp.sdc.versioning;
+
+import org.openecomp.core.dao.BaseDao;
+
+import java.util.Collection;
+
+public class VersionInfoDaoImplStub implements BaseDao<VersionableEntityImplStub> {
+
+    @Override
+    public Collection<VersionableEntityImplStub> list(VersionableEntityImplStub entity) {
+        return null;
+    }
+
+    @Override
+    public void create(VersionableEntityImplStub entity) {
+
+    }
+
+    @Override
+    public void update(VersionableEntityImplStub entity) {
+
+    }
+
+    @Override
+    public VersionableEntityImplStub get(VersionableEntityImplStub entity) {
+        return null;
+    }
+
+    @Override
+    public void delete(VersionableEntityImplStub entity) {
+
+    }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/test/java/org/openecomp/sdc/versioning/VersionableEntityImplStub.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/test/java/org/openecomp/sdc/versioning/VersionableEntityImplStub.java
new file mode 100644 (file)
index 0000000..4c429be
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ *
+ *  Copyright © 2017-2018 European Support Limited
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  * Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.openecomp.sdc.versioning;
+
+import org.openecomp.sdc.versioning.dao.types.Version;
+import org.openecomp.sdc.versioning.dao.types.VersionableEntity;
+
+public class VersionableEntityImplStub implements VersionableEntity {
+    @Override
+    public String getEntityType() {
+        return "entityType";
+    }
+
+    @Override
+    public String getFirstClassCitizenId() {
+        return "firstClassCitizenId";
+    }
+
+    @Override
+    public String getId() {
+        return "id";
+    }
+
+    @Override
+    public void setId(String id) {
+    }
+
+    @Override
+    public Version getVersion() {
+        return new Version();
+    }
+
+    @Override
+    public void setVersion(Version version) {
+
+    }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/test/java/org/openecomp/sdc/versioning/VersioningUtilTest.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/test/java/org/openecomp/sdc/versioning/VersioningUtilTest.java
new file mode 100644 (file)
index 0000000..7448100
--- /dev/null
@@ -0,0 +1,159 @@
+
+/*
+ *
+ *  Copyright © 2017-2018 European Support Limited
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  * Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.openecomp.sdc.versioning;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openecomp.sdc.common.errors.CoreException;
+import org.openecomp.sdc.versioning.dao.types.Version;
+import org.openecomp.sdc.versioning.types.VersionInfo;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+public class VersioningUtilTest {
+
+    @Test
+    public void testResolveVersion() {
+        Version version = new Version();
+        version.setMajor(1);
+        version.setMinor(1);
+
+        VersionInfo versionInfo = new VersionInfo();
+        versionInfo.setActiveVersion(version);
+        versionInfo.setViewableVersions(Arrays.asList(version));
+        versionInfo.setLockingUser("user");
+        Version resolveVersion = VersioningUtil.resolveVersion(version, versionInfo, "user");
+        Assert.assertNotNull(resolveVersion);
+        Assert.assertEquals(1,resolveVersion.getMajor());
+        Assert.assertEquals(1,resolveVersion.getMinor());
+
+    }
+
+    @Test(expected = CoreException.class)
+    public void testResolveVersionNegative() {
+        Version version = new Version();
+        version.setMajor(1);
+        version.setMinor(1);
+
+        VersionInfo versionInfo = new VersionInfo();
+        versionInfo.setActiveVersion(version);
+        versionInfo.setViewableVersions(Arrays.asList(new Version()));
+        versionInfo.setLockingUser("user");
+        VersioningUtil.resolveVersion(null, versionInfo, "user");
+
+    }
+
+    @Test
+    public void testResolveVersionFinalOnly() {
+        Version version = new Version();
+        VersionInfo versionInfo = new VersionInfo();
+        versionInfo.setActiveVersion(version);
+        versionInfo.setViewableVersions(Arrays.asList(version));
+        versionInfo.setLatestFinalVersion(version);
+        Assert.assertNotNull(VersioningUtil.resolveVersion(null, versionInfo, true));
+
+    }
+
+    @Test(expected = CoreException.class)
+    public void testResolveVersionWithNonFinalVersions() {
+        Version version = new Version();
+        VersionInfo versionInfo = new VersionInfo();
+        versionInfo.setActiveVersion(version);
+        versionInfo.setViewableVersions(Arrays.asList(new Version()));
+        versionInfo.setLatestFinalVersion(version);
+        VersioningUtil.resolveVersion(version, versionInfo,true);
+    }
+
+    @Test
+    public void testResolveVersionWithoutFinal() {
+        Version version = new Version();
+        VersionInfo versionInfo = new VersionInfo();
+        versionInfo.setActiveVersion(version);
+        versionInfo.setViewableVersions(Arrays.asList(version));
+        Assert.assertNotNull(VersioningUtil.resolveVersion(null, versionInfo, false));
+
+    }
+
+    @Test(expected = CoreException.class)
+    public void testResolveVersionWithoutFinalVersion() {
+        Version version = new Version();
+        VersionInfo versionInfo = new VersionInfo();
+        versionInfo.setActiveVersion(version);
+        versionInfo.setViewableVersions(Arrays.asList(version));
+        VersioningUtil.resolveVersion(null, versionInfo, true);
+
+    }
+
+    @Test(expected = CoreException.class)
+    public void testResolveVersionFinalOnlyNegative() {
+        Version version = new Version();
+        VersionInfo versionInfo = new VersionInfo();
+        versionInfo.setActiveVersion(version);
+        versionInfo.setViewableVersions(Arrays.asList(version));
+        versionInfo.setLatestFinalVersion(version);
+        VersioningUtil.resolveVersion(version, versionInfo, true);
+
+    }
+
+    @Test(expected = CoreException.class)
+    public void testValidateEntityExistence() {
+        VersioningUtil.validateEntityExistence(null, new VersionableEntityImplStub(), "firstClassCitizenType");
+    }
+
+    @Test(expected = CoreException.class)
+    public void testValidateEntitiesExistence() {
+        Set<String> entityIds = new HashSet<>();
+        entityIds.add("id1");
+        entityIds.add("id2");
+        VersioningUtil.validateEntitiesExistence(entityIds, new VersionableEntityImplStub(),
+                new VersionInfoDaoImplStub(),"firstClassCitizenType");
+    }
+
+    @Test(expected = CoreException.class)
+    public void testValidateEntitiesExistenceSizeOne() {
+        Set<String> entityIds = new HashSet<>();
+        entityIds.add("id1");
+        VersioningUtil.validateEntitiesExistence(entityIds, new VersionableEntityImplStub(),
+                new VersionInfoDaoImplStub(),"firstClassCitizenType");
+    }
+
+    @Test(expected = CoreException.class)
+    public void testValidateContainedEntitiesExistence() {
+        Set<String> inputContainedEntityIds = new HashSet<>();
+        inputContainedEntityIds.add("id1");
+        inputContainedEntityIds.add("id2");
+        Set<String> retrievedContainedEntityIds = new HashSet<>();
+        VersioningUtil.validateContainedEntitiesExistence("containedEntityType",
+                inputContainedEntityIds, new VersionableEntityImplStub(), retrievedContainedEntityIds);
+    }
+
+    @Test(expected = CoreException.class)
+    public void testValidateContainedEntitiesExistenceWithIdOne() {
+        Set<String> inputContainedEntityIds = new HashSet<>();
+        inputContainedEntityIds.add("id1");
+        inputContainedEntityIds.add("id2");
+        Set<String> retrievedContainedEntityIds = new HashSet<>();
+        retrievedContainedEntityIds.add("id1");
+        VersioningUtil.validateContainedEntitiesExistence("containedEntityType",
+                inputContainedEntityIds, new VersionableEntityImplStub(), retrievedContainedEntityIds);
+    }
+}
\ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/test/java/org/openecomp/sdc/versioning/types/ItemTest.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/test/java/org/openecomp/sdc/versioning/types/ItemTest.java
new file mode 100644 (file)
index 0000000..f69cfcc
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ *
+ *  Copyright © 2017-2018 European Support Limited
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  * Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.openecomp.sdc.versioning.types;
+
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openecomp.sdc.versioning.dao.types.VersionStatus;
+
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.Map;
+
+public class ItemTest {
+
+    @Test
+    public void testAddVersionStatus() {
+        Item item = new Item();
+        item.addVersionStatus(VersionStatus.Draft);
+        Assert.assertEquals(1, item.getVersionStatusCounters().size());
+    }
+
+    @Test
+    public void testAddProperty() {
+        Item item = new Item();
+        item.setProperties(new HashMap<>());
+        item.addProperty("item1", new Object());
+        Assert.assertEquals(1, item.getProperties().size());
+    }
+    @Test
+    public void testRemoveVersionStatus() {
+        Item item = new Item();
+        Map<VersionStatus, Integer> versionStatusCounters = new EnumMap<>(VersionStatus.class);
+        versionStatusCounters.put(VersionStatus.Draft, 1);
+        item.setVersionStatusCounters(versionStatusCounters);
+        item.removeVersionStatus(VersionStatus.Draft);
+        Assert.assertEquals(0, item.getVersionStatusCounters().size());
+    }
+
+}
\ No newline at end of file