aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java
diff options
context:
space:
mode:
authorTal Gitelman <tg851x@intl.att.com>2018-09-05 17:47:16 +0300
committerMichael Lando <ml636r@att.com>2018-09-05 19:16:34 +0300
commit503be6d4ac7cfd63d5e17a54bd990de39b201d83 (patch)
treee94882f7e5849f395dc4b1051211b92f43f1fd8c /catalog-be/src/test/java
parentf773610d0952940db42376cbb36ba63cb2cacc35 (diff)
add ability to disable tenant isolation.
Change-Id: I35b6db5ec0d3aa91295f57b60c04243b3f3d2208 Issue-ID: SDC-1571 Signed-off-by: Tal Gitelman <tg851x@intl.att.com>
Diffstat (limited to 'catalog-be/src/test/java')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/EnvironmentsEngineMockTest.java190
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/EnvironmentsEngineTest.java603
2 files changed, 312 insertions, 481 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/EnvironmentsEngineMockTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/EnvironmentsEngineMockTest.java
deleted file mode 100644
index f1ec0d8da6..0000000000
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/EnvironmentsEngineMockTest.java
+++ /dev/null
@@ -1,190 +0,0 @@
-package org.openecomp.sdc.be.components.distribution.engine;
-
-import fj.data.Either;
-import org.apache.http.HttpStatus;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.openecomp.sdc.be.config.ConfigurationManager;
-import org.openecomp.sdc.be.config.DistributionEngineConfiguration;
-import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
-import org.openecomp.sdc.be.dao.cassandra.OperationalEnvironmentDao;
-import org.openecomp.sdc.be.datatypes.enums.EnvironmentStatusEnum;
-import org.openecomp.sdc.be.info.OperationalEnvInfo;
-import org.openecomp.sdc.be.resources.data.OperationalEnvironmentEntry;
-import org.openecomp.sdc.common.http.client.api.HttpResponse;
-
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.when;
-
-@RunWith(value = MockitoJUnitRunner.class)
-public class EnvironmentsEngineMockTest {
-
- @InjectMocks
- private EnvironmentsEngine envEngine;
- @Mock
- private DmaapConsumer dmaapConsumer;
- @Mock
- private OperationalEnvironmentDao operationalEnvironmentDao;
- @Mock
- private DME2EndpointIteratorCreator epIterCreator;
- @Mock
- private ConfigurationManager configurationManager;
- @Mock
- private DistributionEngineConfiguration distributionEngineConfiguration;
- @Mock
- private AaiRequestHandler aaiRequestHandler;
-
- @Before
- public void preStart() {
- when(configurationManager.getDistributionEngineConfiguration()).thenReturn(distributionEngineConfiguration);
- envEngine.setConfigurationManager(configurationManager);
- }
-
- @Test
- public void testInit() {
- List<OperationalEnvironmentEntry> entryList = Arrays.asList(createOpEnvEntry("Env1"), createOpEnvEntry("Env2"));
- Either<List<OperationalEnvironmentEntry>, CassandraOperationStatus> successEither = Either.left(entryList);
- when(operationalEnvironmentDao.getByEnvironmentsStatus(EnvironmentStatusEnum.COMPLETED)).thenReturn(successEither);
-
- when(distributionEngineConfiguration.getEnvironments()).thenReturn(Arrays.asList("Env Loaded From Configuration"));
- when(distributionEngineConfiguration.getUebPublicKey()).thenReturn("Dummy Public Key");
- when(distributionEngineConfiguration.getUebSecretKey()).thenReturn("Dummy Private Key");
- when(distributionEngineConfiguration.getUebServers()).thenReturn(
- Arrays.asList("uebsb91kcdc.it.att.com:3904", "uebsb92kcdc.it.att.com:3904", "uebsb91kcdc.it.att.com:3904"));
-
- envEngine.init();
-
- Map<String, OperationalEnvironmentEntry> mapEnvs = envEngine.getEnvironments();
- assertEquals("unexpected size of map",3, mapEnvs.size());
- }
-
-
- @Test
- public void testGetFullOperationalEnvByIdSuccess() {
- String json = getFullOperationalEnvJson();
-
- HttpResponse<String> restResponse = new HttpResponse<String>(json, HttpStatus.SC_OK, "Successfully completed");
- when(aaiRequestHandler.getOperationalEnvById(Mockito.anyString())).thenReturn(restResponse);
-
- Either<OperationalEnvInfo, Integer> response = envEngine.getOperationalEnvById("DummyId");
- assertTrue("The operational environment request ran as not expected", response.isLeft());
-
- OperationalEnvInfo operationalEnvInfo = response.left().value();
-
- assertEquals("The operational environment json is not as expected", operationalEnvInfo.toString(), json);
- }
-
- @Test
- public void testGetPartialOperationalEnvByIdSuccess() {
- String json = getPartialOperationalEnvJson();
-
- HttpResponse<String> restResponse = new HttpResponse<String>(json, HttpStatus.SC_OK, "Successfully completed");
- when(aaiRequestHandler.getOperationalEnvById(Mockito.anyString())).thenReturn(restResponse);
-
- Either<OperationalEnvInfo, Integer> response = envEngine.getOperationalEnvById("DummyId");
- assertTrue("The operational environment request ran as not expected", response.isLeft());
-
- OperationalEnvInfo operationalEnvInfo = response.left().value();
-
- assertEquals("The operational environment json is not as expected", operationalEnvInfo.toString(), json);
- }
-
-
- @Test
- public void testGetOperationalEnvByIdFailedByJsonConvert() {
- String jsonCorrupted = getCorruptedOperationalEnvJson();
-
- HttpResponse<String> restResponse = new HttpResponse<String>(jsonCorrupted, HttpStatus.SC_OK, "Successfully Completed");
- when(aaiRequestHandler.getOperationalEnvById(Mockito.anyString())).thenReturn(restResponse);
-
- Either<OperationalEnvInfo, Integer> response = envEngine.getOperationalEnvById("DummyId");
- assertTrue("The operational environment request ran as not expected", response.isRight());
- assertEquals("The operational environment request status code is not as expected", (Integer)HttpStatus.SC_INTERNAL_SERVER_ERROR, response.right().value());
- }
-
- @Test
- public void testGetOperationalEnvByIdFailed404() {
- String json = getFullOperationalEnvJson();
- HttpResponse<String> restResponse = new HttpResponse<String>(json, HttpStatus.SC_NOT_FOUND, "Not Found");
- when(aaiRequestHandler.getOperationalEnvById(Mockito.anyString())).thenReturn(restResponse);
-
- Either<OperationalEnvInfo, Integer> response = envEngine.getOperationalEnvById("DummyId");
- assertTrue("The operational environment request ran as not expected", response.isRight());
- assertEquals("The operational environment request status code is not as expected", (Integer)HttpStatus.SC_NOT_FOUND, response.right().value());
- }
-
-
- @Test(expected = IOException.class)
- public void testCorruptedOperationalEnvJson() throws IOException {
- String jsonCorrupted = getCorruptedOperationalEnvJson();
- OperationalEnvInfo.createFromJson(jsonCorrupted);
- }
-
- private String getCorruptedOperationalEnvJson() {
- return "{\"OPERATIONAL-environment-name\":\"Op Env Name\","
- + "\"OPERATIONAL-environment-type\":\"VNF\","
- + "\"OPERATIONAL-environment-status\":\"Activate\","
- + "\"tenant-context\":\"Test\"}";
- }
-
- private String getPartialOperationalEnvJson() {
- return "{" +
- "\"operational-environment-id\":\"UUID of Operational Environment\"," +
- "\"operational-environment-name\":\"Op Env Name\"," +
- "\"operational-environment-type\":\"VNF\"," +
- "\"operational-environment-status\":\"Activate\"," +
- "\"tenant-context\":\"Test\"," +
- "\"workload-context\":\"VNF_Development\"," +
- "\"resource-version\":\"1505228226913\"," +
- "\"relationship-list\":{" +
- "\"relationship\":[]" +
- "}" +
- "}";
- }
-
- private String getFullOperationalEnvJson() {
- return "{" +
- "\"operational-environment-id\":\"OEid1\"," +
- "\"operational-environment-name\":\"OEname1\"," +
- "\"operational-environment-type\":\"OEtype1\"," +
- "\"operational-environment-status\":\"OEstatus1\"," +
- "\"tenant-context\":\"OEtenantcontext1\"," +
- "\"workload-context\":\"OEworkloadcontext1\"," +
- "\"resource-version\":\"1511363173278\"," +
- "\"relationship-list\":{" +
- "\"relationship\":[" +
- "{" +
- "\"related-to\":\"operational-environment\"," +
- "\"relationship-label\":\"managedBy\"," +
- "\"related-link\":\"/aai/v12/cloud-infrastructure/operational-environments/operational-environment/OEid3\"," +
- "\"relationship-data\":[" +
- "{" +
- "\"relationship-key\":\"operational-environment.operational-environment-id\"," +
- "\"relationship-value\":\"OEid3\"" +
- "}" +
- "]," +
- "\"related-to-property\":[" +
- "{" +
- "\"property-key\":\"operational-environment.operational-environment-name\"," +
- "\"property-value\":\"OEname3\"" +
- "}]}]}}";
- }
-
- private OperationalEnvironmentEntry createOpEnvEntry(String name) {
- OperationalEnvironmentEntry entry = new OperationalEnvironmentEntry();
- entry.setEnvironmentId(name);
- return entry;
- }
-
-}
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 bec17b5d08..1050d9a321 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
@@ -3,310 +3,331 @@ package org.openecomp.sdc.be.components.distribution.engine;
import com.att.nsa.apiClient.credentials.ApiCredential;
import fj.data.Either;
import mockit.Deencapsulation;
+import org.apache.http.HttpStatus;
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.components.distribution.engine.IDmaapNotificationData.DmaapActionEnum;
-import org.openecomp.sdc.be.components.distribution.engine.IDmaapNotificationData.OperationaEnvironmentTypeEnum;
+import org.openecomp.sdc.be.config.Configuration;
import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.config.DistributionEngineConfiguration;
+import org.openecomp.sdc.be.config.DmaapConsumerConfiguration;
import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
import org.openecomp.sdc.be.dao.cassandra.OperationalEnvironmentDao;
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 java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
+import java.io.IOException;
+import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
-public class EnvironmentsEngineTest extends BeConfDependentTest {
-
- @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 {
-
- // default test
- Deencapsulation.invoke(testSubject, "init");
- }
-
- @Test
- public void testConnectUebTopicTenantIsolation() throws Exception {
- OperationalEnvironmentEntry opEnvEntry = new OperationalEnvironmentEntry();
- opEnvEntry.setEnvironmentId("mock");
- AtomicBoolean status = null;
- Map<String, DistributionEngineInitTask> envNamePerInitTask = new HashMap<>();
- Map<String, DistributionEnginePollingTask> envNamePerPollingTask = new HashMap<>();
-
- // default test
- testSubject.connectUebTopicTenantIsolation(opEnvEntry, status, envNamePerInitTask, envNamePerPollingTask);
- }
-
- @Test
- public void testConnectUebTopic() throws Exception {
- OperationalEnvironmentEntry opEnvEntry = new OperationalEnvironmentEntry();
- AtomicBoolean status = new AtomicBoolean(true);
- Map<String, DistributionEngineInitTask> envNamePerInitTask = new HashMap<>();
- Map<String, DistributionEnginePollingTask> envNamePerPollingTask = new HashMap<>();
-
- // default test
- Deencapsulation.invoke(testSubject, "connectUebTopic", opEnvEntry, status, envNamePerInitTask,
- envNamePerPollingTask);
- }
-
- @Test
- public void testHandleMessage() throws Exception {
- String notification = "";
- boolean result;
-
- // default test
- result = testSubject.handleMessage(notification);
- }
-
- @Test
- public void testHandleMessageLogic() throws Exception {
- String notification = "";
- boolean result;
-
- // default test
- result = testSubject.handleMessageLogic(notification);
- }
-
- @Test
- public void testValidateNotification() throws Exception {
- Wrapper<Boolean> errorWrapper = new Wrapper<>();
- errorWrapper.setInnerElement(true);
- IDmaapNotificationData notificationData = Mockito.mock(IDmaapNotificationData.class);
- IDmaapAuditNotificationData auditNotificationData = Mockito.mock(IDmaapAuditNotificationData.class);
-
- // default test
- Deencapsulation.invoke(testSubject, "validateNotification", errorWrapper, notificationData,
- auditNotificationData);
- }
-
- @Test
- public void testSaveEntryWithFailedStatus() throws Exception {
- Wrapper<Boolean> errorWrapper = new Wrapper<>();
- OperationalEnvironmentEntry opEnvEntry = new OperationalEnvironmentEntry();
-
- // default test
- Deencapsulation.invoke(testSubject, "saveEntryWithFailedStatus", errorWrapper, opEnvEntry);
- }
-
- @Test
- public void testRetrieveUebAddressesFromAftDme() throws Exception {
- Wrapper<Boolean> errorWrapper = new Wrapper<>();
- OperationalEnvironmentEntry opEnvEntry = new OperationalEnvironmentEntry();
-
- // default test
- Deencapsulation.invoke(testSubject, "retrieveUebAddressesFromAftDme", errorWrapper, opEnvEntry);
- }
-
- @Test
- public void testCreateUebKeys() throws Exception {
- 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
- Deencapsulation.invoke(testSubject, "createUebKeys", errorWrapper, opEnvEntry);
- }
-
- @Test
- public void testCreateUebKeysError() throws Exception {
- 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.right(new CambriaErrorResponse()));
-
- // default test
- Deencapsulation.invoke(testSubject, "createUebKeys", errorWrapper, opEnvEntry);
- }
-
- @Test
- public void testRetrieveOpEnvInfoFromAAI() 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>("{}", 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
- 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 {
- Wrapper<Boolean> errorWrapper = new Wrapper<>();
- 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);
-
- Deencapsulation.invoke(testSubject, "validateActionType", errorWrapper, notificationData);
- }
-
- @Test
- public void testValidateEnvironmentType() 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.ECOMP);
-
- // default test
- 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);
-
- Deencapsulation.invoke(testSubject, "validateEnvironmentType", errorWrapper, notificationData,
- auditNotificationData);
- }
-
- @Test
- public void testMap2OpEnvKey() throws Exception {
- OperationalEnvironmentEntry entry = new OperationalEnvironmentEntry();
- String result;
-
- // default test
- result = Deencapsulation.invoke(testSubject, "map2OpEnvKey", entry);
- }
-
- @Test
- public void testReadEnvFromConfig() throws Exception {
- OperationalEnvironmentEntry result;
-
- // default test
- result = Deencapsulation.invoke(testSubject, "readEnvFromConfig");
- }
-
- @Test
- public void testCreateUebTopicsForEnvironment() throws Exception {
- OperationalEnvironmentEntry opEnvEntry = new OperationalEnvironmentEntry();
-
- // default test
- testSubject.createUebTopicsForEnvironment(opEnvEntry);
- }
-
- @Test
- public void testSetConfigurationManager() throws Exception {
- ConfigurationManager configurationManager = null;
-
- // default test
- Deencapsulation.invoke(testSubject, "setConfigurationManager", new Object[] { ConfigurationManager.class });
- }
-
- @Test
- public void testGetEnvironments() throws Exception {
- Map<String, OperationalEnvironmentEntry> result;
-
- // default test
- result = testSubject.getEnvironments();
- }
-
- @Test
- public void testIsInMap() throws Exception {
- OperationalEnvironmentEntry env = new OperationalEnvironmentEntry();
- env.setEnvironmentId("mock");
- Map<String, OperationalEnvironmentEntry> mockEnvironments = new HashMap<>();
- mockEnvironments.put("mock", new OperationalEnvironmentEntry());
- boolean result;
-
- // default test
- ReflectionTestUtils.setField(testSubject, "environments", mockEnvironments);
- result = testSubject.isInMap(env);
- }
-} \ No newline at end of file
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
+public class EnvironmentsEngineTest {
+
+ @InjectMocks
+ private EnvironmentsEngine envEngine;
+ @Mock
+ private OperationalEnvironmentDao operationalEnvironmentDao;
+ @Mock
+ private ConfigurationManager configurationManager;
+ @Mock
+ private DistributionEngineConfiguration distributionEngineConfiguration;
+ @Mock
+ private AaiRequestHandler aaiRequestHandler;
+
+ @Before
+ public void preStart() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void testInit() {
+ envEngine.setConfigurationManager(configurationManager);
+ Configuration config = Mockito.mock(Configuration.class);
+ DmaapConsumerConfiguration dmaapConf = Mockito.mock(DmaapConsumerConfiguration.class);
+ List<OperationalEnvironmentEntry> entryList = Arrays.asList(createOpEnvEntry("Env1"), createOpEnvEntry("Env2"));
+ Either<List<OperationalEnvironmentEntry>, CassandraOperationStatus> successEither = Either.left(entryList);
+ when(operationalEnvironmentDao.getByEnvironmentsStatus(EnvironmentStatusEnum.COMPLETED)).thenReturn(successEither);
+ when(configurationManager.getDistributionEngineConfiguration()).thenReturn(distributionEngineConfiguration);
+ when(distributionEngineConfiguration.getEnvironments()).thenReturn(Arrays.asList("Env Loaded From Configuration"));
+ when(distributionEngineConfiguration.getUebPublicKey()).thenReturn("Dummy Public Key");
+ when(distributionEngineConfiguration.getUebSecretKey()).thenReturn("Dummy Private Key");
+ when(distributionEngineConfiguration.getUebServers()).thenReturn(
+ Arrays.asList("uebsb91kcdc.it.com:3904", "uebsb92kcdc.it.com:3904", "uebsb91kcdc.it.com:3904"));
+ when(configurationManager.getConfiguration()).thenReturn(config);
+ when(config.getDmaapConsumerConfiguration()).thenReturn(dmaapConf);
+ when(dmaapConf.isActive()).thenReturn(false);
+ envEngine.init();
+
+ Map<String, OperationalEnvironmentEntry> mapEnvs = envEngine.getEnvironments();
+ assertEquals("unexpected size of map",3, mapEnvs.size());
+ }
+
+
+ @Test
+ public void testGetFullOperationalEnvByIdSuccess() {
+ String json = getFullOperationalEnvJson();
+
+ HttpResponse restResponse = new HttpResponse(json, HttpStatus.SC_OK, "Successfully completed");
+ when(aaiRequestHandler.getOperationalEnvById(Mockito.anyString())).thenReturn(restResponse);
+
+ Either<OperationalEnvInfo, Integer> response = envEngine.getOperationalEnvById("DummyId");
+ assertTrue("The operational environment request ran as not expected", response.isLeft());
+
+ OperationalEnvInfo operationalEnvInfo = response.left().value();
+
+ assertEquals("The operational environment json is not as expected", operationalEnvInfo.toString(), json);
+ }
+
+ @Test
+ public void testGetPartialOperationalEnvByIdSuccess() {
+ String json = getPartialOperationalEnvJson();
+
+ HttpResponse<String> restResponse = new HttpResponse<String>(json, HttpStatus.SC_OK, "Successfully completed");
+ when(aaiRequestHandler.getOperationalEnvById(Mockito.anyString())).thenReturn(restResponse);
+
+ Either<OperationalEnvInfo, Integer> response = envEngine.getOperationalEnvById("DummyId");
+ assertTrue("The operational environment request ran as not expected", response.isLeft());
+
+ OperationalEnvInfo operationalEnvInfo = response.left().value();
+
+ assertEquals("The operational environment json is not as expected", operationalEnvInfo.toString(), json);
+ }
+
+
+ @Test
+ public void testGetOperationalEnvByIdFailedByJsonConvert() {
+ String jsonCorrupted = getCorruptedOperationalEnvJson();
+
+ HttpResponse<String> restResponse = new HttpResponse<String>(jsonCorrupted, HttpStatus.SC_OK, "Successfully Completed");
+ when(aaiRequestHandler.getOperationalEnvById(Mockito.anyString())).thenReturn(restResponse);
+
+ Either<OperationalEnvInfo, Integer> response = envEngine.getOperationalEnvById("DummyId");
+ assertTrue("The operational environment request ran as not expected", response.isRight());
+ assertEquals("The operational environment request status code is not as expected", (Integer)HttpStatus.SC_INTERNAL_SERVER_ERROR, response.right().value());
+ }
+
+ @Test
+ public void testGetOperationalEnvByIdFailed404() {
+ String json = getFullOperationalEnvJson();
+ HttpResponse<String> restResponse = new HttpResponse<String>(json, HttpStatus.SC_NOT_FOUND, "Not Found");
+ when(aaiRequestHandler.getOperationalEnvById(Mockito.anyString())).thenReturn(restResponse);
+
+ Either<OperationalEnvInfo, Integer> response = envEngine.getOperationalEnvById("DummyId");
+ assertTrue("The operational environment request ran as not expected", response.isRight());
+ assertEquals("The operational environment request status code is not as expected", (Integer)HttpStatus.SC_NOT_FOUND, response.right().value());
+ }
+
+
+ @Test(expected = IOException.class)
+ public void testCorruptedOperationalEnvJson() throws IOException {
+ String jsonCorrupted = getCorruptedOperationalEnvJson();
+ OperationalEnvInfo.createFromJson(jsonCorrupted);
+ }
+
+ @Test
+ public void getEnvironmentById() {
+ OperationalEnvironmentEntry oe = new OperationalEnvironmentEntry();
+ oe.setEnvironmentId("mock");
+ envEngine.addToMap(oe);
+ assertTrue(envEngine.isInMap("mock"));
+ assertTrue(envEngine.isInMap(oe));
+ OperationalEnvironmentEntry returnedOe = envEngine.getEnvironmentById("mock");
+ assertTrue(oe == returnedOe);
+ }
+
+ private String getCorruptedOperationalEnvJson() {
+ return "{\"OPERATIONAL-environment-name\":\"Op Env Name\","
+ + "\"OPERATIONAL-environment-type\":\"VNF\","
+ + "\"OPERATIONAL-environment-status\":\"Activate\","
+ + "\"tenant-context\":\"Test\"}";
+ }
+
+ private String getPartialOperationalEnvJson() {
+ return "{" +
+ "\"operational-environment-id\":\"UUID of Operational Environment\"," +
+ "\"operational-environment-name\":\"Op Env Name\"," +
+ "\"operational-environment-type\":\"VNF\"," +
+ "\"operational-environment-status\":\"Activate\"," +
+ "\"tenant-context\":\"Test\"," +
+ "\"workload-context\":\"VNF_Development\"," +
+ "\"resource-version\":\"1505228226913\"," +
+ "\"relationship-list\":{" +
+ "\"relationship\":[]" +
+ "}" +
+ "}";
+ }
+
+ private String getFullOperationalEnvJson() {
+ return "{" +
+ "\"operational-environment-id\":\"OEid1\"," +
+ "\"operational-environment-name\":\"OEname1\"," +
+ "\"operational-environment-type\":\"OEtype1\"," +
+ "\"operational-environment-status\":\"OEstatus1\"," +
+ "\"tenant-context\":\"OEtenantcontext1\"," +
+ "\"workload-context\":\"OEworkloadcontext1\"," +
+ "\"resource-version\":\"1511363173278\"," +
+ "\"relationship-list\":{" +
+ "\"relationship\":[" +
+ "{" +
+ "\"related-to\":\"operational-environment\"," +
+ "\"relationship-label\":\"managedBy\"," +
+ "\"related-link\":\"/aai/v12/cloud-infrastructure/operational-environments/operational-environment/OEid3\"," +
+ "\"relationship-data\":[" +
+ "{" +
+ "\"relationship-key\":\"operational-environment.operational-environment-id\"," +
+ "\"relationship-value\":\"OEid3\"" +
+ "}" +
+ "]," +
+ "\"related-to-property\":[" +
+ "{" +
+ "\"property-key\":\"operational-environment.operational-environment-name\"," +
+ "\"property-value\":\"OEname3\"" +
+ "}]}]}}";
+ }
+
+ private OperationalEnvironmentEntry createOpEnvEntry(String name) {
+ OperationalEnvironmentEntry entry = new OperationalEnvironmentEntry();
+ entry.setEnvironmentId(name);
+ return entry;
+ }
+
+ public void testHandleMessageLogic() throws Exception {
+ String notification = "";
+ boolean result;
+
+ // default test
+ result = envEngine.handleMessageLogic(notification);
+ }
+
+ @Test
+ public void testValidateNotification() throws Exception {
+ Wrapper<Boolean> errorWrapper = new Wrapper<>();
+ errorWrapper.setInnerElement(true);
+ IDmaapNotificationData notificationData = Mockito.mock(IDmaapNotificationData.class);
+ IDmaapAuditNotificationData auditNotificationData = Mockito.mock(IDmaapAuditNotificationData.class);
+
+ // default test
+ Deencapsulation.invoke(envEngine, "validateNotification", errorWrapper, notificationData,
+ auditNotificationData);
+ }
+
+ @Test
+ public void testSaveEntryWithFailedStatus() throws Exception {
+ Wrapper<Boolean> errorWrapper = new Wrapper<>();
+ OperationalEnvironmentEntry opEnvEntry = new OperationalEnvironmentEntry();
+
+ // default test
+ Deencapsulation.invoke(envEngine, "saveEntryWithFailedStatus", errorWrapper, opEnvEntry);
+ }
+
+ @Test
+ public void testRetrieveUebAddressesFromAftDme() throws Exception {
+ Wrapper<Boolean> errorWrapper = new Wrapper<>();
+ OperationalEnvironmentEntry opEnvEntry = new OperationalEnvironmentEntry();
+
+ // default test
+ Deencapsulation.invoke(envEngine, "retrieveUebAddressesFromAftDme", errorWrapper, opEnvEntry);
+ }
+
+ @Test
+ public void testRetrieveOpEnvInfoFromAAI() 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>("{}", 200));
+ // default test
+ Deencapsulation.invoke(envEngine, "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
+ Deencapsulation.invoke(envEngine, "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(envEngine, "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(envEngine, "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(envEngine, "validateState", new Wrapper<>(), notificationData);
+ }
+
+ @Test
+ public void testValidateActionType() throws Exception {
+ Wrapper<Boolean> errorWrapper = new Wrapper<>();
+ IDmaapNotificationData notificationData = Mockito.mock(IDmaapNotificationData.class);
+ Mockito.when(notificationData.getAction()).thenReturn(IDmaapNotificationData.DmaapActionEnum.DELETE);
+
+ Deencapsulation.invoke(envEngine, "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(IDmaapNotificationData.DmaapActionEnum.CREATE);
+
+ Deencapsulation.invoke(envEngine, "validateActionType", errorWrapper, notificationData);
+ }
+
+ @Test
+ public void testValidateEnvironmentType() 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(IDmaapNotificationData.OperationaEnvironmentTypeEnum.ECOMP);
+
+ // default test
+ Deencapsulation.invoke(envEngine, "validateEnvironmentType", errorWrapper, notificationData,
+ auditNotificationData);
+ }
+
+ @Test
+ public void testMap2OpEnvKey() throws Exception {
+ OperationalEnvironmentEntry entry = new OperationalEnvironmentEntry();
+ String result;
+
+ // default test
+ result = Deencapsulation.invoke(envEngine, "map2OpEnvKey", entry);
+ }
+}