From 47f2be812ff98c6d9d3862deb55638330e8db4f3 Mon Sep 17 00:00:00 2001 From: vasraz Date: Thu, 24 Jun 2021 14:09:30 +0100 Subject: Remove usage of outdated library JMockit (openecomp-be) Signed-off-by: Vasyl Razinkov Issue-ID: SDC-3379 Change-Id: I7430deaa5993e67293e0f290700274dc2fff2db1 --- .../openecomp-sdc-enrichment-api/pom.xml | 5 - .../types/ComponentMonitoringUploadInfo.java | 8 +- .../types/ComponentMonitoringUploadInfoTest.java | 56 +++---- .../openecomp-sdc-versioning-core/pom.xml | 6 - .../impl/ActionVersioningManagerImpl.java | 10 +- .../impl/ActionVersioningManagerImplTest.java | 176 ++++++++++----------- .../pnfd/AbstractPnfdTransformationEngine.java | 15 +- .../impl/pnfd/PnfTransformationEngineTest.java | 73 +++------ 8 files changed, 157 insertions(+), 192 deletions(-) (limited to 'openecomp-be/lib') diff --git a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-api/pom.xml b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-api/pom.xml index d09775fd19..28d4a1950a 100644 --- a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-api/pom.xml +++ b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-api/pom.xml @@ -54,11 +54,6 @@ openecomp-sdc-versioning-api ${project.version} - - org.jmockit - jmockit - test - diff --git a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-api/src/main/java/org/openecomp/core/enrichment/types/ComponentMonitoringUploadInfo.java b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-api/src/main/java/org/openecomp/core/enrichment/types/ComponentMonitoringUploadInfo.java index bd14e5a1e5..90399247c5 100644 --- a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-api/src/main/java/org/openecomp/core/enrichment/types/ComponentMonitoringUploadInfo.java +++ b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-api/src/main/java/org/openecomp/core/enrichment/types/ComponentMonitoringUploadInfo.java @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.openecomp.core.enrichment.types; import static org.openecomp.core.enrichment.types.MonitoringUploadType.SNMP_POLL; @@ -25,10 +26,12 @@ import static org.openecomp.core.enrichment.types.MonitoringUploadType.VES_EVENT import java.util.HashMap; import java.util.Map; +import lombok.NoArgsConstructor; +@NoArgsConstructor public class ComponentMonitoringUploadInfo { - private Map infoByType = new HashMap<>(); + private final Map infoByType = new HashMap<>(); public MonitoringArtifactInfo getSnmpTrap() { return infoByType.get(SNMP_TRAP); @@ -42,7 +45,8 @@ public class ComponentMonitoringUploadInfo { return infoByType.get(VES_EVENTS); } - public void setMonitoringArtifactFile(MonitoringUploadType type, MonitoringArtifactInfo monitoringArtifactInfo) { + public void setMonitoringArtifactFile(final MonitoringUploadType type, + final MonitoringArtifactInfo monitoringArtifactInfo) { infoByType.put(type, monitoringArtifactInfo); } } diff --git a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-api/src/test/java/org/openecomp/core/enrichment/types/ComponentMonitoringUploadInfoTest.java b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-api/src/test/java/org/openecomp/core/enrichment/types/ComponentMonitoringUploadInfoTest.java index b857d0cc04..977f691c31 100644 --- a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-api/src/test/java/org/openecomp/core/enrichment/types/ComponentMonitoringUploadInfoTest.java +++ b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-api/src/test/java/org/openecomp/core/enrichment/types/ComponentMonitoringUploadInfoTest.java @@ -16,59 +16,43 @@ package org.openecomp.core.enrichment.types; -import static org.hamcrest.CoreMatchers.isA; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; -import java.util.HashMap; -import java.util.Map; -import mockit.Deencapsulation; -import org.junit.Test; - -public class ComponentMonitoringUploadInfoTest { +class ComponentMonitoringUploadInfoTest { @Test - public void testGetSnmpTrap() { - ComponentMonitoringUploadInfo uploadInfo = new ComponentMonitoringUploadInfo(); + void testGetSnmpTrap() { + final ComponentMonitoringUploadInfo uploadInfo = new ComponentMonitoringUploadInfo(); setInternals(uploadInfo); - - assertThat(uploadInfo.getSnmpTrap(), isA(MonitoringArtifactInfo.class)); + Assertions.assertTrue(uploadInfo.getSnmpTrap() instanceof MonitoringArtifactInfo); } @Test - public void testGetSnmpPoll() { - ComponentMonitoringUploadInfo uploadInfo = new ComponentMonitoringUploadInfo(); + void testGetSnmpPoll() { + final ComponentMonitoringUploadInfo uploadInfo = new ComponentMonitoringUploadInfo(); setInternals(uploadInfo); - - assertThat(uploadInfo.getSnmpPoll(), isA(MonitoringArtifactInfo.class)); + Assertions.assertTrue(uploadInfo.getSnmpPoll() instanceof MonitoringArtifactInfo); } @Test - public void testGetVesEvent() { - ComponentMonitoringUploadInfo uploadInfo = new ComponentMonitoringUploadInfo(); + void testGetVesEvent() { + final ComponentMonitoringUploadInfo uploadInfo = new ComponentMonitoringUploadInfo(); setInternals(uploadInfo); - - assertThat(uploadInfo.getVesEvent(), isA(MonitoringArtifactInfo.class)); + Assertions.assertTrue(uploadInfo.getVesEvent() instanceof MonitoringArtifactInfo); } @Test - public void testSetMonitoringArtifactFile() { - ComponentMonitoringUploadInfo uploadInfo = new ComponentMonitoringUploadInfo(); + void testSetMonitoringArtifactFile() { + final ComponentMonitoringUploadInfo uploadInfo = new ComponentMonitoringUploadInfo(); uploadInfo.setMonitoringArtifactFile(MonitoringUploadType.SNMP_POLL, new MonitoringArtifactInfo()); - - assertThat(getInternal(uploadInfo).containsKey(MonitoringUploadType.SNMP_POLL), is(true)); - } - - private Map getInternal(ComponentMonitoringUploadInfo componentMonitoringUploadInfo) { - return Deencapsulation.getField(componentMonitoringUploadInfo, "infoByType"); + Assertions.assertTrue(uploadInfo.getSnmpPoll() instanceof MonitoringArtifactInfo); } - private void setInternals(ComponentMonitoringUploadInfo componentMonitoringUploadInfo) { - Map infoMap = new HashMap<>(); - infoMap.put(MonitoringUploadType.SNMP_POLL, new MonitoringArtifactInfo()); - infoMap.put(MonitoringUploadType.SNMP_TRAP, new MonitoringArtifactInfo()); - infoMap.put(MonitoringUploadType.VES_EVENTS, new MonitoringArtifactInfo()); - Deencapsulation.setField(componentMonitoringUploadInfo, "infoByType", infoMap); + private void setInternals(final ComponentMonitoringUploadInfo componentMonitoringUploadInfo) { + componentMonitoringUploadInfo.setMonitoringArtifactFile(MonitoringUploadType.SNMP_POLL, new MonitoringArtifactInfo()); + componentMonitoringUploadInfo.setMonitoringArtifactFile(MonitoringUploadType.SNMP_TRAP, new MonitoringArtifactInfo()); + componentMonitoringUploadInfo.setMonitoringArtifactFile(MonitoringUploadType.VES_EVENTS, new MonitoringArtifactInfo()); } -} \ No newline at end of file +} diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/pom.xml b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/pom.xml index e956093a54..de50e6f094 100644 --- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/pom.xml +++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/pom.xml @@ -30,12 +30,6 @@ ${project.version} runtime - - org.jmockit - jmockit - ${jmockit.version} - test - org.openecomp.sdc openecomp-sdc-logging-core diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ActionVersioningManagerImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ActionVersioningManagerImpl.java index a69e862582..cbff10cd7b 100644 --- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ActionVersioningManagerImpl.java +++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ActionVersioningManagerImpl.java @@ -15,6 +15,7 @@ */ package org.openecomp.sdc.versioning.impl; +import com.google.common.annotations.VisibleForTesting; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; @@ -62,7 +63,7 @@ public class ActionVersioningManagerImpl implements ActionVersioningManager { private static final Logger LOGGER = LoggerFactory.getLogger(ActionVersioningManagerImpl.class); private static final Version INITIAL_ACTIVE_VERSION = new Version(0, 0); - private static final Map> VERSIONABLE_ENTITIES = new HashMap<>(); + private static Map> VERSIONABLE_ENTITIES = new HashMap<>(); private final VersionInfoDao versionInfoDao; private final VersionInfoDeletedDao versionInfoDeletedDao; private VersionDao versionDao; @@ -78,6 +79,13 @@ public class ActionVersioningManagerImpl implements ActionVersioningManager { this.asdcItemManager = asdcItemManager; } + @VisibleForTesting + ActionVersioningManagerImpl(Map> map) { + this.versionInfoDao = null; + this.versionInfoDeletedDao = null; + VERSIONABLE_ENTITIES = map; + } + private static VersionInfo getVersionInfo(VersionInfoEntity versionInfoEntity, String user, VersionableEntityAction action) { return getVersionInfo(versionInfoEntity.getEntityId(), versionInfoEntity.getEntityType(), versionInfoEntity.getActiveVersion(), versionInfoEntity.getCandidate(), versionInfoEntity.getStatus(), versionInfoEntity.getLatestFinalVersion(), diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/ActionVersioningManagerImplTest.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/ActionVersioningManagerImplTest.java index 18a6081b6c..64c1e38069 100644 --- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/ActionVersioningManagerImplTest.java +++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/ActionVersioningManagerImplTest.java @@ -32,11 +32,11 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Set; -import mockit.Deencapsulation; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -61,6 +61,7 @@ import org.openecomp.sdc.versioning.types.VersionableEntityMetadata; @RunWith(MockitoJUnitRunner.class) public class ActionVersioningManagerImplTest { + @Mock private VersionInfoDao versionInfoDao; @Mock @@ -76,7 +77,7 @@ public class ActionVersioningManagerImplTest { private VersionInfoEntity versionInfoEntity; @Before - public void setUp(){ + public void setUp() { actionVersioningManager = createSUT(); versionInfoEntity = new VersionInfoEntity(); @@ -87,11 +88,11 @@ public class ActionVersioningManagerImplTest { private ActionVersioningManager createSUT() { return new ActionVersioningManagerImpl( - versionInfoDao, - versionInfoDeletedDao, - versionDao, - versionCalculator, - asdcItemManager + versionInfoDao, + versionInfoDeletedDao, + versionDao, + versionCalculator, + asdcItemManager ); } @@ -105,9 +106,9 @@ public class ActionVersioningManagerImplTest { when(versionInfoDeletedDao.list(any(VersionInfoDeletedEntity.class))).thenReturn(new ArrayList<>()); Map result = actionVersioningManager.listDeletedEntitiesVersionInfo( - "mock-type", - "mock-user", - VersionableEntityAction.Read + "mock-type", + "mock-user", + VersionableEntityAction.Read ); assertThat(result, notNullValue()); @@ -136,9 +137,9 @@ public class ActionVersioningManagerImplTest { when(versionInfoDao.list(any(VersionInfoEntity.class))).thenReturn(new ArrayList<>()); Map result = actionVersioningManager.listEntitiesVersionInfo( - "mock-type", - "mock-user", - VersionableEntityAction.Read + "mock-type", + "mock-user", + VersionableEntityAction.Read ); assertThat(result, notNullValue()); @@ -149,10 +150,10 @@ public class ActionVersioningManagerImplTest { when(versionInfoDao.get(any(VersionInfoEntity.class))).thenReturn(versionInfoEntity); VersionInfo result = actionVersioningManager.getEntityVersionInfo( - "mock-type", - "mock-id", - "mock-user", - VersionableEntityAction.Read + "mock-type", + "mock-id", + "mock-user", + VersionableEntityAction.Read ); assertThat(result, notNullValue()); @@ -163,9 +164,9 @@ public class ActionVersioningManagerImplTest { when(versionInfoDao.get(any(VersionInfoEntity.class))).thenReturn(null); Version result = actionVersioningManager.create( - "mock-type", - "mock-id", - "mock-user" + "mock-type", + "mock-id", + "mock-user" ); assertThat(result, notNullValue()); @@ -176,9 +177,9 @@ public class ActionVersioningManagerImplTest { when(versionInfoDao.get(any(VersionInfoEntity.class))).thenReturn(new VersionInfoEntity()); actionVersioningManager.create( - "mock-type", - "mock-id", - "mock-user" + "mock-type", + "mock-id", + "mock-user" ); fail("Should throw CoreException"); @@ -187,9 +188,9 @@ public class ActionVersioningManagerImplTest { @Test public void testCreateAlt() { Version result = actionVersioningManager.create( - "mock-type", - new Version(), - VersionCreationMethod.minor + "mock-type", + new Version(), + VersionCreationMethod.minor ); assertThat(result, notNullValue()); @@ -197,17 +198,16 @@ public class ActionVersioningManagerImplTest { @Test public void testRegister() { - actionVersioningManager.register( - "mock-type", - new VersionableEntityMetadata( - "mock-name", - "mock-id-name", - "mock-ver-id-name" - ) + final VersionableEntityMetadata entityMetadata = new VersionableEntityMetadata( + "mock-name", + "mock-id-name", + "mock-ver-id-name" ); - Map> entities = Deencapsulation.getField(actionVersioningManager, "VERSIONABLE_ENTITIES"); - assertThat(entities, notNullValue()); - assertThat(entities.size(), is(1)); + Map> map = new HashMap<>(); + var action = new ActionVersioningManagerImpl(map); + action.register("mock-type", entityMetadata); + assertThat(map, notNullValue()); + assertThat(map.size(), is(1)); } @Test @@ -217,9 +217,9 @@ public class ActionVersioningManagerImplTest { when(versionInfoDao.get(any(VersionInfoEntity.class))).thenReturn(versionInfoEntity); actionVersioningManager.delete( - "moct-type", - "mock-id", - "mock-user" + "moct-type", + "mock-id", + "mock-user" ); verify(versionInfoDeletedDao).create(any(VersionInfoDeletedEntity.class)); @@ -235,9 +235,9 @@ public class ActionVersioningManagerImplTest { when(versionInfoDao.get(any(VersionInfoEntity.class))).thenReturn(versionInfoEntity); actionVersioningManager.delete( - "moct-type", - "mock-id", - "mock-user" + "moct-type", + "mock-id", + "mock-user" ); fail("Should throw CoreException"); } @@ -247,9 +247,9 @@ public class ActionVersioningManagerImplTest { when(versionInfoDeletedDao.get(any(VersionInfoDeletedEntity.class))).thenReturn(new VersionInfoDeletedEntity()); actionVersioningManager.undoDelete( - "mock-type", - "mock-id", - "mock-user" + "mock-type", + "mock-id", + "mock-user" ); verify(versionInfoDao).create(any(VersionInfoEntity.class)); @@ -261,9 +261,9 @@ public class ActionVersioningManagerImplTest { when(versionInfoDeletedDao.get(any(VersionInfoDeletedEntity.class))).thenReturn(null); actionVersioningManager.undoDelete( - "mock-type", - "mock-id", - "mock-user" + "mock-type", + "mock-id", + "mock-user" ); fail("Should throw CoreException"); @@ -276,9 +276,9 @@ public class ActionVersioningManagerImplTest { when(versionInfoDao.get(any(VersionInfoEntity.class))).thenReturn(versionInfoEntity); Version result = actionVersioningManager.checkout( - "moct-type", - "mock-id", - "mock-user" + "moct-type", + "mock-id", + "mock-user" ); assertThat(result, notNullValue()); @@ -290,9 +290,9 @@ public class ActionVersioningManagerImplTest { when(versionInfoDao.get(any(VersionInfoEntity.class))).thenReturn(null); actionVersioningManager.checkout( - "moct-type", - "mock-id", - "mock-user" + "moct-type", + "mock-id", + "mock-user" ); fail("Should throw CoreException"); @@ -305,9 +305,9 @@ public class ActionVersioningManagerImplTest { when(versionInfoDao.get(any(VersionInfoEntity.class))).thenReturn(versionInfoEntity); actionVersioningManager.checkout( - "mock-type", - "mock-id", - "mock-user" + "mock-type", + "mock-id", + "mock-user" ); fail("Should throw CoreException"); @@ -320,9 +320,9 @@ public class ActionVersioningManagerImplTest { when(versionInfoDao.get(any(VersionInfoEntity.class))).thenReturn(versionInfoEntity); Version result = actionVersioningManager.undoCheckout( - "mock-type", - "mock-id", - "mock-user" + "mock-type", + "mock-id", + "mock-user" ); assertThat(result, notNullValue(Version.class)); } @@ -334,10 +334,10 @@ public class ActionVersioningManagerImplTest { when(versionInfoDao.get(any(VersionInfoEntity.class))).thenReturn(versionInfoEntity); Version result = actionVersioningManager.checkin( - "mock-type", - "mock-id", - "mock-user", - "mock-desc" + "mock-type", + "mock-id", + "mock-user", + "mock-desc" ); assertThat(result, notNullValue(Version.class)); } @@ -349,10 +349,10 @@ public class ActionVersioningManagerImplTest { when(versionInfoDao.get(any(VersionInfoEntity.class))).thenReturn(versionInfoEntity); Version result = actionVersioningManager.checkin( - "mock-type", - "mock-id", - "mock-user", - "mock-desc" + "mock-type", + "mock-id", + "mock-user", + "mock-desc" ); assertThat(result, notNullValue(Version.class)); } @@ -367,9 +367,9 @@ public class ActionVersioningManagerImplTest { when(versionDao.get(anyString(), any(Version.class))).thenReturn(Optional.of(new Version())); actionVersioningManager.submit( - "mock-type", - new Version(), - "mock-desc" + "mock-type", + new Version(), + "mock-desc" ); verify(versionDao).update(anyString(), any(Version.class)); verify(asdcItemManager).updateVersionStatus(anyString(), any(VersionStatus.class), any(VersionStatus.class)); @@ -381,10 +381,10 @@ public class ActionVersioningManagerImplTest { when(versionInfoDao.get(any(VersionInfoEntity.class))).thenReturn(versionInfoEntity); Version result = actionVersioningManager.submit( - "mock-type", - "mock-id", - "mock-user", - "mock-desc" + "mock-type", + "mock-id", + "mock-user", + "mock-desc" ); assertThat(result, notNullValue(Version.class)); } @@ -394,10 +394,10 @@ public class ActionVersioningManagerImplTest { when(versionInfoDao.get(any(VersionInfoEntity.class))).thenReturn(null); actionVersioningManager.submit( - "mock-type", - "mock-id", - "mock-user", - "mock-desc" + "mock-type", + "mock-id", + "mock-user", + "mock-desc" ); fail("Should throw CoreException"); @@ -409,10 +409,10 @@ public class ActionVersioningManagerImplTest { when(versionInfoDao.get(any(VersionInfoEntity.class))).thenReturn(versionInfoEntity); actionVersioningManager.submit( - "mock-type", - "mock-id", - "mock-user", - "mock-desc" + "mock-type", + "mock-id", + "mock-user", + "mock-desc" ); fail("Should throw CoreException"); @@ -424,10 +424,10 @@ public class ActionVersioningManagerImplTest { when(versionInfoDao.get(any(VersionInfoEntity.class))).thenReturn(versionInfoEntity); actionVersioningManager.submit( - "mock-type", - "mock-id", - "mock-user", - "mock-desc" + "mock-type", + "mock-id", + "mock-user", + "mock-desc" ); fail("Should throw CoreException"); @@ -450,4 +450,4 @@ public class ActionVersioningManagerImplTest { actionVersioningManager.listRevisions("mock-id", new Version()); verify(versionDao).listRevisions(anyString(), any(Version.class)); } -} \ No newline at end of file +} diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/AbstractPnfdTransformationEngine.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/AbstractPnfdTransformationEngine.java index f97b1d37b2..94f7531310 100644 --- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/AbstractPnfdTransformationEngine.java +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/AbstractPnfdTransformationEngine.java @@ -16,12 +16,14 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ + package org.openecomp.core.converter.impl.pnfd; import java.io.IOException; import java.io.InputStream; import java.util.List; import java.util.Map; +import lombok.Getter; import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; import org.openecomp.core.converter.ServiceTemplateReaderService; import org.openecomp.core.converter.pnfd.PnfdTransformationEngine; @@ -37,19 +39,23 @@ import org.openecomp.sdc.logging.api.LoggerFactory; public abstract class AbstractPnfdTransformationEngine implements PnfdTransformationEngine { private static final Logger LOGGER = LoggerFactory.getLogger(AbstractPnfdTransformationEngine.class); + protected final ServiceTemplate templateTo; protected final ServiceTemplateReaderService templateFrom; private final PnfdTransformationDescriptorReader pnfdTransformationDescriptorReader = new PnfdTransformationDescriptorReader(); - private final String descriptorResourcePath; protected TransformationDescription transformationDescription; protected Map> transformationGroupByBlockMap; + @Getter + private final String descriptorResourcePath; - public AbstractPnfdTransformationEngine(final ServiceTemplateReaderService templateFrom, final ServiceTemplate templateTo) { + public AbstractPnfdTransformationEngine(final ServiceTemplateReaderService templateFrom, + final ServiceTemplate templateTo) { this(templateFrom, templateTo, "pnfdTransformationTemplate/model-driven-conversion.yaml"); } //used for tests purposes - AbstractPnfdTransformationEngine(final ServiceTemplateReaderService templateFrom, final ServiceTemplate templateTo, + AbstractPnfdTransformationEngine(final ServiceTemplateReaderService templateFrom, + final ServiceTemplate templateTo, final String descriptorResourcePath) { this.templateFrom = templateFrom; this.templateTo = templateTo; @@ -61,7 +67,7 @@ public abstract class AbstractPnfdTransformationEngine implements PnfdTransforma */ protected void readDefinition() { try (final InputStream resourceAsStream = getClass().getClassLoader().getResourceAsStream(descriptorResourcePath)) { - if (resourceAsStream == null) { + if (resourceAsStream == null) { if (LOGGER.isErrorEnabled()) { LOGGER.error("Could not find resource '{}'", descriptorResourcePath); } @@ -77,4 +83,5 @@ public abstract class AbstractPnfdTransformationEngine implements PnfdTransforma * Executes all transformations specified in the descriptor. */ protected abstract void executeTransformations(); + } diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/PnfTransformationEngineTest.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/PnfTransformationEngineTest.java index 63a7d890d0..e5a10105a3 100644 --- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/PnfTransformationEngineTest.java +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/PnfTransformationEngineTest.java @@ -19,65 +19,46 @@ package org.openecomp.core.converter.impl.pnfd; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.mockito.Mockito.spy; - import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; +import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; -import mockit.Deencapsulation; import org.apache.commons.io.IOUtils; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.mockito.Mockito; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil; import org.onap.sdc.tosca.services.YamlUtil; import org.openecomp.core.converter.ServiceTemplateReaderService; -import org.openecomp.core.converter.impl.pnfd.parser.PnfdCustomNodeTypeBlockParser; import org.openecomp.core.converter.pnfd.PnfdTransformationEngine; -import org.openecomp.core.converter.pnfd.model.ConversionDefinition; import org.openecomp.core.impl.services.ServiceTemplateReaderServiceImpl; -@RunWith(Parameterized.class) -public class PnfTransformationEngineTest { +class PnfTransformationEngineTest { - public static final String INPUT_DIR = "pnfDescriptor/in/"; - public static final String OUTPUT_DIR = "pnfDescriptor/out/"; - private String inputFilename; + private static final String INPUT_DIR = "pnfDescriptor/in/"; + private static final String OUTPUT_DIR = "pnfDescriptor/out/"; private final YamlUtil yamlUtil = new YamlUtil(); private final ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil(); - public PnfTransformationEngineTest(final String inputFilename) { - this.inputFilename = inputFilename; - } - - @Parameterized.Parameters(name = "{index}: {0}") - public static Collection input() throws IOException { + private static List input() throws IOException { try (final Stream files = Files.list(getPathFromClasspath(INPUT_DIR))) { - return files.map(path -> path.getFileName().toString()) - .collect(Collectors.toList()); + return files.map(path -> path.getFileName().toString()).collect(Collectors.toList()); } } - @Test - public void testTopologyTemplateConversions() throws IOException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("input") + void testTopologyTemplateConversions(final String inputFilename) throws IOException { final byte[] descriptor = getInputFileResource(inputFilename); final ServiceTemplateReaderService serviceTemplateReaderService = new ServiceTemplateReaderServiceImpl(descriptor); final ServiceTemplate serviceTemplate = new ServiceTemplate(); - PnfdTransformationEngine pnfdTransformationEngine = new PnfdNodeTypeTransformationEngine( - serviceTemplateReaderService, serviceTemplate); + PnfdTransformationEngine pnfdTransformationEngine = new PnfdNodeTypeTransformationEngine(serviceTemplateReaderService, serviceTemplate); pnfdTransformationEngine.transform(); pnfdTransformationEngine = new PnfdNodeTemplateTransformationEngine(serviceTemplateReaderService, serviceTemplate); pnfdTransformationEngine.transform(); @@ -85,26 +66,18 @@ public class PnfTransformationEngineTest { final String yamlContent = yamlUtil.objectToYaml(serviceTemplate); final String result = yamlUtil.objectToYaml(yamlUtil.yamlToObject(yamlContent, ServiceTemplate.class)); final String expectedResult = getExpectedResultFor(inputFilename); - assertEquals(expectedResult, result); - } - - @Test - public void testBuildParseBlock() { - final PnfdCustomNodeTypeBlockParser blockParser = spy(new PnfdCustomNodeTypeBlockParser(null)); - final ConversionDefinition conversionDefinition = Mockito.mock(ConversionDefinition.class); - final Map stringObjectMap = new HashMap<>(); - stringObjectMap.put("type", null); - stringObjectMap.put("name", null); - assertEquals(Optional.empty(), Deencapsulation.invoke(blockParser, "buildParsedBlock", - stringObjectMap, stringObjectMap, conversionDefinition)); + Assertions.assertEquals(expectedResult, result); } - @Test - public void testReadDefinition() { - final PnfdTransformationEngine engine = spy( - new PnfdNodeTemplateTransformationEngine(null, null, "test.txt")); - Deencapsulation.invoke(engine, "readDefinition"); - assertNull(Deencapsulation.getField(engine, "transformationDescription")); + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("input") + void testReadDefinition(final String inputFilename) throws IOException { + final byte[] descriptor = getInputFileResource(inputFilename); + final ServiceTemplateReaderService serviceTemplateReaderService = new ServiceTemplateReaderServiceImpl(descriptor); + final ServiceTemplate serviceTemplate = new ServiceTemplate(); + AbstractPnfdTransformationEngine engine = new PnfdNodeTemplateTransformationEngine(serviceTemplateReaderService, serviceTemplate, "test.txt"); + engine.transform(); + Assertions.assertNotNull(engine.getDescriptorResourcePath()); } private String getExpectedResultFor(final String inputFilename) throws IOException { -- cgit 1.2.3-korg