summaryrefslogtreecommitdiffstats
path: root/catalog-be
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/auditing/impl/AuditConsumerEventFactory.java9
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/health/HealthCheckBusinessLogic.java4
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/scheduledtasks/AsdcComponentsCleanerTask.java6
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/ComponentValidations.java2
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/AuditConsumerEventFactoryTest.java66
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/HealthCheckBusinessLogicTest.java22
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEnginePollingTaskTest.java218
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/health/HealthCheckBusinessLogicHealthTest.java467
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/PropertyInstanceMergeDataBuilderTest.java107
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/scheduledtasks/AsdcComponentsCleanerTaskTest.java149
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/ComponentValidationsTest.java218
11 files changed, 561 insertions, 707 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/auditing/impl/AuditConsumerEventFactory.java b/catalog-be/src/main/java/org/openecomp/sdc/be/auditing/impl/AuditConsumerEventFactory.java
index 9233a1a73e..35d4c4ac27 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/auditing/impl/AuditConsumerEventFactory.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/auditing/impl/AuditConsumerEventFactory.java
@@ -35,18 +35,13 @@ public class AuditConsumerEventFactory extends AuditBaseEventFactory {
this(action, commonFields, buildConsumerName(ecompUser), buildUserName(modifier));
}
- public AuditConsumerEventFactory(AuditingActionEnum action, CommonAuditData commonFields, String ecompUser, String modifier, String timestamp) {
- this(action, commonFields, ecompUser, modifier);
- this.event.setTimestamp1(timestamp);
- }
-
private AuditConsumerEventFactory(AuditingActionEnum action, CommonAuditData commonFields, String ecompUser, String modifier) {
super(action);
event = new ConsumerEvent(getAction().getName(), commonFields, ecompUser, modifier);
}
- static String buildConsumerName(ConsumerDefinition consumer) {
- StringBuilder ecompUser = new StringBuilder();
+ private static String buildConsumerName(ConsumerDefinition consumer) {
+ final var ecompUser = new StringBuilder();
if (consumer != null) {
appendIfNotEmpty(consumer.getConsumerName(), ecompUser, ",");
appendIfNotEmpty(consumer.getConsumerSalt(), ecompUser, ",");
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/health/HealthCheckBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/health/HealthCheckBusinessLogic.java
index 3372d551ca..22013c1c04 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/health/HealthCheckBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/health/HealthCheckBusinessLogic.java
@@ -35,7 +35,6 @@ import static org.openecomp.sdc.common.impl.ExternalConfiguration.getAppVersion;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
-import com.google.common.annotations.VisibleForTesting;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -382,8 +381,7 @@ public class HealthCheckBusinessLogic {
}
}
- @VisibleForTesting
- String buildOnBoardingHealthCheckUrl() {
+ private String buildOnBoardingHealthCheckUrl() {
Configuration.OnboardingConfig onboardingConfig = ConfigurationManager.getConfigurationManager().getConfiguration().getOnboarding();
if (onboardingConfig != null) {
return String.format(hcUrl, onboardingConfig.getProtocol(), onboardingConfig.getHost(), onboardingConfig.getPort(),
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/scheduledtasks/AsdcComponentsCleanerTask.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/scheduledtasks/AsdcComponentsCleanerTask.java
index 64874a9fa8..a0511f4dc0 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/scheduledtasks/AsdcComponentsCleanerTask.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/scheduledtasks/AsdcComponentsCleanerTask.java
@@ -66,9 +66,9 @@ public class AsdcComponentsCleanerTask extends AbstractScheduleTaskRunner implem
}
for (String component : components) {
NodeTypeEnum typeEnum = NodeTypeEnum.getByNameIgnoreCase(component);
- if (typeEnum != null) {
- componentsToClean.add(typeEnum);
- }
+ if (typeEnum != null) {
+ componentsToClean.add(typeEnum);
+ }
}
long intervalInMinutes = cleanComponentsConfiguration.getCleanIntervalInMinutes();
if (intervalInMinutes < 1) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/ComponentValidations.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/ComponentValidations.java
index 10bb1d0ea6..ea5185396d 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/ComponentValidations.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/ComponentValidations.java
@@ -62,7 +62,7 @@ public class ComponentValidations {
.filter(instancesIds -> instancesIds.contains(instanceId)).isPresent();
}
- public static String getNormalizedName(ToscaDataDefinition toscaDataDefinition) {
+ private static String getNormalizedName(ToscaDataDefinition toscaDataDefinition) {
String name = (String) toscaDataDefinition.getToscaPresentationValue(JsonPresentationFields.NAME);
return org.openecomp.sdc.common.util.ValidationUtils.normalizeComponentInstanceName(name);
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/AuditConsumerEventFactoryTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/AuditConsumerEventFactoryTest.java
index b269d7b035..da4aea8e0f 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/AuditConsumerEventFactoryTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/AuditConsumerEventFactoryTest.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,9 +20,8 @@
package org.openecomp.sdc.be.auditing.impl;
-import mockit.Deencapsulation;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
import org.openecomp.sdc.be.model.ConsumerDefinition;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
@@ -30,44 +29,33 @@ import org.openecomp.sdc.be.resources.data.auditing.AuditingGenericEvent;
import org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData;
import org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData.Builder;
-public class AuditConsumerEventFactoryTest {
+class AuditConsumerEventFactoryTest {
- private AuditConsumerEventFactory createTestSubject() {
- Builder newBuilder = CommonAuditData.newBuilder();
- CommonAuditData build = newBuilder.build();
- return new AuditConsumerEventFactory(AuditingActionEnum.ACTIVATE_SERVICE_BY_API, build, new User(),
- new ConsumerDefinition());
- }
+ private AuditConsumerEventFactory createTestSubject() {
+ final CommonAuditData build = CommonAuditData.newBuilder().build();
+ return new AuditConsumerEventFactory(AuditingActionEnum.ACTIVATE_SERVICE_BY_API, build, new User(), new ConsumerDefinition());
+ }
- @Test
- public void testGetDbEvent() throws Exception {
- AuditConsumerEventFactory testSubject;
- AuditingGenericEvent result;
+ @Test
+ void testGetDbEvent() throws Exception {
+ AuditConsumerEventFactory testSubject;
+ AuditingGenericEvent result;
- // default test
- testSubject = createTestSubject();
- result = testSubject.getDbEvent();
- }
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getDbEvent();
+ Assertions.assertNotNull(result);
+ }
- @Test
- public void testGetLogMessage() throws Exception {
- AuditConsumerEventFactory testSubject;
- String result;
+ @Test
+ void testGetLogMessage() throws Exception {
+ AuditConsumerEventFactory testSubject;
+ String result;
- // default test
- testSubject = createTestSubject();
- result = testSubject.getLogMessage();
- }
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getLogMessage();
+ Assertions.assertNotNull(result);
+ }
- @Test
- public void testBuildConsumerName() throws Exception {
- ConsumerDefinition consumer = null;
- String result;
-
- // test 1
- consumer = null;
- result = Deencapsulation.invoke(AuditConsumerEventFactory.class, "buildConsumerName",
- new Object[] { ConsumerDefinition.class });
- Assert.assertEquals("", result);
- }
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/HealthCheckBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/HealthCheckBusinessLogicTest.java
index a31b5feb51..a7bd408b3e 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/HealthCheckBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/HealthCheckBusinessLogicTest.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -22,24 +22,20 @@
package org.openecomp.sdc.be.components;
-import org.junit.Test;
-import org.mockito.Mockito;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.junit.jupiter.api.Test;
import org.openecomp.sdc.be.components.health.HealthCheckBusinessLogic;
-import org.openecomp.sdc.be.switchover.detector.SwitchoverDetector;
import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.api.HealthCheckInfo;
import org.openecomp.sdc.common.api.HealthCheckInfo.HealthCheckStatus;
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
public class HealthCheckBusinessLogicTest {
- private final SwitchoverDetector switchoverDetector = Mockito.mock(SwitchoverDetector.class);
-
- HealthCheckBusinessLogic healthCheckBusinessLogic = new HealthCheckBusinessLogic();
+ final HealthCheckBusinessLogic healthCheckBusinessLogic = new HealthCheckBusinessLogic();
@Test
public void checkStatusUpdated() {
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEnginePollingTaskTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEnginePollingTaskTest.java
index be450c493b..95e3553990 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEnginePollingTaskTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEnginePollingTaskTest.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,120 +20,120 @@
package org.openecomp.sdc.be.components.distribution.engine;
-import mockit.Deencapsulation;
-import org.junit.Test;
+import java.lang.reflect.Method;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.openecomp.sdc.be.components.BeConfDependentTest;
import org.openecomp.sdc.be.components.distribution.engine.report.DistributionCompleteReporter;
+import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.config.DistributionEngineConfiguration;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.resources.data.OperationalEnvironmentEntry;
+import org.openecomp.sdc.common.impl.ExternalConfiguration;
+import org.openecomp.sdc.common.impl.FSConfigurationSource;
import org.openecomp.sdc.common.log.wrappers.LoggerSdcAudit;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-
-public class DistributionEnginePollingTaskTest extends BeConfDependentTest {
-
- @Mock
- private ComponentsUtils componentsUtils;
-
- private DistributionEnginePollingTask createTestSubject() {
- componentsUtils = Mockito.mock(ComponentsUtils.class);
- DistributionEngineConfiguration distributionEngineConfiguration = configurationManager
- .getDistributionEngineConfiguration();
- distributionEngineConfiguration.setDistributionNotifTopicName("StamName");
- distributionEngineConfiguration.setDistributionStatusTopicName("StamName");
- List uebList = new LinkedList<>();
- uebList.add("FirstUEBserver.com");
- distributionEngineConfiguration.setUebServers(uebList);
-
- OperationalEnvironmentEntry environmentEntry = new OperationalEnvironmentEntry();
- HashSet<String> dmaapUebAddress = new HashSet<>();
- dmaapUebAddress.add("STAM");
- environmentEntry.setDmaapUebAddress(dmaapUebAddress);
- return new DistributionEnginePollingTask(distributionEngineConfiguration,
- new DistributionCompleteReporterMock(), componentsUtils, new DistributionEngineClusterHealth(),
- environmentEntry);
- }
-
- @Test
- public void testStartTask() throws Exception {
- DistributionEnginePollingTask testSubject;
- String topicName = "UEBTopic";
-
- // default test
- testSubject = createTestSubject();
- testSubject.startTask(topicName);
- }
-
- @Test
- public void testStopTask() throws Exception {
- DistributionEnginePollingTask testSubject;
-
- // default test
- testSubject = createTestSubject();
- testSubject.stopTask();
- }
-
- @Test
- public void testDestroy() throws Exception {
- DistributionEnginePollingTask testSubject;
-
- // default test
- testSubject = createTestSubject();
- testSubject.destroy();
- }
-
- @Test
- public void testRun() throws Exception {
- DistributionEnginePollingTask testSubject;
-
- // default test
- testSubject = createTestSubject();
- testSubject.run();
- }
-
- @Test
- public void testHandleDistributionNotificationMsg() throws Exception {
- DistributionEnginePollingTask testSubject;
- DistributionStatusNotification notification = new DistributionStatusNotification();
- notification.setDistributionID("mock");
- notification.setConsumerID("mock");
- notification.setArtifactURL("mock");
- notification.setTimestamp(435435);
- notification.setStatus(DistributionStatusNotificationEnum.ALREADY_DEPLOYED);
- notification.setErrorReason("mock");
-
-
-
- // default test
- testSubject = createTestSubject();
- Mockito.doNothing().when(componentsUtils).auditDistributionStatusNotification( Mockito.anyString(),
- Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
- Mockito.anyString(), Mockito.anyString(), Mockito.isNull());
- Deencapsulation.invoke(testSubject, "handleDistributionNotificationMsg",
- notification, new LoggerSdcAudit(DistributionEnginePollingTask.class));
- }
-
- @Test
- public void testShutdownExecutor() throws Exception {
- DistributionEnginePollingTask testSubject;
-
- // default test
- testSubject = createTestSubject();
- Deencapsulation.invoke(testSubject, "shutdownExecutor");
- }
-
- private class DistributionCompleteReporterMock implements DistributionCompleteReporter {
-
- @Override
- public void reportDistributionComplete(DistributionStatusNotification distributionStatusNotification) {
- // TODO Auto-generated method stub
-
- }
-
- }
+class DistributionEnginePollingTaskTest extends BeConfDependentTest {
+
+ // TODO - remove this setup after migration to Junit5 BeConfDependentTest
+ @BeforeAll
+ private static void setup() {
+ configurationManager =
+ new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be"));
+ }
+
+ @Mock
+ private ComponentsUtils componentsUtils;
+
+ private DistributionEnginePollingTask createTestSubject() {
+ componentsUtils = Mockito.mock(ComponentsUtils.class);
+ DistributionEngineConfiguration distributionEngineConfiguration = configurationManager
+ .getDistributionEngineConfiguration();
+ distributionEngineConfiguration.setDistributionNotifTopicName("StamName");
+ distributionEngineConfiguration.setDistributionStatusTopicName("StamName");
+ List uebList = new LinkedList<>();
+ uebList.add("FirstUEBserver.com");
+ distributionEngineConfiguration.setUebServers(uebList);
+
+ OperationalEnvironmentEntry environmentEntry = new OperationalEnvironmentEntry();
+ HashSet<String> dmaapUebAddress = new HashSet<>();
+ dmaapUebAddress.add("STAM");
+ environmentEntry.setDmaapUebAddress(dmaapUebAddress);
+ return new DistributionEnginePollingTask(distributionEngineConfiguration,
+ new DistributionCompleteReporterMock(), componentsUtils, new DistributionEngineClusterHealth(), environmentEntry);
+ }
+
+ @Test
+ void testStartTask() throws Exception {
+ DistributionEnginePollingTask testSubject;
+ String topicName = "UEBTopic";
+
+ // default test
+ testSubject = createTestSubject();
+ testSubject.startTask(topicName);
+ }
+
+ @Test
+ void testStopTask() throws Exception {
+ DistributionEnginePollingTask testSubject;
+
+ // default test
+ testSubject = createTestSubject();
+ testSubject.stopTask();
+ }
+
+ @Test
+ void testDestroy() throws Exception {
+ DistributionEnginePollingTask testSubject;
+
+ // default test
+ testSubject = createTestSubject();
+ testSubject.destroy();
+ }
+
+ @Test
+ void testRun() throws Exception {
+ DistributionEnginePollingTask testSubject;
+
+ // default test
+ testSubject = createTestSubject();
+ testSubject.run();
+ }
+
+ @Test
+ void testHandleDistributionNotificationMsg() throws Exception {
+ DistributionEnginePollingTask testSubject;
+ final DistributionStatusNotification notification = new DistributionStatusNotification();
+ notification.setDistributionID("mock");
+ notification.setConsumerID("mock");
+ notification.setArtifactURL("mock");
+ notification.setTimestamp(435435);
+ notification.setStatus(DistributionStatusNotificationEnum.ALREADY_DEPLOYED);
+ notification.setErrorReason("mock");
+
+ // default test
+ testSubject = createTestSubject();
+ Mockito.doNothing().when(componentsUtils).auditDistributionStatusNotification(Mockito.anyString(),
+ Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
+ Mockito.anyString(), Mockito.anyString(), Mockito.isNull());
+
+ final Class[] argClasses = {DistributionStatusNotification.class, LoggerSdcAudit.class};
+ final Method method = DistributionEnginePollingTask.class.getDeclaredMethod("handleDistributionNotificationMsg", argClasses);
+ method.setAccessible(true);
+ method.invoke(testSubject, notification, new LoggerSdcAudit(DistributionEnginePollingTask.class));
+ }
+
+ private class DistributionCompleteReporterMock implements DistributionCompleteReporter {
+
+ @Override
+ public void reportDistributionComplete(DistributionStatusNotification distributionStatusNotification) {
+ // TODO Auto-generated method stub
+ }
+
+ }
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/health/HealthCheckBusinessLogicHealthTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/health/HealthCheckBusinessLogicHealthTest.java
index 7f4b82bcaf..eee5e3cf56 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/health/HealthCheckBusinessLogicHealthTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/health/HealthCheckBusinessLogicHealthTest.java
@@ -20,289 +20,208 @@
package org.openecomp.sdc.be.components.health;
-import mockit.Deencapsulation;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.junit.MockitoJUnitRunner;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import java.util.LinkedList;
+import java.util.List;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.onap.portalsdk.core.onboarding.exception.CipherUtilException;
import org.openecomp.sdc.be.catalog.impl.DmaapProducerHealth;
import org.openecomp.sdc.be.components.BeConfDependentTest;
import org.openecomp.sdc.be.components.distribution.engine.DistributionEngineClusterHealth;
import org.openecomp.sdc.be.components.distribution.engine.DmaapHealth;
+import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.switchover.detector.SwitchoverDetector;
import org.openecomp.sdc.common.api.HealthCheckInfo;
import org.openecomp.sdc.common.http.client.api.HttpExecuteException;
+import org.openecomp.sdc.common.impl.ExternalConfiguration;
+import org.openecomp.sdc.common.impl.FSConfigurationSource;
import org.springframework.test.util.ReflectionTestUtils;
-import java.util.LinkedList;
-import java.util.List;
-
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
-import static org.openecomp.sdc.common.api.Constants.HC_COMPONENT_ON_BOARDING;
-
-@RunWith(MockitoJUnitRunner.class)
-public class HealthCheckBusinessLogicHealthTest extends BeConfDependentTest {
- private DmaapProducerHealth dmaapProducerHealth = mock(DmaapProducerHealth.class);
- private HealthCheckInfo dmaapProducerHealthCheckInfo = mock(HealthCheckInfo.class);
-
- private SwitchoverDetector switchoverDetector;
-
- private HealthCheckBusinessLogic createTestSubject() {
-
- HealthCheckBusinessLogic healthCheckBusinessLogic = new HealthCheckBusinessLogic();
- DmaapHealth dmaapHealth = new DmaapHealth();
- ReflectionTestUtils.setField(healthCheckBusinessLogic, "dmaapHealth", dmaapHealth);
- PortalHealthCheckBuilder portalHealthCheckBuilder = new PortalHealthCheckBuilder();
- ReflectionTestUtils.setField(healthCheckBusinessLogic, "portalHealthCheck", portalHealthCheckBuilder);
- DistributionEngineClusterHealth distributionEngineClusterHealth = new DistributionEngineClusterHealth();
- ReflectionTestUtils.setField(healthCheckBusinessLogic, "distributionEngineClusterHealth",
- distributionEngineClusterHealth);
- SwitchoverDetector switchoverDetector = new SwitchoverDetector();
- ReflectionTestUtils.setField(healthCheckBusinessLogic, "switchoverDetector", switchoverDetector);
- List<HealthCheckInfo> prevBeHealthCheckInfos = new LinkedList<>();
- ReflectionTestUtils.setField(healthCheckBusinessLogic, "prevBeHealthCheckInfos", prevBeHealthCheckInfos);
- ReflectionTestUtils.setField(healthCheckBusinessLogic, "dmaapProducerHealth", dmaapProducerHealth);
- return healthCheckBusinessLogic;
- }
-
-
-
- @Before
- public void beforeTest() {
- when(dmaapProducerHealth.getHealthCheckInfo())
- .thenReturn(dmaapProducerHealthCheckInfo);
- }
-
- @Test
- public void testInit() throws Exception {
- HealthCheckBusinessLogic testSubject = createTestSubject();
- testSubject.init();
- }
-
- @Test
- public void testIsDistributionEngineUp() throws Exception {
- HealthCheckBusinessLogic testSubject;
- // default test
- testSubject = createTestSubject();
- testSubject.isDistributionEngineUp();
- }
-
- @Test
- public void testGetBeHealthCheckInfosStatus() throws Exception {
- HealthCheckBusinessLogic testSubject;
-
- // default test
- testSubject = createTestSubject();
- testSubject.getBeHealthCheckInfosStatus();
- }
-
- @Test
- public void testGetBeHealthCheckInfos() throws Exception {
- HealthCheckBusinessLogic testSubject;
-
- // default test
- testSubject = createTestSubject();
- Deencapsulation.invoke(testSubject, "getBeHealthCheckInfos");
- }
-
- @Test
- public void testGetDmaapHealthCheck() throws Exception {
- HealthCheckBusinessLogic testSubject;
- List<HealthCheckInfo> healthCheckInfos = new LinkedList<>();
-
- // default test
- testSubject = createTestSubject();
- Deencapsulation.invoke(testSubject, "getDmaapHealthCheck");
- }
-
- @Test
- public void testGetJanusGraphHealthCheck() throws Exception {
- HealthCheckBusinessLogic testSubject;
- List<HealthCheckInfo> healthCheckInfos = new LinkedList<>();
-
- // default test
- testSubject = createTestSubject();
-// testSubject.getJanusGraphHealthCheck(healthCheckInfos);
- healthCheckInfos.add(testSubject.getJanusGraphHealthCheck());
- }
-
- @Test
- public void testGetCassandraHealthCheck() throws Exception {
- HealthCheckBusinessLogic testSubject;
-
- // default test
- testSubject = createTestSubject();
- Deencapsulation.invoke(testSubject, "getCassandraHealthCheck");
- }
-
- @Test
- public void testGetDistributionEngineCheck() throws Exception {
-// HealthCheckBusinessLogic testSubject;
- DistributionEngineClusterHealth testSubject = new DistributionEngineClusterHealth();
-
- // default test
- Deencapsulation.invoke(testSubject, "getHealthCheckInfo");
- }
-
- @Test
- public void testGetAmdocsHealthCheck() throws Exception {
- HealthCheckBusinessLogic testSubject;
- List<HealthCheckInfo> healthCheckInfos = new LinkedList<>();
-
- // default test
- testSubject = createTestSubject();
- String url = testSubject.buildOnBoardingHealthCheckUrl();
- Deencapsulation.invoke(testSubject, "getHostedComponentsBeHealthCheck", HC_COMPONENT_ON_BOARDING, url);
- }
-
- @Test
- public void testGetPortalHealthCheckSuccess() throws Exception {
- PortalHealthCheckBuilder testSubject = spy(PortalHealthCheckBuilder.class);
- String healthCheckURL = testSubject.buildPortalHealthCheckUrl();
- int timeout = 3000;
- doReturn(200).when(testSubject).getStatusCode(eq(healthCheckURL), eq(timeout));
- testSubject.init();
- testSubject.runTask();
- HealthCheckInfo hci = testSubject.getHealthCheckInfo();
- Assert.assertEquals("PORTAL", hci.getHealthCheckComponent());
- Assert.assertEquals(HealthCheckInfo.HealthCheckStatus.UP, hci.getHealthCheckStatus());
- Assert.assertEquals("OK", hci.getDescription());
- }
-
- @Test
- public void testGetPortalHealthCheckFailureMissingConfig() throws Exception{
- PortalHealthCheckBuilder testSubject = new PortalHealthCheckBuilder();
- testSubject.init(null);
- HealthCheckInfo hci = testSubject.getHealthCheckInfo();
- Assert.assertEquals("PORTAL", hci.getHealthCheckComponent());
- Assert.assertEquals(HealthCheckInfo.HealthCheckStatus.DOWN, hci.getHealthCheckStatus());
- Assert.assertEquals("PORTAL health check configuration is missing", hci.getDescription());
- }
-
-
- @Test
- public void testGetPortalHealthCheckFailureErrorResponse() throws HttpExecuteException, CipherUtilException {
- PortalHealthCheckBuilder testSubject = spy(PortalHealthCheckBuilder.class);
- String healthCheckURL = testSubject.buildPortalHealthCheckUrl();
- int timeout = 3000;
-// when(testSubject.getStatusCode(healthCheckURL,timeout)).thenReturn(404);
- doReturn(404).when(testSubject).getStatusCode(eq(healthCheckURL), eq(timeout));
- testSubject.init(testSubject.getConfiguration());
- testSubject.runTask();
- HealthCheckInfo hci = testSubject.getHealthCheckInfo();
- Assert.assertEquals("PORTAL", hci.getHealthCheckComponent());
- Assert.assertEquals(HealthCheckInfo.HealthCheckStatus.DOWN, hci.getHealthCheckStatus());
- Assert.assertEquals("PORTAL responded with 404 status code", hci.getDescription());
- }
-
- @Test
- public void testGetPortalHealthCheckFailureNoResponse() throws HttpExecuteException, CipherUtilException {
- PortalHealthCheckBuilder testSubject = spy(PortalHealthCheckBuilder.class);
- String healthCheckURL = testSubject.buildPortalHealthCheckUrl();
- int timeout = 3000;
-// when(testSubject.getStatusCode(healthCheckURL, timeout)).thenThrow(HttpExecuteException.class);
- doThrow(HttpExecuteException.class).when(testSubject).getStatusCode(eq(healthCheckURL), eq(timeout));
- testSubject.init(testSubject.getConfiguration());
- testSubject.runTask();
- HealthCheckInfo hci = testSubject.getHealthCheckInfo();
- Assert.assertEquals("PORTAL", hci.getHealthCheckComponent());
- Assert.assertEquals(HealthCheckInfo.HealthCheckStatus.DOWN, hci.getHealthCheckStatus());
- Assert.assertEquals("PORTAL is not available", hci.getDescription());
- }
-
- @Test
- public void testGetHostedComponentsBeHealthCheck() throws Exception {
- HealthCheckBusinessLogic testSubject;
- String componentName = "mock";
- String healthCheckUrl = "mock";
- // test 1
- testSubject = createTestSubject();
- Deencapsulation.invoke(testSubject, "getHostedComponentsBeHealthCheck", componentName, healthCheckUrl);
-
- // test 2
- testSubject = createTestSubject();
- healthCheckUrl = "";
- Deencapsulation.invoke(testSubject, "getHostedComponentsBeHealthCheck", componentName, healthCheckUrl);
- }
-
- @Test
- public void testDestroy() throws Exception {
- HealthCheckBusinessLogic testSubject;
-
- // default test
- testSubject = createTestSubject();
- Deencapsulation.invoke(testSubject, "destroy");
- }
-
- @Test
- public void testLogAlarm() throws Exception {
- HealthCheckBusinessLogic testSubject;
- String componentChangedMsg = "mock";
-
- // default test
- testSubject = createTestSubject();
- Deencapsulation.invoke(testSubject, "logAlarm", componentChangedMsg);
- }
-
- @Test
- public void testGetSiteMode() throws Exception {
- HealthCheckBusinessLogic testSubject;
-
- // default test
- testSubject = createTestSubject();
- testSubject.getSiteMode();
- }
-
- @Test
- public void testAnyStatusChanged() throws Exception {
- HealthCheckBusinessLogic testSubject;
- List<HealthCheckInfo> beHealthCheckInfos = null;
- List<HealthCheckInfo> prevBeHealthCheckInfos = null;
- boolean result;
-
- // test 1
- testSubject = createTestSubject();
- beHealthCheckInfos = null;
- prevBeHealthCheckInfos = null;
- result = testSubject.anyStatusChanged(beHealthCheckInfos, prevBeHealthCheckInfos);
- Assert.assertEquals(false, result);
-
- // test 2
- testSubject = createTestSubject();
- prevBeHealthCheckInfos = null;
- beHealthCheckInfos = null;
- result = testSubject.anyStatusChanged(beHealthCheckInfos, prevBeHealthCheckInfos);
- Assert.assertEquals(false, result);
-
- // test 3
- testSubject = createTestSubject();
- beHealthCheckInfos = null;
- prevBeHealthCheckInfos = null;
- result = testSubject.anyStatusChanged(beHealthCheckInfos, prevBeHealthCheckInfos);
- Assert.assertEquals(false, result);
-
- // test 4
- testSubject = createTestSubject();
- prevBeHealthCheckInfos = null;
- beHealthCheckInfos = null;
- result = testSubject.anyStatusChanged(beHealthCheckInfos, prevBeHealthCheckInfos);
- Assert.assertEquals(false, result);
- }
-
- @Test
- public void testBuildOnBoardingHealthCheckUrl() throws Exception {
- HealthCheckBusinessLogic testSubject;
-
- // default test
- testSubject = createTestSubject();
- Deencapsulation.invoke(testSubject, "buildOnBoardingHealthCheckUrl");
- }
+@ExtendWith(MockitoExtension.class)
+class HealthCheckBusinessLogicHealthTest extends BeConfDependentTest {
+
+ // TODO - remove this setup after migration to Junit5 BeConfDependentTest
+ @BeforeAll
+ private static void setup() {
+ configurationManager =
+ new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be"));
+ }
+
+ private final DmaapProducerHealth dmaapProducerHealth = mock(DmaapProducerHealth.class);
+ private final HealthCheckInfo dmaapProducerHealthCheckInfo = mock(HealthCheckInfo.class);
+
+ private HealthCheckBusinessLogic createTestSubject() {
+
+ HealthCheckBusinessLogic healthCheckBusinessLogic = new HealthCheckBusinessLogic();
+ DmaapHealth dmaapHealth = new DmaapHealth();
+ ReflectionTestUtils.setField(healthCheckBusinessLogic, "dmaapHealth", dmaapHealth);
+ PortalHealthCheckBuilder portalHealthCheckBuilder = new PortalHealthCheckBuilder();
+ ReflectionTestUtils.setField(healthCheckBusinessLogic, "portalHealthCheck", portalHealthCheckBuilder);
+ DistributionEngineClusterHealth distributionEngineClusterHealth = new DistributionEngineClusterHealth();
+ ReflectionTestUtils.setField(healthCheckBusinessLogic, "distributionEngineClusterHealth",
+ distributionEngineClusterHealth);
+ SwitchoverDetector switchoverDetector = new SwitchoverDetector();
+ ReflectionTestUtils.setField(healthCheckBusinessLogic, "switchoverDetector", switchoverDetector);
+ List<HealthCheckInfo> prevBeHealthCheckInfos = new LinkedList<>();
+ ReflectionTestUtils.setField(healthCheckBusinessLogic, "prevBeHealthCheckInfos", prevBeHealthCheckInfos);
+ ReflectionTestUtils.setField(healthCheckBusinessLogic, "dmaapProducerHealth", dmaapProducerHealth);
+ return healthCheckBusinessLogic;
+ }
+
+ @BeforeEach
+ private void beforeTest() {
+ when(dmaapProducerHealth.getHealthCheckInfo())
+ .thenReturn(dmaapProducerHealthCheckInfo);
+ }
+
+ @Test
+ void testInit() throws Exception {
+ HealthCheckBusinessLogic testSubject = createTestSubject();
+ testSubject.init();
+ }
+
+ @Test
+ void testIsDistributionEngineUp() throws Exception {
+ HealthCheckBusinessLogic testSubject;
+ // default test
+ testSubject = createTestSubject();
+ testSubject.isDistributionEngineUp();
+ }
+
+ @Test
+ void testGetBeHealthCheckInfosStatus() throws Exception {
+ HealthCheckBusinessLogic testSubject;
+
+ // default test
+ testSubject = createTestSubject();
+ testSubject.getBeHealthCheckInfosStatus();
+ }
+
+ @Test
+ void testGetJanusGraphHealthCheck() throws Exception {
+ HealthCheckBusinessLogic testSubject;
+ List<HealthCheckInfo> healthCheckInfos = new LinkedList<>();
+
+ // default test
+ testSubject = createTestSubject();
+ healthCheckInfos.add(testSubject.getJanusGraphHealthCheck());
+ }
+
+ @Test
+ void testGetPortalHealthCheckSuccess() throws Exception {
+ PortalHealthCheckBuilder testSubject = spy(PortalHealthCheckBuilder.class);
+ String healthCheckURL = testSubject.buildPortalHealthCheckUrl();
+ int timeout = 3000;
+ doReturn(200).when(testSubject).getStatusCode(healthCheckURL, timeout);
+ testSubject.init();
+ testSubject.runTask();
+ HealthCheckInfo hci = testSubject.getHealthCheckInfo();
+ Assertions.assertEquals("PORTAL", hci.getHealthCheckComponent());
+ Assertions.assertEquals(HealthCheckInfo.HealthCheckStatus.UP, hci.getHealthCheckStatus());
+ Assertions.assertEquals("OK", hci.getDescription());
+ }
+
+ @Test
+ void testGetPortalHealthCheckFailureMissingConfig() throws Exception {
+ PortalHealthCheckBuilder testSubject = new PortalHealthCheckBuilder();
+ testSubject.init(null);
+ HealthCheckInfo hci = testSubject.getHealthCheckInfo();
+ Assertions.assertEquals("PORTAL", hci.getHealthCheckComponent());
+ Assertions.assertEquals(HealthCheckInfo.HealthCheckStatus.DOWN, hci.getHealthCheckStatus());
+ Assertions.assertEquals("PORTAL health check configuration is missing", hci.getDescription());
+ }
+
+ @Test
+ void testGetPortalHealthCheckFailureErrorResponse() throws HttpExecuteException, CipherUtilException {
+ PortalHealthCheckBuilder testSubject = spy(PortalHealthCheckBuilder.class);
+ String healthCheckURL = testSubject.buildPortalHealthCheckUrl();
+ int timeout = 3000;
+ doReturn(404).when(testSubject).getStatusCode(healthCheckURL, timeout);
+ testSubject.init(testSubject.getConfiguration());
+ testSubject.runTask();
+ HealthCheckInfo hci = testSubject.getHealthCheckInfo();
+ Assertions.assertEquals("PORTAL", hci.getHealthCheckComponent());
+ Assertions.assertEquals(HealthCheckInfo.HealthCheckStatus.DOWN, hci.getHealthCheckStatus());
+ Assertions.assertEquals("PORTAL responded with 404 status code", hci.getDescription());
+ }
+
+ @Test
+ void testGetPortalHealthCheckFailureNoResponse() throws HttpExecuteException, CipherUtilException {
+ PortalHealthCheckBuilder testSubject = spy(PortalHealthCheckBuilder.class);
+ String healthCheckURL = testSubject.buildPortalHealthCheckUrl();
+ int timeout = 3000;
+ doThrow(HttpExecuteException.class).when(testSubject).getStatusCode(healthCheckURL, timeout);
+ testSubject.init(testSubject.getConfiguration());
+ testSubject.runTask();
+ HealthCheckInfo hci = testSubject.getHealthCheckInfo();
+ Assertions.assertEquals("PORTAL", hci.getHealthCheckComponent());
+ Assertions.assertEquals(HealthCheckInfo.HealthCheckStatus.DOWN, hci.getHealthCheckStatus());
+ Assertions.assertEquals("PORTAL is not available", hci.getDescription());
+ }
+
+ @Test
+ void testDestroy() throws Exception {
+ HealthCheckBusinessLogic testSubject;
+
+ // default test
+ testSubject = createTestSubject();
+ testSubject.init();
+ testSubject.destroy();
+ }
+
+ @Test
+ void testGetSiteMode() throws Exception {
+ HealthCheckBusinessLogic testSubject;
+
+ // default test
+ testSubject = createTestSubject();
+ testSubject.getSiteMode();
+ }
+
+ @Test
+ void testAnyStatusChanged() throws Exception {
+ HealthCheckBusinessLogic testSubject;
+ List<HealthCheckInfo> beHealthCheckInfos = null;
+ List<HealthCheckInfo> prevBeHealthCheckInfos = null;
+ boolean result;
+
+ // test 1
+ testSubject = createTestSubject();
+ beHealthCheckInfos = null;
+ prevBeHealthCheckInfos = null;
+ result = testSubject.anyStatusChanged(beHealthCheckInfos, prevBeHealthCheckInfos);
+ Assertions.assertEquals(false, result);
+
+ // test 2
+ testSubject = createTestSubject();
+ prevBeHealthCheckInfos = null;
+ beHealthCheckInfos = null;
+ result = testSubject.anyStatusChanged(beHealthCheckInfos, prevBeHealthCheckInfos);
+ Assertions.assertEquals(false, result);
+
+ // test 3
+ testSubject = createTestSubject();
+ beHealthCheckInfos = null;
+ prevBeHealthCheckInfos = null;
+ result = testSubject.anyStatusChanged(beHealthCheckInfos, prevBeHealthCheckInfos);
+ Assertions.assertEquals(false, result);
+
+ // test 4
+ testSubject = createTestSubject();
+ prevBeHealthCheckInfos = null;
+ beHealthCheckInfos = null;
+ result = testSubject.anyStatusChanged(beHealthCheckInfos, prevBeHealthCheckInfos);
+ Assertions.assertEquals(false, result);
+ }
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/PropertyInstanceMergeDataBuilderTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/PropertyInstanceMergeDataBuilderTest.java
index a5443ee94c..19c53b9436 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/PropertyInstanceMergeDataBuilderTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/PropertyInstanceMergeDataBuilderTest.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,83 +20,42 @@
package org.openecomp.sdc.be.components.merge.property;
-import mockit.Deencapsulation;
-import org.apache.tinkerpop.gremlin.structure.T;
-import org.junit.Test;
+import java.util.ArrayList;
+import java.util.List;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.model.InputDefinition;
-
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
+import org.openecomp.sdc.be.model.PropertyDefinition;
public class PropertyInstanceMergeDataBuilderTest {
+ @Test
+ public void testBuildDataForMerging() throws Exception {
+ final InputDefinition inputDefinition = new InputDefinition();
+ inputDefinition.setName("mock");
+ final List<GetInputValueDataDefinition> inputValues = new ArrayList<>();
+ inputValues.add(new GetInputValueDataDefinition());
+ inputDefinition.setGetInputValues(inputValues);
+
+ final List<PropertyDataDefinition> oldProps = new ArrayList<>();
+ final List<InputDefinition> oldInputs = new ArrayList<>();
+ oldInputs.add(inputDefinition);
+ oldProps.addAll(oldInputs);
+
+ final List<PropertyDataDefinition> newProps = new ArrayList<>();
+ final List<InputDefinition> newInputs = new ArrayList<>();
+ newInputs.add(inputDefinition);
+ newProps.addAll(oldInputs);
+
+ final List<MergePropertyData> result = PropertyInstanceMergeDataBuilder.buildDataForMerging(oldProps, oldInputs, newProps, newInputs);
+ Assertions.assertNotNull(result);
+ Assertions.assertEquals(1, result.size());
+ Assertions.assertNotNull(result.get(0).getOldProp());
+ Assertions.assertTrue(result.get(0).getOldProp() instanceof PropertyDefinition);
+ Assertions.assertNotNull(result.get(0).getNewProp());
+ Assertions.assertTrue(result.get(0).getNewProp() instanceof PropertyDefinition);
+ }
-
- @Test
- public void testBuildDataForMerging() throws Exception {
- PropertyInstanceMergeDataBuilder testSubject;
- List oldProps = null;
- List<InputDefinition> oldInputs = null;
- List newProps = null;
- List<InputDefinition> newInputs = null;
- List<MergePropertyData> result;
-
- // default test
-
- result = PropertyInstanceMergeDataBuilder.buildDataForMerging(oldProps, oldInputs, newProps, newInputs);
- }
-
- @Test
- public void testBuildMergeData() throws Exception {
- PropertyInstanceMergeDataBuilder testSubject;
- Map<String, T> oldPropsByName = null;
- Map<String, InputDefinition> oldInputsByName = null;
- Map<String, T> newPropsByName = null;
- Map<String, InputDefinition> newInputsByName = null;
- List<MergePropertyData> result;
-
- // default test
-
- result = Deencapsulation.invoke(PropertyInstanceMergeDataBuilder.class, "buildMergeData", new HashMap<>(), new HashMap<>(), new HashMap<>(), new HashMap<>());
- }
-
- @Test
- public void testBuildMergePropertyData() throws Exception {
- PropertyInstanceMergeDataBuilder testSubject;
- PropertyDataDefinition oldProp = null;
- Map<String, InputDefinition> oldInputsByName = null;
- PropertyDataDefinition newProp = null;
- Map<String, InputDefinition> newInputsByName = null;
- MergePropertyData result;
-
- // default test
- result = Deencapsulation.invoke(PropertyInstanceMergeDataBuilder.class, "buildMergePropertyData", new PropertyDataDefinition(), new HashMap<>(),
- new PropertyDataDefinition(), new HashMap<>());
- }
-
- @Test
- public void testGetOldGetInputNamesWhichExistInNewVersion() throws Exception {
- PropertyInstanceMergeDataBuilder testSubject;
- List<GetInputValueDataDefinition> getInputValues = null;
- Map<String, InputDefinition> newInputsByName = null;
- List<String> result;
-
- // default test
- result = Deencapsulation.invoke(PropertyInstanceMergeDataBuilder.class, "getOldGetInputNamesWhichExistInNewVersion", new LinkedList<>(), new HashMap<>());
- }
-
- @Test
- public void testGetOldDeclaredInputsByUser() throws Exception {
- PropertyInstanceMergeDataBuilder testSubject;
- List<GetInputValueDataDefinition> getInputValues = null;
- Map<String, InputDefinition> oldInputsByName = null;
- List<String> result;
-
- // default test
- result = Deencapsulation.invoke(PropertyInstanceMergeDataBuilder.class, "getOldDeclaredInputsByUser", new LinkedList<>(), new HashMap<>());
- }
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/scheduledtasks/AsdcComponentsCleanerTaskTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/scheduledtasks/AsdcComponentsCleanerTaskTest.java
index bfee3d8dd9..6d51c4dc0f 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/scheduledtasks/AsdcComponentsCleanerTaskTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/scheduledtasks/AsdcComponentsCleanerTaskTest.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,73 +20,82 @@
package org.openecomp.sdc.be.components.scheduledtasks;
-import mockit.Deencapsulation;
-import org.junit.Test;
-import org.openecomp.sdc.be.components.BeConfDependentTest;
-
import java.util.concurrent.ExecutorService;
-
-public class AsdcComponentsCleanerTaskTest extends BeConfDependentTest{
-
- private AsdcComponentsCleanerTask createTestSubject() {
- return new AsdcComponentsCleanerTask();
- }
-
- @Test
- public void testInit() throws Exception {
- AsdcComponentsCleanerTask testSubject;
-
- // default test
- testSubject = createTestSubject();
- testSubject.init();
- }
-
- @Test
- public void testDestroy() throws Exception {
- AsdcComponentsCleanerTask testSubject;
-
- // default test
- testSubject = createTestSubject();
- testSubject.destroy();
- }
-
- @Test
- public void testStartTask() throws Exception {
- AsdcComponentsCleanerTask testSubject;
-
- // default test
- testSubject = createTestSubject();
- testSubject.startTask();
- }
-
- @Test
- public void testStopTask() throws Exception {
- AsdcComponentsCleanerTask testSubject;
-
- // default test
- testSubject = createTestSubject();
- Deencapsulation.invoke(testSubject, "stopTask");
- testSubject.init();
- testSubject.startTask();
- Deencapsulation.invoke(testSubject, "stopTask");
- }
-
- @Test
- public void testRun() throws Exception {
- AsdcComponentsCleanerTask testSubject;
-
- // default test
- testSubject = createTestSubject();
- testSubject.run();
- }
-
- @Test
- public void testGetExecutorService() throws Exception {
- AsdcComponentsCleanerTask testSubject;
- ExecutorService result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getExecutorService();
- }
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.openecomp.sdc.be.components.BeConfDependentTest;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.common.impl.ExternalConfiguration;
+import org.openecomp.sdc.common.impl.FSConfigurationSource;
+
+class AsdcComponentsCleanerTaskTest extends BeConfDependentTest {
+
+ private AsdcComponentsCleanerTask createTestSubject() {
+ return new AsdcComponentsCleanerTask();
+ }
+
+ // TODO - remove this setup after migration to Junit5 BeConfDependentTest
+ @BeforeAll
+ private static void setup() {
+ configurationManager =
+ new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be"));
+ }
+
+ @Test
+ void testInit() throws Exception {
+ AsdcComponentsCleanerTask testSubject;
+
+ // default test
+ testSubject = createTestSubject();
+ testSubject.init();
+ }
+
+ @Test
+ void testDestroy() throws Exception {
+ AsdcComponentsCleanerTask testSubject;
+
+ // default test
+ testSubject = createTestSubject();
+ testSubject.destroy();
+ }
+
+ @Test
+ void testStartTask() throws Exception {
+ AsdcComponentsCleanerTask testSubject;
+
+ // default test
+ testSubject = createTestSubject();
+ testSubject.startTask();
+ }
+
+ @Test
+ void testStopTask() throws Exception {
+ AsdcComponentsCleanerTask testSubject;
+
+ // default test
+ testSubject = createTestSubject();
+ testSubject.init();
+ testSubject.destroy();
+ }
+
+ @Test
+ void testRun() throws Exception {
+ AsdcComponentsCleanerTask testSubject;
+
+ // default test
+ testSubject = createTestSubject();
+ testSubject.run();
+ }
+
+ @Test
+ void testGetExecutorService() throws Exception {
+ AsdcComponentsCleanerTask testSubject;
+ ExecutorService result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getExecutorService();
+ Assertions.assertNotNull(result);
+ }
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/ComponentValidationsTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/ComponentValidationsTest.java
index 9c8b5e48a5..bbdbcdf713 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/ComponentValidationsTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/ComponentValidationsTest.java
@@ -16,140 +16,130 @@
package org.openecomp.sdc.be.components.validation;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import fj.data.Either;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
-import mockit.Deencapsulation;
-import org.junit.Before;
-import org.junit.Test;
+import java.util.Optional;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.config.ConfigurationManager;
-import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
-import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.ComponentParametersView;
+import org.openecomp.sdc.be.model.GroupDefinition;
import org.openecomp.sdc.be.model.LifecycleStateEnum;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
-import org.openecomp.sdc.be.model.operations.StorageException;
-import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.GraphLockOperation;
import org.openecomp.sdc.common.impl.ExternalConfiguration;
import org.openecomp.sdc.common.impl.FSConfigurationSource;
-public class ComponentValidationsTest {
-
- @InjectMocks
- ComponentValidations testSubject;
-
- @Mock
- ToscaOperationFacade toscaOperationFacadeMock;
-
- @Mock
- GraphLockOperation graphLockOperationMock;
-
- @Before
- public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
- new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be"));
- }
-
- @Test
- public void testValidateComponentInstanceExist() throws Exception {
- String instanceId = "test";
-
- ComponentInstance instance = new ComponentInstance();
- instance.setUniqueId(instanceId);
- List<ComponentInstance> instances = new ArrayList<>();
- instances.add(instance);
-
- Component component = new Resource();
- component.setComponentInstances(instances);
-
- // default test
- boolean result = ComponentValidations.validateComponentInstanceExist(component, instanceId);
- assertTrue(result);
- }
-
- @Test
- public void testGetNormalizedName() throws Exception {
- String name = "mock";
- ToscaDataDefinition toscaDataDefinition = new AdditionalInfoParameterDataDefinition();
- toscaDataDefinition.setToscaPresentationValue(JsonPresentationFields.NAME, name);
-
- // default test
- String result = ComponentValidations.getNormalizedName(toscaDataDefinition);
- assertEquals(name, result);
- }
-
- @Test
- public void testValidateNameIsUniqueInComponent() throws Exception {
- String currentName = "curr_name";
- String newName = "curr_name";
- String newName2 = "mock";
-
- ComponentInstance instance = new ComponentInstance();
- instance.setName(currentName);
- instance.setNormalizedName(currentName);
- List<ComponentInstance> instances = new ArrayList<>();
- instances.add(instance);
-
- Component component = new Resource();
- component.setComponentInstances(instances);
-
- // default test
- boolean result = ComponentValidations.validateNameIsUniqueInComponent(currentName, newName, component);
- assertTrue(result);
- result = ComponentValidations.validateNameIsUniqueInComponent(currentName, newName2, component);
- assertTrue(result);
- }
-
- @Test(expected=ComponentException.class)
- public void testValidateComponentIsCheckedOutByUserAndLockIt() throws Exception {
- String componentId = "";
- String userId = "";
- Component result;
- Resource resource = new Resource();
- resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
-
- Mockito.when(toscaOperationFacadeMock.getToscaElement(Mockito.anyString(), Mockito.any(ComponentParametersView.class))).thenReturn(Either.left(resource));
-
- // default test
- result = testSubject.validateComponentIsCheckedOutByUser("",ComponentTypeEnum.RESOURCE,
- userId);
- }
-
- @Test
- public void testGetComponent() throws Exception {
- String componentId = "mock";
- ComponentTypeEnum componentType = null;
- Component result;
- Component resource = new Resource();
- resource.setComponentType(ComponentTypeEnum.RESOURCE);
- Mockito.when(toscaOperationFacadeMock.getToscaElement(Mockito.anyString(), Mockito.any(ComponentParametersView.class))).thenReturn(Either.left(resource));
-
- // default test
- result = Deencapsulation.invoke(testSubject, "getComponent", componentId, ComponentTypeEnum.RESOURCE);
- assertThat(result).isInstanceOf(Component.class);
- }
-
- @Test(expected = StorageException.class)
- public void testOnToscaOperationError() throws Exception {
- Component result;
-
- // default test
- result = Deencapsulation.invoke(testSubject, "onToscaOperationError",
- StorageOperationStatus.ARTIFACT_NOT_FOUND,"");
- }
+class ComponentValidationsTest {
+
+ @InjectMocks
+ private ComponentValidations testSubject;
+
+ @Mock
+ private ToscaOperationFacade toscaOperationFacadeMock;
+
+ @Mock
+ private GraphLockOperation graphLockOperationMock;
+
+ @BeforeEach
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be"));
+ }
+
+ @Test
+ void testValidateComponentInstanceExist() throws Exception {
+ String instanceId = "test";
+
+ ComponentInstance instance = new ComponentInstance();
+ instance.setUniqueId(instanceId);
+ List<ComponentInstance> instances = new ArrayList<>();
+ instances.add(instance);
+
+ Component component = new Resource();
+ component.setComponentInstances(instances);
+
+ // default test
+ boolean result = ComponentValidations.validateComponentInstanceExist(component, instanceId);
+ assertTrue(result);
+ }
+
+ @Test
+ void testValidateNameIsUniqueInComponent() throws Exception {
+ String currentName = "curr_name";
+ String newName = "curr_name";
+ String newName2 = "mock";
+
+ ComponentInstance instance = new ComponentInstance();
+ instance.setName(currentName);
+ instance.setNormalizedName(currentName);
+ List<ComponentInstance> instances = new ArrayList<>();
+ instances.add(instance);
+
+ Component component = new Resource();
+ component.setComponentInstances(instances);
+
+ // default test
+ boolean result = ComponentValidations.validateNameIsUniqueInComponent(currentName, newName, component);
+ assertTrue(result);
+
+ result = ComponentValidations.validateNameIsUniqueInComponent(currentName, newName2, component);
+ assertTrue(result);
+
+ final GroupDefinition groupDefinition = new GroupDefinition();
+ groupDefinition.setName(newName2);
+ component.setGroups(Arrays.asList(groupDefinition));
+ result = ComponentValidations.validateNameIsUniqueInComponent(currentName, newName2, component);
+ assertFalse(result);
+ }
+
+ @Test
+ void testValidateComponentIsCheckedOutByUserAndLockIt() throws Exception {
+ String componentId = "";
+ String userId = "";
+ Resource resource = new Resource();
+ resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
+
+ Mockito.when(toscaOperationFacadeMock.getToscaElement(Mockito.anyString(), Mockito.any(ComponentParametersView.class)))
+ .thenReturn(Either.left(resource));
+
+ Assertions.assertThrows(ComponentException.class, () -> {
+ // default test
+ testSubject.validateComponentIsCheckedOutByUser("", ComponentTypeEnum.RESOURCE, userId);
+ });
+ }
+
+ @Test
+ void testGetComponentInstance() {
+ String instanceId = "test";
+
+ ComponentInstance instance = new ComponentInstance();
+ instance.setUniqueId(instanceId);
+ List<ComponentInstance> instances = new ArrayList<>();
+ instances.add(instance);
+
+ Component component = new Resource();
+ component.setComponentInstances(instances);
+
+ final Optional<ComponentInstance> result = testSubject.getComponentInstance(component, instanceId);
+ Assertions.assertNotNull(result);
+ Assertions.assertTrue(result.isPresent());
+ Assertions.assertNotNull(result.get());
+ }
+
}