From bd1e21e8e0aa2f04527be97506588597f7577314 Mon Sep 17 00:00:00 2001 From: Tal Gitelman Date: Wed, 23 May 2018 18:54:31 +0300 Subject: new unit tests for sdc-be Change-Id: I00e47a2209aca116ee47ce4d20994086a292746b Issue-ID: SDC-1333 Signed-off-by: Tal Gitelman --- .../sdc/common/transaction/impl/ESActionTest.java | 29 +++++++ .../transaction/impl/ESRollbackHandlerTest.java | 98 ++++++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 catalog-be/src/test/java/org/openecomp/sdc/common/transaction/impl/ESActionTest.java create mode 100644 catalog-be/src/test/java/org/openecomp/sdc/common/transaction/impl/ESRollbackHandlerTest.java (limited to 'catalog-be/src/test/java/org/openecomp') diff --git a/catalog-be/src/test/java/org/openecomp/sdc/common/transaction/impl/ESActionTest.java b/catalog-be/src/test/java/org/openecomp/sdc/common/transaction/impl/ESActionTest.java new file mode 100644 index 0000000000..e01879226f --- /dev/null +++ b/catalog-be/src/test/java/org/openecomp/sdc/common/transaction/impl/ESActionTest.java @@ -0,0 +1,29 @@ +package org.openecomp.sdc.common.transaction.impl; + +import org.junit.Test; +import org.openecomp.sdc.be.dao.impl.ESCatalogDAO; +import org.openecomp.sdc.be.resources.data.ESArtifactData; +import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBActionCodeEnum; +import org.openecomp.sdc.common.transaction.api.TransactionUtils.ESActionTypeEnum; +import org.openecomp.sdc.exception.IndexingServiceException; + +public class ESActionTest { + + @Test + public void testDoAction() throws Exception { + ESAction testSubject = new ESAction(new ESCatalogDAO(), new ESArtifactData(), ESActionTypeEnum.ADD_ARTIFACT);; + DBActionCodeEnum result; + + // default test + result = testSubject.doAction(); + } + + @Test(expected = IndexingServiceException.class) + public void testDoAction1() throws Exception { + ESAction testSubject = new ESAction(new ESCatalogDAO(), new ESArtifactData(), ESActionTypeEnum.REMOVE_ARTIFACT);; + DBActionCodeEnum result; + + // default test + result = testSubject.doAction(); + } +} \ No newline at end of file diff --git a/catalog-be/src/test/java/org/openecomp/sdc/common/transaction/impl/ESRollbackHandlerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/common/transaction/impl/ESRollbackHandlerTest.java new file mode 100644 index 0000000000..1c31949c1a --- /dev/null +++ b/catalog-be/src/test/java/org/openecomp/sdc/common/transaction/impl/ESRollbackHandlerTest.java @@ -0,0 +1,98 @@ +package org.openecomp.sdc.common.transaction.impl; + +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.api.ResourceUploadStatus; +import org.openecomp.sdc.be.dao.impl.ESCatalogDAO; +import org.openecomp.sdc.be.resources.data.ESArtifactData; +import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBActionCodeEnum; +import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBTypeEnum; +import org.openecomp.sdc.common.transaction.api.TransactionUtils.ESActionTypeEnum; +import org.openecomp.sdc.common.util.MethodActivationStatusEnum; + +import fj.data.Either; +import mockit.Deencapsulation; + +public class ESRollbackHandlerTest { + + @InjectMocks + ESRollbackHandler testSubject; + @Mock + ESCatalogDAO esCatalogDao; + + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + } + + private ESRollbackHandler createTestSubject() { + return new ESRollbackHandler(null, "", ""); + } + + @Test + public void testGetDBType() throws Exception { + DBTypeEnum result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getDBType(); + } + + @Test + public void testIsRollbackForPersistenceData() throws Exception { + boolean result; + + // default test + testSubject = createTestSubject(); + result = Deencapsulation.invoke(testSubject, "isRollbackForPersistenceData"); + } + + @Test + public void testIsRollbackResultValid() throws Exception { + boolean result; + + // default test + testSubject = createTestSubject(); + result = testSubject.isRollbackResultValid(DBActionCodeEnum.FAIL_GENERAL); + result = testSubject.isRollbackResultValid(DBActionCodeEnum.SUCCESS); + } + + @Test + public void testBuildEsRollbackAction() throws Exception { + ESArtifactData artifactData = new ESArtifactData(); + artifactData.setId("mock"); + Either result; + + Either value = Either.left(new ESArtifactData()); + Mockito.when(esCatalogDao.getArtifact(Mockito.anyString())).thenReturn(value); + + // default test + for (ESActionTypeEnum iterable_element : ESActionTypeEnum.values()) { + testSubject = createTestSubject(); + result = testSubject.buildEsRollbackAction(esCatalogDao, artifactData, iterable_element); + } + result = testSubject.buildEsRollbackAction(esCatalogDao, null, ESActionTypeEnum.ADD_ARTIFACT); + } + + @Test + public void testBuildEsRollbackAction2() throws Exception { + ESArtifactData artifactData = new ESArtifactData(); + artifactData.setId("mock"); + Either result; + + Either value = Either.right(ResourceUploadStatus.NOT_EXIST); + Mockito.when(esCatalogDao.getArtifact(Mockito.anyString())).thenReturn(value); + + // default test + for (ESActionTypeEnum iterable_element : ESActionTypeEnum.values()) { + testSubject = createTestSubject(); + result = testSubject.buildEsRollbackAction(esCatalogDao, artifactData, iterable_element); + } + result = testSubject.buildEsRollbackAction(esCatalogDao, null, ESActionTypeEnum.ADD_ARTIFACT); + } +} \ No newline at end of file -- cgit 1.2.3-korg