Increasing code coverage ns-lcm-database-service 84/113484/2
authorwaqas.ikram <waqas.ikram@est.tech>
Fri, 2 Oct 2020 12:21:17 +0000 (13:21 +0100)
committerwaqas.ikram <waqas.ikram@est.tech>
Fri, 2 Oct 2020 13:59:52 +0000 (14:59 +0100)
Change-Id: Iee314c28e9f65e5bcac542b390df0d8b05ed2e31
Issue-ID: SO-2867
Signed-off-by: waqas.ikram <waqas.ikram@est.tech>
so-etsi-nfvo/pom.xml
so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/pom.xml
so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NfvoJob.java
so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NfvoJobStatus.java
so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NfvoNfInst.java
so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NfvoNsInst.java
so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NsLcmOpOcc.java
so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/utils/Utils.java
so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/service/DatabaseServiceProvider.java
so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/database/DatabaseServiceProviderTest.java
so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/database/PojoClassesTests.java [new file with mode: 0644]

index fa85460..6845896 100644 (file)
@@ -28,6 +28,7 @@
     <jaxb-api>2.3.0</jaxb-api>
     <snakeyaml-version>0.11</snakeyaml-version>
     <hamcrest-version>2.2</hamcrest-version>
+    <equalsverifier-version>3.4.1</equalsverifier-version>
   </properties>
 
   <build>
index e043907..cf852c1 100644 (file)
       <artifactId>spring-boot-starter-test</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>nl.jqno.equalsverifier</groupId>
+      <artifactId>equalsverifier</artifactId>
+      <version>${equalsverifier-version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.onap.so</groupId>
+      <artifactId>common</artifactId>
+      <version>${project.version}</version>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 </project>
\ No newline at end of file
index 9453caa..ce2487e 100644 (file)
@@ -238,14 +238,17 @@ public class NfvoJob {
 
     @Override
     public boolean equals(final Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null || getClass() != obj.getClass())
+            return false;
         if (obj instanceof NfvoJob) {
             final NfvoJob other = (NfvoJob) obj;
             return Objects.equals(jobId, other.jobId) && Objects.equals(processInstanceId, other.processInstanceId)
                     && Objects.equals(jobType, other.jobType) && Objects.equals(jobAction, other.jobAction)
                     && Objects.equals(progress, other.progress) && Objects.equals(status, other.status)
                     && Objects.equals(startTime, other.startTime) && Objects.equals(endTime, other.endTime)
-                    && Objects.equals(status, other.status) && Objects.equals(resourceId, other.resourceId)
-                    && Objects.equals(resourceName, other.resourceName)
+                    && Objects.equals(resourceId, other.resourceId) && Objects.equals(resourceName, other.resourceName)
                     && Utils.isEquals(nfvoJobStatuses, other.nfvoJobStatuses);
         }
         return false;
index 89e0770..be673b4 100644 (file)
@@ -116,17 +116,21 @@ public class NfvoJobStatus {
 
     @Override
     public int hashCode() {
-        return Objects.hash(id, status, updatedTime, description, nfvoJob.getJobId());
+        return Objects.hash(id, status, updatedTime, description, nfvoJob != null ? nfvoJob.getJobId() : 0);
     }
 
     @Override
     public boolean equals(final Object obj) {
-
+        if (this == obj)
+            return true;
+        if (obj == null || getClass() != obj.getClass())
+            return false;
         if (obj instanceof NfvoJobStatus) {
             final NfvoJobStatus other = (NfvoJobStatus) obj;
             return Objects.equals(id, other.id) && Objects.equals(status, other.status)
                     && Objects.equals(updatedTime, other.updatedTime) && Objects.equals(description, other.description)
-                    && Objects.equals(nfvoJob.getJobId(), other.nfvoJob.getJobId());
+                    && (nfvoJob == null ? other.nfvoJob == null
+                            : other.nfvoJob != null && Objects.equals(nfvoJob.getJobId(), other.nfvoJob.getJobId()));
         }
         return false;
     }
index e901e10..e685781 100644 (file)
@@ -184,13 +184,15 @@ public class NfvoNfInst {
         final NfvoNfInst that = (NfvoNfInst) object;
         return Objects.equals(nfInstId, that.nfInstId) && Objects.equals(name, that.name)
                 && Objects.equals(vnfdId, that.vnfdId) && Objects.equals(packageId, that.packageId)
-                && Objects.equals(nsInst, that.nsInst) && Objects.equals(status, that.status)
-                && Objects.equals(createTime, that.createTime) && Objects.equals(lastUpdateTime, that.lastUpdateTime);
+                && (nsInst == null ? that.nsInst == null : that.nsInst != null && Objects.equals(nsInst, that.nsInst))
+                && Objects.equals(status, that.status) && Objects.equals(createTime, that.createTime)
+                && Objects.equals(lastUpdateTime, that.lastUpdateTime);
     }
 
     @Override
     public int hashCode() {
-        return Objects.hash(nfInstId, name, vnfdId, packageId, nsInst, status, createTime, lastUpdateTime);
+        return Objects.hash(nfInstId, name, vnfdId, packageId, nsInst != null ? nsInst.getNsInstId() : 0, status,
+                createTime, lastUpdateTime);
     }
 
     @Override
index dd8448f..146e551 100644 (file)
@@ -251,6 +251,10 @@ public class NfvoNsInst {
 
     @Override
     public boolean equals(final Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null || getClass() != obj.getClass())
+            return false;
         if (obj instanceof NfvoNsInst) {
             final NfvoNsInst other = (NfvoNsInst) obj;
             return Objects.equals(nsInstId, other.nsInstId) && Objects.equals(name, other.name)
index c47bbdb..7668ed2 100644 (file)
@@ -193,24 +193,26 @@ public class NsLcmOpOcc {
     }
 
     @Override
-    public boolean equals(final Object object) {
-        if (this == object)
+    public boolean equals(final Object obj) {
+        if (this == obj)
             return true;
-        if (object == null || getClass() != object.getClass())
+        if (obj == null || getClass() != obj.getClass())
             return false;
-        final NsLcmOpOcc that = (NsLcmOpOcc) object;
+        final NsLcmOpOcc that = (NsLcmOpOcc) obj;
         return Objects.equals(id, that.id) && Objects.equals(operationState, that.operationState)
                 && Objects.equals(stateEnteredTime, that.stateEnteredTime) && Objects.equals(startTime, that.startTime)
-                && Objects.equals(nfvoNsInst, that.nfvoNsInst) && Objects.equals(operation, that.operation)
-                && Objects.equals(isAutoInnovation, that.isAutoInnovation)
+                && (nfvoNsInst == null ? that.nfvoNsInst == null
+                        : that.nfvoNsInst != null && Objects.equals(nfvoNsInst, that.nfvoNsInst))
+                && Objects.equals(operation, that.operation) && Objects.equals(isAutoInnovation, that.isAutoInnovation)
                 && Objects.equals(operationParams, that.operationParams)
                 && Objects.equals(isCancelPending, that.isCancelPending);
     }
 
     @Override
     public int hashCode() {
-        return Objects.hash(id, operationState, stateEnteredTime, startTime, nfvoNsInst, operation, isAutoInnovation,
-                operationParams, isCancelPending);
+        return Objects.hash(id, operationState, stateEnteredTime, startTime,
+                nfvoNsInst != null ? nfvoNsInst.getNsInstId() : 0, operation, isAutoInnovation, operationParams,
+                isCancelPending);
     }
 
     @Override
index c55ef57..b84f95a 100644 (file)
@@ -39,10 +39,11 @@ public class Utils {
         if (first == null) {
             return second == null;
         }
+
         if (first.isEmpty()) {
             return second.isEmpty();
         }
-        if (first.size() == second.size()) {
+        if ((first != null && second != null) && (first.size() == second.size())) {
             for (int index = 0; index < first.size(); index++) {
                 if (!Objects.equals(first.get(index), second.get(index))) {
                     return false;
index 8a2a1bd..1487b63 100644 (file)
@@ -120,11 +120,6 @@ public class DatabaseServiceProvider {
         return nfvoNfInstRepository.save(nfvoNfInst) != null;
     }
 
-    public Optional<NfvoNfInst> getNfvoNfInstByNfInstId(final String nfInstId) {
-        logger.info("Querying database for NfvoNfInst using nfInstId: {}", nfInstId);
-        return nfvoNfInstRepository.findByNfInstId(nfInstId);
-    }
-
     public List<NfvoNfInst> getNfvoNfInstByNsInstId(final String nsInstId) {
         logger.info("Querying database for NfvoNfInst using nsInstId: {}", nsInstId);
         return nfvoNfInstRepository.findByNsInstNsInstId(nsInstId);
index 8108749..8070036 100644 (file)
@@ -133,7 +133,7 @@ public class DatabaseServiceProviderTest {
                 .status(State.NOT_INSTANTIATED).createTime(CURRENT_DATE_TIME).lastUpdateTime(CURRENT_DATE_TIME);
         databaseServiceProvider.saveNfvoNfInst(nfInst);
 
-        final Optional<NfvoNfInst> actual = databaseServiceProvider.getNfvoNfInstByNfInstId(nfInst.getNfInstId());
+        final Optional<NfvoNfInst> actual = databaseServiceProvider.getNfvoNfInst(nfInst.getNfInstId());
         final NfvoNfInst actualNfvoNfInst = actual.get();
         assertEquals(nsInst.getNsInstId(), actualNfvoNfInst.getNsInst().getNsInstId());
         assertEquals(nfInst.getNfInstId(), actualNfvoNfInst.getNfInstId());
diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/database/PojoClassesTests.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/database/PojoClassesTests.java
new file mode 100644 (file)
index 0000000..5f033a2
--- /dev/null
@@ -0,0 +1,93 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.etsi.nfvo.ns.lcm.database;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import org.junit.Test;
+import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoJob;
+import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoJobStatus;
+import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNfInst;
+import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNsInst;
+import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NsLcmOpOcc;
+import org.onap.so.openpojo.rules.ToStringTester;
+import com.openpojo.reflection.filters.FilterPackageInfo;
+import com.openpojo.validation.Validator;
+import com.openpojo.validation.ValidatorBuilder;
+import com.openpojo.validation.test.impl.GetterTester;
+import com.openpojo.validation.test.impl.SetterTester;
+import nl.jqno.equalsverifier.EqualsVerifier;
+import nl.jqno.equalsverifier.Warning;
+
+/**
+ * @author Waqas Ikram (waqas.ikram@est.tech)
+ */
+public class PojoClassesTests {
+
+    @Test
+    public void test_database_beans() throws ClassNotFoundException {
+
+        final Validator validator = ValidatorBuilder.create().with(new SetterTester()).with(new GetterTester())
+                .with(new ToStringTester()).build();
+        validator.validate(NfvoNsInst.class.getPackageName(), new FilterPackageInfo());
+    }
+
+    @Test
+    public void test_database_nfvoJob_equalAndHashMethod() throws ClassNotFoundException {
+        EqualsVerifier.forClass(NfvoJob.class)
+                .suppress(Warning.STRICT_INHERITANCE, Warning.NONFINAL_FIELDS, Warning.INHERITED_DIRECTLY_FROM_OBJECT)
+                .withPrefabValues(NfvoJobStatus.class, new NfvoJobStatus().nfvoJob(new NfvoJob()),
+                        new NfvoJobStatus().nfvoJob(new NfvoJob()))
+                .withIgnoredAnnotations(Entity.class, Id.class).verify();
+    }
+
+    @Test
+    public void test_database_nfvoJobStatus_equalAndHashMethod() throws ClassNotFoundException {
+        EqualsVerifier.forClass(NfvoJobStatus.class)
+                .suppress(Warning.STRICT_INHERITANCE, Warning.NONFINAL_FIELDS, Warning.INHERITED_DIRECTLY_FROM_OBJECT)
+                .withPrefabValues(NfvoJob.class, new NfvoJob(), new NfvoJob())
+                .withIgnoredAnnotations(Entity.class, Id.class).verify();
+    }
+
+    @Test
+    public void test_database_nfvoNsInst_equalAndHashMethod() throws ClassNotFoundException {
+        EqualsVerifier.forClass(NfvoNsInst.class)
+                .suppress(Warning.STRICT_INHERITANCE, Warning.NONFINAL_FIELDS, Warning.INHERITED_DIRECTLY_FROM_OBJECT)
+                .withPrefabValues(NfvoNfInst.class, new NfvoNfInst(), new NfvoNfInst())
+                .withPrefabValues(NsLcmOpOcc.class, new NsLcmOpOcc(), new NsLcmOpOcc())
+                .withIgnoredAnnotations(Entity.class, Id.class).verify();
+    }
+
+    @Test
+    public void test_database_nfvoNfInst_equalAndHashMethod() throws ClassNotFoundException {
+        EqualsVerifier.forClass(NfvoNfInst.class)
+                .suppress(Warning.STRICT_INHERITANCE, Warning.NONFINAL_FIELDS, Warning.INHERITED_DIRECTLY_FROM_OBJECT)
+                .withPrefabValues(NfvoNsInst.class, new NfvoNsInst(), new NfvoNsInst())
+                .withIgnoredAnnotations(Entity.class, Id.class).verify();
+    }
+
+    @Test
+    public void test_database_nsLcmOpOcc_equalAndHashMethod() throws ClassNotFoundException {
+        EqualsVerifier.forClass(NsLcmOpOcc.class)
+                .suppress(Warning.STRICT_INHERITANCE, Warning.NONFINAL_FIELDS, Warning.INHERITED_DIRECTLY_FROM_OBJECT)
+                .withPrefabValues(NfvoNsInst.class, new NfvoNsInst(), new NfvoNsInst())
+                .withIgnoredAnnotations(Entity.class, Id.class).verify();
+    }
+}