summaryrefslogtreecommitdiffstats
path: root/feature-healthcheck/src
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2021-08-05 15:45:21 -0400
committerJim Hahn <jrh3@att.com>2021-08-05 16:09:01 -0400
commitf9eaa709e739a1596fafe0d840c354087f7ed5ff (patch)
tree155559ca797819233511a8e49e1ad61400580f62 /feature-healthcheck/src
parentda1b7d9f04453e94fb77ebe4213f456a0be63fc2 (diff)
Use lombok in drools-pdp #3
Updated feature-healthcheck thru feature-pooling-dmaap. Issue-ID: POLICY-3397 Change-Id: Ia7b00a521cdb82ed0eb22bdaed03d02665fbbff1 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'feature-healthcheck/src')
-rw-r--r--feature-healthcheck/src/main/java/org/onap/policy/drools/healthcheck/HealthCheck.java95
-rw-r--r--feature-healthcheck/src/main/java/org/onap/policy/drools/healthcheck/HealthCheckConstants.java11
-rw-r--r--feature-healthcheck/src/main/java/org/onap/policy/drools/healthcheck/HealthCheckManager.java38
-rw-r--r--feature-healthcheck/src/test/java/org/onap/policy/drools/healthcheck/HealthCheckTest.java4
4 files changed, 25 insertions, 123 deletions
diff --git a/feature-healthcheck/src/main/java/org/onap/policy/drools/healthcheck/HealthCheck.java b/feature-healthcheck/src/main/java/org/onap/policy/drools/healthcheck/HealthCheck.java
index b7297998..de00df88 100644
--- a/feature-healthcheck/src/main/java/org/onap/policy/drools/healthcheck/HealthCheck.java
+++ b/feature-healthcheck/src/main/java/org/onap/policy/drools/healthcheck/HealthCheck.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* feature-healthcheck
* ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019, 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,6 +22,9 @@ package org.onap.policy.drools.healthcheck;
import java.util.ArrayList;
import java.util.List;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
import org.onap.policy.common.capabilities.Startable;
/**
@@ -32,6 +35,9 @@ public interface HealthCheck extends Startable {
/**
* Healthcheck Report.
*/
+ @Getter
+ @Setter
+ @ToString
public static class Report {
/**
* Named Entity in the report.
@@ -57,98 +63,17 @@ public interface HealthCheck extends Startable {
* Message from remote entity.
*/
private String message;
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("Report [name=");
- builder.append(getName());
- builder.append(", url=");
- builder.append(getUrl());
- builder.append(", healthy=");
- builder.append(isHealthy());
- builder.append(", code=");
- builder.append(getCode());
- builder.append(", message=");
- builder.append(getMessage());
- builder.append("]");
- return builder.toString();
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getUrl() {
- return url;
- }
-
- public void setUrl(String url) {
- this.url = url;
- }
-
- public boolean isHealthy() {
- return healthy;
- }
-
- public void setHealthy(boolean healthy) {
- this.healthy = healthy;
- }
-
- public int getCode() {
- return code;
- }
-
- public void setCode(int code) {
- this.code = code;
- }
-
- public String getMessage() {
- return message;
- }
-
- public void setMessage(String message) {
- this.message = message;
- }
}
/**
* Report aggregation.
*/
+ @Getter
+ @Setter
+ @ToString
public static class Reports {
private boolean healthy;
private List<Report> details = new ArrayList<>();
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("Reports [healthy=");
- builder.append(isHealthy());
- builder.append(", details=");
- builder.append(getDetails());
- builder.append("]");
- return builder.toString();
- }
-
- public boolean isHealthy() {
- return healthy;
- }
-
- public void setHealthy(boolean healthy) {
- this.healthy = healthy;
- }
-
- public List<Report> getDetails() {
- return details;
- }
-
- public void setDetails(List<Report> details) {
- this.details = details;
- }
}
/**
diff --git a/feature-healthcheck/src/main/java/org/onap/policy/drools/healthcheck/HealthCheckConstants.java b/feature-healthcheck/src/main/java/org/onap/policy/drools/healthcheck/HealthCheckConstants.java
index 70b241dd..e32d7c10 100644
--- a/feature-healthcheck/src/main/java/org/onap/policy/drools/healthcheck/HealthCheckConstants.java
+++ b/feature-healthcheck/src/main/java/org/onap/policy/drools/healthcheck/HealthCheckConstants.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* feature-healthcheck
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,17 +20,16 @@
package org.onap.policy.drools.healthcheck;
+import lombok.AccessLevel;
import lombok.Getter;
+import lombok.NoArgsConstructor;
-public class HealthCheckConstants {
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class HealthCheckConstants {
/**
* Healthcheck Monitor.
*/
@Getter
private static final HealthCheck manager = new HealthCheckManager();
-
- private HealthCheckConstants() {
- // do nothing
- }
}
diff --git a/feature-healthcheck/src/main/java/org/onap/policy/drools/healthcheck/HealthCheckManager.java b/feature-healthcheck/src/main/java/org/onap/policy/drools/healthcheck/HealthCheckManager.java
index 38af2d87..418fe8eb 100644
--- a/feature-healthcheck/src/main/java/org/onap/policy/drools/healthcheck/HealthCheckManager.java
+++ b/feature-healthcheck/src/main/java/org/onap/policy/drools/healthcheck/HealthCheckManager.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,6 +24,9 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import javax.ws.rs.core.Response;
+import lombok.AccessLevel;
+import lombok.Getter;
+import lombok.ToString;
import org.onap.policy.common.endpoints.http.client.HttpClient;
import org.onap.policy.common.endpoints.http.client.HttpClientFactory;
import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
@@ -40,6 +43,8 @@ import org.slf4j.LoggerFactory;
/**
* Healthcheck Monitor.
*/
+@Getter
+@ToString
public class HealthCheckManager implements HealthCheck {
/**
@@ -60,6 +65,8 @@ public class HealthCheckManager implements HealthCheck {
/**
* Healthcheck configuration.
*/
+ @Getter(AccessLevel.NONE)
+ @ToString.Exclude
protected Properties healthCheckProperties = null;
/**
@@ -171,24 +178,6 @@ public class HealthCheckManager implements HealthCheck {
}
/**
- * Get servers.
- *
- * @return list of attached Http Servers
- */
- public List<HttpServletServer> getServers() {
- return this.servers;
- }
-
- /**
- * Get clients.
- *
- * @return list of attached Http Clients
- */
- public List<HttpClient> getClients() {
- return this.clients;
- }
-
- /**
* Gets the body from the response.
*
* @param response response from which to get the body
@@ -220,17 +209,6 @@ public class HealthCheckManager implements HealthCheck {
}
}
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("HealthCheckMonitor [servers=");
- builder.append(servers);
- builder.append(", clients=");
- builder.append(clients);
- builder.append("]");
- return builder.toString();
- }
-
// the following methods may be overridden by junit tests
protected PolicyEngine getEngineManager() {
diff --git a/feature-healthcheck/src/test/java/org/onap/policy/drools/healthcheck/HealthCheckTest.java b/feature-healthcheck/src/test/java/org/onap/policy/drools/healthcheck/HealthCheckTest.java
index 4215aa8c..7040f6d3 100644
--- a/feature-healthcheck/src/test/java/org/onap/policy/drools/healthcheck/HealthCheckTest.java
+++ b/feature-healthcheck/src/test/java/org/onap/policy/drools/healthcheck/HealthCheckTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018, 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -306,7 +306,7 @@ public class HealthCheckTest {
@Test
public void testHealthCheckMonitor_ToString() {
- assertTrue(monitor.toString().startsWith("HealthCheckMonitor ["));
+ assertTrue(monitor.toString().startsWith("HealthCheckManager("));
}
@Test
mp.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");
+ }
+ }
+
}