2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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.onap.so.bpmn.infrastructure.sdnc.mapper;
23 import static com.shazam.shazamcrest.MatcherAssert.assertThat;
24 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertNotNull;
27 import static org.junit.Assert.assertNull;
28 import java.io.IOException;
29 import java.nio.file.Files;
30 import java.nio.file.Paths;
31 import java.util.HashMap;
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 import org.mockito.InjectMocks;
37 import org.mockito.Spy;
38 import org.mockito.junit.MockitoJUnitRunner;
39 import org.onap.sdnc.northbound.client.model.GenericResourceApiNetworkOperationInformation;
40 import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestActionEnumeration;
41 import org.onap.so.bpmn.infrastructure.sdnc.mapper.GeneralTopologyObjectMapper;
42 import org.onap.so.bpmn.infrastructure.sdnc.mapper.NetworkTopologyOperationRequestMapper;
43 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
44 import org.onap.so.bpmn.servicedecomposition.bbobjects.Collection;
45 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
46 import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup;
47 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
48 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
49 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceSubscription;
50 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
51 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoNetwork;
52 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance;
53 import org.onap.so.client.sdnc.beans.SDNCSvcAction;
54 import org.onap.so.client.sdnc.beans.SDNCSvcOperation;
55 import com.fasterxml.jackson.databind.ObjectMapper;
57 @RunWith(MockitoJUnitRunner.class)
58 public class NetworkTopologyOperationRequestMapperTest {
60 private final static String JSON_FILE_LOCATION = "src/test/resources/__files/BuildingBlocks/";
62 private ServiceInstance serviceInstance;
63 private ServiceInstance serviceInstanceNoCollection;
64 private Customer customer;
65 private RequestContext requestContext;
66 private L3Network network;
67 private CloudRegion cloudRegion;
70 private GeneralTopologyObjectMapper generalTopologyObjectMapper;
73 private NetworkTopologyOperationRequestMapper mapper = new NetworkTopologyOperationRequestMapper();
76 public void before() {
77 // prepare and set service instance
78 serviceInstance = new ServiceInstance();
79 serviceInstanceNoCollection = new ServiceInstance();
80 ModelInfoServiceInstance modelInfoServiceInstance = new ModelInfoServiceInstance();
81 modelInfoServiceInstance.setModelInvariantUuid("modelInvariantUuid");
82 modelInfoServiceInstance.setModelName("modelName");
83 modelInfoServiceInstance.setModelUuid("modelUuid");
84 modelInfoServiceInstance.setModelVersion("modelVersion");
85 serviceInstance.setModelInfoServiceInstance(modelInfoServiceInstance);
86 serviceInstanceNoCollection.setModelInfoServiceInstance(modelInfoServiceInstance);
87 // prepare Customer object
88 customer = new Customer();
89 customer.setGlobalCustomerId("globalCustomerId");
90 // serviceInstance.setCustomer(customer);
91 // set Customer on service instance
92 ServiceSubscription serviceSubscription = new ServiceSubscription();
93 serviceSubscription.setServiceType("productFamilyId");
94 customer.setServiceSubscription(serviceSubscription);
96 // set Customer on service instance
97 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
98 customer.getServiceSubscription().getServiceInstances().add(serviceInstanceNoCollection);
100 InstanceGroup networkInstanceGroup = new InstanceGroup();
101 networkInstanceGroup.setId("networkInstanceGroupId");
102 networkInstanceGroup.setInstanceGroupFunction("instanceGroupFunction");
103 Collection networkCollection = new Collection();
104 networkCollection.setInstanceGroup(networkInstanceGroup);
105 serviceInstance.setCollection(networkCollection);
107 requestContext = new RequestContext();
108 Map<String, Object> userParams = new HashMap<>();
109 userParams.put("key1", "value1");
110 requestContext.setUserParams(userParams);
111 requestContext.setProductFamilyId("productFamilyId");
112 requestContext.setMsoRequestId("MsoRequestId");
114 network = new L3Network();
115 network.setNetworkId("TEST_NETWORK_ID");
116 network.setNetworkName("TEST_NETWORK_NAME");
117 ModelInfoNetwork modelInfoNetwork = new ModelInfoNetwork();
118 modelInfoNetwork.setModelInvariantUUID("modelInvariantUuid");
119 modelInfoNetwork.setModelName("modelName");
120 modelInfoNetwork.setModelVersion("modelVersion");
121 modelInfoNetwork.setModelUUID("modelUuid");
122 modelInfoNetwork.setModelCustomizationUUID("modelCustomizationUUID");
123 network.setModelInfoNetwork(modelInfoNetwork);
125 cloudRegion = new CloudRegion();
129 public void createGenericResourceApiNetworkOperationInformationTest() throws Exception {
131 GenericResourceApiNetworkOperationInformation networkSDNCrequest =
132 mapper.reqMapper(SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN,
133 GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network, serviceInstance,
134 customer, requestContext, cloudRegion);
136 ObjectMapper omapper = new ObjectMapper();
137 GenericResourceApiNetworkOperationInformation reqMapper1 =
138 omapper.readValue(getJson("genericResourceApiNetworkOperationInformation.json"),
139 GenericResourceApiNetworkOperationInformation.class);
141 assertThat(networkSDNCrequest, sameBeanAs(reqMapper1).ignoring("sdncRequestHeader.svcRequestId")
142 .ignoring("requestInformation.requestId"));
143 assertEquals("MsoRequestId", networkSDNCrequest.getRequestInformation().getRequestId());
147 public void createGenericResourceApiNetworkOperationInformationReqContextNullTest() throws Exception {
149 RequestContext rc = new RequestContext();
150 rc.setMsoRequestId(null);
151 GenericResourceApiNetworkOperationInformation networkSDNCrequest =
152 mapper.reqMapper(SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN,
153 GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network, serviceInstance,
154 customer, rc, cloudRegion);
155 assertNotNull(networkSDNCrequest.getRequestInformation().getRequestId());
156 GenericResourceApiNetworkOperationInformation networkSDNCrequest2 =
157 mapper.reqMapper(SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN,
158 GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network, serviceInstance,
159 customer, null, cloudRegion);
160 assertNotNull(networkSDNCrequest2.getRequestInformation().getRequestId());
164 public void reqMapperTest() throws Exception {
166 GenericResourceApiNetworkOperationInformation networkSDNCrequest =
167 mapper.reqMapper(SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN,
168 GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network, serviceInstance,
169 customer, requestContext, cloudRegion);
171 assertNull(networkSDNCrequest.getServiceInformation().getOnapModelInformation().getModelCustomizationUuid());
172 assertEquals("modelCustomizationUUID",
173 networkSDNCrequest.getNetworkInformation().getOnapModelInformation().getModelCustomizationUuid());
177 public void reqMapperNoCollectionTest() throws Exception {
178 GenericResourceApiNetworkOperationInformation networkSDNCrequest =
179 mapper.reqMapper(SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN,
180 GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network,
181 serviceInstanceNoCollection, customer, requestContext, cloudRegion);
183 assertNull(networkSDNCrequest.getServiceInformation().getOnapModelInformation().getModelCustomizationUuid());
184 assertEquals("modelCustomizationUUID",
185 networkSDNCrequest.getNetworkInformation().getOnapModelInformation().getModelCustomizationUuid());
189 public void createGenericResourceApiNetworkOperationInformation_UnassignTest() throws Exception {
191 NetworkTopologyOperationRequestMapper mapperUnassign = mapper;
192 GenericResourceApiNetworkOperationInformation networkSDNCrequestUnassign =
193 mapperUnassign.reqMapper(SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.UNASSIGN,
194 GenericResourceApiRequestActionEnumeration.DELETENETWORKINSTANCE, network, serviceInstance,
195 customer, requestContext, cloudRegion);
197 ObjectMapper omapperUnassign = new ObjectMapper();
198 GenericResourceApiNetworkOperationInformation reqMapperUnassign =
199 omapperUnassign.readValue(getJson("genericResourceApiNetworkOperationInformationUnAssign.json"),
200 GenericResourceApiNetworkOperationInformation.class);
202 assertThat(reqMapperUnassign, sameBeanAs(networkSDNCrequestUnassign).ignoring("sdncRequestHeader.svcRequestId")
203 .ignoring("requestInformation.requestId"));
204 assertEquals("MsoRequestId", networkSDNCrequestUnassign.getRequestInformation().getRequestId());
209 public void createGenericResourceApiNetworkOperationInformationNoNetworkNameTest() throws Exception {
211 // set network name NULL
212 network.setNetworkName(null);
213 GenericResourceApiNetworkOperationInformation networkSDNCrequest =
214 mapper.reqMapper(SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN,
215 GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network, serviceInstance,
216 customer, requestContext, cloudRegion);
218 ObjectMapper omapper = new ObjectMapper();
219 GenericResourceApiNetworkOperationInformation reqMapper1 =
220 omapper.readValue(getJson("genericResourceApiNetworkOperationInformationNoNetworkName.json"),
221 GenericResourceApiNetworkOperationInformation.class);
223 assertThat(reqMapper1, sameBeanAs(networkSDNCrequest).ignoring("sdncRequestHeader.svcRequestId")
224 .ignoring("requestInformation.requestId"));
228 * Helper method to load JSON data
230 private String getJson(String filename) throws IOException {
231 return new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + filename)));