1 package org.openecomp.sdcrests.vsp.rest.services;
3 import org.junit.Assert;
4 import org.junit.Before;
6 import org.junit.runner.RunWith;
7 import org.mockito.ArgumentMatchers;
8 import org.mockito.Mock;
9 import org.openecomp.sdc.activitylog.ActivityLogManagerFactory;
10 import org.openecomp.sdc.logging.api.Logger;
11 import org.openecomp.sdc.logging.api.LoggerFactory;
12 import org.openecomp.sdc.vendorsoftwareproduct.ComponentDependencyModelManager;
13 import org.openecomp.sdc.vendorsoftwareproduct.ComponentDependencyModelManagerFactory;
14 import org.openecomp.sdc.vendorsoftwareproduct.ComponentManagerFactory;
15 import org.openecomp.sdc.vendorsoftwareproduct.ProcessManagerFactory;
16 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentDependencyModelEntity;
17 import org.openecomp.sdc.versioning.dao.types.Version;
18 import org.openecomp.sdcrests.vendorsoftwareproducts.types.ComponentDependencyCreationDto;
19 import org.openecomp.sdcrests.vendorsoftwareproducts.types.ComponentDependencyModel;
20 import org.openecomp.sdcrests.vendorsoftwareproducts.types.ComponentDependencyResponseDto;
21 import org.openecomp.sdcrests.vendorsoftwareproducts.types.ComponentRelationType;
22 import org.openecomp.sdcrests.vsp.rest.ComponentDependencies;
23 import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper;
24 import org.powermock.core.classloader.annotations.PrepareForTest;
25 import org.powermock.modules.junit4.PowerMockRunner;
27 import javax.ws.rs.core.Response;
28 import java.util.Collection;
29 import java.util.Collections;
30 import java.util.UUID;
32 import static org.mockito.MockitoAnnotations.initMocks;
33 import static org.powermock.api.mockito.PowerMockito.mockStatic;
34 import static org.powermock.api.mockito.PowerMockito.when;
36 @RunWith(PowerMockRunner.class)
37 @PrepareForTest({ComponentDependenciesImpl.class, ComponentDependencyModelManagerFactory.class})
38 public class ComponentDependenciesImplTest {
40 private Logger logger = LoggerFactory.getLogger(org.openecomp.sdcrests.vsp.rest.services.ComponentDependenciesImplTest.class);
43 private ComponentDependencyModelManagerFactory componentDependencyModelManagerFactory;
46 private ComponentDependencyModelManager componentDependencyModelManager;
48 private final String vspId = UUID.randomUUID().toString();
49 private final String versionId = UUID.randomUUID().toString();
50 private final String entityId = "" + System.currentTimeMillis();
51 private final String user = "cs0008";
58 mockStatic(ComponentDependencyModelManagerFactory.class);
59 when(ComponentDependencyModelManagerFactory.getInstance()).thenReturn(componentDependencyModelManagerFactory);
60 when(componentDependencyModelManagerFactory.createInterface()).thenReturn(componentDependencyModelManager);
62 ComponentDependencyModelEntity e = new ComponentDependencyModelEntity();
63 e.setSourceComponentId("sourceid");
64 e.setTargetComponentId("targetid");
66 e.setVersion(new Version(versionId));
67 e.setRelation(ComponentRelationType.dependsOn.name());
71 when(componentDependencyModelManager.createComponentDependency(
72 ArgumentMatchers.any(),
73 ArgumentMatchers.eq(vspId),
74 ArgumentMatchers.any())).thenReturn(e);
77 Collection<ComponentDependencyModelEntity> entities =
78 Collections.singletonList(e);
79 when(componentDependencyModelManager.list(
80 ArgumentMatchers.eq(vspId),
81 ArgumentMatchers.any())).thenReturn(entities);
84 when(componentDependencyModelManager.get(
85 ArgumentMatchers.eq(vspId),
86 ArgumentMatchers.any(),
87 ArgumentMatchers.eq(entityId)
90 } catch (Exception e) {
91 logger.error(e.getMessage(), e);
96 public void testCreate() {
97 ComponentDependencyModel model = new ComponentDependencyModel();
98 model.setRelationType(ComponentRelationType.dependsOn.name());
99 model.setSourceId("sourceid");
100 model.setTargetId("targetid");
103 ComponentDependencies componentDependencies = new ComponentDependenciesImpl();
104 Response rsp = componentDependencies.create(model, vspId, versionId, user);
105 Assert.assertEquals("Response should be 200", 200, rsp.getStatus());
106 Object e = rsp.getEntity();
107 Assert.assertNotNull(e);
109 ComponentDependencyCreationDto dto = (ComponentDependencyCreationDto) e;
110 Assert.assertEquals("resulting entityId must match", dto.getId(), entityId);
111 } catch (ClassCastException ex) {
112 Assert.fail("unexpected class for DTO " + e.getClass().getName());
117 public void testList() {
119 ComponentDependencies componentDependencies = new ComponentDependenciesImpl();
120 Response rsp = componentDependencies.list(vspId, versionId, user);
121 Assert.assertEquals("Response should be 200", 200, rsp.getStatus());
122 Object e = rsp.getEntity();
123 Assert.assertNotNull(e);
125 @SuppressWarnings("unchecked")
126 GenericCollectionWrapper<ComponentDependencyResponseDto> results =
127 (GenericCollectionWrapper<ComponentDependencyResponseDto>) e;
129 Assert.assertEquals("result length", 1, results.getListCount());
130 Assert.assertEquals("resulting entityId must match", results.getResults().get(0).getId(), entityId);
131 } catch (ClassCastException ex) {
132 Assert.fail("unexpected class for DTO " + e.getClass().getName());
138 public void testDelete() {
140 ComponentDependencies componentDependencies = new ComponentDependenciesImpl();
142 Response rsp = componentDependencies.delete(vspId, versionId, entityId, user);
143 Assert.assertEquals("Response should be 200", 200, rsp.getStatus());
144 Assert.assertNull(rsp.getEntity());
149 public void testUpdate() {
151 ComponentDependencies componentDependencies = new ComponentDependenciesImpl();
153 ComponentDependencyModel model = new ComponentDependencyModel();
154 model.setRelationType(ComponentRelationType.dependsOn.name());
155 model.setSourceId("sourceid");
156 model.setTargetId("targetid");
158 Response rsp = componentDependencies.update(model, vspId, versionId, entityId, user);
159 Assert.assertEquals("Response should be 200", 200, rsp.getStatus());
160 Assert.assertNull(rsp.getEntity());
164 public void testGet() {
166 ComponentDependencies componentDependencies = new ComponentDependenciesImpl();
167 Response rsp = componentDependencies.get(vspId, versionId, entityId, user);
168 Assert.assertEquals("Response should be 200", 200, rsp.getStatus());
169 Assert.assertNotNull(rsp.getEntity());
171 ComponentDependencyResponseDto dto = (ComponentDependencyResponseDto) rsp.getEntity();
172 Assert.assertEquals("resulting entityId must match", dto.getId(), entityId);
173 } catch (ClassCastException ex) {
174 Assert.fail("unexpected class for DTO " + rsp.getEntity().getClass().getName());