Containerization feature of SO
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / client / sdnc / mapper / NetworkTopologyOperationRequestMapperTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.so.client.sdnc.mapper;
22
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;
27
28 import java.io.IOException;
29 import java.nio.file.Files;
30 import java.nio.file.Paths;
31 import java.util.HashMap;
32
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
36 import org.onap.so.bpmn.servicedecomposition.bbobjects.Collection;
37 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
38 import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup;
39 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
40 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
41 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceSubscription;
42 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
43 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoNetwork;
44 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance;
45 import org.onap.so.client.sdnc.beans.SDNCSvcAction;
46 import org.onap.so.client.sdnc.beans.SDNCSvcOperation;
47
48 import org.onap.sdnc.apps.client.model.GenericResourceApiNetworkOperationInformation;
49 import org.onap.sdnc.apps.client.model.GenericResourceApiRequestActionEnumeration;
50 import com.fasterxml.jackson.databind.ObjectMapper;
51
52 public class NetworkTopologyOperationRequestMapperTest {
53
54         private final static String JSON_FILE_LOCATION = "src/test/resources/__files/BuildingBlocks/";
55
56         private ServiceInstance serviceInstance;
57         private ServiceInstance serviceInstanceNoCollection;
58         private Customer customer;
59         private RequestContext requestContext;
60         private L3Network network;
61         private CloudRegion cloudRegion;
62
63         @Before
64         public void before() {
65                 // prepare and set service instance
66                 serviceInstance = new ServiceInstance();
67                 serviceInstanceNoCollection = new ServiceInstance();
68                 ModelInfoServiceInstance modelInfoServiceInstance = new ModelInfoServiceInstance();
69                 modelInfoServiceInstance.setModelInvariantUuid("modelInvariantUuid");
70                 modelInfoServiceInstance.setModelName("modelName");
71                 modelInfoServiceInstance.setModelUuid("modelUuid");
72                 modelInfoServiceInstance.setModelVersion("modelVersion");
73                 serviceInstance.setModelInfoServiceInstance(modelInfoServiceInstance);
74                 serviceInstanceNoCollection.setModelInfoServiceInstance(modelInfoServiceInstance);
75                 // prepare Customer object
76                 customer = new Customer();
77                 customer.setGlobalCustomerId("globalCustomerId");
78                 //serviceInstance.setCustomer(customer);
79                 // set Customer on service instance
80                 ServiceSubscription serviceSubscription = new ServiceSubscription();
81                 serviceSubscription.setServiceType("productFamilyId");
82                 customer.setServiceSubscription(serviceSubscription);
83
84                 // set Customer on service instance
85                 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
86                 customer.getServiceSubscription().getServiceInstances().add(serviceInstanceNoCollection);
87                 //
88                 InstanceGroup networkInstanceGroup = new InstanceGroup();
89                 networkInstanceGroup.setId("networkInstanceGroupId");
90                 networkInstanceGroup.setInstanceGroupFunction("instanceGroupFunction");
91                 Collection networkCollection = new Collection();
92                 networkCollection.setInstanceGroup(networkInstanceGroup);
93                 serviceInstance.setCollection(networkCollection);
94                 //
95                 requestContext = new RequestContext();
96                 HashMap<String, String> userParams = new HashMap<String, String>();
97                 userParams.put("key1", "value1");
98                 requestContext.setUserParams(userParams);
99                 requestContext.setProductFamilyId("productFamilyId");
100
101                 network = new L3Network();
102                 network.setNetworkId("TEST_NETWORK_ID");
103                 network.setNetworkName("TEST_NETWORK_NAME");
104                 ModelInfoNetwork modelInfoNetwork = new ModelInfoNetwork();
105                 modelInfoNetwork.setModelInvariantUUID("modelInvariantUuid");
106                 modelInfoNetwork.setModelName("modelName");
107                 modelInfoNetwork.setModelVersion("modelVersion");
108                 modelInfoNetwork.setModelUUID("modelUuid");
109                 modelInfoNetwork.setModelCustomizationUUID("modelCustomizationUUID");
110                 network.setModelInfoNetwork(modelInfoNetwork);
111
112                 cloudRegion = new CloudRegion();
113         }
114
115         @Test
116         public void createGenericResourceApiNetworkOperationInformationTest() throws Exception {
117
118                 NetworkTopologyOperationRequestMapper mapper = new NetworkTopologyOperationRequestMapper();
119                 GenericResourceApiNetworkOperationInformation networkSDNCrequest = mapper.reqMapper(
120                                 SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network, serviceInstance, customer,
121                                 requestContext, cloudRegion);
122
123                 ObjectMapper omapper = new ObjectMapper();
124                 GenericResourceApiNetworkOperationInformation reqMapper1 = omapper.readValue(
125                                 getJson("genericResourceApiNetworkOperationInformation.json"),
126                                 GenericResourceApiNetworkOperationInformation.class);
127
128                 assertThat(networkSDNCrequest, sameBeanAs(reqMapper1).ignoring("sdncRequestHeader.svcRequestId")
129                                 .ignoring("requestInformation.requestId"));
130         }
131
132         @Test
133         public void reqMapperTest() throws Exception {
134
135                 NetworkTopologyOperationRequestMapper mapper = new NetworkTopologyOperationRequestMapper();
136                 GenericResourceApiNetworkOperationInformation networkSDNCrequest = mapper.reqMapper(
137                                 SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network, serviceInstance, customer,
138                                 requestContext, cloudRegion);
139
140                 assertNull(networkSDNCrequest.getServiceInformation().getOnapModelInformation().getModelCustomizationUuid());
141                 assertEquals("modelCustomizationUUID", networkSDNCrequest.getNetworkInformation().getOnapModelInformation().getModelCustomizationUuid());
142         }
143
144         @Test
145         public void reqMapperNoCollectionTest() throws Exception {
146                 NetworkTopologyOperationRequestMapper mapper = new NetworkTopologyOperationRequestMapper();
147                 GenericResourceApiNetworkOperationInformation networkSDNCrequest = mapper.reqMapper(
148                                 SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network, serviceInstanceNoCollection, customer,
149                                 requestContext, cloudRegion);
150
151                 assertNull(networkSDNCrequest.getServiceInformation().getOnapModelInformation().getModelCustomizationUuid());
152                 assertEquals("modelCustomizationUUID", networkSDNCrequest.getNetworkInformation().getOnapModelInformation().getModelCustomizationUuid());
153         }
154         @Test
155         public void createGenericResourceApiNetworkOperationInformation_UnassignTest() throws Exception {
156
157                 NetworkTopologyOperationRequestMapper mapperUnassign = new NetworkTopologyOperationRequestMapper();
158                 GenericResourceApiNetworkOperationInformation networkSDNCrequestUnassign = mapperUnassign.reqMapper(
159                                 SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.UNASSIGN, GenericResourceApiRequestActionEnumeration.DELETENETWORKINSTANCE, network, serviceInstance, customer,
160                                 requestContext, cloudRegion);
161
162                 ObjectMapper omapperUnassign = new ObjectMapper();
163                 GenericResourceApiNetworkOperationInformation reqMapperUnassign = omapperUnassign.readValue(
164                                 getJson("genericResourceApiNetworkOperationInformationUnAssign.json"),
165                                 GenericResourceApiNetworkOperationInformation.class);
166
167                 assertThat(reqMapperUnassign, sameBeanAs(networkSDNCrequestUnassign).ignoring("sdncRequestHeader.svcRequestId")
168                                 .ignoring("requestInformation.requestId"));
169
170         }
171         
172         @Test
173         public void createGenericResourceApiNetworkOperationInformationNoNetworkNameTest() throws Exception {
174
175                 NetworkTopologyOperationRequestMapper mapper = new NetworkTopologyOperationRequestMapper();
176                 //set network name NULL
177                 network.setNetworkName(null);
178                 GenericResourceApiNetworkOperationInformation networkSDNCrequest = mapper.reqMapper(
179                                 SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network, serviceInstance, customer,
180                                 requestContext, cloudRegion);
181
182                 ObjectMapper omapper = new ObjectMapper();
183                 GenericResourceApiNetworkOperationInformation reqMapper1 = omapper.readValue(
184                                 getJson("genericResourceApiNetworkOperationInformationNoNetworkName.json"),
185                                 GenericResourceApiNetworkOperationInformation.class);
186
187                 assertThat(reqMapper1, sameBeanAs(networkSDNCrequest).ignoring("sdncRequestHeader.svcRequestId")
188                                 .ignoring("requestInformation.requestId"));
189         }
190
191         /*
192          * Helper method to load JSON data
193          */
194         private String getJson(String filename) throws IOException {
195                 return new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + filename)));
196         }
197
198 }