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-dao | |
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-dao')
7 files changed, 42 insertions, 18 deletions
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ArtifactCassandraDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ArtifactCassandraDao.java index 8449e676ca..30da6bce6e 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ArtifactCassandraDao.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ArtifactCassandraDao.java @@ -28,6 +28,7 @@ import org.apache.commons.lang3.tuple.ImmutablePair; import org.openecomp.sdc.be.resources.data.ESArtifactData; import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants; import org.openecomp.sdc.common.log.wrappers.Logger; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; @@ -38,8 +39,10 @@ public class ArtifactCassandraDao extends CassandraDao { private static Logger logger = Logger.getLogger(ArtifactCassandraDao.class.getName()); private ArtifactAccessor artifactAccessor; - public ArtifactCassandraDao() { - super(); + + @Autowired + public ArtifactCassandraDao(CassandraClient cassandraClient) { + super(cassandraClient); } diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/AuditCassandraDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/AuditCassandraDao.java index d5c8a19f06..7c27fc912a 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/AuditCassandraDao.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/AuditCassandraDao.java @@ -30,6 +30,7 @@ import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.dao.cassandra.schema.Table; import org.openecomp.sdc.be.resources.data.auditing.*; import org.openecomp.sdc.common.log.wrappers.Logger; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; @@ -43,8 +44,9 @@ public class AuditCassandraDao extends CassandraDao { private static Logger logger = Logger.getLogger(AuditCassandraDao.class.getName()); - public AuditCassandraDao() { - super(); + @Autowired + public AuditCassandraDao(CassandraClient cassandraClient) { + super(cassandraClient); } @PostConstruct diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/CassandraDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/CassandraDao.java index 284b91ac74..3eba7ae54a 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/CassandraDao.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/CassandraDao.java @@ -27,7 +27,6 @@ import com.datastax.driver.core.querybuilder.QueryBuilder; import com.datastax.driver.mapping.MappingManager; import fj.data.Either; import org.openecomp.sdc.common.log.wrappers.Logger; -import org.springframework.beans.factory.annotation.Autowired; public abstract class CassandraDao { @@ -36,9 +35,12 @@ public abstract class CassandraDao { protected Session session; protected MappingManager manager; - @Autowired protected CassandraClient client; + public CassandraDao(CassandraClient cassandraClient) { + this.client = cassandraClient; + } + /** * the method checks if the given table is empty under the keyspace the * session was opened to. diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ComponentCassandraDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ComponentCassandraDao.java index 11643d16e8..7b23a9db41 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ComponentCassandraDao.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ComponentCassandraDao.java @@ -30,6 +30,7 @@ import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.resources.data.ComponentCacheData; import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants; import org.openecomp.sdc.common.log.wrappers.Logger; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; @@ -45,9 +46,10 @@ public class ComponentCassandraDao extends CassandraDao { private ComponentCacheAccessor componentCacheAccessor; - public ComponentCassandraDao() { - super(); + @Autowired + public ComponentCassandraDao(CassandraClient cassandraClient) { + super(cassandraClient); } @PostConstruct diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/OperationalEnvironmentDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/OperationalEnvironmentDao.java index 783eb9533b..9e1bfd8c35 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/OperationalEnvironmentDao.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/OperationalEnvironmentDao.java @@ -10,6 +10,7 @@ import org.openecomp.sdc.be.resources.data.OperationalEnvironmentEntry; import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants; import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode; import org.openecomp.sdc.common.log.wrappers.Logger; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; @@ -22,8 +23,9 @@ public class OperationalEnvironmentDao extends CassandraDao { private static Logger logger = Logger.getLogger(OperationalEnvironmentDao.class.getName()); private OperationalEnvironmentsAccessor operationalEnvironmentsAccessor; - public OperationalEnvironmentDao() { - super(); + @Autowired + public OperationalEnvironmentDao(CassandraClient cassandraClient) { + super(cassandraClient); } @PostConstruct diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/SdcSchemaFilesCassandraDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/SdcSchemaFilesCassandraDao.java index a9ca4e845b..76aaad95a5 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/SdcSchemaFilesCassandraDao.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/SdcSchemaFilesCassandraDao.java @@ -28,6 +28,7 @@ import org.apache.commons.lang3.tuple.ImmutablePair; import org.openecomp.sdc.be.resources.data.SdcSchemaFilesData; import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants; import org.openecomp.sdc.common.log.wrappers.Logger; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; @@ -38,9 +39,10 @@ public class SdcSchemaFilesCassandraDao extends CassandraDao { private static Logger logger = Logger.getLogger(SdcSchemaFilesCassandraDao.class.getName()); private SdcSchemaFilesAccessor sdcSchemaFilesAccessor; - - public SdcSchemaFilesCassandraDao() { - super(); + + @Autowired + public SdcSchemaFilesCassandraDao(CassandraClient cassandraClient) { + super(cassandraClient); } @PostConstruct diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/ArtifactCassandraDaoTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/ArtifactCassandraDaoTest.java index 0bbe2b6e03..dcd92aef45 100644 --- a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/ArtifactCassandraDaoTest.java +++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/ArtifactCassandraDaoTest.java @@ -13,17 +13,21 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.openecomp.sdc.be.resources.data.ESArtifactData; +import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants; public class ArtifactCassandraDaoTest { @InjectMocks - ArtifactCassandraDao testSubject; + private ArtifactCassandraDao testSubject; @Mock - CassandraClient client; + private CassandraClient client; @Mock - ArtifactAccessor artifactAccessor; + private ArtifactAccessor artifactAccessor; + + @Mock + private MappingManager mappingManager; @Before public void setUp() throws Exception { @@ -89,6 +93,9 @@ public class ArtifactCassandraDaoTest { @Test public void testGetCountOfArtifactById() throws Exception { + Mockito.when(client.isConnected()).thenReturn(true); + Mockito.when(client.connect(AuditingTypesConstants.ARTIFACT_KEYSPACE)).thenReturn(Either.left(ImmutablePair.of(null,mappingManager))); + Mockito.when(mappingManager.createAccessor(ArtifactAccessor.class)).thenReturn(artifactAccessor); String uniqeId = "mock"; Either<Long, CassandraOperationStatus> result; ResultSet value = Mockito.mock(ResultSet.class); @@ -98,17 +105,21 @@ public class ArtifactCassandraDaoTest { Mockito.when(artifactAccessor.getNumOfArtifactsById(uniqeId)).thenReturn(value); // default test + testSubject.init(); result = testSubject.getCountOfArtifactById(uniqeId); } @Test public void testGetCountOfArtifactById1() throws Exception { + Mockito.when(client.isConnected()).thenReturn(true); + Mockito.when(client.connect(AuditingTypesConstants.ARTIFACT_KEYSPACE)).thenReturn(Either.left(ImmutablePair.of(null,mappingManager))); + Mockito.when(mappingManager.createAccessor(ArtifactAccessor.class)).thenReturn(artifactAccessor); String uniqeId = "mock"; Either<Long, CassandraOperationStatus> result; ResultSet value = Mockito.mock(ResultSet.class); Mockito.when(artifactAccessor.getNumOfArtifactsById(uniqeId)).thenReturn(null); - + testSubject.init(); // default test result = testSubject.getCountOfArtifactById(uniqeId); } -}
\ No newline at end of file +} |