aboutsummaryrefslogtreecommitdiffstats
path: root/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
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 /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
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>
Diffstat (limited to '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')
-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
1 files changed, 180 insertions, 0 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());
+ }
+
+
+
+ }
+}