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.client.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.servicedecomposition.bbobjects.CloudRegion;
42 import org.onap.so.bpmn.servicedecomposition.bbobjects.Collection;
43 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
44 import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup;
45 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
46 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
47 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceSubscription;
48 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
49 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoNetwork;
50 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance;
51 import org.onap.so.client.sdnc.beans.SDNCSvcAction;
52 import org.onap.so.client.sdnc.beans.SDNCSvcOperation;
53 import com.fasterxml.jackson.databind.ObjectMapper;
55 @RunWith(MockitoJUnitRunner.class)
56 public class NetworkTopologyOperationRequestMapperTest {
58 private final static String JSON_FILE_LOCATION = "src/test/resources/__files/BuildingBlocks/";
60 private ServiceInstance serviceInstance;
61 private ServiceInstance serviceInstanceNoCollection;
62 private Customer customer;
63 private RequestContext requestContext;
64 private L3Network network;
65 private CloudRegion cloudRegion;
68 private GeneralTopologyObjectMapper generalTopologyObjectMapper;
71 private NetworkTopologyOperationRequestMapper mapper = new NetworkTopologyOperationRequestMapper();
74 public void before() {
75 // prepare and set service instance
76 serviceInstance = new ServiceInstance();
77 serviceInstanceNoCollection = new ServiceInstance();
78 ModelInfoServiceInstance modelInfoServiceInstance = new ModelInfoServiceInstance();
79 modelInfoServiceInstance.setModelInvariantUuid("modelInvariantUuid");
80 modelInfoServiceInstance.setModelName("modelName");
81 modelInfoServiceInstance.setModelUuid("modelUuid");
82 modelInfoServiceInstance.setModelVersion("modelVersion");
83 serviceInstance.setModelInfoServiceInstance(modelInfoServiceInstance);
84 serviceInstanceNoCollection.setModelInfoServiceInstance(modelInfoServiceInstance);
85 // prepare Customer object
86 customer = new Customer();
87 customer.setGlobalCustomerId("globalCustomerId");
88 // serviceInstance.setCustomer(customer);
89 // set Customer on service instance
90 ServiceSubscription serviceSubscription = new ServiceSubscription();
91 serviceSubscription.setServiceType("productFamilyId");
92 customer.setServiceSubscription(serviceSubscription);
94 // set Customer on service instance
95 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
96 customer.getServiceSubscription().getServiceInstances().add(serviceInstanceNoCollection);
98 InstanceGroup networkInstanceGroup = new InstanceGroup();
99 networkInstanceGroup.setId("networkInstanceGroupId");
100 networkInstanceGroup.setInstanceGroupFunction("instanceGroupFunction");
101 Collection networkCollection = new Collection();
102 networkCollection.setInstanceGroup(networkInstanceGroup);
103 serviceInstance.setCollection(networkCollection);
105 requestContext = new RequestContext();
106 Map<String, Object> userParams = new HashMap<>();
107 userParams.put("key1", "value1");
108 requestContext.setUserParams(userParams);
109 requestContext.setProductFamilyId("productFamilyId");
110 requestContext.setMsoRequestId("MsoRequestId");
112 network = new L3Network();
113 network.setNetworkId("TEST_NETWORK_ID");
114 network.setNetworkName("TEST_NETWORK_NAME");
115 ModelInfoNetwork modelInfoNetwork = new ModelInfoNetwork();
116 modelInfoNetwork.setModelInvariantUUID("modelInvariantUuid");
117 modelInfoNetwork.setModelName("modelName");
118 modelInfoNetwork.setModelVersion("modelVersion");
119 modelInfoNetwork.setModelUUID("modelUuid");
120 modelInfoNetwork.setModelCustomizationUUID("modelCustomizationUUID");
121 network.setModelInfoNetwork(modelInfoNetwork);
123 cloudRegion = new CloudRegion();
127 public void createGenericResourceApiNetworkOperationInformationTest() throws Exception {
129 GenericResourceApiNetworkOperationInformation networkSDNCrequest =
130 mapper.reqMapper(SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN,
131 GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network, serviceInstance,
132 customer, requestContext, cloudRegion);
134 ObjectMapper omapper = new ObjectMapper();
135 GenericResourceApiNetworkOperationInformation reqMapper1 =
136 omapper.readValue(getJson("genericResourceApiNetworkOperationInformation.json"),
137 GenericResourceApiNetworkOperationInformation.class);
139 assertThat(networkSDNCrequest, sameBeanAs(reqMapper1).ignoring("sdncRequestHeader.svcRequestId")
140 .ignoring("requestInformation.requestId"));
141 assertEquals("MsoRequestId", networkSDNCrequest.getRequestInformation().getRequestId());
145 public void createGenericResourceApiNetworkOperationInformationReqContextNullTest() throws Exception {
147 RequestContext rc = new RequestContext();
148 rc.setMsoRequestId(null);
149 GenericResourceApiNetworkOperationInformation networkSDNCrequest =
150 mapper.reqMapper(SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN,
151 GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network, serviceInstance,
152 customer, rc, cloudRegion);
153 assertNotNull(networkSDNCrequest.getRequestInformation().getRequestId());
154 GenericResourceApiNetworkOperationInformation networkSDNCrequest2 =
155 mapper.reqMapper(SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN,
156 GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network, serviceInstance,
157 customer, null, cloudRegion);
158 assertNotNull(networkSDNCrequest2.getRequestInformation().getRequestId());
162 public void reqMapperTest() throws Exception {
164 GenericResourceApiNetworkOperationInformation networkSDNCrequest =
165 mapper.reqMapper(SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN,
166 GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network, serviceInstance,
167 customer, requestContext, cloudRegion);
169 assertNull(networkSDNCrequest.getServiceInformation().getOnapModelInformation().getModelCustomizationUuid());
170 assertEquals("modelCustomizationUUID",
171 networkSDNCrequest.getNetworkInformation().getOnapModelInformation().getModelCustomizationUuid());
175 public void reqMapperNoCollectionTest() throws Exception {
176 GenericResourceApiNetworkOperationInformation networkSDNCrequest =
177 mapper.reqMapper(SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN,
178 GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network,
179 serviceInstanceNoCollection, customer, requestContext, cloudRegion);
181 assertNull(networkSDNCrequest.getServiceInformation().getOnapModelInformation().getModelCustomizationUuid());
182 assertEquals("modelCustomizationUUID",
183 networkSDNCrequest.getNetworkInformation().getOnapModelInformation().getModelCustomizationUuid());
187 public void createGenericResourceApiNetworkOperationInformation_UnassignTest() throws Exception {
189 NetworkTopologyOperationRequestMapper mapperUnassign = mapper;
190 GenericResourceApiNetworkOperationInformation networkSDNCrequestUnassign =
191 mapperUnassign.reqMapper(SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.UNASSIGN,
192 GenericResourceApiRequestActionEnumeration.DELETENETWORKINSTANCE, network, serviceInstance,
193 customer, requestContext, cloudRegion);
195 ObjectMapper omapperUnassign = new ObjectMapper();
196 GenericResourceApiNetworkOperationInformation reqMapperUnassign =
197 omapperUnassign.readValue(getJson("genericResourceApiNetworkOperationInformationUnAssign.json"),
198 GenericResourceApiNetworkOperationInformation.class);
200 assertThat(reqMapperUnassign, sameBeanAs(networkSDNCrequestUnassign).ignoring("sdncRequestHeader.svcRequestId")
201 .ignoring("requestInformation.requestId"));
202 assertEquals("MsoRequestId", networkSDNCrequestUnassign.getRequestInformation().getRequestId());
207 public void createGenericResourceApiNetworkOperationInformationNoNetworkNameTest() throws Exception {
209 // set network name NULL
210 network.setNetworkName(null);
211 GenericResourceApiNetworkOperationInformation networkSDNCrequest =
212 mapper.reqMapper(SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN,
213 GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network, serviceInstance,
214 customer, requestContext, cloudRegion);
216 ObjectMapper omapper = new ObjectMapper();
217 GenericResourceApiNetworkOperationInformation reqMapper1 =
218 omapper.readValue(getJson("genericResourceApiNetworkOperationInformationNoNetworkName.json"),
219 GenericResourceApiNetworkOperationInformation.class);
221 assertThat(reqMapper1, sameBeanAs(networkSDNCrequest).ignoring("sdncRequestHeader.svcRequestId")
222 .ignoring("requestInformation.requestId"));
226 * Helper method to load JSON data
228 private String getJson(String filename) throws IOException {
229 return new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + filename)));