summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Guistwite <jguistwite@iconectiv.com>2019-04-25 08:58:06 -0400
committerOren Kleks <orenkle@amdocs.com>2019-04-30 13:02:22 +0000
commit2f580cec3540c8f604b4affb57879ffac193f354 (patch)
tree3c986e24697af11f83383383ac3ac4c272edf05e
parent103d8bde336d93b9b0f203d17a60880b123f758d (diff)
Added some JUnit tests to improve coverage. Additional work could be added to improve results checking in the future.
Issue-ID: SDC-2238 Change-Id: Ief48b90eff33f166ca5f3fa5abb921e0e8c34d26 Signed-off-by: James Guistwite <jguistwite@iconectiv.com>
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/ComponentDependenciesImplTest.java180
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/ComponentImplTest.java198
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/ComponentMonitoringUploadsImplTest.java134
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/ComponentProcessesImplTest.java219
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/ComputeImplTest.java210
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/DeploymentFlavorsImplTest.java168
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/ImagesImplTest.java205
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/NetworksImplTest.java158
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/NicsImplTest.java214
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/OrchestrationTemplateCandidateImplTest.java158
10 files changed, 1838 insertions, 6 deletions
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/ComponentDependenciesImplTest.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/ComponentDependenciesImplTest.java
new file mode 100644
index 0000000000..c59cfd11a3
--- /dev/null
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/ComponentDependenciesImplTest.java
@@ -0,0 +1,180 @@
+package org.openecomp.sdcrests.vsp.rest.services;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentMatchers;
+import org.mockito.Mock;
+import org.openecomp.sdc.activitylog.ActivityLogManagerFactory;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.ComponentDependencyModelManager;
+import org.openecomp.sdc.vendorsoftwareproduct.ComponentDependencyModelManagerFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.ComponentManagerFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.ProcessManagerFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentDependencyModelEntity;
+import org.openecomp.sdc.versioning.dao.types.Version;
+import org.openecomp.sdcrests.vendorsoftwareproducts.types.ComponentDependencyCreationDto;
+import org.openecomp.sdcrests.vendorsoftwareproducts.types.ComponentDependencyModel;
+import org.openecomp.sdcrests.vendorsoftwareproducts.types.ComponentDependencyResponseDto;
+import org.openecomp.sdcrests.vendorsoftwareproducts.types.ComponentRelationType;
+import org.openecomp.sdcrests.vsp.rest.ComponentDependencies;
+import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import javax.ws.rs.core.Response;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.UUID;
+
+import static org.mockito.MockitoAnnotations.initMocks;
+import static org.powermock.api.mockito.PowerMockito.mockStatic;
+import static org.powermock.api.mockito.PowerMockito.when;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({ComponentDependenciesImpl.class, ComponentDependencyModelManagerFactory.class})
+public class ComponentDependenciesImplTest {
+
+ private Logger logger = LoggerFactory.getLogger(org.openecomp.sdcrests.vsp.rest.services.ComponentDependenciesImplTest.class);
+
+ @Mock
+ private ComponentDependencyModelManagerFactory componentDependencyModelManagerFactory;
+
+ @Mock
+ private ComponentDependencyModelManager componentDependencyModelManager;
+
+ private final String vspId = UUID.randomUUID().toString();
+ private final String versionId = UUID.randomUUID().toString();
+ private final String entityId = "" + System.currentTimeMillis();
+ private final String user = "cs0008";
+
+ @Before
+ public void setUp() {
+ try {
+ initMocks(this);
+
+ mockStatic(ComponentDependencyModelManagerFactory.class);
+ when(ComponentDependencyModelManagerFactory.getInstance()).thenReturn(componentDependencyModelManagerFactory);
+ when(componentDependencyModelManagerFactory.createInterface()).thenReturn(componentDependencyModelManager);
+
+ ComponentDependencyModelEntity e = new ComponentDependencyModelEntity();
+ e.setSourceComponentId("sourceid");
+ e.setTargetComponentId("targetid");
+ e.setVspId(vspId);
+ e.setVersion(new Version(versionId));
+ e.setRelation(ComponentRelationType.dependsOn.name());
+ e.setId(entityId);
+
+ // create
+ when(componentDependencyModelManager.createComponentDependency(
+ ArgumentMatchers.any(),
+ ArgumentMatchers.eq(vspId),
+ ArgumentMatchers.any())).thenReturn(e);
+
+ // list
+ Collection<ComponentDependencyModelEntity> entities =
+ Collections.singletonList(e);
+ when(componentDependencyModelManager.list(
+ ArgumentMatchers.eq(vspId),
+ ArgumentMatchers.any())).thenReturn(entities);
+
+ // get
+ when(componentDependencyModelManager.get(
+ ArgumentMatchers.eq(vspId),
+ ArgumentMatchers.any(),
+ ArgumentMatchers.eq(entityId)
+ )).thenReturn(e);
+
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ }
+ }
+
+ @Test
+ public void testCreate() {
+ ComponentDependencyModel model = new ComponentDependencyModel();
+ model.setRelationType(ComponentRelationType.dependsOn.name());
+ model.setSourceId("sourceid");
+ model.setTargetId("targetid");
+
+
+ ComponentDependencies componentDependencies = new ComponentDependenciesImpl();
+ Response rsp = componentDependencies.create(model, vspId, versionId, user);
+ Assert.assertEquals("Response should be 200", 200, rsp.getStatus());
+ Object e = rsp.getEntity();
+ Assert.assertNotNull(e);
+ try {
+ ComponentDependencyCreationDto dto = (ComponentDependencyCreationDto) e;
+ Assert.assertEquals("resulting entityId must match", dto.getId(), entityId);
+ } catch (ClassCastException ex) {
+ Assert.fail("unexpected class for DTO " + e.getClass().getName());
+ }
+ }
+
+ @Test
+ public void testList() {
+
+ ComponentDependencies componentDependencies = new ComponentDependenciesImpl();
+ Response rsp = componentDependencies.list(vspId, versionId, user);
+ Assert.assertEquals("Response should be 200", 200, rsp.getStatus());
+ Object e = rsp.getEntity();
+ Assert.assertNotNull(e);
+ try {
+ @SuppressWarnings("unchecked")
+ GenericCollectionWrapper<ComponentDependencyResponseDto> results =
+ (GenericCollectionWrapper<ComponentDependencyResponseDto>) e;
+
+ Assert.assertEquals("result length", 1, results.getListCount());
+ Assert.assertEquals("resulting entityId must match", results.getResults().get(0).getId(), entityId);
+ } catch (ClassCastException ex) {
+ Assert.fail("unexpected class for DTO " + e.getClass().getName());
+ }
+ }
+
+
+ @Test
+ public void testDelete() {
+
+ ComponentDependencies componentDependencies = new ComponentDependenciesImpl();
+
+ Response rsp = componentDependencies.delete(vspId, versionId, entityId, user);
+ Assert.assertEquals("Response should be 200", 200, rsp.getStatus());
+ Assert.assertNull(rsp.getEntity());
+ }
+
+
+ @Test
+ public void testUpdate() {
+
+ ComponentDependencies componentDependencies = new ComponentDependenciesImpl();
+
+ ComponentDependencyModel model = new ComponentDependencyModel();
+ model.setRelationType(ComponentRelationType.dependsOn.name());
+ model.setSourceId("sourceid");
+ model.setTargetId("targetid");
+
+ Response rsp = componentDependencies.update(model, vspId, versionId, entityId, user);
+ Assert.assertEquals("Response should be 200", 200, rsp.getStatus());
+ Assert.assertNull(rsp.getEntity());
+ }
+
+ @Test
+ public void testGet() {
+
+ ComponentDependencies componentDependencies = new ComponentDependenciesImpl();
+ Response rsp = componentDependencies.get(vspId, versionId, entityId, user);
+ Assert.assertEquals("Response should be 200", 200, rsp.getStatus());
+ Assert.assertNotNull(rsp.getEntity());
+ try {
+ ComponentDependencyResponseDto dto = (ComponentDependencyResponseDto) rsp.getEntity();
+ Assert.assertEquals("resulting entityId must match", dto.getId(), entityId);
+ } catch (ClassCastException ex) {
+ Assert.fail("unexpected class for DTO " + rsp.getEntity().getClass().getName());
+ }
+
+
+
+ }
+}
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/ComponentImplTest.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/ComponentImplTest.java
new file mode 100644
index 0000000000..5add920dd6
--- /dev/null
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/ComponentImplTest.java
@@ -0,0 +1,198 @@
+package org.openecomp.sdcrests.vsp.rest.services;
+
+import org.apache.http.HttpStatus;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentMatchers;
+import org.mockito.Mock;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.ComponentManager;
+import org.openecomp.sdc.vendorsoftwareproduct.ComponentManagerFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity;
+import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityResponse;
+import org.openecomp.sdc.vendorsoftwareproduct.types.QuestionnaireResponse;
+import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentData;
+import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType;
+import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityValidationData;
+import org.openecomp.sdc.versioning.dao.types.Version;
+import org.openecomp.sdcrests.vendorsoftwareproducts.types.ComponentCreationDto;
+import org.openecomp.sdcrests.vendorsoftwareproducts.types.ComponentDto;
+import org.openecomp.sdcrests.vendorsoftwareproducts.types.ComponentRequestDto;
+import org.openecomp.sdcrests.vendorsoftwareproducts.types.QuestionnaireResponseDto;
+import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import javax.ws.rs.core.Response;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.UUID;
+
+import static org.mockito.MockitoAnnotations.initMocks;
+import static org.powermock.api.mockito.PowerMockito.mockStatic;
+import static org.powermock.api.mockito.PowerMockito.when;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({ComponentsImpl.class, ComponentManagerFactory.class})
+public class ComponentImplTest {
+
+ private Logger logger = LoggerFactory.getLogger(ComponentImplTest.class);
+
+
+ @Mock
+ private ComponentManagerFactory componentManagerFactory;
+
+ @Mock
+ private ComponentManager componentManager;
+
+ private final String vspId = UUID.randomUUID().toString();
+ private final String versionId = UUID.randomUUID().toString();
+ private final String componentId = "" + System.currentTimeMillis();
+ private final String user = "cs0008";
+
+ @Before
+ public void setUp() {
+ try {
+ initMocks(this);
+
+ mockStatic(ComponentManagerFactory.class);
+ when(ComponentManagerFactory.getInstance()).thenReturn(componentManagerFactory);
+ when(componentManagerFactory.createInterface()).thenReturn(componentManager);
+
+ ComponentEntity ce = new ComponentEntity();
+ ce.setId(vspId);
+ ce.setVspId(vspId);
+ ce.setVersion(new Version(versionId));
+
+ Collection<ComponentEntity> ceList = Collections.singletonList(ce);
+ when(componentManager.listComponents(
+ ArgumentMatchers.eq(vspId),
+ ArgumentMatchers.any())).thenReturn(ceList);
+
+ when(componentManager.createComponent(
+ ArgumentMatchers.any())).thenReturn(ce);
+
+ CompositionEntityResponse<ComponentData> r = new CompositionEntityResponse<>();
+ r.setId(vspId);
+ when(componentManager.getComponent(
+ ArgumentMatchers.eq(vspId),
+ ArgumentMatchers.any(),
+ ArgumentMatchers.eq(componentId))).thenReturn(r);
+
+ CompositionEntityType tpe = CompositionEntityType.component;
+ CompositionEntityValidationData data = new CompositionEntityValidationData(tpe, vspId);
+ when(componentManager.updateComponent(
+ ArgumentMatchers.any())).thenReturn(data);
+
+
+ QuestionnaireResponse qr = new QuestionnaireResponse();
+ qr.setData("helloworld");
+ when(componentManager.getQuestionnaire(
+ ArgumentMatchers.eq(vspId),
+ ArgumentMatchers.any(),
+ ArgumentMatchers.eq(componentId))).thenReturn(qr);
+
+
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ }
+ }
+
+ @Test
+ public void testList() {
+ ComponentsImpl ci = new ComponentsImpl();
+
+ Response rsp = ci.list(vspId, versionId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Object e = rsp.getEntity();
+ Assert.assertNotNull(e);
+ @SuppressWarnings("unchecked")
+ GenericCollectionWrapper<ComponentDto> results = (GenericCollectionWrapper<ComponentDto>)e;
+ Assert.assertEquals("result length", 1, results.getListCount());
+ }
+
+ @Test
+ public void testDeleteList() {
+ ComponentsImpl ci = new ComponentsImpl();
+ Response rsp = ci.deleteList(vspId, versionId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Assert.assertNull(rsp.getEntity());
+ }
+
+
+
+ @Test
+ public void testCreate() {
+
+ ComponentRequestDto dto = new ComponentRequestDto();
+ dto.setDescription("hello");
+ dto.setName("name");
+ dto.setDisplayName("world");
+
+ ComponentsImpl ci = new ComponentsImpl();
+ Response rsp = ci.create(dto, vspId, versionId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Object e = rsp.getEntity();
+ Assert.assertNotNull(e);
+ try {
+ ComponentCreationDto ccdto = (ComponentCreationDto)e;
+ Assert.assertEquals(vspId, ccdto.getVfcId());
+ } catch (ClassCastException ex) {
+ Assert.fail("unexpected class for DTO " + e.getClass().getName());
+ }
+ }
+
+
+ @Test
+ public void testDelete() {
+ ComponentsImpl ci = new ComponentsImpl();
+ Response rsp = ci.delete(vspId, versionId, componentId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Assert.assertNull(rsp.getEntity());
+ }
+
+
+ @Test
+ public void testGet() {
+ ComponentsImpl ci = new ComponentsImpl();
+ Response rsp = ci.get(vspId, versionId, componentId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Assert.assertNotNull(rsp.getEntity());
+ }
+
+ @Test
+ public void testUpdate() {
+ ComponentsImpl ci = new ComponentsImpl();
+ ComponentRequestDto dto = new ComponentRequestDto();
+ Response rsp = ci.update(dto, vspId, versionId, componentId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Assert.assertNull(rsp.getEntity());
+ }
+
+ @Test
+ public void testGetQuestionaire() {
+ ComponentsImpl ci = new ComponentsImpl();
+ Response rsp = ci.getQuestionnaire(vspId, versionId, componentId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ try {
+ QuestionnaireResponseDto dto = (QuestionnaireResponseDto)rsp.getEntity();
+ Assert.assertEquals("helloworld", dto.getData());
+ }
+ catch (Exception ex) {
+ logger.error("caught exception", ex);
+ Assert.fail(ex.getMessage());
+ }
+ }
+
+
+ @Test
+ public void testUpdateQuestionaire() {
+ ComponentsImpl ci = new ComponentsImpl();
+ Response rsp = ci.updateQuestionnaire("helloworld", vspId, versionId, componentId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Assert.assertNull(rsp.getEntity());
+ }
+}
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/ComponentMonitoringUploadsImplTest.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/ComponentMonitoringUploadsImplTest.java
new file mode 100644
index 0000000000..296ee8d2ca
--- /dev/null
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/ComponentMonitoringUploadsImplTest.java
@@ -0,0 +1,134 @@
+package org.openecomp.sdcrests.vsp.rest.services;
+
+import org.apache.cxf.jaxrs.ext.multipart.Attachment;
+import org.apache.cxf.jaxrs.ext.multipart.ContentDisposition;
+import org.apache.http.HttpStatus;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentMatchers;
+import org.mockito.Mock;
+import org.openecomp.core.enrichment.types.MonitoringUploadType;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.ComponentManager;
+import org.openecomp.sdc.vendorsoftwareproduct.ComponentManagerFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.MonitoringUploadsManager;
+import org.openecomp.sdc.vendorsoftwareproduct.MonitoringUploadsManagerFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.impl.MonitoringUploadsManagerImpl;
+import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.MonitoringUploadStatus;
+import org.openecomp.sdcrests.vendorsoftwareproducts.types.MonitoringUploadStatusDto;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import javax.ws.rs.core.Response;
+import java.io.ByteArrayInputStream;
+import java.util.UUID;
+
+import static org.mockito.MockitoAnnotations.initMocks;
+import static org.powermock.api.mockito.PowerMockito.mockStatic;
+import static org.powermock.api.mockito.PowerMockito.when;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({MonitoringUploadsManagerImpl.class, MonitoringUploadsManagerFactory.class, ComponentManagerFactory.class})
+public class ComponentMonitoringUploadsImplTest {
+
+ private Logger logger = LoggerFactory.getLogger(ComponentMonitoringUploadsImplTest.class);
+
+ @Mock
+ private ComponentManagerFactory componentManagerFactory;
+
+ @Mock
+ private ComponentManager componentManager;
+
+ @Mock
+ private MonitoringUploadsManagerFactory uploadsFactory;
+
+ @Mock
+ private MonitoringUploadsManager uploadsManager;
+
+ private final String vspId = UUID.randomUUID().toString();
+ private final String versionId = UUID.randomUUID().toString();
+ private final String componentId = "" + System.currentTimeMillis();
+ private final String user = "cs0008";
+
+ @Before
+ public void setUp() {
+ try {
+ initMocks(this);
+
+ mockStatic(ComponentManagerFactory.class);
+ when(ComponentManagerFactory.getInstance()).thenReturn(componentManagerFactory);
+ when(componentManagerFactory.createInterface()).thenReturn(componentManager);
+
+ mockStatic(MonitoringUploadsManagerFactory.class);
+ when(MonitoringUploadsManagerFactory.getInstance()).thenReturn(uploadsFactory);
+ when(uploadsFactory.createInterface()).thenReturn(uploadsManager);
+
+ MonitoringUploadStatus result = new MonitoringUploadStatus();
+ result.setSnmpPoll("p");
+ result.setSnmpTrap("t");
+ result.setVesEvent("v");
+ when(uploadsManager.listFilenames(
+ ArgumentMatchers.eq(vspId),
+ ArgumentMatchers.any(),
+ ArgumentMatchers.eq(componentId))).thenReturn(result);
+
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ }
+ }
+
+ @Test
+ public void testUpload() {
+ ComponentMonitoringUploadsImpl bean = new ComponentMonitoringUploadsImpl();
+ byte[] bytes = "Hello".getBytes();
+ Attachment a = new Attachment("foo", new ByteArrayInputStream(bytes), new ContentDisposition("filename"));
+ String type = MonitoringUploadType.SNMP_POLL.toString();
+ try {
+ Response rsp = bean.upload(a, vspId, versionId, componentId, type, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Assert.assertNull(rsp.getEntity());
+ }
+ catch (Exception ex) {
+ logger.error("test failed due to exception", ex);
+ Assert.fail("exception caught " + ex.getMessage());
+ }
+ }
+
+
+ @Test
+ public void testDelete() {
+ ComponentMonitoringUploadsImpl bean = new ComponentMonitoringUploadsImpl();
+ String type = MonitoringUploadType.SNMP_POLL.toString();
+ try {
+ Response rsp = bean.delete(vspId, versionId, componentId, type, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Assert.assertNull(rsp.getEntity());
+ }
+ catch (Exception ex) {
+ logger.error("test failed due to exception", ex);
+ Assert.fail("exception caught " + ex.getMessage());
+ }
+ }
+
+ @Test
+ public void testList() {
+ ComponentMonitoringUploadsImpl bean = new ComponentMonitoringUploadsImpl();
+ try {
+ Response rsp = bean.list(vspId, versionId, componentId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Assert.assertNotNull(rsp.getEntity());
+ MonitoringUploadStatusDto dto = (MonitoringUploadStatusDto)rsp.getEntity();
+ Assert.assertEquals("p",dto.getSnmpPoll());
+ Assert.assertEquals("v",dto.getVesEvent());
+ Assert.assertEquals("t",dto.getSnmpTrap());
+ }
+ catch (Exception ex) {
+ logger.error("test failed due to exception", ex);
+ Assert.fail("exception caught " + ex.getMessage());
+ }
+ }
+
+}
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/ComponentProcessesImplTest.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/ComponentProcessesImplTest.java
new file mode 100644
index 0000000000..111bd8ff92
--- /dev/null
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/ComponentProcessesImplTest.java
@@ -0,0 +1,219 @@
+package org.openecomp.sdcrests.vsp.rest.services;
+
+import org.apache.cxf.jaxrs.ext.multipart.Attachment;
+import org.apache.cxf.jaxrs.ext.multipart.ContentDisposition;
+import org.apache.http.HttpStatus;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentMatchers;
+import org.mockito.Mock;
+import org.openecomp.sdc.activitylog.ActivityLogManager;
+import org.openecomp.sdc.activitylog.ActivityLogManagerFactory;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.ComponentManager;
+import org.openecomp.sdc.vendorsoftwareproduct.ComponentManagerFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.ProcessManager;
+import org.openecomp.sdc.vendorsoftwareproduct.ProcessManagerFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessType;
+import org.openecomp.sdc.versioning.dao.types.Version;
+import org.openecomp.sdcrests.vendorsoftwareproducts.types.*;
+import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper;
+import org.openecomp.sdcrests.wrappers.StringWrapperResponse;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import javax.ws.rs.core.Response;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.UUID;
+
+import static org.mockito.MockitoAnnotations.initMocks;
+import static org.powermock.api.mockito.PowerMockito.*;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({ComponentDependenciesImpl.class, ActivityLogManagerFactory.class, ComponentManagerFactory.class, ProcessManagerFactory.class})
+public class ComponentProcessesImplTest {
+
+ private Logger logger = LoggerFactory.getLogger(ComponentProcessesImplTest.class);
+
+ @Mock
+ private ActivityLogManager activityLogManager;
+ @Mock
+ private ActivityLogManagerFactory activityLogManagerFactory;
+
+ @Mock
+ private ProcessManagerFactory processManagerFactory;
+
+ @Mock
+ private ProcessManager processManager;
+
+ @Mock
+ private ComponentManagerFactory componentManagerFactory;
+
+ @Mock
+ private ComponentManager componentManager;
+
+ private final String vspId = UUID.randomUUID().toString();
+ private final String versionId = UUID.randomUUID().toString();
+ private final String componentId = "" + System.currentTimeMillis();
+ private final String processId = "" + System.currentTimeMillis();
+ private final String user = "cs0008";
+
+ @Before
+ public void setUp() {
+ try {
+ initMocks(this);
+
+ mockStatic(ProcessManagerFactory.class);
+ when(ProcessManagerFactory.getInstance()).thenReturn(processManagerFactory);
+ when(processManagerFactory.createInterface()).thenReturn(processManager);
+
+ mockStatic(ActivityLogManagerFactory.class);
+ when(ActivityLogManagerFactory.getInstance()).thenReturn(activityLogManagerFactory);
+ when(activityLogManagerFactory.createInterface()).thenReturn(activityLogManager);
+
+ mockStatic(ComponentManagerFactory.class);
+ when(ComponentManagerFactory.getInstance()).thenReturn(componentManagerFactory);
+ when(componentManagerFactory.createInterface()).thenReturn(componentManager);
+
+ ProcessEntity pe = new ProcessEntity();
+ pe.setId(vspId);
+ pe.setComponentId(componentId);
+ pe.setVspId(vspId);
+ pe.setVersion(new Version(versionId));
+
+ Collection<ProcessEntity> peList = Collections.singletonList(pe);
+ when(processManager.listProcesses(
+ ArgumentMatchers.eq(vspId),
+ ArgumentMatchers.any(),
+ ArgumentMatchers.eq(componentId))).thenReturn(peList);
+
+ when(processManager.createProcess(
+ ArgumentMatchers.any())).thenReturn(pe);
+
+ when(processManager.getProcess(
+ ArgumentMatchers.eq(vspId),
+ ArgumentMatchers.any(),
+ ArgumentMatchers.eq(componentId),
+ ArgumentMatchers.eq(processId))).thenReturn(pe);
+
+ File processArtifact = new File(vspId);
+ when(processManager.getProcessArtifact(
+ ArgumentMatchers.eq(vspId),
+ ArgumentMatchers.any(),
+ ArgumentMatchers.eq(componentId),
+ ArgumentMatchers.eq(processId))).thenReturn(processArtifact);
+
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ }
+ }
+
+ @Test
+ public void testList() {
+ ComponentProcessesImpl cpi = new ComponentProcessesImpl();
+
+ Response rsp = cpi.list(vspId, versionId, componentId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Object e = rsp.getEntity();
+ Assert.assertNotNull(e);
+ @SuppressWarnings("unchecked")
+ GenericCollectionWrapper<ProcessEntityDto> results = (GenericCollectionWrapper<ProcessEntityDto>)e;
+ Assert.assertEquals("result length", 1, results.getListCount());
+ }
+
+ @Test
+ public void testDeleteList() {
+ ComponentProcessesImpl cpi = new ComponentProcessesImpl();
+ Response rsp = cpi.deleteList(vspId, versionId, componentId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Assert.assertNull(rsp.getEntity());
+ }
+
+
+
+ @Test
+ public void testCreate() {
+
+ ProcessRequestDto dto = new ProcessRequestDto();
+ dto.setDescription("hello");
+ dto.setName("name");
+ dto.setType(ProcessType.Other);
+
+ ComponentProcessesImpl cpi = new ComponentProcessesImpl();
+ Response rsp = cpi.create(dto, vspId, versionId, componentId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Object e = rsp.getEntity();
+ Assert.assertNotNull(e);
+ try {
+ StringWrapperResponse swr = (StringWrapperResponse)e;
+ Assert.assertEquals(vspId, swr.getValue());
+ } catch (ClassCastException ex) {
+ Assert.fail("unexpected class for DTO " + e.getClass().getName());
+ }
+ }
+
+
+ @Test
+ public void testDelete() {
+ ComponentProcessesImpl cpi = new ComponentProcessesImpl();
+ Response rsp = cpi.delete(vspId, versionId, componentId, processId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Assert.assertNull(rsp.getEntity());
+ }
+
+
+ @Test
+ public void testGet() {
+ ComponentProcessesImpl cpi = new ComponentProcessesImpl();
+ Response rsp = cpi.get(vspId, versionId, componentId, processId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Assert.assertNotNull(rsp.getEntity());
+ }
+
+ @Test
+ public void testUpdate() {
+ ComponentProcessesImpl cpi = new ComponentProcessesImpl();
+ ProcessRequestDto dto = new ProcessRequestDto();
+ Response rsp = cpi.update(dto, vspId, versionId, componentId, processId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Assert.assertNull(rsp.getEntity());
+ }
+
+ @Test
+ public void testGetUploadedFile() {
+ ComponentProcessesImpl cpi = new ComponentProcessesImpl();
+ Response rsp = cpi.getUploadedFile(vspId, versionId, componentId, processId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Assert.assertNotEquals(rsp.getHeaderString("Content-Disposition").indexOf(vspId),-1);
+ }
+
+
+ @Test
+ public void testDeleteUploadedFile() {
+ ComponentProcessesImpl cpi = new ComponentProcessesImpl();
+ Response rsp = cpi.deleteUploadedFile(vspId, versionId, componentId, processId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Assert.assertNull(rsp.getEntity());
+ }
+
+
+ @Test
+ public void testUploadFile() {
+ ComponentProcessesImpl cpi = new ComponentProcessesImpl();
+
+ Attachment attachment = mock(Attachment.class);
+ when(attachment.getContentDisposition()).thenReturn(new ContentDisposition("test"));
+ byte[] bytes = "Hello World".getBytes();
+ when(attachment.getObject(ArgumentMatchers.any())).thenReturn(new ByteArrayInputStream(bytes));
+ Response rsp = cpi.uploadFile(attachment, vspId, versionId, componentId, processId, user);
+ Assert.assertNull(rsp.getEntity());
+ }
+
+}
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/ComputeImplTest.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/ComputeImplTest.java
new file mode 100644
index 0000000000..b1526a2ea4
--- /dev/null
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/ComputeImplTest.java
@@ -0,0 +1,210 @@
+package org.openecomp.sdcrests.vsp.rest.services;
+
+import org.apache.http.HttpStatus;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentMatchers;
+import org.mockito.Mock;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.ComponentManager;
+import org.openecomp.sdc.vendorsoftwareproduct.ComponentManagerFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.ComputeManager;
+import org.openecomp.sdc.vendorsoftwareproduct.ComputeManagerFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComputeEntity;
+import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityResponse;
+import org.openecomp.sdc.vendorsoftwareproduct.types.ListComputeResponse;
+import org.openecomp.sdc.vendorsoftwareproduct.types.QuestionnaireResponse;
+import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType;
+import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityValidationData;
+import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComputeData;
+import org.openecomp.sdcrests.vendorsoftwareproducts.types.ComputeCreationDto;
+import org.openecomp.sdcrests.vendorsoftwareproducts.types.ComputeDetailsDto;
+import org.openecomp.sdcrests.vendorsoftwareproducts.types.ComputeDto;
+import org.openecomp.sdcrests.vendorsoftwareproducts.types.QuestionnaireResponseDto;
+import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import javax.ws.rs.core.Response;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.UUID;
+
+import static org.mockito.MockitoAnnotations.initMocks;
+import static org.powermock.api.mockito.PowerMockito.mockStatic;
+import static org.powermock.api.mockito.PowerMockito.when;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({ComputeImpl.class, ComponentManagerFactory.class, ComputeManagerFactory.class})
+public class ComputeImplTest {
+
+ private Logger logger = LoggerFactory.getLogger(ComputeImplTest.class);
+
+ @Mock
+ private ComputeManagerFactory computeManagerFactory;
+
+ @Mock
+ private ComputeManager computeManager;
+
+ @Mock
+ private ComponentManagerFactory componentManagerFactory;
+
+ @Mock
+ private ComponentManager componentManager;
+
+ private final String vspId = UUID.randomUUID().toString();
+ private final String versionId = UUID.randomUUID().toString();
+ private final String componentId = "" + System.currentTimeMillis();
+ private final String computeId = "" + System.currentTimeMillis();
+ private final String user = "cs0008";
+
+ @Before
+ public void setUp() {
+ try {
+ initMocks(this);
+
+ mockStatic(ComponentManagerFactory.class);
+ when(ComponentManagerFactory.getInstance()).thenReturn(componentManagerFactory);
+ when(componentManagerFactory.createInterface()).thenReturn(componentManager);
+
+ mockStatic(ComputeManagerFactory.class);
+ when(ComputeManagerFactory.getInstance()).thenReturn(computeManagerFactory);
+ when(computeManagerFactory.createInterface()).thenReturn(computeManager);
+
+
+ ListComputeResponse lcr = new ListComputeResponse();
+ lcr.setAssociatedWithDeploymentFlavor(false);
+ lcr.setComputeEntity(new ComputeEntity());
+ lcr.getComputeEntity().setComponentId(componentId);
+ lcr.getComputeEntity().setCompositionData("{\"name\":\"nm\",\"description\":\"d\"}");
+
+
+ Collection<ListComputeResponse> cList = Collections.singletonList(lcr);
+ when(computeManager.listComputes(
+ ArgumentMatchers.eq(vspId),
+ ArgumentMatchers.any(),
+ ArgumentMatchers.eq(componentId))).thenReturn(cList);
+
+ ComputeEntity ce = new ComputeEntity();
+ ce.setComponentId(componentId);
+ ce.setId(computeId);
+ ce.setCompositionData("data");
+ when(computeManager.createCompute(
+ ArgumentMatchers.any())).thenReturn(ce);
+
+ CompositionEntityResponse<ComputeData> r = new CompositionEntityResponse<>();
+ r.setId(vspId);
+ when(computeManager.getCompute(
+ ArgumentMatchers.eq(vspId),
+ ArgumentMatchers.any(),
+ ArgumentMatchers.eq(componentId),
+ ArgumentMatchers.eq(computeId))).thenReturn(r);
+
+ CompositionEntityType tpe = CompositionEntityType.component;
+ CompositionEntityValidationData data = new CompositionEntityValidationData(tpe, vspId);
+ when(computeManager.updateCompute(
+ ArgumentMatchers.any())).thenReturn(data);
+
+
+ QuestionnaireResponse qr = new QuestionnaireResponse();
+ qr.setData("helloworld");
+ when(computeManager.getComputeQuestionnaire(
+ ArgumentMatchers.eq(vspId),
+ ArgumentMatchers.any(),
+ ArgumentMatchers.eq(componentId),
+ ArgumentMatchers.eq(computeId))).thenReturn(qr);
+
+
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ }
+ }
+
+ @Test
+ public void testList() {
+ ComputeImpl ci = new ComputeImpl();
+
+ Response rsp = ci.list(vspId, versionId, componentId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Object e = rsp.getEntity();
+ Assert.assertNotNull(e);
+ @SuppressWarnings("unchecked")
+ GenericCollectionWrapper<ComputeDto> results = (GenericCollectionWrapper<ComputeDto>)e;
+ Assert.assertEquals("result length", 1, results.getListCount());
+ }
+
+
+ @Test
+ public void testCreate() {
+
+ ComputeDetailsDto dto = new ComputeDetailsDto();
+ dto.setDescription("hello");
+ dto.setName("name");
+
+ ComputeImpl ci = new ComputeImpl();
+ Response rsp = ci.create(dto, vspId, versionId, componentId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Object e = rsp.getEntity();
+ Assert.assertNotNull(e);
+ try {
+ ComputeCreationDto ccdto = (ComputeCreationDto)e;
+ Assert.assertEquals(computeId, ccdto.getId());
+ } catch (ClassCastException ex) {
+ Assert.fail("unexpected class for DTO " + e.getClass().getName());
+ }
+ }
+
+
+ @Test
+ public void testDelete() {
+ ComputeImpl ci = new ComputeImpl();
+ Response rsp = ci.delete(vspId, versionId, componentId, computeId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Assert.assertNull(rsp.getEntity());
+ }
+
+
+ @Test
+ public void testGet() {
+ ComputeImpl ci = new ComputeImpl();
+ Response rsp = ci.get(vspId, versionId, componentId, computeId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Assert.assertNotNull(rsp.getEntity());
+ }
+
+ @Test
+ public void testUpdate() {
+ ComputeImpl ci = new ComputeImpl();
+ ComputeDetailsDto dto = new ComputeDetailsDto();
+ Response rsp = ci.update(dto, vspId, versionId, componentId, computeId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Assert.assertNull(rsp.getEntity());
+ }
+
+ @Test
+ public void testGetQuestionaire() {
+ ComputeImpl ci = new ComputeImpl();
+ Response rsp = ci.getQuestionnaire(vspId, versionId, componentId, computeId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ try {
+ QuestionnaireResponseDto dto = (QuestionnaireResponseDto)rsp.getEntity();
+ Assert.assertEquals("helloworld", dto.getData());
+ }
+ catch (Exception ex) {
+ logger.error("caught exception", ex);
+ Assert.fail(ex.getMessage());
+ }
+ }
+
+
+ @Test
+ public void testUpdateQuestionaire() {
+ ComputeImpl ci = new ComputeImpl();
+ Response rsp = ci.updateQuestionnaire("helloworld", vspId, versionId, componentId, computeId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Assert.assertNull(rsp.getEntity());
+ }
+}
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/DeploymentFlavorsImplTest.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/DeploymentFlavorsImplTest.java
new file mode 100644
index 0000000000..0ed38a51aa
--- /dev/null
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/DeploymentFlavorsImplTest.java
@@ -0,0 +1,168 @@
+package org.openecomp.sdcrests.vsp.rest.services;
+
+import org.apache.http.HttpStatus;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentMatchers;
+import org.mockito.Mock;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.DeploymentFlavorManager;
+import org.openecomp.sdc.vendorsoftwareproduct.DeploymentFlavorManagerFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.DeploymentFlavorEntity;
+import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityResponse;
+import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType;
+import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityValidationData;
+import org.openecomp.sdc.vendorsoftwareproduct.types.composition.DeploymentFlavor;
+import org.openecomp.sdc.versioning.dao.types.Version;
+import org.openecomp.sdcrests.vendorsoftwareproducts.types.DeploymentFlavorCreationDto;
+import org.openecomp.sdcrests.vendorsoftwareproducts.types.DeploymentFlavorRequestDto;
+import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import javax.ws.rs.core.Response;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.UUID;
+
+import static org.mockito.MockitoAnnotations.initMocks;
+import static org.powermock.api.mockito.PowerMockito.mockStatic;
+import static org.powermock.api.mockito.PowerMockito.when;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({DeploymentFlavorsImpl.class, DeploymentFlavorManagerFactory.class})
+public class DeploymentFlavorsImplTest {
+
+ private Logger logger = LoggerFactory.getLogger(DeploymentFlavorsImplTest.class);
+
+
+ @Mock
+ private DeploymentFlavorManagerFactory deploymentFlavorManagerFactory;
+
+ @Mock
+ private DeploymentFlavorManager deploymentFlavorManager;
+
+ private final String vspId = UUID.randomUUID().toString();
+ private final String versionId = UUID.randomUUID().toString();
+ private final String deploymentFlavorId = "" + System.currentTimeMillis();
+ private final String user = "cs0008";
+
+ @Before
+ public void setUp() {
+ try {
+ initMocks(this);
+
+ mockStatic(DeploymentFlavorManagerFactory.class);
+ when(DeploymentFlavorManagerFactory.getInstance()).thenReturn(deploymentFlavorManagerFactory);
+ when(deploymentFlavorManagerFactory.createInterface()).thenReturn(deploymentFlavorManager);
+
+ DeploymentFlavorEntity e = new DeploymentFlavorEntity();
+ e.setId(deploymentFlavorId);
+ e.setVspId(vspId);
+ e.setVersion(new Version(versionId));
+
+ Collection<DeploymentFlavorEntity> lst = Collections.singletonList(e);
+ when(deploymentFlavorManager.listDeploymentFlavors(
+ ArgumentMatchers.eq(vspId),
+ ArgumentMatchers.any())).thenReturn(lst);
+
+ when(deploymentFlavorManager.createDeploymentFlavor(
+ ArgumentMatchers.any())).thenReturn(e);
+
+ CompositionEntityResponse<DeploymentFlavor> r = new CompositionEntityResponse<>();
+ r.setId(vspId);
+ when(deploymentFlavorManager.getDeploymentFlavor(
+ ArgumentMatchers.eq(vspId),
+ ArgumentMatchers.any(),
+ ArgumentMatchers.eq(deploymentFlavorId))).thenReturn(r);
+
+ CompositionEntityType tpe = CompositionEntityType.component;
+ CompositionEntityValidationData data = new CompositionEntityValidationData(tpe, vspId);
+ when(deploymentFlavorManager.updateDeploymentFlavor(
+ ArgumentMatchers.any())).thenReturn(data);
+
+
+
+ when(deploymentFlavorManager.getDeploymentFlavorSchema(
+ ArgumentMatchers.eq(vspId),
+ ArgumentMatchers.any())).thenReturn(r);
+
+
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ }
+ }
+
+ @Test
+ public void testList() {
+ DeploymentFlavorsImpl dfi = new DeploymentFlavorsImpl();
+
+ Response rsp = dfi.list(vspId, versionId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Object e = rsp.getEntity();
+ Assert.assertNotNull(e);
+ @SuppressWarnings("unchecked")
+ GenericCollectionWrapper<DeploymentFlavorCreationDto> results = (GenericCollectionWrapper<DeploymentFlavorCreationDto>) e;
+ Assert.assertEquals("result length", 1, results.getListCount());
+ }
+
+ @Test
+ public void testCreate() {
+
+ DeploymentFlavorRequestDto dto = new DeploymentFlavorRequestDto();
+ dto.setDescription("hello");
+ dto.setModel("model");
+ dto.setFeatureGroupId("fgi");
+
+ DeploymentFlavorsImpl dfi = new DeploymentFlavorsImpl();
+ Response rsp = dfi.create(dto, vspId, versionId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Object e = rsp.getEntity();
+ Assert.assertNotNull(e);
+ try {
+ DeploymentFlavorCreationDto responseDto = (DeploymentFlavorCreationDto)e;
+ Assert.assertEquals(deploymentFlavorId, responseDto.getDeploymentFlavorId());
+ } catch (ClassCastException ex) {
+ Assert.fail("unexpected class for DTO " + e.getClass().getName());
+ }
+ }
+
+
+ @Test
+ public void testDelete() {
+ DeploymentFlavorsImpl dfi = new DeploymentFlavorsImpl();
+ Response rsp = dfi.delete(vspId, versionId, deploymentFlavorId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Assert.assertNull(rsp.getEntity());
+ }
+
+
+ @Test
+ public void testGet() {
+ DeploymentFlavorsImpl dfi = new DeploymentFlavorsImpl();
+ Response rsp = dfi.get(vspId, versionId, deploymentFlavorId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Assert.assertNotNull(rsp.getEntity());
+ }
+
+ @Test
+ public void testGetSchema() {
+ DeploymentFlavorsImpl dfi = new DeploymentFlavorsImpl();
+ Response rsp = dfi.get(vspId, versionId, deploymentFlavorId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Assert.assertNotNull(rsp.getEntity());
+ }
+
+ @Test
+ public void testUpdate() {
+ DeploymentFlavorsImpl dfi = new DeploymentFlavorsImpl();
+ DeploymentFlavorRequestDto dto = new DeploymentFlavorRequestDto();
+ Response rsp = dfi.update(dto, vspId, versionId, deploymentFlavorId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Assert.assertNull(rsp.getEntity());
+ }
+
+}
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/ImagesImplTest.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/ImagesImplTest.java
new file mode 100644
index 0000000000..9805b77eb8
--- /dev/null
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/ImagesImplTest.java
@@ -0,0 +1,205 @@
+package org.openecomp.sdcrests.vsp.rest.services;
+
+import org.apache.http.HttpStatus;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentMatchers;
+import org.mockito.Mock;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.ComponentManager;
+import org.openecomp.sdc.vendorsoftwareproduct.ComponentManagerFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.ImageManager;
+import org.openecomp.sdc.vendorsoftwareproduct.ImageManagerFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ImageEntity;
+import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityResponse;
+import org.openecomp.sdc.vendorsoftwareproduct.types.QuestionnaireResponse;
+import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType;
+import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityValidationData;
+import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Image;
+import org.openecomp.sdcrests.vendorsoftwareproducts.types.ImageCreationDto;
+import org.openecomp.sdcrests.vendorsoftwareproducts.types.ImageDto;
+import org.openecomp.sdcrests.vendorsoftwareproducts.types.ImageRequestDto;
+import org.openecomp.sdcrests.vendorsoftwareproducts.types.QuestionnaireResponseDto;
+import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import javax.ws.rs.core.Response;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.UUID;
+
+import static org.mockito.MockitoAnnotations.initMocks;
+import static org.powermock.api.mockito.PowerMockito.mockStatic;
+import static org.powermock.api.mockito.PowerMockito.when;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({ComputeImpl.class, ComponentManagerFactory.class, ImageManagerFactory.class})
+public class ImagesImplTest {
+
+ private Logger logger = LoggerFactory.getLogger(ImagesImplTest.class);
+
+ @Mock
+ private ImageManagerFactory imageManagerFactory;
+
+ @Mock
+ private ImageManager imageManager;
+
+ @Mock
+ private ComponentManagerFactory componentManagerFactory;
+
+ @Mock
+ private ComponentManager componentManager;
+
+ private final String vspId = UUID.randomUUID().toString();
+ private final String versionId = UUID.randomUUID().toString();
+ private final String componentId = "" + System.currentTimeMillis();
+ private final String imageId = "" + System.currentTimeMillis();
+ private final String user = "cs0008";
+
+ @Before
+ public void setUp() {
+ try {
+ initMocks(this);
+
+ mockStatic(ComponentManagerFactory.class);
+ when(ComponentManagerFactory.getInstance()).thenReturn(componentManagerFactory);
+ when(componentManagerFactory.createInterface()).thenReturn(componentManager);
+
+ mockStatic(ImageManagerFactory.class);
+ when(ImageManagerFactory.getInstance()).thenReturn(imageManagerFactory);
+ when(imageManagerFactory.createInterface()).thenReturn(imageManager);
+
+
+
+ ImageEntity ie = new ImageEntity();
+ ie.setComponentId(componentId);
+ ie.setId(imageId);
+ ie.setCompositionData("{\"name\":\"nm\",\"description\":\"d\"}");
+
+
+ Collection<ImageEntity> cList = Collections.singletonList(ie);
+ when(imageManager.listImages(
+ ArgumentMatchers.eq(vspId),
+ ArgumentMatchers.any(),
+ ArgumentMatchers.eq(componentId))).thenReturn(cList);
+
+ when(imageManager.createImage(
+ ArgumentMatchers.any())).thenReturn(ie);
+
+ CompositionEntityResponse<Image> r = new CompositionEntityResponse<>();
+ r.setId(vspId);
+ when(imageManager.getImage(
+ ArgumentMatchers.eq(vspId),
+ ArgumentMatchers.any(),
+ ArgumentMatchers.eq(componentId),
+ ArgumentMatchers.eq(imageId))).thenReturn(r);
+
+ CompositionEntityType tpe = CompositionEntityType.component;
+ CompositionEntityValidationData data = new CompositionEntityValidationData(tpe, vspId);
+ when(imageManager.updateImage(
+ ArgumentMatchers.any())).thenReturn(data);
+
+
+ QuestionnaireResponse qr = new QuestionnaireResponse();
+ qr.setData("helloworld");
+ when(imageManager.getImageQuestionnaire(
+ ArgumentMatchers.eq(vspId),
+ ArgumentMatchers.any(),
+ ArgumentMatchers.eq(componentId),
+ ArgumentMatchers.eq(imageId))).thenReturn(qr);
+
+
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ }
+ }
+
+ @Test
+ public void testList() {
+ ImagesImpl ii = new ImagesImpl();
+
+ Response rsp = ii.list(vspId, versionId, componentId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Object e = rsp.getEntity();
+ Assert.assertNotNull(e);
+ @SuppressWarnings("unchecked")
+ GenericCollectionWrapper<ImageDto> results = (GenericCollectionWrapper<ImageDto>)e;
+ Assert.assertEquals("result length", 1, results.getListCount());
+ }
+
+
+ @Test
+ public void testCreate() {
+
+ ImageRequestDto dto = new ImageRequestDto();
+ dto.setDescription("hello");
+ dto.setFileName("name");
+
+ ImagesImpl ii = new ImagesImpl();
+ Response rsp = ii.create(dto, vspId, versionId, componentId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Object e = rsp.getEntity();
+ Assert.assertNotNull(e);
+ try {
+ ImageCreationDto creationDto = (ImageCreationDto)e;
+ Assert.assertEquals(imageId, creationDto.getId());
+ } catch (ClassCastException ex) {
+ Assert.fail("unexpected class for DTO " + e.getClass().getName());
+ }
+ }
+
+
+ @Test
+ public void testDelete() {
+ ImagesImpl ii = new ImagesImpl();
+ Response rsp = ii.delete(vspId, versionId, componentId, imageId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Assert.assertNull(rsp.getEntity());
+ }
+
+
+ @Test
+ public void testGet() {
+ ImagesImpl ii = new ImagesImpl();
+ Response rsp = ii.get(vspId, versionId, componentId, imageId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Assert.assertNotNull(rsp.getEntity());
+ }
+
+ @Test
+ public void testUpdate() {
+ ImagesImpl ii = new ImagesImpl();
+ ImageRequestDto dto = new ImageRequestDto();
+ Response rsp = ii.update(dto, vspId, versionId, componentId, imageId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Assert.assertNull(rsp.getEntity());
+ }
+
+ @Test
+ public void testGetQuestionaire() {
+ ImagesImpl ii = new ImagesImpl();
+ Response rsp = ii.getQuestionnaire(vspId, versionId, componentId, imageId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ try {
+ QuestionnaireResponseDto dto = (QuestionnaireResponseDto)rsp.getEntity();
+ Assert.assertEquals("helloworld", dto.getData());
+ }
+ catch (Exception ex) {
+ logger.error("caught exception", ex);
+ Assert.fail(ex.getMessage());
+ }
+ }
+
+
+ @Test
+ public void testUpdateQuestionaire() {
+ ImagesImpl ii = new ImagesImpl();
+ Response rsp = ii.updateQuestionnaire("helloworld", vspId, versionId, componentId, imageId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Assert.assertNull(rsp.getEntity());
+ }
+}
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/NetworksImplTest.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/NetworksImplTest.java
new file mode 100644
index 0000000000..7c95d0a274
--- /dev/null
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/NetworksImplTest.java
@@ -0,0 +1,158 @@
+package org.openecomp.sdcrests.vsp.rest.services;
+
+import org.apache.http.HttpStatus;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentMatchers;
+import org.mockito.Mock;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.NetworkManager;
+import org.openecomp.sdc.vendorsoftwareproduct.NetworkManagerFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity;
+import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityResponse;
+import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType;
+import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityValidationData;
+import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Network;
+import org.openecomp.sdc.versioning.dao.types.Version;
+import org.openecomp.sdcrests.vendorsoftwareproducts.types.NetworkDto;
+import org.openecomp.sdcrests.vendorsoftwareproducts.types.NetworkRequestDto;
+import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper;
+import org.openecomp.sdcrests.wrappers.StringWrapperResponse;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import javax.ws.rs.core.Response;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.UUID;
+
+import static org.mockito.MockitoAnnotations.initMocks;
+import static org.powermock.api.mockito.PowerMockito.mockStatic;
+import static org.powermock.api.mockito.PowerMockito.when;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({NetworksImpl.class, NetworkManagerFactory.class})
+public class NetworksImplTest {
+
+ private Logger logger = LoggerFactory.getLogger(NetworksImplTest.class);
+
+ @Mock
+ private NetworkManagerFactory networkManagerFactory;
+
+ @Mock
+ private NetworkManager networkManager;
+
+
+ private final String vspId = UUID.randomUUID().toString();
+ private final String versionId = UUID.randomUUID().toString();
+ private final String networkId = "" + System.currentTimeMillis();
+ private final String user = "cs0008";
+
+ @Before
+ public void setUp() {
+ try {
+ initMocks(this);
+
+ mockStatic(NetworkManagerFactory.class);
+ when(NetworkManagerFactory.getInstance()).thenReturn(networkManagerFactory);
+ when(networkManagerFactory.createInterface()).thenReturn(networkManager);
+
+
+ NetworkEntity e = new NetworkEntity();
+ e.setId(networkId);
+ e.setVspId(vspId);
+ e.setVersion(new Version(versionId));
+ e.setCompositionData("{\"name\":\"nm\",\"description\":\"d\"}");
+
+
+ Collection<NetworkEntity> lst = Collections.singletonList(e);
+ when(networkManager.listNetworks(
+ ArgumentMatchers.eq(vspId),
+ ArgumentMatchers.any())).thenReturn(lst);
+
+ when(networkManager.createNetwork(
+ ArgumentMatchers.any())).thenReturn(e);
+
+ CompositionEntityResponse<Network> r = new CompositionEntityResponse<>();
+ r.setId(vspId);
+ when(networkManager.getNetwork(
+ ArgumentMatchers.eq(vspId),
+ ArgumentMatchers.any(),
+ ArgumentMatchers.eq(networkId))).thenReturn(r);
+
+ CompositionEntityType tpe = CompositionEntityType.component;
+ CompositionEntityValidationData data = new CompositionEntityValidationData(tpe, vspId);
+ when(networkManager.updateNetwork(
+ ArgumentMatchers.any())).thenReturn(data);
+
+
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ }
+ }
+
+ @Test
+ public void testList() {
+ NetworksImpl bean = new NetworksImpl();
+
+ Response rsp = bean.list(vspId, versionId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Object e = rsp.getEntity();
+ Assert.assertNotNull(e);
+ @SuppressWarnings("unchecked")
+ GenericCollectionWrapper<NetworkDto> results = (GenericCollectionWrapper<NetworkDto>)e;
+ Assert.assertEquals("result length", 1, results.getListCount());
+ }
+
+
+ @Test
+ public void testCreate() {
+
+ NetworkRequestDto dto = new NetworkRequestDto();
+ dto.setName("name");
+ dto.setDhcp(true);
+
+ NetworksImpl bean = new NetworksImpl();
+ Response rsp = bean.create(dto, vspId, versionId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Object e = rsp.getEntity();
+ Assert.assertNotNull(e);
+ try {
+ StringWrapperResponse s = (StringWrapperResponse)e;
+ Assert.assertEquals(networkId, s.getValue());
+ } catch (ClassCastException ex) {
+ Assert.fail("unexpected class for DTO " + e.getClass().getName());
+ }
+ }
+
+
+ @Test
+ public void testDelete() {
+ NetworksImpl bean = new NetworksImpl();
+ Response rsp = bean.delete(vspId, versionId, networkId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Assert.assertNull(rsp.getEntity());
+ }
+
+
+ @Test
+ public void testGet() {
+ NetworksImpl bean = new NetworksImpl();
+ Response rsp = bean.get(vspId, versionId, networkId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Assert.assertNotNull(rsp.getEntity());
+ }
+
+ @Test
+ public void testUpdate() {
+ NetworksImpl bean = new NetworksImpl();
+ NetworkRequestDto dto = new NetworkRequestDto();
+ Response rsp = bean.update(dto, vspId, versionId, networkId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Assert.assertNull(rsp.getEntity());
+ }
+
+}
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/NicsImplTest.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/NicsImplTest.java
new file mode 100644
index 0000000000..6a82e3c423
--- /dev/null
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/NicsImplTest.java
@@ -0,0 +1,214 @@
+package org.openecomp.sdcrests.vsp.rest.services;
+
+import org.apache.http.HttpStatus;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentMatchers;
+import org.mockito.Mock;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.ComponentManager;
+import org.openecomp.sdc.vendorsoftwareproduct.ComponentManagerFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.NicManager;
+import org.openecomp.sdc.vendorsoftwareproduct.NicManagerFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity;
+import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityResponse;
+import org.openecomp.sdc.vendorsoftwareproduct.types.QuestionnaireResponse;
+import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType;
+import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityValidationData;
+import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic;
+import org.openecomp.sdcrests.vendorsoftwareproducts.types.NicCreationResponseDto;
+import org.openecomp.sdcrests.vendorsoftwareproducts.types.NicDto;
+import org.openecomp.sdcrests.vendorsoftwareproducts.types.NicRequestDto;
+import org.openecomp.sdcrests.vendorsoftwareproducts.types.QuestionnaireResponseDto;
+import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import javax.ws.rs.core.Response;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.UUID;
+
+import static org.mockito.MockitoAnnotations.initMocks;
+import static org.powermock.api.mockito.PowerMockito.mockStatic;
+import static org.powermock.api.mockito.PowerMockito.when;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({NicsImpl.class, ComponentManagerFactory.class, NicManagerFactory.class})
+public class NicsImplTest {
+
+ private Logger logger = LoggerFactory.getLogger(NicsImplTest.class);
+
+ @Mock
+ private NicManagerFactory nicManagerFactory;
+
+ @Mock
+ private NicManager nicManager;
+
+ @Mock
+ private ComponentManagerFactory componentManagerFactory;
+
+ @Mock
+ private ComponentManager componentManager;
+
+ private final String vspId = UUID.randomUUID().toString();
+ private final String versionId = UUID.randomUUID().toString();
+ private final String componentId = "" + System.currentTimeMillis();
+ private final String nicId = "" + System.currentTimeMillis();
+ private final String user = "cs0008";
+
+ @Before
+ public void setUp() {
+ try {
+ initMocks(this);
+
+ mockStatic(ComponentManagerFactory.class);
+ when(ComponentManagerFactory.getInstance()).thenReturn(componentManagerFactory);
+ when(componentManagerFactory.createInterface()).thenReturn(componentManager);
+
+ mockStatic(NicManagerFactory.class);
+ when(NicManagerFactory.getInstance()).thenReturn(nicManagerFactory);
+ when(nicManagerFactory.createInterface()).thenReturn(nicManager);
+
+
+
+ NicEntity e = new NicEntity();
+ e.setComponentId(componentId);
+ e.setId(nicId);
+ e.setCompositionData("{\"name\":\"nm\",\"description\":\"d\"}");
+
+
+ Collection<NicEntity> lst = Collections.singletonList(e);
+ when(nicManager.listNics(
+ ArgumentMatchers.eq(vspId),
+ ArgumentMatchers.any(),
+ ArgumentMatchers.eq(componentId))).thenReturn(lst);
+
+ when(nicManager.createNic(
+ ArgumentMatchers.any())).thenReturn(e);
+
+ CompositionEntityResponse<Nic> r = new CompositionEntityResponse<>();
+ r.setId(vspId);
+ when(nicManager.getNic(
+ ArgumentMatchers.eq(vspId),
+ ArgumentMatchers.any(),
+ ArgumentMatchers.eq(componentId),
+ ArgumentMatchers.eq(nicId))).thenReturn(r);
+
+ CompositionEntityType tpe = CompositionEntityType.component;
+ CompositionEntityValidationData data = new CompositionEntityValidationData(tpe, vspId);
+ when(nicManager.updateNic(
+ ArgumentMatchers.any())).thenReturn(data);
+
+
+ QuestionnaireResponse qr = new QuestionnaireResponse();
+ qr.setData("helloworld");
+ when(nicManager.getNicQuestionnaire(
+ ArgumentMatchers.eq(vspId),
+ ArgumentMatchers.any(),
+ ArgumentMatchers.eq(componentId),
+ ArgumentMatchers.eq(nicId))).thenReturn(qr);
+
+
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ }
+ }
+
+ @Test
+ public void testList() {
+ NicsImpl bean = new NicsImpl();
+
+ Response rsp = bean.list(vspId, versionId, componentId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Object e = rsp.getEntity();
+ Assert.assertNotNull(e);
+ @SuppressWarnings("unchecked")
+ GenericCollectionWrapper<NicDto> results = (GenericCollectionWrapper<NicDto>)e;
+ Assert.assertEquals("result length", 1, results.getListCount());
+ }
+
+
+ @Test
+ public void testCreate() {
+
+ NicRequestDto dto = new NicRequestDto();
+ dto.setDescription("hello");
+ dto.setName("name");
+ dto.setNetworkDescription("nd");
+ dto.setNetworkId(nicId);
+ dto.setNetworkType("External");
+
+ NicsImpl bean = new NicsImpl();
+ Response rsp = bean.create(dto, vspId, versionId, componentId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Object e = rsp.getEntity();
+ Assert.assertNotNull(e);
+ try {
+ NicCreationResponseDto creationDto = (NicCreationResponseDto)e;
+ Assert.assertEquals(nicId, creationDto.getNicId());
+ } catch (ClassCastException ex) {
+ Assert.fail("unexpected class for DTO " + e.getClass().getName());
+ }
+ }
+
+
+ @Test
+ public void testDelete() {
+ NicsImpl bean = new NicsImpl();
+ Response rsp = bean.delete(vspId, versionId, componentId, nicId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Assert.assertNull(rsp.getEntity());
+ }
+
+
+ @Test
+ public void testGet() {
+ NicsImpl bean = new NicsImpl();
+ Response rsp = bean.get(vspId, versionId, componentId, nicId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Assert.assertNotNull(rsp.getEntity());
+ }
+
+ @Test
+ public void testUpdate() {
+ NicsImpl bean = new NicsImpl();
+ NicRequestDto dto = new NicRequestDto();
+ dto.setDescription("hello");
+ dto.setName("name");
+ dto.setNetworkDescription("nd");
+ dto.setNetworkId(nicId);
+ dto.setNetworkType("External");
+
+ Response rsp = bean.update(dto, vspId, versionId, componentId, nicId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Assert.assertNull(rsp.getEntity());
+ }
+
+ @Test
+ public void testGetQuestionaire() {
+ NicsImpl bean = new NicsImpl();
+ Response rsp = bean.getQuestionnaire(vspId, versionId, componentId, nicId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ try {
+ QuestionnaireResponseDto dto = (QuestionnaireResponseDto)rsp.getEntity();
+ Assert.assertEquals("helloworld", dto.getData());
+ }
+ catch (Exception ex) {
+ logger.error("caught exception", ex);
+ Assert.fail(ex.getMessage());
+ }
+ }
+
+
+ @Test
+ public void testUpdateQuestionaire() {
+ NicsImpl bean = new NicsImpl();
+ Response rsp = bean.updateQuestionnaire("helloworld", vspId, versionId, componentId, nicId, user);
+ Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
+ Assert.assertNull(rsp.getEntity());
+ }
+}
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/OrchestrationTemplateCandidateImplTest.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/OrchestrationTemplateCandidateImplTest.java
index 2dc6cd737c..1e2debf033 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/OrchestrationTemplateCandidateImplTest.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/OrchestrationTemplateCandidateImplTest.java
@@ -1,10 +1,13 @@
package org.openecomp.sdcrests.vsp.rest.services;
+import org.apache.commons.lang3.tuple.Pair;
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.apache.cxf.jaxrs.ext.multipart.ContentDisposition;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.ArgumentMatchers;
import org.mockito.Mock;
import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
import org.openecomp.sdc.activitylog.ActivityLogManager;
@@ -16,30 +19,38 @@ import org.openecomp.sdc.vendorsoftwareproduct.OrchestrationTemplateCandidateMan
import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductManager;
import org.openecomp.sdc.vendorsoftwareproduct.VspManagerFactory;
import org.openecomp.sdc.vendorsoftwareproduct.security.SecurityManagerException;
+import org.openecomp.sdc.vendorsoftwareproduct.types.OrchestrationTemplateActionResponse;
import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
+import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileStatus;
+import org.openecomp.sdc.vendorsoftwareproduct.types.ValidationResponse;
+import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.FilesDataStructure;
+import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.Module;
+import org.openecomp.sdcrests.vendorsoftwareproducts.types.FileDataStructureDto;
+import org.openecomp.sdcrests.vendorsoftwareproducts.types.OrchestrationTemplateActionResponseDto;
import org.openecomp.sdcrests.vendorsoftwareproducts.types.UploadFileResponseDto;
import org.openecomp.sdcrests.vsp.rest.data.PackageArchive;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
-import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response;
+import java.io.IOException;
+import java.util.Arrays;
import java.util.Optional;
+import java.util.UUID;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertFalse;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.MockitoAnnotations.initMocks;
-import static org.powermock.api.mockito.PowerMockito.mock;
-import static org.powermock.api.mockito.PowerMockito.mockStatic;
-import static org.powermock.api.mockito.PowerMockito.when;
-import static org.powermock.api.mockito.PowerMockito.whenNew;
+import static org.powermock.api.mockito.PowerMockito.*;
@RunWith(PowerMockRunner.class)
@PrepareForTest({VspManagerFactory.class, ActivityLogManagerFactory.class,
OrchestrationTemplateCandidateManagerFactory.class, OrchestrationTemplateCandidateImpl.class})
public class OrchestrationTemplateCandidateImplTest {
- Logger logger = LoggerFactory.getLogger(OrchestrationTemplateCandidateImplTest.class);
+ private Logger logger = LoggerFactory.getLogger(OrchestrationTemplateCandidateImplTest.class);
+
@Mock
private OrchestrationTemplateCandidateManager candidateManager;
@Mock
@@ -57,6 +68,12 @@ public class OrchestrationTemplateCandidateImplTest {
private OrchestrationTemplateCandidateImpl orchestrationTemplateCandidate;
+ private final String candidateId = UUID.randomUUID().toString();
+ private final String softwareProductId = UUID.randomUUID().toString();
+ private final String versionId = UUID.randomUUID().toString();
+
+ private final String user = "cs0008";
+
@Before
public void setUp(){
try {
@@ -78,6 +95,46 @@ public class OrchestrationTemplateCandidateImplTest {
uploadFileResponse.setOnboardingType(OnboardingTypesEnum.ZIP);
uploadFileResponse.setNetworkPackageName("test");
when(candidateManager.upload(any(), any(), any(), any(), any())).thenReturn(uploadFileResponse);
+
+
+ // get using the candidate manager.
+ Optional<Pair<String,byte[]>> zipFile =
+ Optional.of(Pair.of("Hello", "World".getBytes()));
+
+ when(candidateManager.get(
+ ArgumentMatchers.eq(candidateId),
+ ArgumentMatchers.any())).thenReturn(zipFile);
+
+ when(vendorSoftwareProductManager.get(
+ ArgumentMatchers.eq(softwareProductId),
+ ArgumentMatchers.any())).thenReturn(zipFile);
+
+
+ OrchestrationTemplateActionResponse processResponse =
+ new OrchestrationTemplateActionResponse();
+ processResponse.setStatus(UploadFileStatus.Success);
+ when(candidateManager.process(
+ ArgumentMatchers.eq(candidateId),
+ ArgumentMatchers.any())).thenReturn(processResponse);
+
+
+ ValidationResponse vr = new ValidationResponse();
+ when(candidateManager.updateFilesDataStructure(
+ ArgumentMatchers.eq(candidateId),
+ ArgumentMatchers.any(),
+ ArgumentMatchers.any())).thenReturn(vr);
+
+ FilesDataStructure fds = new FilesDataStructure();
+ fds.setArtifacts(Arrays.asList("a","b"));
+ fds.setNested(Arrays.asList("foo", "bar"));
+ fds.setUnassigned(Arrays.asList("c", "d"));
+ fds.setModules(Arrays.asList(new Module(), new Module()));
+
+ when(candidateManager.getFilesDataStructure(
+ ArgumentMatchers.eq(candidateId),
+ ArgumentMatchers.any())).thenReturn(Optional.of(fds));
+
+
}catch (Exception e){
logger.error(e.getMessage(), e);
}
@@ -118,4 +175,93 @@ public class OrchestrationTemplateCandidateImplTest {
assertFalse(((UploadFileResponseDto)response.getEntity()).getErrors().isEmpty());
}
+
+ @Test
+ public void testCandidateGet() throws IOException {
+ orchestrationTemplateCandidate = new OrchestrationTemplateCandidateImpl();
+ Response rsp = orchestrationTemplateCandidate.get(candidateId, versionId, user);
+ Assert.assertEquals("Response status equals", Response.Status.OK.getStatusCode(), rsp.getStatus());
+ Assert.assertNotEquals(rsp.getHeaderString("Content-Disposition").indexOf("Candidate"),-1);
+ byte[] content = (byte[])rsp.getEntity();
+ Assert.assertEquals("World", new String(content));
+
+ }
+
+ @Test
+ public void testVendorSoftwareProductGet() throws IOException {
+ orchestrationTemplateCandidate = new OrchestrationTemplateCandidateImpl();
+ Response rsp = orchestrationTemplateCandidate.get(softwareProductId, versionId, user);
+ Assert.assertEquals("Response status equals", Response.Status.OK.getStatusCode(), rsp.getStatus());
+ Assert.assertNotEquals(rsp.getHeaderString("Content-Disposition").indexOf("Processed"),-1);
+ byte[] content = (byte[])rsp.getEntity();
+ Assert.assertEquals("World", new String(content));
+ }
+
+ @Test
+ public void testMissingGet() throws IOException {
+ orchestrationTemplateCandidate = new OrchestrationTemplateCandidateImpl();
+ Response rsp = orchestrationTemplateCandidate.get(UUID.randomUUID().toString(), versionId, user);
+ Assert.assertEquals("Response status equals", Response.Status.NOT_FOUND.getStatusCode(), rsp.getStatus());
+ }
+
+ @Test
+ public void testAbort() {
+ try {
+ orchestrationTemplateCandidate = new OrchestrationTemplateCandidateImpl();
+ Response rsp = orchestrationTemplateCandidate.abort(candidateId, versionId);
+ Assert.assertEquals("Response status equals", Response.Status.OK.getStatusCode(), rsp.getStatus());
+ Assert.assertNull(rsp.getEntity());
+ }
+ catch (Exception ex) {
+ logger.error("unexpected exception", ex);
+ Assert.fail("abort should not throw an exception");
+ }
+ }
+
+ @Test
+ public void testProcess() {
+ try {
+ orchestrationTemplateCandidate = new OrchestrationTemplateCandidateImpl();
+ Response rsp = orchestrationTemplateCandidate.process(candidateId, versionId, user);
+ Assert.assertEquals("Response status equals", Response.Status.OK.getStatusCode(), rsp.getStatus());
+ Assert.assertNotNull(rsp.getEntity());
+ OrchestrationTemplateActionResponseDto dto = (OrchestrationTemplateActionResponseDto)rsp.getEntity();
+ Assert.assertEquals("status check", UploadFileStatus.Success, dto.getStatus());
+ }
+ catch (Exception ex) {
+ logger.error("unexpected exception", ex);
+ Assert.fail("abort should not throw an exception");
+ }
+ }
+
+ @Test
+ public void testFilesDataStructureUpload() {
+ try {
+ FileDataStructureDto dto = new FileDataStructureDto();
+ dto.setArtifacts(Arrays.asList("a", "b", "c"));
+ orchestrationTemplateCandidate = new OrchestrationTemplateCandidateImpl();
+ Response rsp = orchestrationTemplateCandidate.updateFilesDataStructure(candidateId, versionId, dto, user);
+ Assert.assertEquals("Response status equals", Response.Status.OK.getStatusCode(), rsp.getStatus());
+ }
+ catch (Exception ex) {
+ logger.error("unexpected exception", ex);
+ Assert.fail("abort should not throw an exception");
+ }
+ }
+
+ @Test
+ public void testFilesDataStructureGet() {
+ try {
+ FileDataStructureDto dto = new FileDataStructureDto();
+ dto.setArtifacts(Arrays.asList("a", "b", "c"));
+ orchestrationTemplateCandidate = new OrchestrationTemplateCandidateImpl();
+ Response rsp = orchestrationTemplateCandidate.getFilesDataStructure(candidateId, versionId, user);
+ Assert.assertEquals("Response status equals", Response.Status.OK.getStatusCode(), rsp.getStatus());
+ }
+ catch (Exception ex) {
+ logger.error("unexpected exception", ex);
+ Assert.fail("abort should not throw an exception");
+ }
+ }
+
}