aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-dao/src
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-dao/src')
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ComponentCassandraDao.java6
-rw-r--r--catalog-dao/src/test/java/org/openecomp/sdc/be/dao/AccountTest.java7
-rw-r--r--catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/ArtifactCassandraDaoTest.java133
-rw-r--r--catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/AuditCassandraDaoTest.java390
-rw-r--r--catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/CassandraClientTest.java150
-rw-r--r--catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/ComponentCassandraDaoTest.java363
-rw-r--r--catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/OperationalEnvironmentDaoTest.java161
-rw-r--r--catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/SdcSchemaFilesCassandraDaoTest.java99
-rw-r--r--catalog-dao/src/test/java/org/openecomp/sdc/be/utils/DAOConfDependentTest.java13
9 files changed, 1263 insertions, 59 deletions
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 211cb6716c..82630e063a 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
@@ -101,9 +101,7 @@ public class ComponentCassandraDao extends CassandraDao {
}
events.all().forEach(event -> {
components.add(event);
- if (logger.isTraceEnabled()) {
- logger.trace("Fetch component uid = {} isDirty = {}", event.getId(), event.getIsDirty());
- }
+ logger.trace("Fetch component uid = {} isDirty = {}", event.getId(), event.getIsDirty());
});
logger.debug("Number of components to fetch was {}. Actually, {} components fetched", ids.size(),
@@ -128,9 +126,7 @@ public class ComponentCassandraDao extends CassandraDao {
}
events.all().forEach(event -> {
components.add(event);
- if (logger.isTraceEnabled()) {
logger.trace("Fetch component uid = {} isDirty = {}", event.getId(), event.getIsDirty());
- }
});
logger.debug("Number of components fetched was {}.", components.size());
diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/AccountTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/AccountTest.java
index 414748a416..7d99916ff8 100644
--- a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/AccountTest.java
+++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/AccountTest.java
@@ -9,6 +9,11 @@ public class AccountTest {
}
@Test
+ public void testCtor() throws Exception {
+ new Account("mock", "mock");
+ }
+
+ @Test
public void testGetName() throws Exception {
Account testSubject;
String result;
@@ -57,6 +62,8 @@ public class AccountTest {
// default test
testSubject = createTestSubject();
result = testSubject.equals(other);
+ result = testSubject.equals(testSubject);
+ result = testSubject.equals(createTestSubject());
}
@Test
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
new file mode 100644
index 0000000000..250459f276
--- /dev/null
+++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/ArtifactCassandraDaoTest.java
@@ -0,0 +1,133 @@
+package org.openecomp.sdc.be.dao.cassandra;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.net.InetAddress;
+import java.nio.ByteBuffer;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+
+import org.apache.commons.lang3.tuple.ImmutablePair;
+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.resources.data.ESArtifactData;
+
+import com.datastax.driver.core.ColumnDefinitions;
+import com.datastax.driver.core.LocalDate;
+import com.datastax.driver.core.ResultSet;
+import com.datastax.driver.core.Row;
+import com.datastax.driver.core.Session;
+import com.datastax.driver.core.Token;
+import com.datastax.driver.core.TupleValue;
+import com.datastax.driver.core.TypeCodec;
+import com.datastax.driver.core.UDTValue;
+import com.datastax.driver.mapping.MappingManager;
+import com.google.common.reflect.TypeToken;
+
+import fj.data.Either;
+
+public class ArtifactCassandraDaoTest {
+
+ @InjectMocks
+ ArtifactCassandraDao testSubject;
+
+ @Mock
+ CassandraClient client;
+
+ @Mock
+ ArtifactAccessor artifactAccessor;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void testInit() throws Exception {
+ Mockito.when(client.isConnected()).thenReturn(true);
+ Either<ImmutablePair<Session, MappingManager>, CassandraOperationStatus> value = Either.right(CassandraOperationStatus.CLUSTER_NOT_CONNECTED);
+ Mockito.when(client.connect(Mockito.anyString())).thenReturn(value);
+ testSubject.init();
+ }
+
+ @Test
+ public void testInitError() throws Exception {
+ testSubject.init();
+ }
+
+ @Test
+ public void testSaveArtifact() throws Exception {
+ ESArtifactData artifact = null;
+ CassandraOperationStatus result;
+
+ // default test
+ result = testSubject.saveArtifact(artifact);
+ }
+
+ @Test
+ public void testGetArtifact() throws Exception {
+ String artifactId = "";
+ Either<ESArtifactData, CassandraOperationStatus> result;
+
+ // default test
+ result = testSubject.getArtifact(artifactId);
+ }
+
+ @Test
+ public void testDeleteArtifact() throws Exception {
+ String artifactId = "";
+ CassandraOperationStatus result;
+
+ // default test
+ result = testSubject.deleteArtifact(artifactId);
+ }
+
+ @Test
+ public void testDeleteAllArtifacts() throws Exception {
+ CassandraOperationStatus result;
+
+ // default test
+ result = testSubject.deleteAllArtifacts();
+ }
+
+ @Test
+ public void testIsTableEmpty() throws Exception {
+ String tableName = "";
+ Either<Boolean, CassandraOperationStatus> result;
+
+ // default test
+ result = testSubject.isTableEmpty(tableName);
+ }
+
+ @Test
+ public void testGetCountOfArtifactById() throws Exception {
+ String uniqeId = "mock";
+ Either<Long, CassandraOperationStatus> result;
+ ResultSet value = Mockito.mock(ResultSet.class);
+ Row value2 = Mockito.mock(Row.class);
+ Mockito.when(value2.getLong(0)).thenReturn(0L);
+ Mockito.when(value.one()).thenReturn(value2);
+ Mockito.when(artifactAccessor.getNumOfArtifactsById(uniqeId)).thenReturn(value);
+
+ // default test
+ result = testSubject.getCountOfArtifactById(uniqeId);
+ }
+
+ @Test
+ public void testGetCountOfArtifactById1() throws Exception {
+ String uniqeId = "mock";
+ Either<Long, CassandraOperationStatus> result;
+ ResultSet value = Mockito.mock(ResultSet.class);
+ Mockito.when(artifactAccessor.getNumOfArtifactsById(uniqeId)).thenReturn(null);
+
+ // default test
+ result = testSubject.getCountOfArtifactById(uniqeId);
+ }
+} \ No newline at end of file
diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/AuditCassandraDaoTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/AuditCassandraDaoTest.java
index c7cdca0b9e..511f8bd5bb 100644
--- a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/AuditCassandraDaoTest.java
+++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/AuditCassandraDaoTest.java
@@ -1,8 +1,15 @@
package org.openecomp.sdc.be.dao.cassandra;
+import java.util.LinkedList;
import java.util.List;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+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.ActionStatus;
import org.openecomp.sdc.be.resources.data.auditing.AuditingGenericEvent;
import org.openecomp.sdc.be.resources.data.auditing.DistributionDeployEvent;
@@ -10,142 +17,455 @@ import org.openecomp.sdc.be.resources.data.auditing.DistributionNotificationEven
import org.openecomp.sdc.be.resources.data.auditing.DistributionStatusEvent;
import org.openecomp.sdc.be.resources.data.auditing.ResourceAdminEvent;
-import fj.data.Either;
+import com.datastax.driver.core.Session;
+import com.datastax.driver.mapping.MappingManager;
+import com.datastax.driver.mapping.Result;
+import fj.data.Either;
public class AuditCassandraDaoTest {
- private AuditCassandraDao createTestSubject() {
- return new AuditCassandraDao();
- }
+ @InjectMocks
+ AuditCassandraDao testSubject;
-
+ @Mock
+ AuditAccessor auditAccessor;
-
+ @Mock
+ CassandraClient client;
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void testInit() throws Exception {
+ Mockito.when(client.isConnected()).thenReturn(true);
+ Either<ImmutablePair<Session, MappingManager>, CassandraOperationStatus> value = Either
+ .right(CassandraOperationStatus.CLUSTER_NOT_CONNECTED);
+ Mockito.when(client.connect(Mockito.anyString())).thenReturn(value);
+ testSubject.init();
+ }
+
+ @Test
+ public void testInitFail2() throws Exception {
+ Mockito.when(client.isConnected()).thenReturn(false);
+ testSubject.init();
+ }
-
@Test
public void testGetListOfDistributionStatuses() throws Exception {
- AuditCassandraDao testSubject;
+ String did = "";
+ Either<List<DistributionStatusEvent>, ActionStatus> result;
+
+ Result<DistributionStatusEvent> value = Mockito.mock(Result.class);
+ LinkedList<DistributionStatusEvent> value2 = new LinkedList<>();
+ value2.add(new DistributionStatusEvent());
+ Mockito.when(value.all()).thenReturn(value2);
+ Mockito.when(auditAccessor.getListOfDistributionStatuses(Mockito.anyString())).thenReturn(value);
+
+ // default test
+ result = testSubject.getListOfDistributionStatuses(did);
+ }
+
+ @Test
+ public void testGetListOfDistributionStatusesException() throws Exception {
+ String did = "";
+ Either<List<DistributionStatusEvent>, ActionStatus> result;
+
+ Mockito.when(auditAccessor.getListOfDistributionStatuses(Mockito.anyString()))
+ .thenThrow(RuntimeException.class);
+
+ // default test
+ result = testSubject.getListOfDistributionStatuses(did);
+ }
+
+ @Test
+ public void testGetListOfDistributionStatusesEmptyList() throws Exception {
String did = "";
Either<List<DistributionStatusEvent>, ActionStatus> result;
// default test
- testSubject = createTestSubject();
result = testSubject.getListOfDistributionStatuses(did);
}
-
@Test
public void testGetDistributionDeployByStatus() throws Exception {
- AuditCassandraDao testSubject;
String did = "";
String action = "";
String status = "";
Either<List<DistributionDeployEvent>, ActionStatus> result;
+ Result<DistributionDeployEvent> value = Mockito.mock(Result.class);
+ LinkedList<DistributionDeployEvent> value2 = new LinkedList<>();
+ value2.add(new DistributionDeployEvent());
+ Mockito.when(value.all()).thenReturn(value2);
+ Mockito.when(auditAccessor.getDistributionDeployByStatus(Mockito.anyString(), Mockito.anyString(),
+ Mockito.anyString())).thenReturn(value);
+
+ // default test
+ result = testSubject.getDistributionDeployByStatus(did, action, status);
+ }
+
+ @Test
+ public void testGetDistributionDeployByStatusEmptyList() throws Exception {
+ String did = "";
+ String action = "";
+ String status = "";
+ Either<List<DistributionDeployEvent>, ActionStatus> result;
+
+ Result<DistributionDeployEvent> value = Mockito.mock(Result.class);
+ LinkedList<DistributionDeployEvent> value2 = new LinkedList<>();
+ value2.add(new DistributionDeployEvent());
+ Mockito.when(value.all()).thenReturn(value2);
+ Mockito.when(auditAccessor.getDistributionDeployByStatus(Mockito.anyString(), Mockito.anyString(),
+ Mockito.anyString())).thenReturn(null);
+
+ // default test
+ result = testSubject.getDistributionDeployByStatus(did, action, status);
+ }
+
+ @Test
+ public void testGetDistributionDeployByStatusException() throws Exception {
+ String did = "";
+ String action = "";
+ String status = "";
+ Either<List<DistributionDeployEvent>, ActionStatus> result;
+
+ Mockito.when(auditAccessor.getDistributionDeployByStatus(Mockito.anyString(), Mockito.anyString(),
+ Mockito.anyString())).thenThrow(RuntimeException.class);
+
// default test
- testSubject = createTestSubject();
result = testSubject.getDistributionDeployByStatus(did, action, status);
}
-
@Test
public void testGetDistributionRequest() throws Exception {
- AuditCassandraDao testSubject;
String did = "";
String action = "";
Either<List<ResourceAdminEvent>, ActionStatus> result;
// default test
- testSubject = createTestSubject();
result = testSubject.getDistributionRequest(did, action);
}
-
+ @Test
+ public void testGetDistributionRequestList() throws Exception {
+ String did = "";
+ String action = "";
+ Either<List<ResourceAdminEvent>, ActionStatus> result;
+
+ Result<ResourceAdminEvent> value = Mockito.mock(Result.class);
+ List<ResourceAdminEvent> value2 = new LinkedList<>();
+ value2.add(new ResourceAdminEvent());
+ Mockito.when(value.all()).thenReturn(value2);
+ Mockito.when(auditAccessor.getDistributionRequest(Mockito.anyString(), Mockito.anyString())).thenReturn(value);
+
+ // default test
+ result = testSubject.getDistributionRequest(did, action);
+ }
+
+ @Test
+ public void testGetDistributionRequestException() throws Exception {
+ String did = "";
+ String action = "";
+ Either<List<ResourceAdminEvent>, ActionStatus> result;
+
+ Mockito.when(auditAccessor.getDistributionRequest(Mockito.anyString(), Mockito.anyString()))
+ .thenThrow(RuntimeException.class);
+
+ // default test
+ result = testSubject.getDistributionRequest(did, action);
+ }
+
@Test
public void testGetDistributionNotify() throws Exception {
- AuditCassandraDao testSubject;
+ String did = "";
+ String action = "";
+ Either<List<DistributionNotificationEvent>, ActionStatus> result;
+
+ Result<DistributionNotificationEvent> value = Mockito.mock(Result.class);
+ List<DistributionNotificationEvent> value2 = new LinkedList<>();
+ value2.add(new DistributionNotificationEvent());
+ Mockito.when(value.all()).thenReturn(value2);
+
+ Mockito.when(auditAccessor.getDistributionNotify(Mockito.anyString(), Mockito.anyString())).thenReturn(value);
+
+ // default test
+ result = testSubject.getDistributionNotify(did, action);
+ }
+
+ @Test
+ public void testGetDistributionNotifyException() throws Exception {
+ String did = "";
+ String action = "";
+ Either<List<DistributionNotificationEvent>, ActionStatus> result;
+
+ Mockito.when(auditAccessor.getDistributionNotify(Mockito.anyString(), Mockito.anyString()))
+ .thenThrow(RuntimeException.class);
+
+ // default test
+ result = testSubject.getDistributionNotify(did, action);
+ }
+
+ @Test
+ public void testGetDistributionNotifyNull() throws Exception {
String did = "";
String action = "";
Either<List<DistributionNotificationEvent>, ActionStatus> result;
// default test
- testSubject = createTestSubject();
result = testSubject.getDistributionNotify(did, action);
}
-
@Test
public void testGetByServiceInstanceId() throws Exception {
- AuditCassandraDao testSubject;
+ String serviceInstanceId = "";
+ Either<List<ResourceAdminEvent>, ActionStatus> result;
+
+ Result<ResourceAdminEvent> value = Mockito.mock(Result.class);
+ List<ResourceAdminEvent> value2 = new LinkedList<>();
+ value2.add(new ResourceAdminEvent());
+ Mockito.when(value.all()).thenReturn(value2);
+ Mockito.when(auditAccessor.getByServiceInstanceId(Mockito.anyString())).thenReturn(value);
+ // default test
+ result = testSubject.getByServiceInstanceId(serviceInstanceId);
+ }
+
+ @Test
+ public void testGetByServiceInstanceIdException() throws Exception {
+ String serviceInstanceId = "";
+ Either<List<ResourceAdminEvent>, ActionStatus> result;
+
+ Mockito.when(auditAccessor.getByServiceInstanceId(Mockito.anyString())).thenThrow(RuntimeException.class);
+ // default test
+ result = testSubject.getByServiceInstanceId(serviceInstanceId);
+ }
+
+ @Test
+ public void testGetByServiceInstanceIdNull() throws Exception {
String serviceInstanceId = "";
Either<List<ResourceAdminEvent>, ActionStatus> result;
// default test
- testSubject = createTestSubject();
result = testSubject.getByServiceInstanceId(serviceInstanceId);
}
-
@Test
public void testGetServiceDistributionStatusesList() throws Exception {
- AuditCassandraDao testSubject;
String serviceInstanceId = "";
Either<List<? extends AuditingGenericEvent>, ActionStatus> result;
+ Result<ResourceAdminEvent> value = Mockito.mock(Result.class);
+ List<ResourceAdminEvent> value2 = new LinkedList<>();
+ value2.add(new ResourceAdminEvent());
+ Mockito.when(value.all()).thenReturn(value2);
+ Mockito.when(auditAccessor.getServiceDistributionStatus(Mockito.anyString())).thenReturn(value);
+
// default test
- testSubject = createTestSubject();
result = testSubject.getServiceDistributionStatusesList(serviceInstanceId);
}
+ @Test
+ public void testGetServiceDistributionStatusesList2() throws Exception {
+ String serviceInstanceId = "";
+ Either<List<? extends AuditingGenericEvent>, ActionStatus> result;
+
+ Result<ResourceAdminEvent> value = Mockito.mock(Result.class);
+ List<ResourceAdminEvent> value2 = new LinkedList<>();
+ value2.add(new ResourceAdminEvent());
+ Mockito.when(value.all()).thenReturn(value2);
+ Mockito.when(auditAccessor.getServiceDistributionStatus(Mockito.anyString())).thenReturn(value);
+
+ Result<DistributionDeployEvent> value3 = Mockito.mock(Result.class);
+ List<DistributionDeployEvent> value4 = new LinkedList<>();
+ value4.add(new DistributionDeployEvent());
+ Mockito.when(value3.all()).thenReturn(value4);
+ Mockito.when(auditAccessor.getServiceDistributionDeploy(Mockito.anyString())).thenReturn(value3);
+
+ // default test
+ result = testSubject.getServiceDistributionStatusesList(serviceInstanceId);
+ }
+
+ @Test
+ public void testGetServiceDistributionStatusesList3() throws Exception {
+ String serviceInstanceId = "";
+ Either<List<? extends AuditingGenericEvent>, ActionStatus> result;
+
+ Result<ResourceAdminEvent> value = Mockito.mock(Result.class);
+ List<ResourceAdminEvent> value2 = new LinkedList<>();
+ value2.add(new ResourceAdminEvent());
+ Mockito.when(value.all()).thenReturn(value2);
+ Mockito.when(auditAccessor.getServiceDistributionStatus(Mockito.anyString())).thenReturn(value);
+
+ Result<DistributionDeployEvent> value3 = Mockito.mock(Result.class);
+ List<DistributionDeployEvent> value4 = new LinkedList<>();
+ value4.add(new DistributionDeployEvent());
+ Mockito.when(value3.all()).thenReturn(value4);
+ Mockito.when(auditAccessor.getServiceDistributionDeploy(Mockito.anyString())).thenReturn(value3);
+
+
+ Result<DistributionNotificationEvent> value5 = Mockito.mock(Result.class);
+ List<DistributionNotificationEvent> value6 = new LinkedList<>();
+ value6.add(new DistributionNotificationEvent());
+ Mockito.when(value5.all()).thenReturn(value6);
+ Mockito.when(auditAccessor.getServiceDistributionNotify(Mockito.anyString())).thenReturn(value5);
+
+ // default test
+ result = testSubject.getServiceDistributionStatusesList(serviceInstanceId);
+ }
@Test
- public void testGetAuditByServiceIdAndPrevVersion() throws Exception {
- AuditCassandraDao testSubject;
+ public void testGetServiceDistributionStatusesListException3() throws Exception {
+ String serviceInstanceId = "";
+ Either<List<? extends AuditingGenericEvent>, ActionStatus> result;
+
+ Result<ResourceAdminEvent> value = Mockito.mock(Result.class);
+ List<ResourceAdminEvent> value2 = new LinkedList<>();
+ value2.add(new ResourceAdminEvent());
+ Mockito.when(value.all()).thenReturn(value2);
+ Mockito.when(auditAccessor.getServiceDistributionStatus(Mockito.anyString())).thenReturn(value);
+
+ Result<DistributionDeployEvent> value3 = Mockito.mock(Result.class);
+ List<DistributionDeployEvent> value4 = new LinkedList<>();
+ value4.add(new DistributionDeployEvent());
+ Mockito.when(value3.all()).thenReturn(value4);
+ Mockito.when(auditAccessor.getServiceDistributionDeploy(Mockito.anyString())).thenReturn(value3);
+
+ Mockito.when(auditAccessor.getServiceDistributionNotify(Mockito.anyString())).thenThrow(RuntimeException.class);
+
+ // default test
+ result = testSubject.getServiceDistributionStatusesList(serviceInstanceId);
+ }
+
+ @Test
+ public void testGetServiceDistributionStatusesListException2() throws Exception {
+ String serviceInstanceId = "";
+ Either<List<? extends AuditingGenericEvent>, ActionStatus> result;
+
+ Result<ResourceAdminEvent> value = Mockito.mock(Result.class);
+ List<ResourceAdminEvent> value2 = new LinkedList<>();
+ value2.add(new ResourceAdminEvent());
+ Mockito.when(value.all()).thenReturn(value2);
+ Mockito.when(auditAccessor.getServiceDistributionStatus(Mockito.anyString())).thenReturn(value);
+
+ Mockito.when(auditAccessor.getServiceDistributionDeploy(Mockito.anyString())).thenThrow(RuntimeException.class);
+
+ // default test
+ result = testSubject.getServiceDistributionStatusesList(serviceInstanceId);
+ }
+
+ @Test
+ public void testGetServiceDistributionStatusesListException() throws Exception {
+ String serviceInstanceId = "";
+ Either<List<? extends AuditingGenericEvent>, ActionStatus> result;
+
+ Mockito.when(auditAccessor.getServiceDistributionStatus(Mockito.anyString())).thenThrow(RuntimeException.class);
+
+ // default test
+ result = testSubject.getServiceDistributionStatusesList(serviceInstanceId);
+ }
+
+ @Test
+ public void testGetServiceDistributionStatusesListNull() throws Exception {
+ String serviceInstanceId = "";
+ Either<List<? extends AuditingGenericEvent>, ActionStatus> result;
+
+ // default test
+ result = testSubject.getServiceDistributionStatusesList(serviceInstanceId);
+ }
+
+ @Test
+ public void testGetAuditByServiceIdAndPrevVersionNull() throws Exception {
String serviceInstanceId = "";
String prevVersion = "";
Either<List<ResourceAdminEvent>, ActionStatus> result;
// default test
- testSubject = createTestSubject();
result = testSubject.getAuditByServiceIdAndPrevVersion(serviceInstanceId, prevVersion);
}
-
@Test
+ public void testGetAuditByServiceIdAndPrevVersion() throws Exception {
+ String serviceInstanceId = "";
+ String prevVersion = "";
+ Either<List<ResourceAdminEvent>, ActionStatus> result;
+
+ Result<ResourceAdminEvent> value = Mockito.mock(Result.class);
+ List<ResourceAdminEvent> value2 = new LinkedList<>();
+ value2.add(new ResourceAdminEvent());
+ Mockito.when(value.all()).thenReturn(value2);
+ Mockito.when(auditAccessor.getAuditByServiceIdAndPrevVersion(Mockito.anyString(), Mockito.anyString())).thenReturn(value);
+
+ // default test
+ result = testSubject.getAuditByServiceIdAndPrevVersion(serviceInstanceId, prevVersion);
+ }
+
+ @Test
+ public void testGetAuditByServiceIdAndPrevVersionException() throws Exception {
+ String serviceInstanceId = "";
+ String prevVersion = "";
+ Either<List<ResourceAdminEvent>, ActionStatus> result;
+
+ Mockito.when(auditAccessor.getAuditByServiceIdAndPrevVersion(Mockito.anyString(), Mockito.anyString())).thenThrow(RuntimeException.class);
+
+ // default test
+ result = testSubject.getAuditByServiceIdAndPrevVersion(serviceInstanceId, prevVersion);
+ }
+
+ @Test
+ public void testGetAuditByServiceIdAndCurrVersionNull() throws Exception {
+ String serviceInstanceId = "";
+ String currVersion = "";
+ Either<List<ResourceAdminEvent>, ActionStatus> result;
+
+ // default test
+ result = testSubject.getAuditByServiceIdAndCurrVersion(serviceInstanceId, currVersion);
+ }
+
+ @Test
public void testGetAuditByServiceIdAndCurrVersion() throws Exception {
- AuditCassandraDao testSubject;
String serviceInstanceId = "";
String currVersion = "";
Either<List<ResourceAdminEvent>, ActionStatus> result;
+ Result<ResourceAdminEvent> value = Mockito.mock(Result.class);
+ List<ResourceAdminEvent> value2 = new LinkedList<>();
+ value2.add(new ResourceAdminEvent());
+ Mockito.when(value.all()).thenReturn(value2);
+ Mockito.when(auditAccessor.getAuditByServiceIdAndCurrVersion(Mockito.anyString(), Mockito.anyString())).thenReturn(value);
+
// default test
- testSubject = createTestSubject();
result = testSubject.getAuditByServiceIdAndCurrVersion(serviceInstanceId, currVersion);
}
+
+ @Test
+ public void testGetAuditByServiceIdAndCurrVersionException() throws Exception {
+ String serviceInstanceId = "";
+ String currVersion = "";
+ Either<List<ResourceAdminEvent>, ActionStatus> result;
+ Mockito.when(auditAccessor.getAuditByServiceIdAndCurrVersion(Mockito.anyString(), Mockito.anyString())).thenThrow(RuntimeException.class);
+
+ // default test
+ result = testSubject.getAuditByServiceIdAndCurrVersion(serviceInstanceId, currVersion);
+ }
@Test
public void testIsTableEmpty() throws Exception {
- AuditCassandraDao testSubject;
String tableName = "";
Either<Boolean, CassandraOperationStatus> result;
// default test
- testSubject = createTestSubject();
result = testSubject.isTableEmpty(tableName);
}
-
@Test
public void testDeleteAllAudit() throws Exception {
- AuditCassandraDao testSubject;
CassandraOperationStatus result;
// default test
- testSubject = createTestSubject();
result = testSubject.deleteAllAudit();
}
} \ No newline at end of file
diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/CassandraClientTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/CassandraClientTest.java
new file mode 100644
index 0000000000..2f637f7a14
--- /dev/null
+++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/CassandraClientTest.java
@@ -0,0 +1,150 @@
+package org.openecomp.sdc.be.dao.cassandra;
+
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.apache.tinkerpop.gremlin.structure.T;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.utils.DAOConfDependentTest;
+
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.Cluster.Builder;
+import com.datastax.driver.core.Session;
+import com.datastax.driver.mapping.MappingManager;
+
+import fj.data.Either;
+import mockit.Deencapsulation;
+
+public class CassandraClientTest extends DAOConfDependentTest {
+
+ private CassandraClient createTestSubject() {
+ return new CassandraClient();
+ }
+
+ @Test
+ public void testSetLocalDc() throws Exception {
+ CassandraClient testSubject;
+ Cluster.Builder clusterBuilder = null;
+
+ Builder mock = Mockito.mock(Cluster.Builder.class);
+ Mockito.when(mock.withLoadBalancingPolicy(Mockito.any())).thenReturn(new Builder());
+ // default test
+ testSubject = createTestSubject();
+ Deencapsulation.invoke(testSubject, "setLocalDc", new Object[] { Cluster.Builder.class });
+
+ ConfigurationManager.getConfigurationManager().getConfiguration().getCassandraConfig()
+ .setLocalDataCenter("mock");
+
+ testSubject = createTestSubject();
+ Deencapsulation.invoke(testSubject, "setLocalDc", mock);
+ }
+
+ @Test
+ public void testEnableSsl() throws Exception {
+ CassandraClient testSubject;
+ Cluster.Builder clusterBuilder = null;
+
+ Builder mock = Mockito.mock(Cluster.Builder.class);
+ Mockito.when(mock.withSSL()).thenReturn(new Builder());
+
+ ConfigurationManager.getConfigurationManager().getConfiguration().getCassandraConfig().setSsl(false);
+ // default test
+ testSubject = createTestSubject();
+ Deencapsulation.invoke(testSubject, "enableSsl", mock);
+
+ ConfigurationManager.getConfigurationManager().getConfiguration().getCassandraConfig().setSsl(true);
+ // default test
+ testSubject = createTestSubject();
+ Deencapsulation.invoke(testSubject, "enableSsl", mock);
+ ConfigurationManager.getConfigurationManager().getConfiguration().getCassandraConfig().setTruststorePath(null);
+ ConfigurationManager.getConfigurationManager().getConfiguration().getCassandraConfig()
+ .setTruststorePassword(null);
+ Deencapsulation.invoke(testSubject, "enableSsl", mock);
+ }
+
+ @Test
+ public void testEnableAuthentication() throws Exception {
+ CassandraClient testSubject;
+ Builder mock = Mockito.mock(Cluster.Builder.class);
+ Mockito.when(mock.withCredentials(Mockito.any(), Mockito.any())).thenReturn(new Builder());
+
+ // default test
+ testSubject = createTestSubject();
+ Deencapsulation.invoke(testSubject, "enableAuthentication", Cluster.Builder.class);
+
+ ConfigurationManager.getConfigurationManager().getConfiguration().getCassandraConfig().setAuthenticate(true);
+ Deencapsulation.invoke(testSubject, "enableAuthentication", mock);
+ ConfigurationManager.getConfigurationManager().getConfiguration().getCassandraConfig().setUsername(null);
+ ConfigurationManager.getConfigurationManager().getConfiguration().getCassandraConfig().setPassword(null);
+ Deencapsulation.invoke(testSubject, "enableAuthentication", mock);
+ }
+
+ @Test
+ public void testConnect() throws Exception {
+ CassandraClient testSubject;
+ String keyspace = "";
+ Either<ImmutablePair<Session, MappingManager>, CassandraOperationStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.connect(keyspace);
+ }
+
+ @Test
+ public void testSave() throws Exception {
+ CassandraClient testSubject;
+ T entity = null;
+ Class<T> clazz = null;
+ MappingManager manager = null;
+ CassandraOperationStatus result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.save(entity, clazz, manager);
+ }
+
+ @Test
+ public void testGetById() throws Exception {
+ CassandraClient testSubject;
+ String id = "";
+ Class<T> clazz = null;
+ MappingManager manager = null;
+ Either<T, CassandraOperationStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getById(id, clazz, manager);
+ }
+
+ @Test
+ public void testDelete() throws Exception {
+ CassandraClient testSubject;
+ String id = "";
+ Class<T> clazz = null;
+ MappingManager manager = null;
+ CassandraOperationStatus result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.delete(id, clazz, manager);
+ }
+
+ @Test
+ public void testIsConnected() throws Exception {
+ CassandraClient testSubject;
+ boolean result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.isConnected();
+ }
+
+ @Test
+ public void testCloseClient() throws Exception {
+ CassandraClient testSubject;
+
+ // default test
+ testSubject = createTestSubject();
+ testSubject.closeClient();
+ }
+} \ No newline at end of file
diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/ComponentCassandraDaoTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/ComponentCassandraDaoTest.java
index ed8e2a7776..8869c8174b 100644
--- a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/ComponentCassandraDaoTest.java
+++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/ComponentCassandraDaoTest.java
@@ -1,49 +1,396 @@
package org.openecomp.sdc.be.dao.cassandra;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+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.ActionStatus;
import org.openecomp.sdc.be.resources.data.ComponentCacheData;
-import fj.data.Either;
+import com.datastax.driver.core.Session;
+import com.datastax.driver.mapping.MappingManager;
+import com.datastax.driver.mapping.Result;
+import fj.data.Either;
public class ComponentCassandraDaoTest {
- private ComponentCassandraDao createTestSubject() {
- return new ComponentCassandraDao();
+ @InjectMocks
+ ComponentCassandraDao testSubject;
+
+ @Mock
+ CassandraClient clientMock;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void testInit() throws Exception {
+
+ // default test
+ testSubject.init();
+
+ Mockito.when(clientMock.isConnected()).thenReturn(true);
+ Session sessMock = Mockito.mock(Session.class);
+ MappingManager mappMock = Mockito.mock(MappingManager.class);
+ ImmutablePair<Session, MappingManager> ipMock = ImmutablePair.of(sessMock, mappMock);
+ Either<ImmutablePair<Session, MappingManager>, CassandraOperationStatus> value = Either.left(ipMock);
+ Mockito.when(clientMock.connect(Mockito.any())).thenReturn(value);
+ testSubject.init();
+ }
+
+ @Test
+ public void testInitException() throws Exception {
+
+ // default test
+ testSubject.init();
+
+ Mockito.when(clientMock.isConnected()).thenReturn(true);
+ Either<ImmutablePair<Session, MappingManager>, CassandraOperationStatus> value = Either
+ .right(CassandraOperationStatus.CLUSTER_NOT_CONNECTED);
+ Mockito.when(clientMock.connect(Mockito.any())).thenReturn(value);
+ try {
+ testSubject.init();
+ } catch (Exception e) {
+ assertTrue(e.getClass() == RuntimeException.class);
+ }
+ }
+
+ @Test
+ public void testGetComponents() throws Exception {
+ List<String> ids;
+ Either<List<ComponentCacheData>, ActionStatus> result;
+
+ // test 1
+ ids = null;
+ result = testSubject.getComponents(ids);
+
+
+ // test 2
+ ids = new LinkedList<>();
+ result = testSubject.getComponents(ids);
+
+ Session sessMock = Mockito.mock(Session.class);
+ MappingManager mappMock = Mockito.mock(MappingManager.class);
+ ComponentCacheAccessor componentCacheAccessorMock = Mockito.mock(ComponentCacheAccessor.class);
+ ImmutablePair<Session, MappingManager> ipMock = ImmutablePair.of(sessMock, mappMock);
+
+ Mockito.when(clientMock.isConnected()).thenReturn(true);
+ Either<ImmutablePair<Session, MappingManager>, CassandraOperationStatus> value = Either.left(ipMock);
+ Mockito.when(clientMock.connect(Mockito.any())).thenReturn(value);
+ Mockito.when(mappMock.createAccessor(ComponentCacheAccessor.class)).thenReturn(componentCacheAccessorMock);
+
+ Result<ComponentCacheData> value2 = Mockito.mock(Result.class);
+ Mockito.when(componentCacheAccessorMock.getComponents(Mockito.any())).thenReturn(value2);
+ List<ComponentCacheData> value3 = new LinkedList<>();
+ value3.add(new ComponentCacheData("mock"));
+ Mockito.when(value2.all()).thenReturn(value3);
+ testSubject.init();
+
+ ids.add("mock");
+ testSubject.getComponents(ids);
+ }
+
+ @Test
+ public void testGetComponentsNull() throws Exception {
+ List<String> ids = new LinkedList<>();
+ Either<List<ComponentCacheData>, ActionStatus> result;
+
+ Session sessMock = Mockito.mock(Session.class);
+ MappingManager mappMock = Mockito.mock(MappingManager.class);
+ ComponentCacheAccessor componentCacheAccessorMock = Mockito.mock(ComponentCacheAccessor.class);
+ ImmutablePair<Session, MappingManager> ipMock = ImmutablePair.of(sessMock, mappMock);
+
+ Mockito.when(clientMock.isConnected()).thenReturn(true);
+ Either<ImmutablePair<Session, MappingManager>, CassandraOperationStatus> value = Either.left(ipMock);
+ Mockito.when(clientMock.connect(Mockito.any())).thenReturn(value);
+ Mockito.when(mappMock.createAccessor(ComponentCacheAccessor.class)).thenReturn(componentCacheAccessorMock);
+
+ Mockito.when(componentCacheAccessorMock.getComponents(Mockito.any())).thenReturn(null);
+ testSubject.init();
+
+ ids.add("mock");
+ testSubject.getComponents(ids);
+ }
+
+ @Test
+ public void testGetComponentsException() throws Exception {
+ List<String> ids = new LinkedList<>();
+ Either<List<ComponentCacheData>, ActionStatus> result;
+
+ Session sessMock = Mockito.mock(Session.class);
+ MappingManager mappMock = Mockito.mock(MappingManager.class);
+ ComponentCacheAccessor componentCacheAccessorMock = Mockito.mock(ComponentCacheAccessor.class);
+ ImmutablePair<Session, MappingManager> ipMock = ImmutablePair.of(sessMock, mappMock);
+
+ Mockito.when(clientMock.isConnected()).thenReturn(true);
+ Either<ImmutablePair<Session, MappingManager>, CassandraOperationStatus> value = Either.left(ipMock);
+ Mockito.when(clientMock.connect(Mockito.any())).thenReturn(value);
+ Mockito.when(mappMock.createAccessor(ComponentCacheAccessor.class)).thenReturn(componentCacheAccessorMock);
+
+ Mockito.when(componentCacheAccessorMock.getComponents(Mockito.any())).thenThrow(RuntimeException.class);
+ testSubject.init();
+
+ ids.add("mock");
+ testSubject.getComponents(ids);
}
@Test
public void testGetAllComponentIdTimeAndType() throws Exception {
- ComponentCassandraDao testSubject;
Either<List<ComponentCacheData>, ActionStatus> result;
// default test
- testSubject = createTestSubject();
result = testSubject.getAllComponentIdTimeAndType();
+
+ Session sessMock = Mockito.mock(Session.class);
+ MappingManager mappMock = Mockito.mock(MappingManager.class);
+ ComponentCacheAccessor componentCacheAccessorMock = Mockito.mock(ComponentCacheAccessor.class);
+ ImmutablePair<Session, MappingManager> ipMock = ImmutablePair.of(sessMock, mappMock);
+
+ Mockito.when(clientMock.isConnected()).thenReturn(true);
+ Either<ImmutablePair<Session, MappingManager>, CassandraOperationStatus> value = Either.left(ipMock);
+ Mockito.when(clientMock.connect(Mockito.any())).thenReturn(value);
+ Mockito.when(mappMock.createAccessor(ComponentCacheAccessor.class)).thenReturn(componentCacheAccessorMock);
+
+ Result<ComponentCacheData> value2 = Mockito.mock(Result.class);
+ Mockito.when(componentCacheAccessorMock.getAllComponentIdTimeAndType()).thenReturn(value2);
+ List<ComponentCacheData> value3 = new LinkedList<>();
+ value3.add(new ComponentCacheData("mock"));
+ Mockito.when(value2.all()).thenReturn(value3);
+ testSubject.init();
+
+ testSubject.getAllComponentIdTimeAndType();
}
+ @Test
+ public void testGetAllComponentIdTimeAndTypeNull() throws Exception {
+ Either<List<ComponentCacheData>, ActionStatus> result;
+
+ // default test
+ result = testSubject.getAllComponentIdTimeAndType();
+
+ Session sessMock = Mockito.mock(Session.class);
+ MappingManager mappMock = Mockito.mock(MappingManager.class);
+ ComponentCacheAccessor componentCacheAccessorMock = Mockito.mock(ComponentCacheAccessor.class);
+ ImmutablePair<Session, MappingManager> ipMock = ImmutablePair.of(sessMock, mappMock);
+
+ Mockito.when(clientMock.isConnected()).thenReturn(true);
+ Either<ImmutablePair<Session, MappingManager>, CassandraOperationStatus> value = Either.left(ipMock);
+ Mockito.when(clientMock.connect(Mockito.any())).thenReturn(value);
+ Mockito.when(mappMock.createAccessor(ComponentCacheAccessor.class)).thenReturn(componentCacheAccessorMock);
+
+ Mockito.when(componentCacheAccessorMock.getAllComponentIdTimeAndType()).thenReturn(null);
+ testSubject.init();
+
+ result = testSubject.getAllComponentIdTimeAndType();
+ }
+ @Test
+ public void testGetComponent() throws Exception {
+ String id = "";
+ Either<ComponentCacheData, ActionStatus> result;
+ // test 1
+ id = null;
+ result = testSubject.getComponent(id);
+ //Assert.assertEquals(null, result);
+ // test 2
+ id = "";
+ result = testSubject.getComponent(id);
+ //Assert.assertEquals(null, result);
+
+ Session sessMock = Mockito.mock(Session.class);
+ MappingManager mappMock = Mockito.mock(MappingManager.class);
+ ComponentCacheAccessor componentCacheAccessorMock = Mockito.mock(ComponentCacheAccessor.class);
+ ImmutablePair<Session, MappingManager> ipMock = ImmutablePair.of(sessMock, mappMock);
+
+ Mockito.when(clientMock.isConnected()).thenReturn(true);
+ Either<ImmutablePair<Session, MappingManager>, CassandraOperationStatus> value = Either.left(ipMock);
+ Mockito.when(clientMock.connect(Mockito.any())).thenReturn(value);
+ Mockito.when(mappMock.createAccessor(ComponentCacheAccessor.class)).thenReturn(componentCacheAccessorMock);
+
+ Result<ComponentCacheData> value2 = Mockito.mock(Result.class);
+ Mockito.when(componentCacheAccessorMock.getComponent(Mockito.any())).thenReturn(value2);
+ ComponentCacheData value3 = new ComponentCacheData();
+ Mockito.when(value2.one()).thenReturn(value3);
+ testSubject.init();
+
+ result = testSubject.getComponent(id);
+ }
+ @Test
+ public void testGetComponentNull1() throws Exception {
+ String id = "";
+ Either<ComponentCacheData, ActionStatus> result;
+
+ Session sessMock = Mockito.mock(Session.class);
+ MappingManager mappMock = Mockito.mock(MappingManager.class);
+ ComponentCacheAccessor componentCacheAccessorMock = Mockito.mock(ComponentCacheAccessor.class);
+ ImmutablePair<Session, MappingManager> ipMock = ImmutablePair.of(sessMock, mappMock);
+
+ Mockito.when(clientMock.isConnected()).thenReturn(true);
+ Either<ImmutablePair<Session, MappingManager>, CassandraOperationStatus> value = Either.left(ipMock);
+ Mockito.when(clientMock.connect(Mockito.any())).thenReturn(value);
+ Mockito.when(mappMock.createAccessor(ComponentCacheAccessor.class)).thenReturn(componentCacheAccessorMock);
+
+ Mockito.when(componentCacheAccessorMock.getComponent(Mockito.any())).thenReturn(null);
+ testSubject.init();
+
+ result = testSubject.getComponent(id);
+ }
+
+ @Test
+ public void testGetComponentNull2() throws Exception {
+ String id = "";
+ Either<ComponentCacheData, ActionStatus> result;
+ // test 1
+ id = null;
+ result = testSubject.getComponent(id);
+ //Assert.assertEquals(null, result);
+
+ // test 2
+ id = "";
+ result = testSubject.getComponent(id);
+ //Assert.assertEquals(null, result);
+
+ Session sessMock = Mockito.mock(Session.class);
+ MappingManager mappMock = Mockito.mock(MappingManager.class);
+ ComponentCacheAccessor componentCacheAccessorMock = Mockito.mock(ComponentCacheAccessor.class);
+ ImmutablePair<Session, MappingManager> ipMock = ImmutablePair.of(sessMock, mappMock);
+
+ Mockito.when(clientMock.isConnected()).thenReturn(true);
+ Either<ImmutablePair<Session, MappingManager>, CassandraOperationStatus> value = Either.left(ipMock);
+ Mockito.when(clientMock.connect(Mockito.any())).thenReturn(value);
+ Mockito.when(mappMock.createAccessor(ComponentCacheAccessor.class)).thenReturn(componentCacheAccessorMock);
+
+ Result<ComponentCacheData> value2 = Mockito.mock(Result.class);
+ Mockito.when(componentCacheAccessorMock.getComponent(Mockito.any())).thenReturn(value2);
+ Mockito.when(value2.one()).thenReturn(null);
+ testSubject.init();
+
+ result = testSubject.getComponent(id);
+ }
@Test
+ public void testSaveComponent() throws Exception {
+ ComponentCacheData componentCacheData = null;
+ CassandraOperationStatus result;
+
+ // default test
+ result = testSubject.saveComponent(componentCacheData);
+ }
+
+ @Test
public void testIsTableEmpty() throws Exception {
- ComponentCassandraDao testSubject;
String tableName = "";
Either<Boolean, CassandraOperationStatus> result;
// default test
- testSubject = createTestSubject();
result = testSubject.isTableEmpty(tableName);
}
-
+ @Test
+ public void testGetComponents_1() throws Exception {
+ Map<String, Long> idToTimestampMap = null;
+ Either<ImmutablePair<List<ComponentCacheData>, Set<String>>, ActionStatus> result;
+
+ // test 1
+ idToTimestampMap = null;
+ result = testSubject.getComponents(idToTimestampMap);
+ //Assert.assertEquals(null, result);
+
+ Session sessMock = Mockito.mock(Session.class);
+ MappingManager mappMock = Mockito.mock(MappingManager.class);
+ ComponentCacheAccessor componentCacheAccessorMock = Mockito.mock(ComponentCacheAccessor.class);
+ ImmutablePair<Session, MappingManager> ipMock = ImmutablePair.of(sessMock, mappMock);
+
+ Mockito.when(clientMock.isConnected()).thenReturn(true);
+ Either<ImmutablePair<Session, MappingManager>, CassandraOperationStatus> value = Either.left(ipMock);
+ Mockito.when(clientMock.connect(Mockito.any())).thenReturn(value);
+ Mockito.when(mappMock.createAccessor(ComponentCacheAccessor.class)).thenReturn(componentCacheAccessorMock);
+
+ Result<ComponentCacheData> value2 = Mockito.mock(Result.class);
+ Mockito.when(componentCacheAccessorMock.getComponents(Mockito.any(List.class))).thenReturn(value2);
+ List<ComponentCacheData> value3 = new LinkedList<>();
+ ComponentCacheData e = new ComponentCacheData("mock");
+ Mockito.when(value2.all()).thenReturn(value3);
+ testSubject.init();
+
+ idToTimestampMap = new HashMap<>();
+ idToTimestampMap.put("mock", 0L);
+ e.setModificationTime(new Date());
+ value3.add(e);
+ result = testSubject.getComponents(idToTimestampMap);
+ }
+ @Test
+ public void testGetComponents_1Null() throws Exception {
+ Map<String, Long> idToTimestampMap = null;
+ Either<ImmutablePair<List<ComponentCacheData>, Set<String>>, ActionStatus> result;
+
+ Session sessMock = Mockito.mock(Session.class);
+ MappingManager mappMock = Mockito.mock(MappingManager.class);
+ ComponentCacheAccessor componentCacheAccessorMock = Mockito.mock(ComponentCacheAccessor.class);
+ ImmutablePair<Session, MappingManager> ipMock = ImmutablePair.of(sessMock, mappMock);
+
+ Mockito.when(clientMock.isConnected()).thenReturn(true);
+ Either<ImmutablePair<Session, MappingManager>, CassandraOperationStatus> value = Either.left(ipMock);
+ Mockito.when(clientMock.connect(Mockito.any())).thenReturn(value);
+ Mockito.when(mappMock.createAccessor(ComponentCacheAccessor.class)).thenReturn(componentCacheAccessorMock);
+
+ Mockito.when(componentCacheAccessorMock.getComponents(Mockito.any(List.class))).thenReturn(null);
+ testSubject.init();
+
+ idToTimestampMap = new HashMap<>();
+ idToTimestampMap.put("mock", 0L);
+ result = testSubject.getComponents(idToTimestampMap);
+ }
+
+ @Test
+ public void testGetComponents_1Exception() throws Exception {
+ Map<String, Long> idToTimestampMap = null;
+ Either<ImmutablePair<List<ComponentCacheData>, Set<String>>, ActionStatus> result;
+
+ Session sessMock = Mockito.mock(Session.class);
+ MappingManager mappMock = Mockito.mock(MappingManager.class);
+ ComponentCacheAccessor componentCacheAccessorMock = Mockito.mock(ComponentCacheAccessor.class);
+ ImmutablePair<Session, MappingManager> ipMock = ImmutablePair.of(sessMock, mappMock);
+
+ Mockito.when(clientMock.isConnected()).thenReturn(true);
+ Either<ImmutablePair<Session, MappingManager>, CassandraOperationStatus> value = Either.left(ipMock);
+ Mockito.when(clientMock.connect(Mockito.any())).thenReturn(value);
+ Mockito.when(mappMock.createAccessor(ComponentCacheAccessor.class)).thenReturn(componentCacheAccessorMock);
+
+ Mockito.when(componentCacheAccessorMock.getComponents(Mockito.any(List.class))).thenThrow(RuntimeException.class);
+ testSubject.init();
+
+ idToTimestampMap = new HashMap<>();
+ idToTimestampMap.put("mock", 0L);
+ result = testSubject.getComponents(idToTimestampMap);
+ }
+ @Test
+ public void testDeleteComponent() throws Exception {
+ String id = "";
+ CassandraOperationStatus result;
+ // default test
+ result = testSubject.deleteComponent(id);
+ }
} \ No newline at end of file
diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/OperationalEnvironmentDaoTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/OperationalEnvironmentDaoTest.java
new file mode 100644
index 0000000000..12418a44fd
--- /dev/null
+++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/OperationalEnvironmentDaoTest.java
@@ -0,0 +1,161 @@
+package org.openecomp.sdc.be.dao.cassandra;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
+import org.apache.commons.lang3.tuple.ImmutablePair;
+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.datatypes.enums.EnvironmentStatusEnum;
+import org.openecomp.sdc.be.resources.data.OperationalEnvironmentEntry;
+
+import com.datastax.driver.core.Session;
+import com.datastax.driver.mapping.MappingManager;
+import com.datastax.driver.mapping.Result;
+
+import fj.data.Either;
+
+public class OperationalEnvironmentDaoTest {
+
+ @InjectMocks
+ OperationalEnvironmentDao testSubject;
+
+ @Mock
+ CassandraClient clientMock;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void testInit() throws Exception {
+
+ // default test
+ testSubject.init();
+
+ Mockito.when(clientMock.isConnected()).thenReturn(true);
+ Session sessMock = Mockito.mock(Session.class);
+ MappingManager mappMock = Mockito.mock(MappingManager.class);
+ ImmutablePair<Session, MappingManager> ipMock = ImmutablePair.of(sessMock, mappMock);
+ Either<ImmutablePair<Session, MappingManager>, CassandraOperationStatus> value = Either.left(ipMock);
+ Mockito.when(clientMock.connect(Mockito.any())).thenReturn(value);
+ testSubject.init();
+ }
+
+ @Test
+ public void testInitException() throws Exception {
+
+ // default test
+ testSubject.init();
+
+ Mockito.when(clientMock.isConnected()).thenReturn(true);
+ Either<ImmutablePair<Session, MappingManager>, CassandraOperationStatus> value = Either
+ .right(CassandraOperationStatus.CLUSTER_NOT_CONNECTED);
+ Mockito.when(clientMock.connect(Mockito.any())).thenReturn(value);
+ try {
+ testSubject.init();
+ } catch (Exception e) {
+ assertTrue(e.getClass() == RuntimeException.class);
+ }
+ }
+
+ @Test
+ public void testSave() throws Exception {
+ OperationalEnvironmentEntry operationalEnvironmentEntry = null;
+ CassandraOperationStatus result;
+
+ // default test
+ result = testSubject.save(operationalEnvironmentEntry);
+ }
+
+ @Test
+ public void testGet() throws Exception {
+ String envId = "";
+ Either<OperationalEnvironmentEntry, CassandraOperationStatus> result;
+
+ // default test
+ result = testSubject.get(envId);
+ }
+
+ @Test
+ public void testDelete() throws Exception {
+ String envId = "";
+ CassandraOperationStatus result;
+
+ // default test
+ result = testSubject.delete(envId);
+ }
+
+ @Test
+ public void testDeleteAll() throws Exception {
+ CassandraOperationStatus result;
+
+ // default test
+ result = testSubject.deleteAll();
+
+ Mockito.when(clientMock.isConnected()).thenReturn(true);
+ Session sessMock = Mockito.mock(Session.class);
+ MappingManager mappMock = Mockito.mock(MappingManager.class);
+ ImmutablePair<Session, MappingManager> ipMock = ImmutablePair.of(sessMock, mappMock);
+ Either<ImmutablePair<Session, MappingManager>, CassandraOperationStatus> value = Either.left(ipMock);
+ Mockito.when(clientMock.connect(Mockito.any())).thenReturn(value);
+ testSubject.init();
+
+ result = testSubject.deleteAll();
+ }
+
+ @Test
+ public void testIsTableEmpty() throws Exception {
+ String tableName = "";
+ Either<Boolean, CassandraOperationStatus> result;
+
+ // default test
+ result = testSubject.isTableEmpty(tableName);
+ }
+
+ @Test
+ public void testGetByEnvironmentsStatus() throws Exception {
+ Either<List<OperationalEnvironmentEntry>, CassandraOperationStatus> result;
+
+ Mockito.when(clientMock.isConnected()).thenReturn(true);
+ Session sessMock = Mockito.mock(Session.class);
+ MappingManager mappMock = Mockito.mock(MappingManager.class);
+ ImmutablePair<Session, MappingManager> ipMock = ImmutablePair.of(sessMock, mappMock);
+ Either<ImmutablePair<Session, MappingManager>, CassandraOperationStatus> value = Either.left(ipMock);
+ Mockito.when(clientMock.connect(Mockito.any())).thenReturn(value);
+ OperationalEnvironmentsAccessor value2 = Mockito.mock(OperationalEnvironmentsAccessor.class);
+ Mockito.when(mappMock.createAccessor(OperationalEnvironmentsAccessor.class)).thenReturn(value2);
+ Result<OperationalEnvironmentEntry> value3 = Mockito.mock(Result.class);
+ Mockito.when(value2.getByEnvironmentsStatus(Mockito.any(String.class))).thenReturn(value3);
+ testSubject.init();
+
+ // default test
+ result = testSubject.getByEnvironmentsStatus(EnvironmentStatusEnum.COMPLETED);
+ }
+
+ @Test
+ public void testGetByEnvironmentsStatusNull() throws Exception {
+ Either<List<OperationalEnvironmentEntry>, CassandraOperationStatus> result;
+
+ Mockito.when(clientMock.isConnected()).thenReturn(true);
+ Session sessMock = Mockito.mock(Session.class);
+ MappingManager mappMock = Mockito.mock(MappingManager.class);
+ ImmutablePair<Session, MappingManager> ipMock = ImmutablePair.of(sessMock, mappMock);
+ Either<ImmutablePair<Session, MappingManager>, CassandraOperationStatus> value = Either.left(ipMock);
+ Mockito.when(clientMock.connect(Mockito.any())).thenReturn(value);
+ OperationalEnvironmentsAccessor value2 = Mockito.mock(OperationalEnvironmentsAccessor.class);
+ Mockito.when(mappMock.createAccessor(OperationalEnvironmentsAccessor.class)).thenReturn(value2);
+ Result<OperationalEnvironmentEntry> value3 = null;
+ Mockito.when(value2.getByEnvironmentsStatus(Mockito.any(String.class))).thenReturn(value3);
+ testSubject.init();
+
+ // default test
+ result = testSubject.getByEnvironmentsStatus(EnvironmentStatusEnum.COMPLETED);
+ }
+} \ No newline at end of file
diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/SdcSchemaFilesCassandraDaoTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/SdcSchemaFilesCassandraDaoTest.java
index 96e8a7e70b..402cfc56d8 100644
--- a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/SdcSchemaFilesCassandraDaoTest.java
+++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/SdcSchemaFilesCassandraDaoTest.java
@@ -1,53 +1,130 @@
package org.openecomp.sdc.be.dao.cassandra;
+import static org.junit.Assert.assertTrue;
+
import java.util.List;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+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.resources.data.SdcSchemaFilesData;
+import com.datastax.driver.core.Session;
+import com.datastax.driver.mapping.MappingManager;
+
import fj.data.Either;
public class SdcSchemaFilesCassandraDaoTest {
- private SdcSchemaFilesCassandraDao createTestSubject() {
- return new SdcSchemaFilesCassandraDao();
+ @InjectMocks
+ SdcSchemaFilesCassandraDao testSubject;
+
+ @Mock
+ CassandraClient clientMock;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void testInit() throws Exception {
+
+ // default test
+ testSubject.init();
+
+ Mockito.when(clientMock.isConnected()).thenReturn(true);
+ Session sessMock = Mockito.mock(Session.class);
+ MappingManager mappMock = Mockito.mock(MappingManager.class);
+ ImmutablePair<Session, MappingManager> ipMock = ImmutablePair.of(sessMock, mappMock);
+ Either<ImmutablePair<Session, MappingManager>, CassandraOperationStatus> value = Either.left(ipMock);
+ Mockito.when(clientMock.connect(Mockito.any())).thenReturn(value);
+ testSubject.init();
+ }
+
+ @Test
+ public void testInitException() throws Exception {
+
+ // default test
+ testSubject.init();
+
+ Mockito.when(clientMock.isConnected()).thenReturn(true);
+ Either<ImmutablePair<Session, MappingManager>, CassandraOperationStatus> value = Either
+ .right(CassandraOperationStatus.CLUSTER_NOT_CONNECTED);
+ Mockito.when(clientMock.connect(Mockito.any())).thenReturn(value);
+ try {
+ testSubject.init();
+ } catch (Exception e) {
+ assertTrue(e.getClass() == RuntimeException.class);
+ }
+ }
+
+ @Test
+ public void testSaveSchemaFile() throws Exception {
+ SdcSchemaFilesData schemaFileData = null;
+ CassandraOperationStatus result;
+
+ // default test
+ result = testSubject.saveSchemaFile(schemaFileData);
}
+
+ @Test
+ public void testGetSchemaFile() throws Exception {
+ String schemaFileId = null;
+ Either<SdcSchemaFilesData, CassandraOperationStatus> result;
+ // default test
+ result = testSubject.getSchemaFile(schemaFileId);
+ }
+
+ @Test
+ public void testDeleteSchemaFile() throws Exception {
+ String schemaFileId = null;
+ CassandraOperationStatus result;
+ // default test
+ result = testSubject.deleteSchemaFile(schemaFileId);
+ }
@Test
public void testGetSpecificSchemaFiles() throws Exception {
- SdcSchemaFilesCassandraDao testSubject;
String sdcreleasenum = "";
String conformancelevel = "";
Either<List<SdcSchemaFilesData>, CassandraOperationStatus> result;
// default test
- testSubject = createTestSubject();
result = testSubject.getSpecificSchemaFiles(sdcreleasenum, conformancelevel);
}
-
@Test
- public void testDeleteAllArtifacts() throws Exception {
- SdcSchemaFilesCassandraDao testSubject;
+ public void testDeleteAll() throws Exception {
CassandraOperationStatus result;
// default test
- testSubject = createTestSubject();
+ result = testSubject.deleteAllArtifacts();
+
+ Mockito.when(clientMock.isConnected()).thenReturn(true);
+ Session sessMock = Mockito.mock(Session.class);
+ MappingManager mappMock = Mockito.mock(MappingManager.class);
+ ImmutablePair<Session, MappingManager> ipMock = ImmutablePair.of(sessMock, mappMock);
+ Either<ImmutablePair<Session, MappingManager>, CassandraOperationStatus> value = Either.left(ipMock);
+ Mockito.when(clientMock.connect(Mockito.any())).thenReturn(value);
+ testSubject.init();
+
result = testSubject.deleteAllArtifacts();
}
-
@Test
public void testIsTableEmpty() throws Exception {
- SdcSchemaFilesCassandraDao testSubject;
String tableName = "";
Either<Boolean, CassandraOperationStatus> result;
// default test
- testSubject = createTestSubject();
result = testSubject.isTableEmpty(tableName);
}
} \ No newline at end of file
diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/utils/DAOConfDependentTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/utils/DAOConfDependentTest.java
new file mode 100644
index 0000000000..4759d5ba26
--- /dev/null
+++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/utils/DAOConfDependentTest.java
@@ -0,0 +1,13 @@
+package org.openecomp.sdc.be.utils;
+
+import org.junit.BeforeClass;
+import org.openecomp.sdc.common.test.BaseConfDependent;
+
+public class DAOConfDependentTest extends BaseConfDependent {
+ @BeforeClass
+ public static void setupBeforeClass() {
+ componentName = "catalog-dao";
+ confPath = "src/test/resources/config";
+ setUp();
+ }
+}