From a7bd374357e0737e419d196a16ff09a644417f97 Mon Sep 17 00:00:00 2001 From: Chris André Date: Thu, 30 Apr 2020 15:41:41 -0400 Subject: Refactor to remove false positives from Sonar - change `updateResourceInstancesNames` to account for case where `preparedResource` is null - change `findInputByName` to return an Either in order to make exceptions explicit - create `rollbackWithEither` (+ tests) to make exceptions more explicit Issue-ID: SDC-2992 Signed-off-by: Chris Andre Change-Id: I487994a3f9e88b0a2b14d2679c3587d85d8aa12d --- .../components/impl/ResourceBusinessLogicTest.java | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'catalog-be/src/test/java/org') diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java index c19d997d73..4d773a54da 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java @@ -59,6 +59,7 @@ import org.openecomp.sdc.be.components.csar.CsarArtifactsAndGroupsBusinessLogic; import org.openecomp.sdc.be.components.csar.CsarBusinessLogic; import org.openecomp.sdc.be.components.csar.CsarInfo; import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationEnum; +import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; import org.openecomp.sdc.be.components.impl.generic.GenericTypeBusinessLogic; import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic; @@ -2221,5 +2222,29 @@ public class ResourceBusinessLogicTest { Assert.assertEquals(true,res.isLeft()); } + @Test + public void rollbackWithEitherAlwaysReturnARuntimeException() { + JanusGraphDao janusGraphDao = mockJanusGraphDao; + ActionStatus actionStatus = ActionStatus.INPUTS_NOT_FOUND; + String params = "testName"; + + Either result = + ResourceBusinessLogic.rollbackWithEither(janusGraphDao, actionStatus, params); + + assertTrue(result.isRight()); + assertTrue(result.right().value() instanceof ByActionStatusComponentException); + } + @Test + public void rollbackWithEitherWorksWithNullJanusGraphDao() { + JanusGraphDao janusGraphDao = null; + ActionStatus actionStatus = ActionStatus.INPUTS_NOT_FOUND; + String params = "testName"; + + Either result = + ResourceBusinessLogic.rollbackWithEither(janusGraphDao, actionStatus, params); + + assertTrue(result.isRight()); + assertTrue(result.right().value() instanceof ByActionStatusComponentException); + } } -- cgit 1.2.3-korg