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 static org.mockito.Mockito.when;
24 import static org.mockito.MockitoAnnotations.openMocks;
26 import java.util.Collection;
27 import java.util.Collections;
28 import java.util.UUID;
29 import javax.ws.rs.core.Response;
30 import org.apache.http.HttpStatus;
31 import org.junit.Assert;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.mockito.ArgumentMatchers;
35 import org.mockito.Mock;
36 import org.openecomp.sdc.vendorsoftwareproduct.NetworkManager;
37 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity;
38 import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityResponse;
39 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType;
40 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityValidationData;
41 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Network;
42 import org.openecomp.sdc.versioning.dao.types.Version;
43 import org.openecomp.sdcrests.vendorsoftwareproducts.types.NetworkDto;
44 import org.openecomp.sdcrests.vendorsoftwareproducts.types.NetworkRequestDto;
45 import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper;
46 import org.openecomp.sdcrests.wrappers.StringWrapperResponse;
48 public class NetworksImplTest {
51 private NetworkManager mockedNetworkManager;
53 private final String vspId = UUID.randomUUID().toString();
54 private final String versionId = UUID.randomUUID().toString();
55 private final String networkId = "" + System.currentTimeMillis();
56 private final String user = "cs0008";
62 NetworkEntity e = new NetworkEntity();
65 e.setVersion(new Version(versionId));
66 e.setCompositionData("{\"name\":\"nm\",\"description\":\"d\"}");
68 Collection<NetworkEntity> lst = Collections.singletonList(e);
69 when(mockedNetworkManager.listNetworks(
70 ArgumentMatchers.eq(vspId),
71 ArgumentMatchers.any())).thenReturn(lst);
73 when(mockedNetworkManager.createNetwork(
74 ArgumentMatchers.any())).thenReturn(e);
76 CompositionEntityResponse<Network> r = new CompositionEntityResponse<>();
78 when(mockedNetworkManager.getNetwork(
79 ArgumentMatchers.eq(vspId),
80 ArgumentMatchers.any(),
81 ArgumentMatchers.eq(networkId))).thenReturn(r);
83 CompositionEntityType tpe = CompositionEntityType.component;
84 CompositionEntityValidationData data = new CompositionEntityValidationData(tpe, vspId);
85 when(mockedNetworkManager.updateNetwork(
86 ArgumentMatchers.any())).thenReturn(data);
90 public void testList() {
91 NetworksImpl bean = new NetworksImpl(mockedNetworkManager);
93 Response rsp = bean.list(vspId, versionId, user);
94 Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
95 Object e = rsp.getEntity();
96 Assert.assertNotNull(e);
97 @SuppressWarnings("unchecked")
98 GenericCollectionWrapper<NetworkDto> results = (GenericCollectionWrapper<NetworkDto>) e;
99 Assert.assertEquals("result length", 1, results.getListCount());
104 public void testCreate() {
106 NetworkRequestDto dto = new NetworkRequestDto();
110 NetworksImpl bean = new NetworksImpl(mockedNetworkManager);
111 Response rsp = bean.create(dto, vspId, versionId, user);
112 Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
113 Object e = rsp.getEntity();
114 Assert.assertNotNull(e);
116 StringWrapperResponse s = (StringWrapperResponse) e;
117 Assert.assertEquals(networkId, s.getValue());
118 } catch (ClassCastException ex) {
119 Assert.fail("unexpected class for DTO " + e.getClass().getName());
125 public void testDelete() {
126 NetworksImpl bean = new NetworksImpl(mockedNetworkManager);
127 Response rsp = bean.delete(vspId, versionId, networkId, user);
128 Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
129 Assert.assertNull(rsp.getEntity());
134 public void testGet() {
135 NetworksImpl bean = new NetworksImpl(mockedNetworkManager);
136 Response rsp = bean.get(vspId, versionId, networkId, user);
137 Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
138 Assert.assertNotNull(rsp.getEntity());
142 public void testUpdate() {
143 NetworksImpl bean = new NetworksImpl(mockedNetworkManager);
144 NetworkRequestDto dto = new NetworkRequestDto();
145 Response rsp = bean.update(dto, vspId, versionId, networkId, user);
146 Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
147 Assert.assertNull(rsp.getEntity());