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 {
45 public void testParseOrchestration() throws JsonParseException, JsonMappingException, IOException, ValidationException {
46 ObjectMapper mapper = new ObjectMapper();
47 String requestJSON = " {\"requestDetails\": {\"requestInfo\": { \"source\": \"VID\", \"requestorId\": \"zz9999\"}}}";
48 ServiceInstancesRequest sir = mapper.readValue(requestJSON, ServiceInstancesRequest.class);
49 MsoRequest msoRequest = new MsoRequest("1234");
50 msoRequest.parseOrchestration(sir);
51 assertEquals(msoRequest.getRequestInfo().getSource(), "VID");
52 assertEquals(msoRequest.getRequestInfo().getRequestorId(), "zz9999");
56 @Test(expected = ValidationException.class)
57 public void testParseOrchestrationFailure() throws JsonParseException, JsonMappingException, IOException, ValidationException {
58 ObjectMapper mapper = new ObjectMapper();
59 String requestJSON = " {\"requestDetails\": {\"requestInfo\": { \"source\": \"VID\"}}}";
60 ServiceInstancesRequest sir = mapper.readValue(requestJSON, ServiceInstancesRequest.class);
61 MsoRequest msoRequest = new MsoRequest("1234");
62 msoRequest.parseOrchestration(sir);
67 public void testParseV3VnfCreate() throws JsonParseException, JsonMappingException, IOException, ValidationException {
70 requestJSON = IOUtils.toString(ClassLoader.class.getResourceAsStream("/v3VnfCreate.json"));
72 } catch (IOException e) {
73 fail("Exception caught");
77 ObjectMapper mapper = new ObjectMapper();
78 HashMap<String, String> instanceIdMap = new HashMap<>();
79 instanceIdMap.put("serviceInstanceId", "3eecada1-83a4-4f33-9ed2-7937e7b8dbbc");
80 ServiceInstancesRequest sir = mapper.readValue(requestJSON, ServiceInstancesRequest.class);
81 MsoRequest msoRequest = new MsoRequest("1234");
82 msoRequest.parse(sir, instanceIdMap, Action.createInstance, "v3");
83 assertEquals(msoRequest.getRequestInfo().getSource(), "VID");
84 assertFalse(msoRequest.getALaCarteFlag());
85 assertEquals(msoRequest.getReqVersion(), 3);
86 boolean testIsALaCarteSet = msoRequest.getServiceInstancesRequest().getRequestDetails().getRequestParameters().isaLaCarteSet();
87 assertFalse(testIsALaCarteSet);
91 @Test(expected = ValidationException.class)
92 public void testParseV3VolumeGroupFail() throws JsonParseException, JsonMappingException, IOException, ValidationException {
95 requestJSON = IOUtils.toString(ClassLoader.class.getResourceAsStream("/v3VolumeGroupBad.json"));
97 } catch (IOException e) {
98 fail("Exception caught");
102 ObjectMapper mapper = new ObjectMapper();
103 HashMap<String, String> instanceIdMap = new HashMap<>();
104 instanceIdMap.put("serviceInstanceId", "3eecada1-83a4-4f33-9ed2-7937e7b8dbbc");
105 ServiceInstancesRequest sir = mapper.readValue(requestJSON, ServiceInstancesRequest.class);
106 MsoRequest msoRequest = new MsoRequest("1234");
107 msoRequest.parse(sir, instanceIdMap, Action.updateInstance, "v3");
112 public void testParseV3UpdateNetwork() throws JsonParseException, JsonMappingException, IOException, ValidationException {
115 requestJSON = IOUtils.toString(ClassLoader.class.getResourceAsStream("/v3UpdateNetwork.json"));
117 } catch (IOException e) {
118 fail("Exception caught");
122 ObjectMapper mapper = new ObjectMapper();
123 HashMap<String, String> instanceIdMap = new HashMap<>();
124 instanceIdMap.put("serviceInstanceId", "3eecada1-83a4-4f33-9ed2-7937e7b8dbbc");
125 ServiceInstancesRequest sir = mapper.readValue(requestJSON, ServiceInstancesRequest.class);
126 MsoRequest msoRequest = new MsoRequest("1234");
127 msoRequest.parse(sir, instanceIdMap, Action.updateInstance, "v3");
131 @Test(expected = ValidationException.class)
132 public void testParseV3UpdateNetworkFail() throws JsonParseException, JsonMappingException, IOException, ValidationException {
135 requestJSON = IOUtils.toString(ClassLoader.class.getResourceAsStream("/v3UpdateNetworkBad.json"));
137 } catch (IOException e) {
138 fail("Exception caught");
142 ObjectMapper mapper = new ObjectMapper();
143 HashMap<String, String> instanceIdMap = new HashMap<>();
144 instanceIdMap.put("serviceInstanceId", "3eecada1-83a4-4f33-9ed2-7937e7b8dbbc");
145 ServiceInstancesRequest sir = mapper.readValue(requestJSON, ServiceInstancesRequest.class);
146 MsoRequest msoRequest = new MsoRequest("1234");
147 msoRequest.parse(sir, instanceIdMap, Action.updateInstance, "v3");
152 public void testParseV3DeleteNetwork() throws JsonParseException, JsonMappingException, IOException, ValidationException {
155 requestJSON = IOUtils.toString(ClassLoader.class.getResourceAsStream("/v3DeleteNetwork.json"));
157 } catch (IOException e) {
158 fail("Exception caught");
162 ObjectMapper mapper = new ObjectMapper();
163 HashMap<String, String> instanceIdMap = new HashMap<>();
164 instanceIdMap.put("serviceInstanceId", "3eecada1-83a4-4f33-9ed2-7937e7b8dbbc");
165 ServiceInstancesRequest sir = mapper.readValue(requestJSON, ServiceInstancesRequest.class);
166 MsoRequest msoRequest = new MsoRequest("1234");
167 msoRequest.parse(sir, instanceIdMap, Action.deleteInstance, "v3");
171 public void testParseV3ServiceInstanceDelete() throws JsonParseException, JsonMappingException, IOException, ValidationException {
172 String requestJSON1, requestJSON2;
174 requestJSON1 = IOUtils.toString(ClassLoader.class.getResourceAsStream("/v3DeleteServiceInstance.json"));
175 requestJSON2 = IOUtils.toString(ClassLoader.class.getResourceAsStream("/v3DeleteServiceInstanceALaCarte.json"));
177 } catch (IOException e) {
178 fail("Exception caught");
182 ObjectMapper mapper = new ObjectMapper();
183 HashMap<String, String> instanceIdMap = new HashMap<>();
184 instanceIdMap.put("serviceInstanceId", "3eecada1-83a4-4f33-9ed2-7937e7b8dbbc");
185 ServiceInstancesRequest sir = mapper.readValue(requestJSON1, ServiceInstancesRequest.class);
186 MsoRequest msoRequest = new MsoRequest("1234");
187 msoRequest.parse(sir, instanceIdMap, Action.deleteInstance, "v3");
188 boolean testIsALaCarteSet = msoRequest.getServiceInstancesRequest().getRequestDetails().getRequestParameters().isaLaCarteSet();
189 assertTrue(testIsALaCarteSet);
190 assertFalse(msoRequest.getALaCarteFlag());
191 sir = mapper.readValue(requestJSON2, ServiceInstancesRequest.class);
192 msoRequest = new MsoRequest("12345");
193 msoRequest.parse(sir, instanceIdMap, Action.deleteInstance, "v3");
194 testIsALaCarteSet = msoRequest.getServiceInstancesRequest().getRequestDetails().getRequestParameters().isaLaCarteSet();
195 assertTrue(testIsALaCarteSet);
196 assertTrue(msoRequest.getALaCarteFlag());
200 @Test(expected = ValidationException.class)
201 public void testParseV3ServiceInstanceCreateFail() throws JsonParseException, JsonMappingException, IOException, ValidationException {
204 requestJSON2 = IOUtils.toString(ClassLoader.class.getResourceAsStream("/v3DeleteServiceInstanceALaCarte.json"));
206 } catch (IOException e) {
207 fail("Exception caught");
211 ObjectMapper mapper = new ObjectMapper();
212 HashMap<String, String> instanceIdMap = new HashMap<>();
213 instanceIdMap.put("serviceInstanceId", "3eecada1-83a4-4f33-9ed2-7937e7b8dbbc");
214 ServiceInstancesRequest sir = mapper.readValue(requestJSON2, ServiceInstancesRequest.class);
215 MsoRequest msoRequest = new MsoRequest("1234");
216 msoRequest.parse(sir, instanceIdMap, Action.createInstance, "v3");
220 @Test(expected = ValidationException.class)
221 public void testParseV3ServiceInstanceDeleteMacroFail() throws JsonParseException, JsonMappingException, IOException, ValidationException {
224 requestJSON = IOUtils.toString(ClassLoader.class.getResourceAsStream("/v3DeleteServiceInstanceBad.json"));
226 } catch (IOException e) {
227 fail("Exception caught");
231 ObjectMapper mapper = new ObjectMapper();
232 HashMap<String, String> instanceIdMap = new HashMap<>();
233 instanceIdMap.put("serviceInstanceId", "3eecada1-83a4-4f33-9ed2-7937e7b8dbbc");
234 ServiceInstancesRequest sir = mapper.readValue(requestJSON, ServiceInstancesRequest.class);
235 MsoRequest msoRequest = new MsoRequest("1234");
236 msoRequest.parse(sir, instanceIdMap, Action.deleteInstance, "v3");
241 public void testVfModuleV4UsePreLoad() throws JsonParseException, JsonMappingException, IOException, ValidationException {
244 requestJSON = IOUtils.toString(ClassLoader.class.getResourceAsStream("/v4CreateVfModule.json"));
246 } catch (IOException e) {
247 fail("Exception caught");
252 ObjectMapper mapper = new ObjectMapper();
253 HashMap<String, String> instanceIdMap = new HashMap<>();
254 instanceIdMap.put("serviceInstanceId", "3eecada1-83a4-4f33-9ed2-7937e7b8dbbc");
255 instanceIdMap.put("vnfInstanceId", "3eecada1-83a4-4f33-9ed2-7937e7b8dbbc");
256 ServiceInstancesRequest sir = mapper.readValue(requestJSON, ServiceInstancesRequest.class);
257 MsoRequest msoRequest = new MsoRequest("1234");
258 msoRequest.parse(sir, instanceIdMap, Action.createInstance, "v4");
262 requestJSON = IOUtils.toString(ClassLoader.class.getResourceAsStream("/v4CreateVfModuleNoCustomizationId.json"));
264 } catch (IOException e) {
265 fail("Exception caught");
270 mapper = new ObjectMapper();
271 instanceIdMap = new HashMap<>();
272 instanceIdMap.put("serviceInstanceId", "3eecada1-83a4-4f33-9ed2-7937e7b8dbbc");
273 instanceIdMap.put("vnfInstanceId", "3eecada1-83a4-4f33-9ed2-7937e7b8dbbc");
274 sir = mapper.readValue(requestJSON, ServiceInstancesRequest.class);
275 msoRequest = new MsoRequest("1234");
276 msoRequest.parse(sir, instanceIdMap, Action.createInstance, "v4");
279 @Test(expected = ValidationException.class)
280 public void testV4UsePreLoadMissingModelCustomizationId() throws JsonParseException, JsonMappingException, IOException, ValidationException {
283 requestJSON = IOUtils.toString(ClassLoader.class.getResourceAsStream("/v4CreateVfModuleMissingModelCustomizationId.json"));
285 } catch (IOException e) {
286 fail("Exception caught");
291 ObjectMapper mapper = new ObjectMapper();
292 HashMap<String, String> instanceIdMap = new HashMap<>();
293 instanceIdMap.put("serviceInstanceId", "3eecada1-83a4-4f33-9ed2-7937e7b8dbbc");
294 instanceIdMap.put("vnfInstanceId", "3eecada1-83a4-4f33-9ed2-7937e7b8dbbc");
295 ServiceInstancesRequest sir = mapper.readValue(requestJSON, ServiceInstancesRequest.class);
296 MsoRequest msoRequest = new MsoRequest("1234");
297 msoRequest.parse(sir, instanceIdMap, Action.createInstance, "v4");