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.assertNull;
28 import java.io.IOException;
29 import java.nio.file.Files;
30 import java.nio.file.Paths;
31 import java.util.HashMap;
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.junit.runner.RunWith;
37 import org.mockito.InjectMocks;
38 import org.mockito.Spy;
39 import org.mockito.junit.MockitoJUnitRunner;
40 import org.onap.sdnc.northbound.client.model.GenericResourceApiNetworkOperationInformation;
41 import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestActionEnumeration;
42 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
43 import org.onap.so.bpmn.servicedecomposition.bbobjects.Collection;
44 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
45 import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup;
46 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
47 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
48 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceSubscription;
49 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
50 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoNetwork;
51 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance;
52 import org.onap.so.client.sdnc.beans.SDNCSvcAction;
53 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");
113 network = new L3Network();
114 network.setNetworkId("TEST_NETWORK_ID");
115 network.setNetworkName("TEST_NETWORK_NAME");
116 ModelInfoNetwork modelInfoNetwork = new ModelInfoNetwork();
117 modelInfoNetwork.setModelInvariantUUID("modelInvariantUuid");
118 modelInfoNetwork.setModelName("modelName");
119 modelInfoNetwork.setModelVersion("modelVersion");
120 modelInfoNetwork.setModelUUID("modelUuid");
121 modelInfoNetwork.setModelCustomizationUUID("modelCustomizationUUID");
122 network.setModelInfoNetwork(modelInfoNetwork);
124 cloudRegion = new CloudRegion();
128 public void createGenericResourceApiNetworkOperationInformationTest() throws Exception {
130 GenericResourceApiNetworkOperationInformation networkSDNCrequest = mapper.reqMapper(
131 SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network, serviceInstance, customer,
132 requestContext, cloudRegion);
134 ObjectMapper omapper = new ObjectMapper();
135 GenericResourceApiNetworkOperationInformation reqMapper1 = omapper.readValue(
136 getJson("genericResourceApiNetworkOperationInformation.json"),
137 GenericResourceApiNetworkOperationInformation.class);
139 assertThat(networkSDNCrequest, sameBeanAs(reqMapper1).ignoring("sdncRequestHeader.svcRequestId")
140 .ignoring("requestInformation.requestId"));
144 public void reqMapperTest() throws Exception {
146 GenericResourceApiNetworkOperationInformation networkSDNCrequest = mapper.reqMapper(
147 SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network, serviceInstance, customer,
148 requestContext, cloudRegion);
150 assertNull(networkSDNCrequest.getServiceInformation().getOnapModelInformation().getModelCustomizationUuid());
151 assertEquals("modelCustomizationUUID", networkSDNCrequest.getNetworkInformation().getOnapModelInformation().getModelCustomizationUuid());
155 public void reqMapperNoCollectionTest() throws Exception {
156 GenericResourceApiNetworkOperationInformation networkSDNCrequest = mapper.reqMapper(
157 SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network, serviceInstanceNoCollection, customer,
158 requestContext, cloudRegion);
160 assertNull(networkSDNCrequest.getServiceInformation().getOnapModelInformation().getModelCustomizationUuid());
161 assertEquals("modelCustomizationUUID", networkSDNCrequest.getNetworkInformation().getOnapModelInformation().getModelCustomizationUuid());
164 public void createGenericResourceApiNetworkOperationInformation_UnassignTest() throws Exception {
166 NetworkTopologyOperationRequestMapper mapperUnassign = mapper;
167 GenericResourceApiNetworkOperationInformation networkSDNCrequestUnassign = mapperUnassign.reqMapper(
168 SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.UNASSIGN, GenericResourceApiRequestActionEnumeration.DELETENETWORKINSTANCE, network, serviceInstance, customer,
169 requestContext, cloudRegion);
171 ObjectMapper omapperUnassign = new ObjectMapper();
172 GenericResourceApiNetworkOperationInformation reqMapperUnassign = omapperUnassign.readValue(
173 getJson("genericResourceApiNetworkOperationInformationUnAssign.json"),
174 GenericResourceApiNetworkOperationInformation.class);
176 assertThat(reqMapperUnassign, sameBeanAs(networkSDNCrequestUnassign).ignoring("sdncRequestHeader.svcRequestId")
177 .ignoring("requestInformation.requestId"));
182 public void createGenericResourceApiNetworkOperationInformationNoNetworkNameTest() throws Exception {
184 //set network name NULL
185 network.setNetworkName(null);
186 GenericResourceApiNetworkOperationInformation networkSDNCrequest = mapper.reqMapper(
187 SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network, serviceInstance, customer,
188 requestContext, cloudRegion);
190 ObjectMapper omapper = new ObjectMapper();
191 GenericResourceApiNetworkOperationInformation reqMapper1 = omapper.readValue(
192 getJson("genericResourceApiNetworkOperationInformationNoNetworkName.json"),
193 GenericResourceApiNetworkOperationInformation.class);
195 assertThat(reqMapper1, sameBeanAs(networkSDNCrequest).ignoring("sdncRequestHeader.svcRequestId")
196 .ignoring("requestInformation.requestId"));
200 * Helper method to load JSON data
202 private String getJson(String filename) throws IOException {
203 return new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + filename)));