2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdcrests.vsp.rest.services;
23 import org.junit.Assert;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.mockito.ArgumentMatchers;
27 import org.mockito.Mock;
28 import org.openecomp.sdc.logging.api.Logger;
29 import org.openecomp.sdc.logging.api.LoggerFactory;
30 import org.openecomp.sdc.vendorsoftwareproduct.ComponentDependencyModelManager;
31 import org.openecomp.sdc.vendorsoftwareproduct.ComponentDependencyModelManagerFactory;
32 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentDependencyModelEntity;
33 import org.openecomp.sdc.versioning.dao.types.Version;
34 import org.openecomp.sdcrests.vendorsoftwareproducts.types.ComponentDependencyCreationDto;
35 import org.openecomp.sdcrests.vendorsoftwareproducts.types.ComponentDependencyModel;
36 import org.openecomp.sdcrests.vendorsoftwareproducts.types.ComponentDependencyResponseDto;
37 import org.openecomp.sdcrests.vendorsoftwareproducts.types.ComponentRelationType;
38 import org.openecomp.sdcrests.vsp.rest.ComponentDependencies;
39 import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper;
41 import javax.ws.rs.core.Response;
42 import java.util.Collection;
43 import java.util.Collections;
44 import java.util.UUID;
46 import static org.mockito.MockitoAnnotations.openMocks;
47 import static org.mockito.Mockito.when;
49 public class ComponentDependenciesImplTest {
51 private Logger logger = LoggerFactory.getLogger(org.openecomp.sdcrests.vsp.rest.services.ComponentDependenciesImplTest.class);
54 private ComponentDependencyModelManagerFactory componentDependencyModelManagerFactory;
57 private ComponentDependencyModelManager componentDependencyModelManager;
59 private final String vspId = UUID.randomUUID().toString();
60 private final String versionId = UUID.randomUUID().toString();
61 private final String entityId = "" + System.currentTimeMillis();
62 private final String user = "cs0008";
64 private ComponentDependencies componentDependencies;
71 ComponentDependencyModelEntity e = new ComponentDependencyModelEntity();
72 e.setSourceComponentId("sourceid");
73 e.setTargetComponentId("targetid");
75 e.setVersion(new Version(versionId));
76 e.setRelation(ComponentRelationType.dependsOn.name());
80 when(componentDependencyModelManager.createComponentDependency(
81 ArgumentMatchers.any(),
82 ArgumentMatchers.eq(vspId),
83 ArgumentMatchers.any())).thenReturn(e);
86 Collection<ComponentDependencyModelEntity> entities =
87 Collections.singletonList(e);
88 when(componentDependencyModelManager.list(
89 ArgumentMatchers.eq(vspId),
90 ArgumentMatchers.any())).thenReturn(entities);
93 when(componentDependencyModelManager.get(
94 ArgumentMatchers.eq(vspId),
95 ArgumentMatchers.any(),
96 ArgumentMatchers.eq(entityId)
99 componentDependencies = new ComponentDependenciesImpl(componentDependencyModelManager);
101 } catch (Exception e) {
102 logger.error(e.getMessage(), e);
107 public void testCreate() {
108 ComponentDependencyModel model = new ComponentDependencyModel();
109 model.setRelationType(ComponentRelationType.dependsOn.name());
110 model.setSourceId("sourceid");
111 model.setTargetId("targetid");
113 Response rsp = componentDependencies.create(model, vspId, versionId, user);
114 Assert.assertEquals("Response should be 200", 200, rsp.getStatus());
115 Object e = rsp.getEntity();
116 Assert.assertNotNull(e);
118 ComponentDependencyCreationDto dto = (ComponentDependencyCreationDto) e;
119 Assert.assertEquals("resulting entityId must match", dto.getId(), entityId);
120 } catch (ClassCastException ex) {
121 Assert.fail("unexpected class for DTO " + e.getClass().getName());
126 public void testList() {
128 Response rsp = componentDependencies.list(vspId, versionId, user);
129 Assert.assertEquals("Response should be 200", 200, rsp.getStatus());
130 Object e = rsp.getEntity();
131 Assert.assertNotNull(e);
133 @SuppressWarnings("unchecked")
134 GenericCollectionWrapper<ComponentDependencyResponseDto> results =
135 (GenericCollectionWrapper<ComponentDependencyResponseDto>) e;
137 Assert.assertEquals("result length", 1, results.getListCount());
138 Assert.assertEquals("resulting entityId must match", results.getResults().get(0).getId(), entityId);
139 } catch (ClassCastException ex) {
140 Assert.fail("unexpected class for DTO " + e.getClass().getName());
146 public void testDelete() {
148 Response rsp = componentDependencies.delete(vspId, versionId, entityId, user);
149 Assert.assertEquals("Response should be 200", 200, rsp.getStatus());
150 Assert.assertNull(rsp.getEntity());
155 public void testUpdate() {
157 ComponentDependencyModel model = new ComponentDependencyModel();
158 model.setRelationType(ComponentRelationType.dependsOn.name());
159 model.setSourceId("sourceid");
160 model.setTargetId("targetid");
162 Response rsp = componentDependencies.update(model, vspId, versionId, entityId, user);
163 Assert.assertEquals("Response should be 200", 200, rsp.getStatus());
164 Assert.assertNull(rsp.getEntity());
168 public void testGet() {
170 Response rsp = componentDependencies.get(vspId, versionId, entityId, user);
171 Assert.assertEquals("Response should be 200", 200, rsp.getStatus());
172 Assert.assertNotNull(rsp.getEntity());
174 ComponentDependencyResponseDto dto = (ComponentDependencyResponseDto) rsp.getEntity();
175 Assert.assertEquals("resulting entityId must match", dto.getId(), entityId);
176 } catch (ClassCastException ex) {
177 Assert.fail("unexpected class for DTO " + rsp.getEntity().getClass().getName());