diff options
author | Wojciech Sliwka <wojciech.sliwka@nokia.com> | 2019-06-27 12:35:47 +0200 |
---|---|---|
committer | Ofir Sonsino <ofir.sonsino@intl.att.com> | 2019-07-07 08:22:31 +0000 |
commit | bf2ffad5b686eb0ffddbeeeca5824b8caea0c8ff (patch) | |
tree | 53e09d40e18b4aecff6f501633d374b87c4688be /catalog-be/src/test | |
parent | 868746d27adc90efeba5909d3eb60a6e0cd24c27 (diff) |
Remove field injection in catalog-dao
Change-Id: I24c3a898fa34491e80074944614722fbb3085515
Issue-ID: SDC-2398
Signed-off-by: Wojciech Sliwka <wojciech.sliwka@nokia.com>
Diffstat (limited to 'catalog-be/src/test')
7 files changed, 53 insertions, 25 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CertificationRequestTransitionTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CertificationRequestTransitionTest.java index 48b79eafd3..e5462c6d71 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CertificationRequestTransitionTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CertificationRequestTransitionTest.java @@ -25,6 +25,7 @@ import org.junit.Test; import org.openecomp.sdc.be.auditing.impl.AuditingManager; import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic; import org.openecomp.sdc.be.dao.cassandra.AuditCassandraDao; +import org.openecomp.sdc.be.dao.cassandra.CassandraClient; import org.openecomp.sdc.be.dao.impl.AuditingDao; import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphClient; @@ -41,13 +42,15 @@ import fj.data.Either; import mockit.Deencapsulation; import org.openecomp.sdc.test.utils.TestConfigurationProvider; +import static org.mockito.Mockito.mock; + public class CertificationRequestTransitionTest extends LifecycleTestBase { private CertificationRequestTransition createTestSubject() { return new CertificationRequestTransition( - new ComponentsUtils(new AuditingManager(new AuditingDao(), new AuditCassandraDao(), new TestConfigurationProvider())), + new ComponentsUtils(new AuditingManager(new AuditingDao(), new AuditCassandraDao(mock(CassandraClient.class)), new TestConfigurationProvider())), new ToscaElementLifecycleOperation(), new ServiceBusinessLogic(), new ToscaOperationFacade(), new JanusGraphDao(new JanusGraphClient())); } @@ -92,4 +95,4 @@ public class CertificationRequestTransitionTest extends LifecycleTestBase { testSubject = createTestSubject(); result = Deencapsulation.invoke(testSubject, "validateConfiguredAtomicReqCapSatisfied", component); } -}
\ No newline at end of file +} diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/ArtifactCassandraDaoMock.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/ArtifactCassandraDaoMock.java index 290ba07883..1e913ed798 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/ArtifactCassandraDaoMock.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/ArtifactCassandraDaoMock.java @@ -1,12 +1,18 @@ package org.openecomp.sdc.be.components.path.beans; import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao; +import org.openecomp.sdc.be.dao.cassandra.CassandraClient; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; @Component("artifact-cassandra-dao") public class ArtifactCassandraDaoMock extends ArtifactCassandraDao { + + public ArtifactCassandraDaoMock(CassandraClient cassandraClient) { + super(cassandraClient); + } + @PostConstruct @Override public void init() { diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/AuditCassandraDaoMock.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/AuditCassandraDaoMock.java index c4885e1f07..ce50d586b5 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/AuditCassandraDaoMock.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/AuditCassandraDaoMock.java @@ -1,6 +1,7 @@ package org.openecomp.sdc.be.components.path.beans; import org.openecomp.sdc.be.dao.cassandra.AuditCassandraDao; +import org.openecomp.sdc.be.dao.cassandra.CassandraClient; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; @@ -8,6 +9,10 @@ import javax.annotation.PostConstruct; @Component("audit-cassandra-dao") public class AuditCassandraDaoMock extends AuditCassandraDao{ + public AuditCassandraDaoMock(CassandraClient cassandraClient) { + super(cassandraClient); + } + @PostConstruct public void init() { diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/ComponentCassandraDaoMock.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/ComponentCassandraDaoMock.java index 6a9731e86d..65d4219aa7 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/ComponentCassandraDaoMock.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/ComponentCassandraDaoMock.java @@ -3,6 +3,7 @@ package org.openecomp.sdc.be.components.path.beans; import fj.data.Either; import org.apache.commons.lang3.tuple.ImmutablePair; import org.openecomp.sdc.be.dao.api.ActionStatus; +import org.openecomp.sdc.be.dao.cassandra.CassandraClient; import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus; import org.openecomp.sdc.be.dao.cassandra.ComponentCacheAccessor; import org.openecomp.sdc.be.dao.cassandra.ComponentCassandraDao; @@ -20,8 +21,8 @@ public class ComponentCassandraDaoMock extends ComponentCassandraDao { public static Integer DEFAULT_FETCH_SIZE = 500; private ComponentCacheAccessor componentCacheAccessor; - public ComponentCassandraDaoMock() { - super(); + public ComponentCassandraDaoMock(CassandraClient cassandraClient) { + super(cassandraClient); } @PostConstruct diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/EnvironmentCassandraDaoMock.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/EnvironmentCassandraDaoMock.java index 2d7b1ad287..3ddda8a987 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/EnvironmentCassandraDaoMock.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/EnvironmentCassandraDaoMock.java @@ -1,5 +1,6 @@ package org.openecomp.sdc.be.components.path.beans; +import org.openecomp.sdc.be.dao.cassandra.CassandraClient; import org.openecomp.sdc.be.dao.cassandra.OperationalEnvironmentDao; import org.springframework.stereotype.Component; @@ -7,6 +8,11 @@ import javax.annotation.PostConstruct; @Component("operational-environment-dao") public class EnvironmentCassandraDaoMock extends OperationalEnvironmentDao { + + public EnvironmentCassandraDaoMock(CassandraClient cassandraClient) { + super(cassandraClient); + } + @PostConstruct @Override public void init() { diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/SdcSchemaFilesCassandraDaoMock.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/SdcSchemaFilesCassandraDaoMock.java index 4e0105f067..a4d634ae56 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/SdcSchemaFilesCassandraDaoMock.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/SdcSchemaFilesCassandraDaoMock.java @@ -1,5 +1,6 @@ package org.openecomp.sdc.be.components.path.beans; +import org.openecomp.sdc.be.dao.cassandra.CassandraClient; import org.openecomp.sdc.be.dao.cassandra.SdcSchemaFilesCassandraDao; import org.springframework.stereotype.Component; @@ -8,6 +9,10 @@ import javax.annotation.PostConstruct; @Component("sdc-schema-files-cassandra-dao") public class SdcSchemaFilesCassandraDaoMock extends SdcSchemaFilesCassandraDao { + public SdcSchemaFilesCassandraDaoMock(CassandraClient cassandraClient) { + super(cassandraClient); + } + @PostConstruct @Override public void init() { diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/impl/ComponentsUtilsTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/impl/ComponentsUtilsTest.java index fdcd6d8c75..b76ac2e70f 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/impl/ComponentsUtilsTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/impl/ComponentsUtilsTest.java @@ -33,6 +33,7 @@ import org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum; import org.openecomp.sdc.be.config.ConfigurationManager; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.dao.cassandra.AuditCassandraDao; +import org.openecomp.sdc.be.dao.cassandra.CassandraClient; import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus; import org.openecomp.sdc.be.dao.graph.datatype.AdditionalInformationEnum; import org.openecomp.sdc.be.dao.impl.AuditingDao; @@ -55,12 +56,13 @@ import java.util.List; import org.openecomp.sdc.test.utils.TestConfigurationProvider; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; public class ComponentsUtilsTest { private ComponentsUtils createTestSubject() { - return new ComponentsUtils(new AuditingManager(new AuditingDao(), new AuditCassandraDao(), new TestConfigurationProvider())); + return new ComponentsUtils(new AuditingManager(new AuditingDao(), new AuditCassandraDao(mock(CassandraClient.class)), new TestConfigurationProvider())); } @Before @@ -68,7 +70,7 @@ public class ComponentsUtilsTest { String appConfigDir = "src/test/resources/config/catalog-be"; ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir); ConfigurationManager configurationManager = new ConfigurationManager(configurationSource); - ComponentsUtils componentsUtils = new ComponentsUtils(Mockito.mock(AuditingManager.class)); + ComponentsUtils componentsUtils = new ComponentsUtils(mock(AuditingManager.class)); } @Test @@ -611,7 +613,7 @@ public class ComponentsUtilsTest { @Test public void testconvertJsonToObject() throws Exception { - AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); + AuditingManager auditingmanager = mock(AuditingManager.class); ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); when(auditingmanager.auditEvent(any())).thenReturn("OK"); @@ -628,7 +630,7 @@ public class ComponentsUtilsTest { @Test public void testconvertJsonToObject_NllData() throws Exception { - AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); + AuditingManager auditingmanager = mock(AuditingManager.class); ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); when(auditingmanager.auditEvent(any())).thenReturn("OK"); User user = new User(); @@ -641,7 +643,7 @@ public class ComponentsUtilsTest { @Test public void testconvertJsonToObjectInvalidData() throws Exception { - AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); + AuditingManager auditingmanager = mock(AuditingManager.class); ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); when(auditingmanager.auditEvent(any())).thenReturn("OK"); @@ -657,7 +659,7 @@ public class ComponentsUtilsTest { @Test public void testconvertToStorageOperationStatus() { - AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); + AuditingManager auditingmanager = mock(AuditingManager.class); ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); when(auditingmanager.auditEvent(any())).thenReturn("OK"); Assert.assertEquals(StorageOperationStatus.OK,compUtils.convertToStorageOperationStatus(CassandraOperationStatus.OK)); @@ -669,7 +671,7 @@ public class ComponentsUtilsTest { @Test public void testgetResponseFormatByDataType() { - AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); + AuditingManager auditingmanager = mock(AuditingManager.class); ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); when(auditingmanager.auditEvent(any())).thenReturn("OK"); DataTypeDefinition dataType = new DataTypeDefinition(); @@ -683,7 +685,7 @@ public class ComponentsUtilsTest { @Test public void testGetResponseFormatByPolicyType_POLICY_TYPE_ALREADY_EXIST() throws Exception { - AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); + AuditingManager auditingmanager = mock(AuditingManager.class); ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); when(auditingmanager.auditEvent(any())).thenReturn("OK"); PolicyTypeDefinition policyType = new PolicyTypeDefinition(); @@ -696,7 +698,7 @@ public class ComponentsUtilsTest { @Test public void testGetResponseFormatByPolicyType_PolicyID_NULL() throws Exception { - AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); + AuditingManager auditingmanager = mock(AuditingManager.class); ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); when(auditingmanager.auditEvent(any())).thenReturn("OK"); ResponseFormat responseFormat = compUtils.getResponseFormatByPolicyType(ActionStatus.POLICY_TYPE_ALREADY_EXIST, null); @@ -707,7 +709,7 @@ public class ComponentsUtilsTest { @Test public void testGetResponseFormatByGroupType_GROUP_MEMBER_EMPTY() throws Exception { - AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); + AuditingManager auditingmanager = mock(AuditingManager.class); ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); when(auditingmanager.auditEvent(any())).thenReturn("OK"); GroupTypeDefinition groupType = new GroupTypeDefinition(); @@ -721,7 +723,7 @@ public class ComponentsUtilsTest { @Test public void testConvertFromStorageResponseForDataType_ALL() throws Exception { - AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); + AuditingManager auditingmanager = mock(AuditingManager.class); ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); when(auditingmanager.auditEvent(any())).thenReturn("OK"); @@ -738,7 +740,7 @@ public class ComponentsUtilsTest { @Test public void testConvertFromStorageResponseForGroupType_ALL() throws Exception { - AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); + AuditingManager auditingmanager = mock(AuditingManager.class); ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); when(auditingmanager.auditEvent(any())).thenReturn("OK"); @@ -752,7 +754,7 @@ public class ComponentsUtilsTest { @Test public void testConvertFromStorageResponseForConsumer_ALL() throws Exception { - AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); + AuditingManager auditingmanager = mock(AuditingManager.class); ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); when(auditingmanager.auditEvent(any())).thenReturn("OK"); @@ -767,7 +769,7 @@ public class ComponentsUtilsTest { @Test public void testGetResponseFormatAdditionalProperty_ALL() throws Exception { - AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); + AuditingManager auditingmanager = mock(AuditingManager.class); ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); when(auditingmanager.auditEvent(any())).thenReturn("OK"); @@ -802,7 +804,7 @@ public class ComponentsUtilsTest { @Test public void testConvertFromResultStatusEnum_ALL() throws Exception { - AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); + AuditingManager auditingmanager = mock(AuditingManager.class); ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); when(auditingmanager.auditEvent(any())).thenReturn("OK"); Assert.assertEquals(ActionStatus.OK,compUtils.convertFromResultStatusEnum(ResultStatusEnum.OK, null)); @@ -815,7 +817,7 @@ public class ComponentsUtilsTest { @Test public void testconvertFromStorageResponseForAdditionalInformation() throws Exception{ - AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); + AuditingManager auditingmanager = mock(AuditingManager.class); ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); when(auditingmanager.auditEvent(any())).thenReturn("OK"); Assert.assertEquals(ActionStatus.OK,compUtils.convertFromStorageResponseForAdditionalInformation(StorageOperationStatus.OK)); @@ -825,7 +827,7 @@ public class ComponentsUtilsTest { @Test public void testgetResponseFormatByComponent() throws Exception{ - AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); + AuditingManager auditingmanager = mock(AuditingManager.class); ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); when(auditingmanager.auditEvent(any())).thenReturn("OK"); Component component = new Resource(); @@ -846,7 +848,7 @@ public class ComponentsUtilsTest { @Test public void testConvertFromStorageResponseForResourceInstanceProperty_ALL() throws Exception { - AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); + AuditingManager auditingmanager = mock(AuditingManager.class); ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); when(auditingmanager.auditEvent(any())).thenReturn("OK"); Assert.assertEquals(ActionStatus.OK,compUtils.convertFromStorageResponseForResourceInstanceProperty(StorageOperationStatus.OK)); @@ -860,7 +862,7 @@ public class ComponentsUtilsTest { @Test public void testConvertFromStorageResponseForResourceInstance_ALL() throws Exception { - AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); + AuditingManager auditingmanager = mock(AuditingManager.class); ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); when(auditingmanager.auditEvent(any())).thenReturn("OK"); Assert.assertEquals(ActionStatus.GENERAL_ERROR,compUtils.convertFromStorageResponseForResourceInstance(StorageOperationStatus.ARTIFACT_NOT_FOUND, false)); @@ -877,7 +879,7 @@ public class ComponentsUtilsTest { @Test public void testConvertFromStorageResponse_ALL() throws Exception { - AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); + AuditingManager auditingmanager = mock(AuditingManager.class); ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); when(auditingmanager.auditEvent(any())).thenReturn("OK"); Assert.assertEquals(ActionStatus.GENERAL_ERROR,compUtils.convertFromStorageResponse(StorageOperationStatus.CONNECTION_FAILURE, ComponentTypeEnum.RESOURCE)); @@ -899,4 +901,4 @@ public class ComponentsUtilsTest { Assert.assertEquals(ActionStatus.INVALID_PROPERTY,compUtils.convertFromStorageResponse(StorageOperationStatus.INVALID_PROPERTY, ComponentTypeEnum.RESOURCE)); Assert.assertEquals(ActionStatus.COMPONENT_IS_ARCHIVED,compUtils.convertFromStorageResponse(StorageOperationStatus.COMPONENT_IS_ARCHIVED, ComponentTypeEnum.RESOURCE)); } -}
\ No newline at end of file +} |