diff options
author | Annick Boghossian <Annick.Boghossian@team.telstra.com> | 2019-12-09 15:48:38 +1100 |
---|---|---|
committer | Ofir Sonsino <ofir.sonsino@intl.att.com> | 2019-12-18 11:27:39 +0000 |
commit | 0ce779a2e1d9272ea3a0680b51ac032d6da8098a (patch) | |
tree | e66a6109dc26f33c2f45cbb775c624022127e088 /catalog-be/src/test | |
parent | 8acb01dfb8a8fb2f6f77f154382933283b269566 (diff) |
Increased code coverage using junits
Issue-ID: SDC-2699
Change-Id: Ifb0b9616a0218028b06755d6ef7150d54a82ecbb
Signed-off-by: Atif Husain <atif.husain@team.telstra.com>
Diffstat (limited to 'catalog-be/src/test')
5 files changed, 323 insertions, 54 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/externalapi/AuditActivateServiceExternalApiEventFactoryTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/externalapi/AuditActivateServiceExternalApiEventFactoryTest.java index e2598f1499..e6aaec97ae 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/externalapi/AuditActivateServiceExternalApiEventFactoryTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/externalapi/AuditActivateServiceExternalApiEventFactoryTest.java @@ -20,31 +20,110 @@ package org.openecomp.sdc.be.auditing.impl.externalapi; +import org.junit.Before; import org.junit.Test; -import org.openecomp.sdc.be.model.User; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.*; + +import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.openecomp.sdc.be.auditing.api.AuditEventFactory; +import org.openecomp.sdc.be.auditing.impl.AuditingManager; +import org.openecomp.sdc.be.config.Configuration; +import org.openecomp.sdc.be.dao.api.ActionStatus; +import org.openecomp.sdc.be.dao.cassandra.AuditCassandraDao; +import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus; +import org.openecomp.sdc.be.dao.impl.AuditingDao; +import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum; +import org.openecomp.sdc.be.resources.data.auditing.AuditingGenericEvent; +import org.openecomp.sdc.be.resources.data.auditing.ExternalApiEvent; import org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData; -import org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData.Builder; import org.openecomp.sdc.be.resources.data.auditing.model.DistributionData; import org.openecomp.sdc.be.resources.data.auditing.model.ResourceCommonInfo; -import org.openecomp.sdc.be.resources.data.auditing.model.ResourceVersionInfo; - +import org.openecomp.sdc.test.utils.TestConfigurationProvider; +@RunWith(MockitoJUnitRunner.class) public class AuditActivateServiceExternalApiEventFactoryTest { private AuditActivateServiceExternalApiEventFactory createTestSubject() { - Builder newBuilder = CommonAuditData.newBuilder(); + CommonAuditData.Builder newBuilder = CommonAuditData.newBuilder() + .description(DESCRIPTION) + .status(STATUS_OK) + .requestId(REQUEST_ID) + .serviceInstanceId(SERVICE_INSTANCE_ID); CommonAuditData commonAuData = newBuilder.build(); - ResourceVersionInfo.Builder newBuilder2 = ResourceVersionInfo.newBuilder(); - return new AuditActivateServiceExternalApiEventFactory(commonAuData,new ResourceCommonInfo(),new DistributionData("",""),"", new User()); + return new AuditActivateServiceExternalApiEventFactory(commonAuData, + new ResourceCommonInfo(RESOURCE_TYPE), + new DistributionData(DIST_CONSUMER_ID,DIST_RESOURCE_URL),INVARIANT_UUID, + modifier); + } + + private AuditingManager auditingManager; + + @Mock + private static AuditCassandraDao cassandraDao; + @Mock + private static AuditingDao auditingDao; + @Mock + private static Configuration.ElasticSearchConfig esConfig; + + @Captor + private ArgumentCaptor<ExternalApiEvent> eventCaptor; + + @Before + public void setUp() { + init(esConfig); + auditingManager = new AuditingManager(auditingDao, cassandraDao, new TestConfigurationProvider()); } @Test public void testGetLogMessage() throws Exception { AuditActivateServiceExternalApiEventFactory testSubject; - String result; // default test testSubject = createTestSubject(); - result = testSubject.getLogMessage(); + testSubject.getLogMessage(); + assertThat(testSubject.getLogMessage()).isNotBlank(); + assertThat(testSubject.getLogMessage()).isEqualTo(EXPECTED_ACTIVATE_SERVICE_API_LOG_STR); + } + + @Test + public void testActivateServiceEvent() { + AuditEventFactory builder = new AuditActivateServiceExternalApiEventFactory( + CommonAuditData.newBuilder() + .description(DESCRIPTION) + .status(STATUS_OK) + .requestId(REQUEST_ID) + .serviceInstanceId(SERVICE_INSTANCE_ID) + .build(), + new ResourceCommonInfo(RESOURCE_NAME, RESOURCE_TYPE), + new DistributionData(DIST_CONSUMER_ID, DIST_RESOURCE_URL), + INVARIANT_UUID, modifier); + + when(auditingDao.addRecord(any(AuditingGenericEvent.class), eq(AuditingActionEnum.ACTIVATE_SERVICE_BY_API.getAuditingEsType()))) + .thenReturn(ActionStatus.OK); + when(cassandraDao.saveRecord(any(AuditingGenericEvent.class))).thenReturn(CassandraOperationStatus.OK); + + assertThat(auditingManager.auditEvent(builder)).isEqualTo(EXPECTED_ACTIVATE_SERVICE_API_LOG_STR); + verifyExternalApiEvent(AuditingActionEnum.ACTIVATE_SERVICE_BY_API.getName()); + + } + + private void verifyExternalApiEvent(String action) { + verify(cassandraDao).saveRecord(eventCaptor.capture()); + ExternalApiEvent storedEvent = eventCaptor.getValue(); + assertThat(storedEvent.getModifier()).isEqualTo(MODIFIER_UID); + assertThat(storedEvent.getDesc()).isEqualTo(DESCRIPTION); + assertThat(storedEvent.getStatus()).isEqualTo(STATUS_OK); + assertThat(storedEvent.getServiceInstanceId()).isEqualTo(SERVICE_INSTANCE_ID); + assertThat(storedEvent.getAction()).isEqualTo(action); + assertThat(storedEvent.getResourceType()).isEqualTo(RESOURCE_TYPE); } } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/externalapi/AuditChangeLifecycleExternalApiEventFactoryTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/externalapi/AuditChangeLifecycleExternalApiEventFactoryTest.java index ce9645f31f..04fa768fb0 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/externalapi/AuditChangeLifecycleExternalApiEventFactoryTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/externalapi/AuditChangeLifecycleExternalApiEventFactoryTest.java @@ -20,32 +20,131 @@ package org.openecomp.sdc.be.auditing.impl.externalapi; +import org.junit.Before; import org.junit.Test; -import org.openecomp.sdc.be.model.User; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.*; + +import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.openecomp.sdc.be.auditing.api.AuditEventFactory; +import org.openecomp.sdc.be.auditing.impl.AuditingManager; +import org.openecomp.sdc.be.config.Configuration; +import org.openecomp.sdc.be.dao.api.ActionStatus; +import org.openecomp.sdc.be.dao.cassandra.AuditCassandraDao; +import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus; +import org.openecomp.sdc.be.dao.impl.AuditingDao; +import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum; +import org.openecomp.sdc.be.resources.data.auditing.AuditingGenericEvent; +import org.openecomp.sdc.be.resources.data.auditing.ExternalApiEvent; import org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData; import org.openecomp.sdc.be.resources.data.auditing.model.DistributionData; import org.openecomp.sdc.be.resources.data.auditing.model.ResourceCommonInfo; import org.openecomp.sdc.be.resources.data.auditing.model.ResourceVersionInfo; +import org.openecomp.sdc.test.utils.TestConfigurationProvider; - +@RunWith(MockitoJUnitRunner.class) public class AuditChangeLifecycleExternalApiEventFactoryTest { private AuditChangeLifecycleExternalApiEventFactory createTestSubject() { - org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData.Builder newBuilder = CommonAuditData.newBuilder(); + CommonAuditData.Builder newBuilder = CommonAuditData.newBuilder() + .description(DESCRIPTION) + .status(STATUS_OK) + .requestId(REQUEST_ID) + .serviceInstanceId(SERVICE_INSTANCE_ID); CommonAuditData commonAuData = newBuilder.build(); - ResourceVersionInfo.Builder newBuilder2 = ResourceVersionInfo.newBuilder(); - ResourceVersionInfo resAuData = newBuilder2.build(); - return new AuditChangeLifecycleExternalApiEventFactory(commonAuData,new ResourceCommonInfo(), new DistributionData("",""), - resAuData, resAuData, "", new User()); + ResourceVersionInfo.Builder newBuilder2 = ResourceVersionInfo.newBuilder() + .artifactUuid(ARTIFACT_UUID) + .state(PREV_RESOURCE_STATE) + .version(PREV_RESOURCE_VERSION); + ResourceVersionInfo resAuData1 = newBuilder2.build(); + ResourceVersionInfo.Builder newBuilder3 = ResourceVersionInfo.newBuilder() + .artifactUuid(ARTIFACT_UUID) + .state(CURRENT_STATE) + .version(CURRENT_VERSION); + ResourceVersionInfo resAuData2 = newBuilder3.build(); + return new AuditChangeLifecycleExternalApiEventFactory(commonAuData, + new ResourceCommonInfo(RESOURCE_NAME, RESOURCE_TYPE), + new DistributionData(DIST_CONSUMER_ID,DIST_RESOURCE_URL), + resAuData1, + resAuData2, + INVARIANT_UUID, + modifier); + } + + private AuditingManager auditingManager; + @Mock + private static AuditCassandraDao cassandraDao; + @Mock + private static AuditingDao auditingDao; + @Mock + private static Configuration.ElasticSearchConfig esConfig; + + @Captor + private ArgumentCaptor<ExternalApiEvent> eventCaptor; + + @Before + public void setUp() { + init(esConfig); + auditingManager = new AuditingManager(auditingDao, cassandraDao, new TestConfigurationProvider()); } @Test public void testGetLogMessage() throws Exception { AuditChangeLifecycleExternalApiEventFactory testSubject; - String result; // default test testSubject = createTestSubject(); - result = testSubject.getLogMessage(); + assertThat(testSubject.getLogMessage()).isNotBlank(); + assertThat(testSubject.getLogMessage()).isEqualTo(EXPECTED_CHANGE_LIFECYCLE_EXTERNAL_API_LOG_STR); + } + + @Test + public void testChangeLifecycleEvent() { + AuditEventFactory factory = new AuditChangeLifecycleExternalApiEventFactory( + CommonAuditData.newBuilder() + .description(DESCRIPTION) + .status(STATUS_OK) + .requestId(REQUEST_ID) + .serviceInstanceId(SERVICE_INSTANCE_ID) + .build(), + new ResourceCommonInfo(RESOURCE_NAME, RESOURCE_TYPE), + new DistributionData(DIST_CONSUMER_ID, DIST_RESOURCE_URL), + ResourceVersionInfo.newBuilder() + .artifactUuid(ARTIFACT_UUID) + .state(PREV_RESOURCE_STATE) + .version(PREV_RESOURCE_VERSION) + .build(), + ResourceVersionInfo.newBuilder() + .artifactUuid(ARTIFACT_UUID) + .state(CURRENT_STATE) + .version(CURRENT_VERSION) + .build(), + INVARIANT_UUID, modifier); + + when(auditingDao.addRecord(any(AuditingGenericEvent.class), eq(AuditingActionEnum.CHANGE_LIFECYCLE_BY_API.getAuditingEsType()))) + .thenReturn(ActionStatus.OK); + when(cassandraDao.saveRecord(any(AuditingGenericEvent.class))).thenReturn(CassandraOperationStatus.OK); + + assertThat(auditingManager.auditEvent(factory)).isEqualTo(EXPECTED_CHANGE_LIFECYCLE_EXTERNAL_API_LOG_STR); + verifyExternalApiEvent(AuditingActionEnum.CHANGE_LIFECYCLE_BY_API.getName()); + } + + private void verifyExternalApiEvent(String action) { + verify(cassandraDao).saveRecord(eventCaptor.capture()); + ExternalApiEvent storedEvent = eventCaptor.getValue(); + assertThat(storedEvent.getModifier()).isEqualTo(MODIFIER_UID); + assertThat(storedEvent.getDesc()).isEqualTo(DESCRIPTION); + assertThat(storedEvent.getStatus()).isEqualTo(STATUS_OK); + assertThat(storedEvent.getServiceInstanceId()).isEqualTo(SERVICE_INSTANCE_ID); + assertThat(storedEvent.getAction()).isEqualTo(action); + assertThat(storedEvent.getResourceType()).isEqualTo(RESOURCE_TYPE); } } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/externalapi/AuditCreateResourceExternalApiEventFactoryTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/externalapi/AuditCreateResourceExternalApiEventFactoryTest.java index d04ba231d8..06f91c561d 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/externalapi/AuditCreateResourceExternalApiEventFactoryTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/externalapi/AuditCreateResourceExternalApiEventFactoryTest.java @@ -20,30 +20,121 @@ package org.openecomp.sdc.be.auditing.impl.externalapi; +import org.junit.Before; import org.junit.Test; -import org.openecomp.sdc.be.model.User; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.*; + +import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.openecomp.sdc.be.auditing.api.AuditEventFactory; +import org.openecomp.sdc.be.auditing.impl.AuditingManager; +import org.openecomp.sdc.be.config.Configuration; +import org.openecomp.sdc.be.dao.api.ActionStatus; +import org.openecomp.sdc.be.dao.cassandra.AuditCassandraDao; +import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus; +import org.openecomp.sdc.be.dao.impl.AuditingDao; +import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum; +import org.openecomp.sdc.be.resources.data.auditing.AuditingGenericEvent; +import org.openecomp.sdc.be.resources.data.auditing.ExternalApiEvent; import org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData; import org.openecomp.sdc.be.resources.data.auditing.model.DistributionData; import org.openecomp.sdc.be.resources.data.auditing.model.ResourceCommonInfo; import org.openecomp.sdc.be.resources.data.auditing.model.ResourceVersionInfo; +import org.openecomp.sdc.test.utils.TestConfigurationProvider; +@RunWith(MockitoJUnitRunner.class) public class AuditCreateResourceExternalApiEventFactoryTest { private AuditCreateResourceExternalApiEventFactory createTestSubject() { - CommonAuditData.Builder newBuilder = CommonAuditData.newBuilder(); + CommonAuditData.Builder newBuilder = CommonAuditData.newBuilder() + .description(DESCRIPTION) + .status(STATUS_OK) + .requestId(REQUEST_ID) + .serviceInstanceId(SERVICE_INSTANCE_ID); CommonAuditData commonAuData = newBuilder.build(); - ResourceVersionInfo.Builder newBuilder2 = ResourceVersionInfo.newBuilder(); + ResourceVersionInfo.Builder newBuilder2 = ResourceVersionInfo.newBuilder() + .version(CURRENT_VERSION) + .state(CURRENT_STATE) + .artifactUuid(ARTIFACT_UUID); ResourceVersionInfo resAuData = newBuilder2.build(); - return new AuditCreateResourceExternalApiEventFactory(commonAuData,new ResourceCommonInfo(),new DistributionData("",""),resAuData,"", new User()); + return new AuditCreateResourceExternalApiEventFactory(commonAuData, + new ResourceCommonInfo(RESOURCE_NAME,RESOURCE_TYPE), + new DistributionData(DIST_CONSUMER_ID,DIST_RESOURCE_URL), + resAuData, + INVARIANT_UUID, + modifier); } + private AuditingManager auditingManager; + @Mock + private static AuditCassandraDao cassandraDao; + @Mock + private static AuditingDao auditingDao; + @Mock + private static Configuration.ElasticSearchConfig esConfig; + + @Captor + private ArgumentCaptor<ExternalApiEvent> eventCaptor; + + @Before + public void setUp() { + init(esConfig); + auditingManager = new AuditingManager(auditingDao, cassandraDao, new TestConfigurationProvider()); + } + + @Test public void testGetLogMessage() throws Exception { AuditCreateResourceExternalApiEventFactory testSubject; - String result; // default test testSubject = createTestSubject(); - result = testSubject.getLogMessage(); + assertThat(testSubject.getLogMessage()).isNotBlank(); + assertThat(testSubject.getLogMessage()).isEqualTo(EXPECTED_EXTERNAL_CREATE_RESOURCE_LOG_STR); + } + + @Test + public void testCreateResourceEvent() { + AuditEventFactory factory = new AuditCreateResourceExternalApiEventFactory( + CommonAuditData.newBuilder() + .description(DESCRIPTION) + .status(STATUS_OK) + .requestId(REQUEST_ID) + .serviceInstanceId(SERVICE_INSTANCE_ID) + .build(), + new ResourceCommonInfo(RESOURCE_NAME, RESOURCE_TYPE), + new DistributionData(DIST_CONSUMER_ID, DIST_RESOURCE_URL), + ResourceVersionInfo.newBuilder() + .artifactUuid(ARTIFACT_UUID) + .state(CURRENT_STATE) + .version(CURRENT_VERSION) + .build(), + INVARIANT_UUID, modifier); + + when(auditingDao.addRecord(any(AuditingGenericEvent.class), eq(AuditingActionEnum.CREATE_RESOURCE_BY_API.getAuditingEsType()))) + .thenReturn(ActionStatus.OK); + when(cassandraDao.saveRecord(any(AuditingGenericEvent.class))).thenReturn(CassandraOperationStatus.OK); + + assertThat(auditingManager.auditEvent(factory)).isEqualTo(EXPECTED_EXTERNAL_CREATE_RESOURCE_LOG_STR); + verifyExternalApiEvent(AuditingActionEnum.CREATE_RESOURCE_BY_API.getName()); + } + + private void verifyExternalApiEvent(String action) { + verify(cassandraDao).saveRecord(eventCaptor.capture()); + ExternalApiEvent storedEvent = eventCaptor.getValue(); + assertThat(storedEvent.getModifier()).isEqualTo(MODIFIER_UID); + assertThat(storedEvent.getDesc()).isEqualTo(DESCRIPTION); + assertThat(storedEvent.getStatus()).isEqualTo(STATUS_OK); + assertThat(storedEvent.getServiceInstanceId()).isEqualTo(SERVICE_INSTANCE_ID); + assertThat(storedEvent.getAction()).isEqualTo(action); + assertThat(storedEvent.getResourceType()).isEqualTo(RESOURCE_TYPE); } } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/common/transaction/mngr/SdncTransactionTest.java b/catalog-be/src/test/java/org/openecomp/sdc/common/transaction/mngr/SdncTransactionTest.java index 091e15661c..f902f520a6 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/common/transaction/mngr/SdncTransactionTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/common/transaction/mngr/SdncTransactionTest.java @@ -85,7 +85,7 @@ public class SdncTransactionTest { janusGraphGenericDao); doBasicJanusGraphAction(transactionId, tx, false, true); - assertSame(tx.getStatus(), TransactionStatusEnum.OPEN); + assertSame(TransactionStatusEnum.OPEN, tx.getStatus()); } @Test @@ -95,7 +95,7 @@ public class SdncTransactionTest { janusGraphGenericDao); doESAddArtifactAction(transactionId, tx, true, true); - assertSame(tx.getStatus(), TransactionStatusEnum.OPEN); + assertSame(TransactionStatusEnum.OPEN, tx.getStatus()); } @Test @@ -104,7 +104,7 @@ public class SdncTransactionTest { TransactionSdncImpl tx = new TransactionSdncImpl(transactionId, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT, esCatalogDao, janusGraphGenericDao); doFinishTransaction(transactionId, tx, true); - assertSame(tx.getStatus(), TransactionStatusEnum.CLOSED); + assertSame(TransactionStatusEnum.CLOSED, tx.getStatus()); } @Test @@ -115,9 +115,9 @@ public class SdncTransactionTest { doFinishTransaction(transactionId, tx, true); TransactionCodeEnum finishTransaction = tx.finishTransaction(); - assertSame(finishTransaction, TransactionCodeEnum.TRANSACTION_CLOSED); + assertSame(TransactionCodeEnum.TRANSACTION_CLOSED, finishTransaction); verify(log).info(TransactionUtils.TRANSACTION_MARKER, LogMessages.COMMIT_ON_CLOSED_TRANSACTION, transactionId, TransactionStatusEnum.CLOSED.name(), TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name()); - assertSame(tx.getStatus(), TransactionStatusEnum.CLOSED); + assertSame(TransactionStatusEnum.CLOSED, tx.getStatus()); } @@ -129,7 +129,7 @@ public class SdncTransactionTest { doBasicJanusGraphAction(transactionId, tx, true, true); Either<TestResponse, TransactionCodeEnum> doBasicJanusGraphAction = doBasicJanusGraphAction(transactionId, tx, true, false); assertTrue(doBasicJanusGraphAction.isRight()); - assertNotSame(tx.getStatus(), TransactionStatusEnum.OPEN); + assertNotSame(TransactionStatusEnum.OPEN, tx.getStatus()); verify(log).info(TransactionUtils.TRANSACTION_MARKER, LogMessages.DOUBLE_FINISH_FLAG_ACTION, transactionId, DBTypeEnum.JANUSGRAPH .name(), TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name()); } @@ -143,18 +143,18 @@ public class SdncTransactionTest { Either<DBActionCodeEnum, TransactionCodeEnum> eitherESResult = tx.invokeESAction(false, ESActionTypeEnum.ADD_ARTIFACT, createDummyArtifactData()); assertTrue(eitherESResult.isRight()); - assertSame(eitherESResult.right().value(), TransactionCodeEnum.TRANSACTION_CLOSED); + assertSame(TransactionCodeEnum.TRANSACTION_CLOSED, eitherESResult.right().value()); Either<Object, TransactionCodeEnum> eitherJanusGraphResult = tx.invokeJanusGraphAction(false, createBasicAction(TestAction.JanusGraphAction, TestResponse.JanusGraphResponseSuccess)); assertTrue(eitherJanusGraphResult.isRight()); - assertSame(eitherJanusGraphResult.right().value(), TransactionCodeEnum.TRANSACTION_CLOSED); + assertSame(TransactionCodeEnum.TRANSACTION_CLOSED, eitherJanusGraphResult.right().value()); Either<Object, TransactionCodeEnum> eitherGeneralDBAction = tx.invokeGeneralDBAction(true, DBTypeEnum.JANUSGRAPH, createBasicAction(TestAction.JanusGraphAction, TestResponse.JanusGraphResponseSuccess), createBasicAction(TestAction.Rollback, TestResponse.JanusGraphResponseSuccess)); assertTrue(eitherGeneralDBAction.isRight()); - assertSame(eitherGeneralDBAction.right().value(), TransactionCodeEnum.TRANSACTION_CLOSED); + assertSame(TransactionCodeEnum.TRANSACTION_CLOSED, eitherGeneralDBAction.right().value()); - assertSame(tx.getStatus(), TransactionStatusEnum.CLOSED); + assertSame(TransactionStatusEnum.CLOSED, tx.getStatus()); verify(log, times(3)).info(TransactionUtils.TRANSACTION_MARKER, LogMessages.ACTION_ON_CLOSED_TRANSACTION, transactionId, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name()); } @@ -166,14 +166,14 @@ public class SdncTransactionTest { janusGraphGenericDao); doBasicJanusGraphAction(transactionId, tx, false, true); - assertSame(tx.getStatus(), TransactionStatusEnum.OPEN); + assertSame(TransactionStatusEnum.OPEN, tx.getStatus()); doESAddArtifactAction(transactionId, tx, true, true); - assertSame(tx.getStatus(), TransactionStatusEnum.OPEN); + assertSame(TransactionStatusEnum.OPEN, tx.getStatus()); doFinishTransaction(transactionId, tx, true); - assertSame(tx.getStatus(), TransactionStatusEnum.CLOSED); + assertSame(TransactionStatusEnum.CLOSED, tx.getStatus()); } @@ -189,8 +189,8 @@ public class SdncTransactionTest { Either<TestResponse, TransactionCodeEnum> eitherTransactionResult = tx.invokeJanusGraphAction(false, createCrushingAction(TestAction.JanusGraphAction, crushMessage)); assertTrue(eitherTransactionResult.isRight()); - assertSame(eitherTransactionResult.right().value(), TransactionCodeEnum.ROLLBACK_SUCCESS); - assertSame(tx.getStatus(), TransactionStatusEnum.CLOSED); + assertSame(TransactionCodeEnum.ROLLBACK_SUCCESS, eitherTransactionResult.right().value()); + assertSame(TransactionStatusEnum.CLOSED, tx.getStatus()); verify(log).info(TransactionUtils.TRANSACTION_MARKER, LogMessages.DB_ACTION_FAILED_WITH_EXCEPTION, DBTypeEnum.JANUSGRAPH .name(), transactionId, crushMessage, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name()); @@ -219,8 +219,8 @@ public class SdncTransactionTest { Either<TestResponse, TransactionCodeEnum> eitherTransactionResult = tx.invokeJanusGraphAction(false, createCrushingAction(TestAction.JanusGraphAction, crushMessage)); assertTrue(eitherTransactionResult.isRight()); - assertSame(tx.getStatus(), TransactionStatusEnum.FAILED_ROLLBACK); - assertSame(eitherTransactionResult.right().value(), TransactionCodeEnum.ROLLBACK_FAILED); + assertSame(TransactionStatusEnum.FAILED_ROLLBACK, tx.getStatus()); + assertSame(TransactionCodeEnum.ROLLBACK_FAILED, eitherTransactionResult.right().value()); verify(log).info(TransactionUtils.TRANSACTION_MARKER, LogMessages.DB_ACTION_FAILED_WITH_EXCEPTION, DBTypeEnum.JANUSGRAPH .name(), transactionId, crushMessage, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name()); @@ -245,8 +245,8 @@ public class SdncTransactionTest { when(janusGraphGenericDao.rollback()).thenReturn(JanusGraphOperationStatus.OK); // finishTransaction TransactionCodeEnum transactionCode = tx.finishTransaction(); - assertSame(transactionCode, TransactionCodeEnum.ROLLBACK_SUCCESS); - assertSame(tx.getStatus(), TransactionStatusEnum.CLOSED); + assertSame(TransactionCodeEnum.ROLLBACK_SUCCESS, transactionCode); + assertSame(TransactionStatusEnum.CLOSED, tx.getStatus()); verify(log, times(1)).debug(LogMessages.ROLLBACK_PERSISTENT_ACTION, DBTypeEnum.ELASTIC_SEARCH.name(), transactionId, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name()); verify(log, times(1)).debug(TransactionUtils.TRANSACTION_MARKER, LogMessages.ROLLBACK_PERSISTENT_ACTION, DBTypeEnum.ELASTIC_SEARCH.name(), transactionId, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name()); @@ -274,8 +274,8 @@ public class SdncTransactionTest { Mockito.doThrow(new RuntimeException(esError)).when(esCatalogDao).deleteArtifact(Mockito.anyString()); // finishTransaction TransactionCodeEnum transactionCode = tx.finishTransaction(); - assertSame(transactionCode, TransactionCodeEnum.ROLLBACK_FAILED); - assertSame(tx.getStatus(), TransactionStatusEnum.FAILED_ROLLBACK); + assertSame(TransactionCodeEnum.ROLLBACK_FAILED, transactionCode); + assertSame(TransactionStatusEnum.FAILED_ROLLBACK, tx.getStatus()); verify(log, times(1)).debug(LogMessages.ROLLBACK_PERSISTENT_ACTION, DBTypeEnum.ELASTIC_SEARCH.name(), transactionId, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name()); verify(log, times(1)).debug(TransactionUtils.TRANSACTION_MARKER, LogMessages.ROLLBACK_PERSISTENT_ACTION, DBTypeEnum.ELASTIC_SEARCH.name(), transactionId, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name()); @@ -299,13 +299,13 @@ public class SdncTransactionTest { Either<TestResponse, TransactionCodeEnum> eitherResult = tx.invokeGeneralDBAction(false, DBTypeEnum.MYSTERY, generalAction, rollbackAction); assertTrue(eitherResult.isLeft()); - assertSame(eitherResult.left().value(), TestResponse.GeneralSuccess); - assertSame(tx.getStatus(), TransactionStatusEnum.OPEN); + assertSame(TestResponse.GeneralSuccess, eitherResult.left().value()); + assertSame(TransactionStatusEnum.OPEN, tx.getStatus()); eitherResult = tx.invokeGeneralDBAction(false, DBTypeEnum.MYSTERY, crushingAction, rollbackAction); assertTrue(eitherResult.isRight()); - assertSame(eitherResult.right().value(), TransactionCodeEnum.ROLLBACK_SUCCESS); - assertSame(tx.getStatus(), TransactionStatusEnum.CLOSED); + assertSame(TransactionCodeEnum.ROLLBACK_SUCCESS, eitherResult.right().value()); + assertSame(TransactionStatusEnum.CLOSED, tx.getStatus()); verify(log).info(TransactionUtils.TRANSACTION_MARKER, LogMessages.DB_ACTION_FAILED_WITH_EXCEPTION, DBTypeEnum.MYSTERY.name(), transactionId, crushMessage, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name()); @@ -323,7 +323,7 @@ public class SdncTransactionTest { if (isVerifyAction) { // Check JanusGraph Action assertTrue(eitherJanusGraphResult.isLeft()); - assertSame(eitherJanusGraphResult.left().value(), TestResponse.JanusGraphResponseSuccess); + assertSame(TestResponse.JanusGraphResponseSuccess, eitherJanusGraphResult.left().value()); verify(log).debug(TestAction.JanusGraphAction.name()); verify(log).debug(LogMessages.INVOKE_ACTION, transactionId, DBTypeEnum.JANUSGRAPH.name(), TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name()); verifyNoErrorsInLog(); @@ -342,7 +342,7 @@ public class SdncTransactionTest { verify(log).debug(LogMessages.COMMIT_ACTION_ALL_DB, transactionId, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name()); verify(log).debug(LogMessages.COMMIT_ACTION_SPECIFIC_DB, transactionId, DBTypeEnum.JANUSGRAPH .name(), TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name()); - assertSame(transactionCode, TransactionCodeEnum.SUCCESS); + assertSame(TransactionCodeEnum.SUCCESS, transactionCode); } return transactionCode; } @@ -358,7 +358,7 @@ public class SdncTransactionTest { if (isVerifyAction) { // Check JanusGraph Action assertTrue(eitherEsAction.isLeft()); - assertSame(eitherEsAction.left().value(), DBActionCodeEnum.SUCCESS); + assertSame(DBActionCodeEnum.SUCCESS, eitherEsAction.left().value()); verify(log).debug(LogMessages.INVOKE_ACTION, transactionId, DBTypeEnum.ELASTIC_SEARCH.name(), TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name()); verifyNoErrorsInLog(); verifyNoInfoInLog(); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/externalupload/utils/ServiceUtilsTest.java b/catalog-be/src/test/java/org/openecomp/sdc/externalupload/utils/ServiceUtilsTest.java index 95d4b81420..4f23aa290e 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/externalupload/utils/ServiceUtilsTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/externalupload/utils/ServiceUtilsTest.java @@ -46,8 +46,8 @@ public class ServiceUtilsTest { public void shouldGetObjectAsMap() { TestModel testModel = getTestModel(); Map<String, Object> objectAsMap = ServiceUtils.getObjectAsMap(testModel); - assertEquals(objectAsMap.size(), 1); - assertEquals(objectAsMap.get(PROP), OBJ_1); + assertEquals(1, objectAsMap.size()); + assertEquals(OBJ_1, objectAsMap.get(PROP)); } @Test |