diff options
author | waqas.ikram <waqas.ikram@est.tech> | 2020-10-02 13:21:17 +0100 |
---|---|---|
committer | waqas.ikram <waqas.ikram@est.tech> | 2020-10-02 14:59:52 +0100 |
commit | 1ae0b7fb1fd12587f24b19cabfcfc93e2204204e (patch) | |
tree | 9061f59e03d07d9f0c4e4e6730c4394479273bc4 | |
parent | 23312bd92a1bc9a64b26602a2798c05005187d0f (diff) |
Increasing code coverage ns-lcm-database-service
Change-Id: Iee314c28e9f65e5bcac542b390df0d8b05ed2e31
Issue-ID: SO-2867
Signed-off-by: waqas.ikram <waqas.ikram@est.tech>
11 files changed, 140 insertions, 23 deletions
diff --git a/so-etsi-nfvo/pom.xml b/so-etsi-nfvo/pom.xml index fa85460086..6845896fc0 100644 --- a/so-etsi-nfvo/pom.xml +++ b/so-etsi-nfvo/pom.xml @@ -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> diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/pom.xml b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/pom.xml index e0439073bb..cf852c14b0 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/pom.xml +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/pom.xml @@ -31,5 +31,17 @@ <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 diff --git a/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 b/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 index 9453caac9e..ce2487ea9d 100644 --- a/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 +++ b/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 @@ -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; diff --git a/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 b/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 index 89e07701ed..be673b47fa 100644 --- a/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 +++ b/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 @@ -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; } diff --git a/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 b/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 index e901e10596..e685781308 100644 --- a/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 +++ b/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 @@ -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 diff --git a/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 b/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 index dd8448fe56..146e5512fc 100644 --- a/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 +++ b/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 @@ -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) diff --git a/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 b/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 index c47bbdbefb..7668ed272d 100644 --- a/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 +++ b/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 @@ -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 diff --git a/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 b/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 index c55ef5728e..b84f95aa50 100644 --- a/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 +++ b/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 @@ -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; diff --git a/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 b/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 index 8a2a1bdd89..1487b630c7 100644 --- a/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 +++ b/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 @@ -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); 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/DatabaseServiceProviderTest.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/DatabaseServiceProviderTest.java index 8108749d48..8070036791 100644 --- 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/DatabaseServiceProviderTest.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/DatabaseServiceProviderTest.java @@ -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 index 0000000000..5f033a2438 --- /dev/null +++ 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 @@ -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(); + } +} |