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=========================================================
20 package org.openecomp.mso.apihandlerinfra;
22 import org.apache.commons.io.IOUtils;
23 import org.codehaus.jackson.JsonParseException;
24 import org.codehaus.jackson.map.JsonMappingException;
25 import org.codehaus.jackson.map.ObjectMapper;
26 import org.junit.Test;
28 import static org.junit.Assert.assertEquals;
31 import static org.junit.Assert.assertFalse;
32 import static org.junit.Assert.assertTrue;
33 import static org.junit.Assert.fail;
35 import java.io.IOException;
36 import java.util.HashMap;
38 import org.openecomp.mso.apihandler.common.ValidationException;
39 import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.ServiceInstancesRequest;
41 public class MsoRequestTest {
46 public void testParseOrchestration() throws JsonParseException, JsonMappingException, IOException, ValidationException{
47 ObjectMapper mapper = new ObjectMapper();
48 String requestJSON = " {\"requestDetails\": {\"requestInfo\": { \"source\": \"VID\", \"requestorId\": \"zz9999\"}}}";
49 ServiceInstancesRequest sir = mapper.readValue(requestJSON, ServiceInstancesRequest.class);
50 MsoRequest msoRequest = new MsoRequest ("1234");
51 msoRequest.parseOrchestration(sir);
52 assertEquals(msoRequest.getRequestInfo().getSource(),"VID");
53 assertEquals(msoRequest.getRequestInfo().getRequestorId(),"zz9999");
57 @Test(expected = ValidationException.class)
58 public void testParseOrchestrationFailure() throws JsonParseException, JsonMappingException, IOException, ValidationException{
59 ObjectMapper mapper = new ObjectMapper();
60 String requestJSON = " {\"requestDetails\": {\"requestInfo\": { \"source\": \"VID\"}}}";
61 ServiceInstancesRequest sir = mapper.readValue(requestJSON, ServiceInstancesRequest.class);
62 MsoRequest msoRequest = new MsoRequest ("1234");
63 msoRequest.parseOrchestration(sir);
68 public void testParseV3VnfCreate() throws JsonParseException, JsonMappingException, IOException, ValidationException{
71 requestJSON = IOUtils.toString (ClassLoader.class.getResourceAsStream ("/v3VnfCreate.json"));
73 } catch (IOException e) {
74 fail ("Exception caught");
78 ObjectMapper mapper = new ObjectMapper();
79 HashMap<String, String> instanceIdMap = new HashMap<String,String>();
80 instanceIdMap.put("serviceInstanceId", "3eecada1-83a4-4f33-9ed2-7937e7b8dbbc");
81 ServiceInstancesRequest sir = mapper.readValue(requestJSON, ServiceInstancesRequest.class);
82 MsoRequest msoRequest = new MsoRequest ("1234");
83 msoRequest.parse(sir, instanceIdMap, Action.createInstance, "v3");
84 assertEquals(msoRequest.getRequestInfo().getSource(),"VID");
85 assertFalse(msoRequest.getALaCarteFlag());
86 assertEquals(msoRequest.getReqVersion(),3);
87 boolean testIsALaCarteSet = msoRequest.getServiceInstancesRequest().getRequestDetails().getRequestParameters().isALaCarteSet();
88 assertFalse(testIsALaCarteSet);
92 @Test(expected = ValidationException.class)
93 public void testParseV3VolumeGroupFail() throws JsonParseException, JsonMappingException, IOException, ValidationException{
96 requestJSON = IOUtils.toString (ClassLoader.class.getResourceAsStream ("/v3VolumeGroupBad.json"));
98 } catch (IOException e) {
99 fail ("Exception caught");
100 e.printStackTrace ();
103 ObjectMapper mapper = new ObjectMapper();
104 HashMap<String, String> instanceIdMap = new HashMap<String,String>();
105 instanceIdMap.put("serviceInstanceId", "3eecada1-83a4-4f33-9ed2-7937e7b8dbbc");
106 ServiceInstancesRequest sir = mapper.readValue(requestJSON, ServiceInstancesRequest.class);
107 MsoRequest msoRequest = new MsoRequest ("1234");
108 msoRequest.parse(sir, instanceIdMap, Action.updateInstance, "v3");
113 public void testParseV3UpdateNetwork() throws JsonParseException, JsonMappingException, IOException, ValidationException{
116 requestJSON = IOUtils.toString (ClassLoader.class.getResourceAsStream ("/v3UpdateNetwork.json"));
118 } catch (IOException e) {
119 fail ("Exception caught");
120 e.printStackTrace ();
123 ObjectMapper mapper = new ObjectMapper();
124 HashMap<String, String> instanceIdMap = new HashMap<String,String>();
125 instanceIdMap.put("serviceInstanceId", "3eecada1-83a4-4f33-9ed2-7937e7b8dbbc");
126 ServiceInstancesRequest sir = mapper.readValue(requestJSON, ServiceInstancesRequest.class);
127 MsoRequest msoRequest = new MsoRequest ("1234");
128 msoRequest.parse(sir, instanceIdMap, Action.updateInstance, "v3");
132 @Test(expected = ValidationException.class)
133 public void testParseV3UpdateNetworkFail() throws JsonParseException, JsonMappingException, IOException, ValidationException{
136 requestJSON = IOUtils.toString (ClassLoader.class.getResourceAsStream ("/v3UpdateNetworkBad.json"));
138 } catch (IOException e) {
139 fail ("Exception caught");
140 e.printStackTrace ();
143 ObjectMapper mapper = new ObjectMapper();
144 HashMap<String, String> instanceIdMap = new HashMap<String,String>();
145 instanceIdMap.put("serviceInstanceId", "3eecada1-83a4-4f33-9ed2-7937e7b8dbbc");
146 ServiceInstancesRequest sir = mapper.readValue(requestJSON, ServiceInstancesRequest.class);
147 MsoRequest msoRequest = new MsoRequest ("1234");
148 msoRequest.parse(sir, instanceIdMap, Action.updateInstance, "v3");
153 public void testParseV3DeleteNetwork() throws JsonParseException, JsonMappingException, IOException, ValidationException{
156 requestJSON = IOUtils.toString (ClassLoader.class.getResourceAsStream ("/v3DeleteNetwork.json"));
158 } catch (IOException e) {
159 fail ("Exception caught");
160 e.printStackTrace ();
163 ObjectMapper mapper = new ObjectMapper();
164 HashMap<String, String> instanceIdMap = new HashMap<String,String>();
165 instanceIdMap.put("serviceInstanceId", "3eecada1-83a4-4f33-9ed2-7937e7b8dbbc");
166 ServiceInstancesRequest sir = mapper.readValue(requestJSON, ServiceInstancesRequest.class);
167 MsoRequest msoRequest = new MsoRequest ("1234");
168 msoRequest.parse(sir, instanceIdMap, Action.deleteInstance, "v3");
172 public void testParseV3ServiceInstanceDelete() throws JsonParseException, JsonMappingException, IOException, ValidationException{
173 String requestJSON1, requestJSON2;
175 requestJSON1 = IOUtils.toString (ClassLoader.class.getResourceAsStream ("/v3DeleteServiceInstance.json"));
176 requestJSON2 = IOUtils.toString (ClassLoader.class.getResourceAsStream ("/v3DeleteServiceInstanceALaCarte.json"));
178 } catch (IOException e) {
179 fail ("Exception caught");
180 e.printStackTrace ();
183 ObjectMapper mapper = new ObjectMapper();
184 HashMap<String, String> instanceIdMap = new HashMap<String,String>();
185 instanceIdMap.put("serviceInstanceId", "3eecada1-83a4-4f33-9ed2-7937e7b8dbbc");
186 ServiceInstancesRequest sir = mapper.readValue(requestJSON1, ServiceInstancesRequest.class);
187 MsoRequest msoRequest = new MsoRequest ("1234");
188 msoRequest.parse(sir, instanceIdMap, Action.deleteInstance, "v3");
189 boolean testIsALaCarteSet = msoRequest.getServiceInstancesRequest().getRequestDetails().getRequestParameters().isALaCarteSet();
190 assertTrue(testIsALaCarteSet);
191 assertFalse(msoRequest.getALaCarteFlag());
192 sir = mapper.readValue(requestJSON2, ServiceInstancesRequest.class);
193 msoRequest = new MsoRequest ("12345");
194 msoRequest.parse(sir, instanceIdMap, Action.deleteInstance, "v3");
195 testIsALaCarteSet = msoRequest.getServiceInstancesRequest().getRequestDetails().getRequestParameters().isALaCarteSet();
196 assertTrue(testIsALaCarteSet);
197 assertTrue(msoRequest.getALaCarteFlag());
201 @Test(expected = ValidationException.class)
202 public void testParseV3ServiceInstanceCreateFail() throws JsonParseException, JsonMappingException, IOException, ValidationException{
205 requestJSON2 = IOUtils.toString (ClassLoader.class.getResourceAsStream ("/v3DeleteServiceInstanceALaCarte.json"));
207 } catch (IOException e) {
208 fail ("Exception caught");
209 e.printStackTrace ();
212 ObjectMapper mapper = new ObjectMapper();
213 HashMap<String, String> instanceIdMap = new HashMap<String,String>();
214 instanceIdMap.put("serviceInstanceId", "3eecada1-83a4-4f33-9ed2-7937e7b8dbbc");
215 ServiceInstancesRequest sir = mapper.readValue(requestJSON2, ServiceInstancesRequest.class);
216 MsoRequest msoRequest = new MsoRequest ("1234");
217 msoRequest.parse(sir, instanceIdMap, Action.createInstance, "v3");
221 @Test(expected = ValidationException.class)
222 public void testParseV3ServiceInstanceDeleteMacroFail() throws JsonParseException, JsonMappingException, IOException, ValidationException{
225 requestJSON = IOUtils.toString (ClassLoader.class.getResourceAsStream ("/v3DeleteServiceInstanceBad.json"));
227 } catch (IOException e) {
228 fail ("Exception caught");
229 e.printStackTrace ();
232 ObjectMapper mapper = new ObjectMapper();
233 HashMap<String, String> instanceIdMap = new HashMap<String,String>();
234 instanceIdMap.put("serviceInstanceId", "3eecada1-83a4-4f33-9ed2-7937e7b8dbbc");
235 ServiceInstancesRequest sir = mapper.readValue(requestJSON, ServiceInstancesRequest.class);
236 MsoRequest msoRequest = new MsoRequest ("1234");
237 msoRequest.parse(sir, instanceIdMap, Action.deleteInstance, "v3");
242 public void testVfModuleV4UsePreLoad() throws JsonParseException, JsonMappingException, IOException, ValidationException {
245 requestJSON = IOUtils.toString (ClassLoader.class.getResourceAsStream ("/v4CreateVfModule.json"));
247 } catch (IOException e) {
248 fail ("Exception caught");
249 e.printStackTrace ();
253 ObjectMapper mapper = new ObjectMapper();
254 HashMap<String, String> instanceIdMap = new HashMap<String,String>();
255 instanceIdMap.put("serviceInstanceId", "3eecada1-83a4-4f33-9ed2-7937e7b8dbbc");
256 instanceIdMap.put("vnfInstanceId", "3eecada1-83a4-4f33-9ed2-7937e7b8dbbc");
257 ServiceInstancesRequest sir = mapper.readValue(requestJSON, ServiceInstancesRequest.class);
258 MsoRequest msoRequest = new MsoRequest ("1234");
259 msoRequest.parse(sir, instanceIdMap, Action.createInstance, "v4");
264 requestJSON = IOUtils.toString (ClassLoader.class.getResourceAsStream ("/v4CreateVfModuleNoCustomizationId.json"));
266 } catch (IOException e) {
267 fail ("Exception caught");
268 e.printStackTrace ();
272 mapper = new ObjectMapper();
273 instanceIdMap = new HashMap<String,String>();
274 instanceIdMap.put("serviceInstanceId", "3eecada1-83a4-4f33-9ed2-7937e7b8dbbc");
275 instanceIdMap.put("vnfInstanceId", "3eecada1-83a4-4f33-9ed2-7937e7b8dbbc");
276 sir = mapper.readValue(requestJSON, ServiceInstancesRequest.class);
277 msoRequest = new MsoRequest ("1234");
278 msoRequest.parse(sir, instanceIdMap, Action.createInstance, "v4");
281 @Test(expected = ValidationException.class)
282 public void testV4UsePreLoadMissingModelCustomizationId() throws JsonParseException, JsonMappingException, IOException, ValidationException {
285 requestJSON = IOUtils.toString (ClassLoader.class.getResourceAsStream ("/v4CreateVfModuleMissingModelCustomizationId.json"));
287 } catch (IOException e) {
288 fail ("Exception caught");
289 e.printStackTrace ();
293 ObjectMapper mapper = new ObjectMapper();
294 HashMap<String, String> instanceIdMap = new HashMap<String,String>();
295 instanceIdMap.put("serviceInstanceId", "3eecada1-83a4-4f33-9ed2-7937e7b8dbbc");
296 instanceIdMap.put("vnfInstanceId", "3eecada1-83a4-4f33-9ed2-7937e7b8dbbc");
297 ServiceInstancesRequest sir = mapper.readValue(requestJSON, ServiceInstancesRequest.class);
298 MsoRequest msoRequest = new MsoRequest ("1234");
299 msoRequest.parse(sir, instanceIdMap, Action.createInstance, "v4");