vnf spin up gr api vnf s base module fails
[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 import java.util.Map;
33
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;
54
55 import com.fasterxml.jackson.databind.ObjectMapper;
56
57 @RunWith(MockitoJUnitRunner.class)
58 public class NetworkTopologyOperationRequestMapperTest {
59
60         private final static String JSON_FILE_LOCATION = "src/test/resources/__files/BuildingBlocks/";
61
62         private ServiceInstance serviceInstance;
63         private ServiceInstance serviceInstanceNoCollection;
64         private Customer customer;
65         private RequestContext requestContext;
66         private L3Network network;
67         private CloudRegion cloudRegion;
68         
69         @Spy
70         private GeneralTopologyObjectMapper generalTopologyObjectMapper;
71         
72         @InjectMocks
73         private NetworkTopologyOperationRequestMapper mapper = new NetworkTopologyOperationRequestMapper();
74
75         @Before
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);
95
96                 // set Customer on service instance
97                 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
98                 customer.getServiceSubscription().getServiceInstances().add(serviceInstanceNoCollection);
99                 //
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);
106                 //
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
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);
123
124                 cloudRegion = new CloudRegion();
125         }
126
127         @Test
128         public void createGenericResourceApiNetworkOperationInformationTest() throws Exception {
129
130                 GenericResourceApiNetworkOperationInformation networkSDNCrequest = mapper.reqMapper(
131                                 SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network, serviceInstance, customer,
132                                 requestContext, cloudRegion);
133
134                 ObjectMapper omapper = new ObjectMapper();
135                 GenericResourceApiNetworkOperationInformation reqMapper1 = omapper.readValue(
136                                 getJson("genericResourceApiNetworkOperationInformation.json"),
137                                 GenericResourceApiNetworkOperationInformation.class);
138
139                 assertThat(networkSDNCrequest, sameBeanAs(reqMapper1).ignoring("sdncRequestHeader.svcRequestId")
140                                 .ignoring("requestInformation.requestId"));
141         }
142
143         @Test
144         public void reqMapperTest() throws Exception {
145
146                 GenericResourceApiNetworkOperationInformation networkSDNCrequest = mapper.reqMapper(
147                                 SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network, serviceInstance, customer,
148                                 requestContext, cloudRegion);
149
150                 assertNull(networkSDNCrequest.getServiceInformation().getOnapModelInformation().getModelCustomizationUuid());
151                 assertEquals("modelCustomizationUUID", networkSDNCrequest.getNetworkInformation().getOnapModelInformation().getModelCustomizationUuid());
152         }
153
154         @Test
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);
159
160                 assertNull(networkSDNCrequest.getServiceInformation().getOnapModelInformation().getModelCustomizationUuid());
161                 assertEquals("modelCustomizationUUID", networkSDNCrequest.getNetworkInformation().getOnapModelInformation().getModelCustomizationUuid());
162         }
163         @Test
164         public void createGenericResourceApiNetworkOperationInformation_UnassignTest() throws Exception {
165
166                 NetworkTopologyOperationRequestMapper mapperUnassign = mapper;
167                 GenericResourceApiNetworkOperationInformation networkSDNCrequestUnassign = mapperUnassign.reqMapper(
168                                 SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.UNASSIGN, GenericResourceApiRequestActionEnumeration.DELETENETWORKINSTANCE, network, serviceInstance, customer,
169                                 requestContext, cloudRegion);
170
171                 ObjectMapper omapperUnassign = new ObjectMapper();
172                 GenericResourceApiNetworkOperationInformation reqMapperUnassign = omapperUnassign.readValue(
173                                 getJson("genericResourceApiNetworkOperationInformationUnAssign.json"),
174                                 GenericResourceApiNetworkOperationInformation.class);
175
176                 assertThat(reqMapperUnassign, sameBeanAs(networkSDNCrequestUnassign).ignoring("sdncRequestHeader.svcRequestId")
177                                 .ignoring("requestInformation.requestId"));
178
179         }
180         
181         @Test
182         public void createGenericResourceApiNetworkOperationInformationNoNetworkNameTest() throws Exception {
183
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);
189
190                 ObjectMapper omapper = new ObjectMapper();
191                 GenericResourceApiNetworkOperationInformation reqMapper1 = omapper.readValue(
192                                 getJson("genericResourceApiNetworkOperationInformationNoNetworkName.json"),
193                                 GenericResourceApiNetworkOperationInformation.class);
194
195                 assertThat(reqMapper1, sameBeanAs(networkSDNCrequest).ignoring("sdncRequestHeader.svcRequestId")
196                                 .ignoring("requestInformation.requestId"));
197         }
198
199         /*
200          * Helper method to load JSON data
201          */
202         private String getJson(String filename) throws IOException {
203                 return new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + filename)));
204         }
205
206 }