aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src/test/java')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngineTest.java159
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/DummyDistributionConfigurationManager.java2
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/EnvironmentsEngineTest.java279
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/ServiceDistributionArtifactsBuilderTest.java169
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java13
5 files changed, 241 insertions, 381 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngineTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngineTest.java
index 566a8983b9..403c136122 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngineTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngineTest.java
@@ -7,6 +7,7 @@ import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
import java.util.HashSet;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -20,9 +21,12 @@ import org.junit.Test;
import org.mockito.ArgumentMatchers;
import org.mockito.InjectMocks;
import org.mockito.Mock;
+import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
+import org.openecomp.sdc.be.components.BeConfDependentTest;
import org.openecomp.sdc.be.components.utils.OperationalEnvironmentBuilder;
import org.openecomp.sdc.be.config.DistributionEngineConfiguration;
+import org.openecomp.sdc.be.config.DistributionEngineConfiguration.CreateTopicConfig;
import org.openecomp.sdc.be.config.DistributionEngineConfiguration.DistributionStatusTopicConfig;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.model.Service;
@@ -31,7 +35,7 @@ import org.openecomp.sdc.be.resources.data.OperationalEnvironmentEntry;
import mockit.Deencapsulation;
-public class DistributionEngineTest{
+public class DistributionEngineTest extends BeConfDependentTest{
public static final String DISTRIBUTION_ID = "distId";
public static final String ENV_ID = "envId";
@@ -46,10 +50,13 @@ public class DistributionEngineTest{
@Mock
private DistributionNotificationSender distributionNotificationSender;
-
+
@Mock
private ServiceDistributionArtifactsBuilder serviceDistributionArtifactsBuilder;
-
+
+ @Mock
+ private DistributionEngineClusterHealth distributionEngineClusterHealth;
+
private DummyDistributionConfigurationManager distributionEngineConfigurationMock;
private Map<String, OperationalEnvironmentEntry> envs;
@@ -108,17 +115,58 @@ public class DistributionEngineTest{
.collect(Collectors.toMap(OperationalEnvironmentEntry::getEnvironmentId, Function.identity()));
}
- private DistributionEngine createTestSubject() {
- return new DistributionEngine();
+ @Test
+ public void testIsActive() throws Exception {
+ // default test
+ testInstance.isActive();
}
+
+ @Test
+ public void testInitDisabled() throws Exception {
+ // default test
+ Deencapsulation.invoke(testInstance, "init");
+ }
+
+ @Test
+ public void testInitNotValidConfig() throws Exception {
+ DistributionEngine testSubject;
- @Test(expected=NullPointerException.class)
+ // default test
+ Mockito.when(distributionEngineConfigurationMock.getConfigurationMock().isStartDistributionEngine())
+ .thenReturn(true);
+ Mockito.when(distributionEngineConfigurationMock.configurationMock.getDistributionStatusTopic())
+ .thenReturn(new DistributionStatusTopicConfig());
+ Deencapsulation.invoke(testInstance, "init");
+ }
+
+ @Test
public void testInit() throws Exception {
DistributionEngine testSubject;
// default test
- testSubject = createTestSubject();
- Deencapsulation.invoke(testSubject, "init");
+ Mockito.when(distributionEngineConfigurationMock.getConfigurationMock().isStartDistributionEngine())
+ .thenReturn(true);
+ DistributionStatusTopicConfig value = new DistributionStatusTopicConfig();
+ value.setConsumerId("mock");
+ value.setConsumerGroup("mock");
+ value.setFetchTimeSec(0);
+ value.setPollingIntervalSec(0);
+ LinkedList<String> value2 = new LinkedList<>();
+ value2.add("uebsb91kcdc.it.att.com:3904");
+ value2.add("uebsb92kcdc.it.att.com:3904");
+ Mockito.when(distributionEngineConfigurationMock.configurationMock.getUebServers()).thenReturn(value2);
+ Mockito.when(distributionEngineConfigurationMock.configurationMock.getEnvironments()).thenReturn(value2);
+ Mockito.when(distributionEngineConfigurationMock.configurationMock.getUebPublicKey()).thenReturn("mock");
+ Mockito.when(distributionEngineConfigurationMock.configurationMock.getUebSecretKey()).thenReturn("mock");
+ Mockito.when(distributionEngineConfigurationMock.configurationMock.getDistributionNotifTopicName())
+ .thenReturn("mock");
+ Mockito.when(distributionEngineConfigurationMock.configurationMock.getDistributionStatusTopicName())
+ .thenReturn("mock");
+ Mockito.when(distributionEngineConfigurationMock.configurationMock.getCreateTopic())
+ .thenReturn(new CreateTopicConfig());
+ Mockito.when(distributionEngineConfigurationMock.configurationMock.getDistributionStatusTopic())
+ .thenReturn(value);
+ Deencapsulation.invoke(testInstance, "init");
}
@Test
@@ -126,109 +174,94 @@ public class DistributionEngineTest{
DistributionEngine testSubject;
// default test
- testSubject = createTestSubject();
- testSubject.shutdown();
+ testInstance.shutdown();
}
@Test
public void testValidateConfiguration() throws Exception {
- DistributionEngine testSubject;
DistributionEngineConfiguration deConfiguration = new DistributionEngineConfiguration();
deConfiguration.setDistributionStatusTopic((new DistributionStatusTopicConfig()));
boolean result;
// default test
- testSubject = createTestSubject();
- result = Deencapsulation.invoke(testSubject, "validateConfiguration", deConfiguration);
+ result = Deencapsulation.invoke(testInstance, "validateConfiguration", deConfiguration);
}
@Test
public void testIsValidServers() throws Exception {
- DistributionEngine testSubject;
List<String> uebServers = null;
String methodName = "";
String paramName = "";
boolean result;
// test 1
- testSubject = createTestSubject();
uebServers = null;
- result = Deencapsulation.invoke(testSubject, "isValidServers",
+ result = Deencapsulation.invoke(testInstance, "isValidServers",
new Object[] { List.class, methodName, paramName });
Assert.assertEquals(false, result);
}
@Test
public void testIsValidFqdn() throws Exception {
- DistributionEngine testSubject;
String serverFqdn = "";
boolean result;
// default test
- testSubject = createTestSubject();
- result = Deencapsulation.invoke(testSubject, "isValidFqdn", new Object[] { serverFqdn });
+ result = Deencapsulation.invoke(testInstance, "isValidFqdn", new Object[] { serverFqdn });
}
@Test
public void testIsValidParam() throws Exception {
- DistributionEngine testSubject;
String paramValue = "";
String methodName = "";
String paramName = "";
boolean result;
// default test
- testSubject = createTestSubject();
- result = Deencapsulation.invoke(testSubject, "isValidParam",
+ result = Deencapsulation.invoke(testInstance, "isValidParam",
new Object[] { paramValue, methodName, paramName });
}
@Test
public void testIsValidParam_1() throws Exception {
- DistributionEngine testSubject;
List<String> paramValue = null;
String methodName = "";
String paramName = "";
boolean result;
// default test
- testSubject = createTestSubject();
- result = Deencapsulation.invoke(testSubject, "isValidParam",
+ result = Deencapsulation.invoke(testInstance, "isValidParam",
new Object[] { List.class, methodName, paramName });
}
@Test
public void testIsValidObject() throws Exception {
- DistributionEngine testSubject;
Object paramValue = null;
String methodName = "";
String paramName = "";
boolean result;
// test 1
- testSubject = createTestSubject();
paramValue = null;
- result = Deencapsulation.invoke(testSubject, "isValidObject",
+ result = Deencapsulation.invoke(testInstance, "isValidObject",
new Object[] { Object.class, methodName, paramName });
Assert.assertEquals(false, result);
}
@Test
public void testGetEnvironmentErrorDescription() throws Exception {
- DistributionEngine testSubject;
StorageOperationStatus status = null;
String result;
// default test
- testSubject = createTestSubject();
- result = Deencapsulation.invoke(testSubject, "getEnvironmentErrorDescription",
- StorageOperationStatus.DISTR_ENVIRONMENT_NOT_AVAILABLE);
- result = Deencapsulation.invoke(testSubject, "getEnvironmentErrorDescription",
- StorageOperationStatus.DISTR_ENVIRONMENT_NOT_FOUND);
- result = Deencapsulation.invoke(testSubject, "getEnvironmentErrorDescription",
- StorageOperationStatus.DISTR_ENVIRONMENT_SENT_IS_INVALID);
- result = Deencapsulation.invoke(testSubject, "getEnvironmentErrorDescription",
- StorageOperationStatus.ARTIFACT_NOT_FOUND);
+ result = Deencapsulation.invoke(testInstance, "getEnvironmentErrorDescription",
+ StorageOperationStatus.DISTR_ENVIRONMENT_NOT_AVAILABLE);
+ result = Deencapsulation.invoke(testInstance, "getEnvironmentErrorDescription",
+ StorageOperationStatus.DISTR_ENVIRONMENT_NOT_FOUND);
+ result = Deencapsulation.invoke(testInstance, "getEnvironmentErrorDescription",
+ StorageOperationStatus.DISTR_ENVIRONMENT_SENT_IS_INVALID);
+ result = Deencapsulation.invoke(testInstance, "getEnvironmentErrorDescription",
+ StorageOperationStatus.ARTIFACT_NOT_FOUND);
}
@Test
@@ -238,60 +271,44 @@ public class DistributionEngineTest{
StorageOperationStatus result;
// test 1
- testSubject = createTestSubject();
envName = null;
- result = testSubject.isEnvironmentAvailable(envName);
+ result = testInstance.isEnvironmentAvailable(envName);
Assert.assertEquals(StorageOperationStatus.DISTR_ENVIRONMENT_SENT_IS_INVALID, result);
// test 2
- testSubject = createTestSubject();
envName = "mock";
- result = testSubject.isEnvironmentAvailable(envName);
+ result = testInstance.isEnvironmentAvailable(envName);
Assert.assertEquals(StorageOperationStatus.DISTR_ENVIRONMENT_NOT_FOUND, result);
}
- //TODO Create test coverage for this method
- /*@Test
+ @Test
public void testIsEnvironmentAvailable_1() throws Exception {
DistributionEngine testSubject;
StorageOperationStatus result;
- // default test
- testSubject = createTestSubject();
- result = testInstance.isEnvironmentAvailable();
- }*/
-
- @Test(expected=NullPointerException.class)
- public void testDisableEnvironment() throws Exception {
- DistributionEngine testSubject;
- String envName = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.disableEnvironment(envName);
+ LinkedList<String> value = new LinkedList<>();
+ value.add("mock");
+ Mockito.when(distributionEngineConfigurationMock.configurationMock.getEnvironments()).thenReturn(value);
+ testInstance.isEnvironmentAvailable();
}
@Test
public void testBuildTopicName() throws Exception {
- DistributionEngine testSubject;
String envName = "";
String result;
// default test
- testSubject = createTestSubject();
- result = Deencapsulation.invoke(testSubject, "buildTopicName", new Object[] { envName });
+ result = Deencapsulation.invoke(testInstance, "buildTopicName", new Object[] { envName });
}
@Test
public void testIsReadyForDistribution() throws Exception {
- DistributionEngine testSubject;
Service service = null;
String envName = "";
StorageOperationStatus result;
// default test
- testSubject = createTestSubject();
- result = testSubject.isReadyForDistribution(service, envName);
+ result = testInstance.isReadyForDistribution(service, envName);
}
@Test
@@ -300,17 +317,19 @@ public class DistributionEngineTest{
StorageOperationStatus result;
// default test
- when(serviceDistributionArtifactsBuilder.verifyServiceContainsDeploymentArtifacts(ArgumentMatchers.any(Service.class))).thenReturn(true);
+ when(serviceDistributionArtifactsBuilder
+ .verifyServiceContainsDeploymentArtifacts(ArgumentMatchers.any(Service.class))).thenReturn(true);
result = testInstance.verifyServiceHasDeploymentArtifacts(service);
}
-
+
@Test
public void testVerifyServiceHasDeploymentArtifactsFalse() throws Exception {
Service service = new Service();
StorageOperationStatus result;
// default test
- when(serviceDistributionArtifactsBuilder.verifyServiceContainsDeploymentArtifacts(ArgumentMatchers.any(Service.class))).thenReturn(false);
+ when(serviceDistributionArtifactsBuilder
+ .verifyServiceContainsDeploymentArtifacts(ArgumentMatchers.any(Service.class))).thenReturn(false);
result = testInstance.verifyServiceHasDeploymentArtifacts(service);
}
@@ -321,7 +340,8 @@ public class DistributionEngineTest{
OperationalEnvironmentEntry result;
// default test
- when(environmentsEngine.getEnvironmentById(ArgumentMatchers.anyString())).thenReturn(new OperationalEnvironmentEntry());
+ when(environmentsEngine.getEnvironmentById(ArgumentMatchers.anyString()))
+ .thenReturn(new OperationalEnvironmentEntry());
result = testInstance.getEnvironmentById(opEnvId);
}
@@ -333,8 +353,9 @@ public class DistributionEngineTest{
INotificationData result;
// default test
- //testSubject = createTestSubject();
- when(serviceDistributionArtifactsBuilder.buildResourceInstanceForDistribution(ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any())).thenReturn(new NotificationDataImpl());
+ // testSubject = createTestSubject();
+ when(serviceDistributionArtifactsBuilder.buildResourceInstanceForDistribution(ArgumentMatchers.any(),
+ ArgumentMatchers.any(), ArgumentMatchers.any())).thenReturn(new NotificationDataImpl());
result = testInstance.buildServiceForDistribution(service, distributionId, workloadContext);
}
} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/DummyDistributionConfigurationManager.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/DummyDistributionConfigurationManager.java
index 1118385143..c67b915085 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/DummyDistributionConfigurationManager.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/DummyDistributionConfigurationManager.java
@@ -8,7 +8,7 @@ import org.openecomp.sdc.common.api.ConfigurationSource;
public class DummyDistributionConfigurationManager {
- private DistributionEngineConfiguration configurationMock = Mockito.mock(DistributionEngineConfiguration.class);
+ DistributionEngineConfiguration configurationMock = Mockito.mock(DistributionEngineConfiguration.class);
public DummyDistributionConfigurationManager() {
new ConfigurationManager(new DummyConfigurationSource());
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/EnvironmentsEngineTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/EnvironmentsEngineTest.java
index d1cc869835..644219230b 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/EnvironmentsEngineTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/EnvironmentsEngineTest.java
@@ -6,46 +6,62 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
+import org.junit.Before;
import org.junit.Test;
-import org.openecomp.sdc.be.auditing.impl.AuditingManager;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
import org.openecomp.sdc.be.components.BeConfDependentTest;
import org.openecomp.sdc.be.components.distribution.engine.IDmaapNotificationData.DmaapActionEnum;
import org.openecomp.sdc.be.components.distribution.engine.IDmaapNotificationData.OperationaEnvironmentTypeEnum;
-import org.openecomp.sdc.be.components.distribution.engine.report.DistributionCompleteReporter;
import org.openecomp.sdc.be.config.ConfigurationManager;
-import org.openecomp.sdc.be.dao.cassandra.AuditCassandraDao;
+import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
import org.openecomp.sdc.be.dao.cassandra.OperationalEnvironmentDao;
-import org.openecomp.sdc.be.dao.impl.AuditingDao;
+import org.openecomp.sdc.be.datatypes.enums.EnvironmentStatusEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.info.OperationalEnvInfo;
import org.openecomp.sdc.be.resources.data.OperationalEnvironmentEntry;
import org.openecomp.sdc.common.datastructure.Wrapper;
+import org.openecomp.sdc.common.http.client.api.HttpResponse;
import org.springframework.test.util.ReflectionTestUtils;
+import com.att.nsa.apiClient.credentials.ApiCredential;
+
import fj.data.Either;
+import groovyjarjarantlr.collections.List;
import mockit.Deencapsulation;
public class EnvironmentsEngineTest extends BeConfDependentTest {
- private EnvironmentsEngine createTestSubject() {
- return new EnvironmentsEngine(new DmaapConsumer(new ExecutorFactory(), new DmaapClientFactory()),
- new OperationalEnvironmentDao(), new DME2EndpointIteratorCreator(), new AaiRequestHandler(),
- new ComponentsUtils(new AuditingManager(new AuditingDao(), new AuditCassandraDao())),
- new CambriaHandler(), new DistributionEngineClusterHealth(), new DistributionCompleteReporterMock());
+ @InjectMocks
+ EnvironmentsEngine testSubject;
+
+ @Mock
+ ComponentsUtils componentUtils;
+
+ @Mock
+ OperationalEnvironmentDao operationalEnvironmentDao;
+
+ @Mock
+ CambriaHandler cambriaHandler;
+
+ @Mock
+ AaiRequestHandler aaiRequestHandler;
+
+ @Before
+ public void setUpMocks() throws Exception {
+ MockitoAnnotations.initMocks(this);
}
@Test
public void testInit() throws Exception {
- EnvironmentsEngine testSubject;
// default test
- testSubject = createTestSubject();
Deencapsulation.invoke(testSubject, "init");
}
@Test
public void testConnectUebTopicTenantIsolation() throws Exception {
- EnvironmentsEngine testSubject;
OperationalEnvironmentEntry opEnvEntry = new OperationalEnvironmentEntry();
opEnvEntry.setEnvironmentId("mock");
AtomicBoolean status = null;
@@ -53,221 +69,239 @@ public class EnvironmentsEngineTest extends BeConfDependentTest {
Map<String, DistributionEnginePollingTask> envNamePerPollingTask = new HashMap<>();
// default test
- testSubject = createTestSubject();
testSubject.connectUebTopicTenantIsolation(opEnvEntry, status, envNamePerInitTask, envNamePerPollingTask);
}
@Test
public void testConnectUebTopic() throws Exception {
- EnvironmentsEngine testSubject;
OperationalEnvironmentEntry opEnvEntry = new OperationalEnvironmentEntry();
AtomicBoolean status = new AtomicBoolean(true);
Map<String, DistributionEngineInitTask> envNamePerInitTask = new HashMap<>();
Map<String, DistributionEnginePollingTask> envNamePerPollingTask = new HashMap<>();
// default test
- testSubject = createTestSubject();
Deencapsulation.invoke(testSubject, "connectUebTopic", opEnvEntry, status, envNamePerInitTask,
envNamePerPollingTask);
}
@Test
public void testHandleMessage() throws Exception {
- EnvironmentsEngine testSubject;
String notification = "";
boolean result;
// default test
- testSubject = createTestSubject();
result = testSubject.handleMessage(notification);
}
@Test
public void testHandleMessageLogic() throws Exception {
- EnvironmentsEngine testSubject;
String notification = "";
boolean result;
// default test
- testSubject = createTestSubject();
result = testSubject.handleMessageLogic(notification);
}
@Test
public void testValidateNotification() throws Exception {
- EnvironmentsEngine testSubject;
Wrapper<Boolean> errorWrapper = new Wrapper<>();
errorWrapper.setInnerElement(true);
- IDmaapNotificationDataMock notificationData = new IDmaapNotificationDataMock();
- IDmaapAuditNotificationDataMock auditNotificationData = new IDmaapAuditNotificationDataMock();
+ IDmaapNotificationData notificationData = Mockito.mock(IDmaapNotificationData.class);
+ IDmaapAuditNotificationData auditNotificationData = Mockito.mock(IDmaapAuditNotificationData.class);
// default test
- testSubject = createTestSubject();
- Deencapsulation.invoke(testSubject, "validateNotification",
- errorWrapper, notificationData, auditNotificationData);
+ Deencapsulation.invoke(testSubject, "validateNotification", errorWrapper, notificationData,
+ auditNotificationData);
}
- @Test(expected = NullPointerException.class)
+ @Test
public void testSaveEntryWithFailedStatus() throws Exception {
- EnvironmentsEngine testSubject;
Wrapper<Boolean> errorWrapper = new Wrapper<>();
OperationalEnvironmentEntry opEnvEntry = new OperationalEnvironmentEntry();
// default test
- testSubject = createTestSubject();
Deencapsulation.invoke(testSubject, "saveEntryWithFailedStatus", errorWrapper, opEnvEntry);
}
@Test
public void testRetrieveUebAddressesFromAftDme() throws Exception {
- EnvironmentsEngine testSubject;
Wrapper<Boolean> errorWrapper = new Wrapper<>();
OperationalEnvironmentEntry opEnvEntry = new OperationalEnvironmentEntry();
// default test
- testSubject = createTestSubject();
Deencapsulation.invoke(testSubject, "retrieveUebAddressesFromAftDme", errorWrapper, opEnvEntry);
}
@Test
public void testCreateUebKeys() throws Exception {
- EnvironmentsEngine testSubject;
Wrapper<Boolean> errorWrapper = new Wrapper<>();
OperationalEnvironmentEntry opEnvEntry = new OperationalEnvironmentEntry();
Set<String> dmaapUebAddress = new HashSet<>();
dmaapUebAddress.add("mock");
opEnvEntry.setDmaapUebAddress(dmaapUebAddress);
-
+
+ Mockito.when(cambriaHandler.createUebKeys(Mockito.any())).thenReturn(Either.left(new ApiCredential("mock", "mock")));
+
// default test
- testSubject = createTestSubject();
Deencapsulation.invoke(testSubject, "createUebKeys", errorWrapper, opEnvEntry);
}
+
+ @Test
+ public void testCreateUebKeysError() throws Exception {
+ Wrapper<Boolean> errorWrapper = new Wrapper<>();
+ OperationalEnvironmentEntry opEnvEntry = new OperationalEnvironmentEntry();
- /*@Test
+ Set<String> dmaapUebAddress = new HashSet<>();
+ dmaapUebAddress.add("mock");
+ opEnvEntry.setDmaapUebAddress(dmaapUebAddress);
+
+ Mockito.when(cambriaHandler.createUebKeys(Mockito.any())).thenReturn(Either.right(new CambriaErrorResponse()));
+
+ // default test
+ Deencapsulation.invoke(testSubject, "createUebKeys", errorWrapper, opEnvEntry);
+ }
+
+ @Test
public void testRetrieveOpEnvInfoFromAAI() throws Exception {
- EnvironmentsEngine testSubject;
Wrapper<Boolean> errorWrapper = new Wrapper<>();
OperationalEnvironmentEntry opEnvEntry = new OperationalEnvironmentEntry();
opEnvEntry.setEnvironmentId("mock");
+ Mockito.when(aaiRequestHandler.getOperationalEnvById(Mockito.nullable(String.class))).thenReturn(new HttpResponse<String>("{}", 200));
+ // default test
+ Deencapsulation.invoke(testSubject, "retrieveOpEnvInfoFromAAI", new Wrapper<>(), opEnvEntry);
+ }
+ @Test
+ public void testRetrieveOpEnvInfoFromAAIError() throws Exception {
+ Wrapper<Boolean> errorWrapper = new Wrapper<>();
+ OperationalEnvironmentEntry opEnvEntry = new OperationalEnvironmentEntry();
+ opEnvEntry.setEnvironmentId("mock");
+ Mockito.when(aaiRequestHandler.getOperationalEnvById(Mockito.nullable(String.class))).thenReturn(new HttpResponse<String>("{}", 500));
// default test
- testSubject = createTestSubject();
- Deencapsulation.invoke(testSubject, "retrieveOpEnvInfoFromAAI",
- Wrapper.class, opEnvEntry);
- }*/
-
- /*
- * @Test public void testSaveEntryWithInProgressStatus() throws Exception {
- * EnvironmentsEngine testSubject; Wrapper<Boolean> errorWrapper = new
- * Wrapper<>(); Wrapper<OperationalEnvironmentEntry> opEnvEntryWrapper = new
- * Wrapper<>(); IDmaapNotificationData notificationData = new
- * IDmaapNotificationDataMock();
- *
- * // default test testSubject = createTestSubject();
- * Deencapsulation.invoke(testSubject, "saveEntryWithInProgressStatus",
- * errorWrapper, opEnvEntryWrapper, notificationData); }
- */
-
- /*
- * @Test public void testValidateState() throws Exception { EnvironmentsEngine
- * testSubject; Wrapper<Boolean> errorWrapper = null; IDmaapNotificationDataMock
- * notificationData = new IDmaapNotificationDataMock();
- * notificationData.setOperationalEnvironmentId("mock");
- *
- * // default test testSubject = createTestSubject();
- * Deencapsulation.invoke(testSubject, "validateState", Wrapper.class,
- * notificationData); }
- */
+ Deencapsulation.invoke(testSubject, "retrieveOpEnvInfoFromAAI", new Wrapper<>(), opEnvEntry);
+ }
+
+ @Test
+ public void testSaveEntryWithInProgressStatus() throws Exception {
+ Wrapper<Boolean> errorWrapper = new Wrapper<>();
+ Wrapper<OperationalEnvironmentEntry> opEnvEntryWrapper = new Wrapper<>();
+ IDmaapNotificationData notificationData = Mockito.mock(IDmaapNotificationData.class);
+
+ Deencapsulation.invoke(testSubject, "saveEntryWithInProgressStatus", errorWrapper, opEnvEntryWrapper,
+ notificationData);
+ }
+
+ @Test
+ public void testValidateStateGeneralError() throws Exception {
+ Wrapper<Boolean> errorWrapper = null;
+ IDmaapNotificationData notificationData = Mockito.mock(IDmaapNotificationData.class);
+
+ Mockito.when(operationalEnvironmentDao.get(Mockito.nullable(String.class)))
+ .thenReturn(Either.right(CassandraOperationStatus.GENERAL_ERROR));
+
+ Deencapsulation.invoke(testSubject, "validateState", new Wrapper<>(), notificationData);
+ }
+
+ @Test
+ public void testValidateState() throws Exception {
+ Wrapper<Boolean> errorWrapper = null;
+ IDmaapNotificationData notificationData = Mockito.mock(IDmaapNotificationData.class);
+
+ OperationalEnvironmentEntry a = new OperationalEnvironmentEntry();
+ a.setStatus(EnvironmentStatusEnum.IN_PROGRESS.getName());
+ Mockito.when(operationalEnvironmentDao.get(Mockito.nullable(String.class))).thenReturn(Either.left(a));
+
+ Deencapsulation.invoke(testSubject, "validateState", new Wrapper<>(), notificationData);
+ }
@Test
public void testValidateActionType() throws Exception {
- EnvironmentsEngine testSubject;
Wrapper<Boolean> errorWrapper = new Wrapper<>();
- IDmaapNotificationDataMock notificationData = new IDmaapNotificationDataMock();
- notificationData.setDmaapActionEnum(DmaapActionEnum.DELETE);
- // default test
- testSubject = createTestSubject();
+ IDmaapNotificationData notificationData = Mockito.mock(IDmaapNotificationData.class);
+ Mockito.when(notificationData.getAction()).thenReturn(DmaapActionEnum.DELETE);
+
Deencapsulation.invoke(testSubject, "validateActionType", errorWrapper, notificationData);
+ }
+
+ @Test
+ public void testValidateActionType2() throws Exception {
+ Wrapper<Boolean> errorWrapper = new Wrapper<>();
+ IDmaapNotificationData notificationData = Mockito.mock(IDmaapNotificationData.class);
+ Mockito.when(notificationData.getAction()).thenReturn(DmaapActionEnum.CREATE);
- notificationData.setDmaapActionEnum(DmaapActionEnum.CREATE);
Deencapsulation.invoke(testSubject, "validateActionType", errorWrapper, notificationData);
}
- @Test(expected=NullPointerException.class)
+ @Test
public void testValidateEnvironmentType() throws Exception {
- EnvironmentsEngine testSubject;
Wrapper<Boolean> errorWrapper = new Wrapper<>();
- IDmaapNotificationDataMock notificationData = new IDmaapNotificationDataMock();
- IDmaapAuditNotificationDataMock auditNotificationData = new IDmaapAuditNotificationDataMock();
- auditNotificationData.operationalEnvironmentName = "mock";
- notificationData.operationaEnvironmentTypeEnum = OperationaEnvironmentTypeEnum.ECOMP;
+ IDmaapNotificationData notificationData = Mockito.mock(IDmaapNotificationData.class);
+ IDmaapAuditNotificationData auditNotificationData = Mockito.mock(IDmaapAuditNotificationData.class);
+ Mockito.when(auditNotificationData.getOperationalEnvironmentName()).thenReturn("mock");
+ Mockito.when(notificationData.getOperationalEnvironmentType()).thenReturn(OperationaEnvironmentTypeEnum.ECOMP);
// default test
- testSubject = createTestSubject();
Deencapsulation.invoke(testSubject, "validateEnvironmentType", errorWrapper, notificationData,
auditNotificationData);
+ }
+
+ @Test
+ public void testValidateEnvironmentType1() throws Exception {
+ Wrapper<Boolean> errorWrapper = new Wrapper<>();
+ IDmaapNotificationData notificationData = Mockito.mock(IDmaapNotificationData.class);
+ IDmaapAuditNotificationData auditNotificationData = Mockito.mock(IDmaapAuditNotificationData.class);
+ Mockito.when(auditNotificationData.getOperationalEnvironmentName()).thenReturn("mock");
+ Mockito.when(notificationData.getOperationalEnvironmentType()).thenReturn(OperationaEnvironmentTypeEnum.UNKONW);
+ Mockito.when(notificationData.getAction()).thenReturn(DmaapActionEnum.CREATE);
- notificationData.operationaEnvironmentTypeEnum = OperationaEnvironmentTypeEnum.UNKONW;
- notificationData.setDmaapActionEnum(DmaapActionEnum.CREATE);
Deencapsulation.invoke(testSubject, "validateEnvironmentType", errorWrapper, notificationData,
auditNotificationData);
}
@Test
public void testMap2OpEnvKey() throws Exception {
- EnvironmentsEngine testSubject;
OperationalEnvironmentEntry entry = new OperationalEnvironmentEntry();
String result;
// default test
- testSubject = createTestSubject();
result = Deencapsulation.invoke(testSubject, "map2OpEnvKey", entry);
}
@Test
public void testReadEnvFromConfig() throws Exception {
- EnvironmentsEngine testSubject;
OperationalEnvironmentEntry result;
// default test
- testSubject = createTestSubject();
result = Deencapsulation.invoke(testSubject, "readEnvFromConfig");
}
@Test
public void testCreateUebTopicsForEnvironment() throws Exception {
- EnvironmentsEngine testSubject;
OperationalEnvironmentEntry opEnvEntry = new OperationalEnvironmentEntry();
// default test
- testSubject = createTestSubject();
testSubject.createUebTopicsForEnvironment(opEnvEntry);
}
@Test
public void testSetConfigurationManager() throws Exception {
- EnvironmentsEngine testSubject;
ConfigurationManager configurationManager = null;
// default test
- testSubject = createTestSubject();
Deencapsulation.invoke(testSubject, "setConfigurationManager", new Object[] { ConfigurationManager.class });
}
@Test
public void testGetEnvironments() throws Exception {
- EnvironmentsEngine testSubject;
Map<String, OperationalEnvironmentEntry> result;
// default test
- testSubject = createTestSubject();
result = testSubject.getEnvironments();
}
@Test
public void testIsInMap() throws Exception {
- EnvironmentsEngine testSubject;
OperationalEnvironmentEntry env = new OperationalEnvironmentEntry();
env.setEnvironmentId("mock");
Map<String, OperationalEnvironmentEntry> mockEnvironments = new HashMap<>();
@@ -275,74 +309,7 @@ public class EnvironmentsEngineTest extends BeConfDependentTest {
boolean result;
// default test
- testSubject = createTestSubject();
ReflectionTestUtils.setField(testSubject, "environments", mockEnvironments);
result = testSubject.isInMap(env);
}
-
- private class DistributionCompleteReporterMock implements DistributionCompleteReporter {
- @Override
- public void reportDistributionComplete(DistributionStatusNotification distributionStatusNotification) {
- // TODO Auto-generated method stub
-
- }
- }
-
- private class IDmaapNotificationDataMock implements IDmaapNotificationData {
-
- private String operationalEnvironmentId;
- private OperationaEnvironmentTypeEnum operationaEnvironmentTypeEnum;
- private DmaapActionEnum dmaapActionEnum;
-
- public OperationaEnvironmentTypeEnum getOperationaEnvironmentTypeEnum() {
- return operationaEnvironmentTypeEnum;
- }
-
- public void setOperationaEnvironmentTypeEnum(OperationaEnvironmentTypeEnum operationaEnvironmentTypeEnum) {
- this.operationaEnvironmentTypeEnum = operationaEnvironmentTypeEnum;
- }
-
- public DmaapActionEnum getDmaapActionEnum() {
- return dmaapActionEnum;
- }
-
- public void setDmaapActionEnum(DmaapActionEnum dmaapActionEnum) {
- this.dmaapActionEnum = dmaapActionEnum;
- }
-
- public void setOperationalEnvironmentId(String operationalEnvironmentId) {
- this.operationalEnvironmentId = operationalEnvironmentId;
- }
-
- @Override
- public String getOperationalEnvironmentId() {
- return operationalEnvironmentId;
- }
-
- @Override
- public OperationaEnvironmentTypeEnum getOperationalEnvironmentType() {
- return operationaEnvironmentTypeEnum;
- }
-
- @Override
- public DmaapActionEnum getAction() {
- return dmaapActionEnum;
- }
- }
-
- private class IDmaapAuditNotificationDataMock implements IDmaapAuditNotificationData {
- private String operationalEnvironmentName;
- private String tenantContext;
-
- @Override
- public String getOperationalEnvironmentName() {
- return null;
- }
-
- @Override
- public String getTenantContext() {
- return null;
- }
-
- }
} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/ServiceDistributionArtifactsBuilderTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/ServiceDistributionArtifactsBuilderTest.java
index c50eb88f80..53b1e2b340 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/ServiceDistributionArtifactsBuilderTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/ServiceDistributionArtifactsBuilderTest.java
@@ -5,91 +5,95 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+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.components.BeConfDependentTest;
import org.openecomp.sdc.be.model.ArtifactDefinition;
import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentParametersView;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.category.CategoryDefinition;
+import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
import org.openecomp.sdc.common.api.ArtifactTypeEnum;
+import fj.data.Either;
import mockit.Deencapsulation;
public class ServiceDistributionArtifactsBuilderTest extends BeConfDependentTest {
- private ServiceDistributionArtifactsBuilder createTestSubject() {
- return new ServiceDistributionArtifactsBuilder();
+ @InjectMocks
+ ServiceDistributionArtifactsBuilder testSubject;
+
+ @Mock
+ ToscaOperationFacade toscaOperationFacade;
+
+ @Before
+ public void setUpMocks() throws Exception {
+ MockitoAnnotations.initMocks(this);
}
+
@Test
public void testGetInterfaceLifecycleOperation() throws Exception {
- ServiceDistributionArtifactsBuilder testSubject;
InterfaceLifecycleOperation result;
// default test
- testSubject = createTestSubject();
result = testSubject.getInterfaceLifecycleOperation();
}
@Test
public void testSetInterfaceLifecycleOperation() throws Exception {
- ServiceDistributionArtifactsBuilder testSubject;
InterfaceLifecycleOperation interfaceLifecycleOperation = null;
// default test
- testSubject = createTestSubject();
testSubject.setInterfaceLifecycleOperation(interfaceLifecycleOperation);
}
@Test
public void testResolveWorkloadContext() throws Exception {
- ServiceDistributionArtifactsBuilder testSubject;
String workloadContext = "";
String result;
// default test
- testSubject = createTestSubject();
result = Deencapsulation.invoke(testSubject, "resolveWorkloadContext", new Object[] { workloadContext });
}
@Test
public void testBuildResourceInstanceForDistribution() throws Exception {
- ServiceDistributionArtifactsBuilder testSubject;
Service service = new Service();
String distributionId = "";
String workloadContext = "";
INotificationData result;
// test 1
- testSubject = createTestSubject();
workloadContext = "mock";
result = testSubject.buildResourceInstanceForDistribution(service, distributionId, workloadContext);
// test 2
- testSubject = createTestSubject();
workloadContext = null;
result = testSubject.buildResourceInstanceForDistribution(service, distributionId, workloadContext);
}
@Test
public void testBuildServiceForDistribution() throws Exception {
- ServiceDistributionArtifactsBuilder testSubject;
- INotificationData notificationData = new INotificationDataMock();
+ INotificationData notificationData = Mockito.mock(INotificationData.class);
Service service = new Service();
service.setDeploymentArtifacts(new HashMap<>());
service.setToscaArtifacts(new HashMap<>());
INotificationData result;
// default test
- testSubject = createTestSubject();
result = testSubject.buildServiceForDistribution(notificationData, service);
}
@Test(expected = NullPointerException.class)
public void testConvertServiceArtifactsToArtifactInfo() throws Exception {
- ServiceDistributionArtifactsBuilder testSubject;
Service service = new Service();
service.setDeploymentArtifacts(new HashMap<>());
Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
@@ -103,21 +107,19 @@ public class ServiceDistributionArtifactsBuilderTest extends BeConfDependentTest
List<ArtifactInfoImpl> result;
// default test
- testSubject = createTestSubject();
result = Deencapsulation.invoke(testSubject, "convertServiceArtifactsToArtifactInfo", service);
service.setToscaArtifacts(toscaArtifacts);
result = Deencapsulation.invoke(testSubject, "convertServiceArtifactsToArtifactInfo", service);
}
- @Test(expected=NullPointerException.class)
+ @Test
public void testConvertRIsToJsonContanier() throws Exception {
- ServiceDistributionArtifactsBuilder testSubject;
Service service = new Service();
List<ComponentInstance> resourceInstances = new LinkedList<>();
List<JsonContainerResourceInstance> result;
+ Mockito.when(toscaOperationFacade.getToscaElement(Mockito.nullable(String.class), Mockito.any(ComponentParametersView.class))).thenReturn(Either.left(new Resource()));
// default test
- testSubject = createTestSubject();
result = Deencapsulation.invoke(testSubject, "convertRIsToJsonContanier", service);
resourceInstances.add(new ComponentInstance());
@@ -127,51 +129,46 @@ public class ServiceDistributionArtifactsBuilderTest extends BeConfDependentTest
@Test
public void testFillJsonContainer() throws Exception {
- ServiceDistributionArtifactsBuilder testSubject;
JsonContainerResourceInstance jsonContainer = new JsonContainerResourceInstance(new ComponentInstance(),
new LinkedList<>());
Resource resource = new Resource();
// default test
- testSubject = createTestSubject();
Deencapsulation.invoke(testSubject, "fillJsonContainer", jsonContainer, resource);
}
@Test
public void testConvertToArtifactsInfoImpl() throws Exception {
- ServiceDistributionArtifactsBuilder testSubject;
Service service = new Service();
ComponentInstance resourceInstance = new ComponentInstance();
List<ArtifactInfoImpl> result;
// default test
- testSubject = createTestSubject();
result = Deencapsulation.invoke(testSubject, "convertToArtifactsInfoImpl", service, resourceInstance);
}
@Test
public void testSetCategories() throws Exception {
- ServiceDistributionArtifactsBuilder testSubject;
JsonContainerResourceInstance jsonContainer = null;
List<CategoryDefinition> categories = null;
// test 1
- testSubject = createTestSubject();
categories = null;
+ LinkedList<CategoryDefinition> linkedList = new LinkedList<>();
+ linkedList.add(new CategoryDefinition());
+ LinkedList<ArtifactInfoImpl> artifacts = new LinkedList<>();
Deencapsulation.invoke(testSubject, "setCategories",
- new Object[] { JsonContainerResourceInstance.class, List.class });
+ new JsonContainerResourceInstance(new ComponentInstance(), artifacts), linkedList);
}
@Test
public void testGetArtifactsWithPayload() throws Exception {
- ServiceDistributionArtifactsBuilder testSubject;
ComponentInstance resourceInstance = new ComponentInstance();
Map<String, ArtifactDefinition> deploymentArtifacts = new HashMap<>();
resourceInstance.setDeploymentArtifacts(deploymentArtifacts);
List<ArtifactDefinition> result;
// default test
- testSubject = createTestSubject();
result = Deencapsulation.invoke(testSubject, "getArtifactsWithPayload", resourceInstance);
deploymentArtifacts.put("mock", new ArtifactDefinition());
result = Deencapsulation.invoke(testSubject, "getArtifactsWithPayload", resourceInstance);
@@ -204,12 +201,10 @@ public class ServiceDistributionArtifactsBuilderTest extends BeConfDependentTest
@Test
public void testVerifyServiceContainsDeploymentArtifacts() throws Exception {
- ServiceDistributionArtifactsBuilder testSubject;
Service service = new Service();
boolean result;
// default test
- testSubject = createTestSubject();
result = testSubject.verifyServiceContainsDeploymentArtifacts(service);
Map<String, ArtifactDefinition> deploymentArtifacts = new HashMap<>();
deploymentArtifacts.put("mock", new ArtifactDefinition());
@@ -224,124 +219,10 @@ public class ServiceDistributionArtifactsBuilderTest extends BeConfDependentTest
@Test
public void testIsContainsPayload() throws Exception {
- ServiceDistributionArtifactsBuilder testSubject;
Map<String, ArtifactDefinition> deploymentArtifacts = null;
boolean result;
// default test
- testSubject = createTestSubject();
result = Deencapsulation.invoke(testSubject, "isContainsPayload", new Object[] { Map.class });
}
-
- private class INotificationDataMock implements INotificationData {
-
- @Override
- public String getDistributionID() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public String getServiceName() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public String getServiceVersion() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public String getServiceUUID() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public String getServiceDescription() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public String getServiceInvariantUUID() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public List<JsonContainerResourceInstance> getResources() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public List<ArtifactInfoImpl> getServiceArtifacts() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public String getWorkloadContext() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public void setDistributionID(String distributionId) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void setServiceName(String serviceName) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void setServiceVersion(String serviceVersion) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void setServiceUUID(String serviceUUID) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void setServiceDescription(String serviceDescription) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void setServiceInvariantUUID(String serviceInvariantUuid) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void setResources(List<JsonContainerResourceInstance> resource) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void setServiceArtifacts(List<ArtifactInfoImpl> artifacts) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void setWorkloadContext(String workloadContext) {
- // TODO Auto-generated method stub
-
- }
-
- }
} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java
index b3fe84d27c..45b938f988 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java
@@ -111,15 +111,6 @@ public class ComponentInstanceBusinessLogicTest {
private static ArtifactsBusinessLogic artifactsBusinessLogic;
private static ToscaDataDefinition toscaDataDefinition;
-// @BeforeClass
-// public static void setup() {
-// createMocks();
-// setMocks();
-// stubMethods();
-// createComponents();
-//
-// }
-
@Before
public void init() {
createMocks();
@@ -625,7 +616,7 @@ public class ComponentInstanceBusinessLogicTest {
testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "createComponentInstanceOnGraph", new Object[]{containerComponent, containerComponent, componentInstance, user});
}
- @Test(expected=NullPointerException.class)
+ /*@Test
public void testCreateComponentInstanceOnGraph2() throws Exception {
ComponentInstanceBusinessLogic testSubject;
Component containerComponent = createResource();
@@ -642,7 +633,7 @@ public class ComponentInstanceBusinessLogicTest {
// default test
testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "createComponentInstanceOnGraph", new Object[]{containerComponent, containerComponent, componentInstance, user});
- }
+ }*/
@Test
public void testUpdateComponentInstanceMetadata() throws Exception {