dde7ecf20b3cb4b0682b73c29ef3dc586babbbf8
[so.git] / mso-api-handlers / mso-api-handler-infra / src / test / java / org / openecomp / mso / apihandlerinfra / MsoRequestTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * OPENECOMP - MSO
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 package org.openecomp.mso.apihandlerinfra;
21
22 import org.openecomp.mso.apihandler.common.ValidationException;
23 import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.ServiceInstancesRequest;
24 import org.apache.commons.io.IOUtils;
25 import org.codehaus.jackson.JsonParseException;
26 import org.codehaus.jackson.map.JsonMappingException;
27 import org.codehaus.jackson.map.ObjectMapper;
28 import org.junit.Test;
29
30 import java.io.IOException;
31 import java.util.HashMap;
32
33 import static org.junit.Assert.*;
34
35 public class MsoRequestTest {
36
37
38
39         @Test
40         public void testParseOrchestration() throws JsonParseException, JsonMappingException, IOException, ValidationException{
41                         ObjectMapper mapper = new ObjectMapper();
42                         String requestJSON = " {\"requestDetails\": {\"requestInfo\": { \"source\": \"VID\", \"requestorId\": \"zz9999\"}}}";
43                         ServiceInstancesRequest sir  = mapper.readValue(requestJSON, ServiceInstancesRequest.class);
44                         MsoRequest msoRequest = new MsoRequest ("1234");
45                         msoRequest.parseOrchestration(sir);
46                         assertEquals(msoRequest.getRequestInfo().getSource(),"VID");
47                         assertEquals(msoRequest.getRequestInfo().getRequestorId(),"zz9999");
48
49         }
50
51         @Test(expected = ValidationException.class)
52         public void testParseOrchestrationFailure() throws JsonParseException, JsonMappingException, IOException, ValidationException{
53                         ObjectMapper mapper = new ObjectMapper();
54                         String requestJSON = " {\"requestDetails\": {\"requestInfo\": { \"source\": \"VID\"}}}";
55                         ServiceInstancesRequest sir  = mapper.readValue(requestJSON, ServiceInstancesRequest.class);
56                         MsoRequest msoRequest = new MsoRequest ("1234");
57                         msoRequest.parseOrchestration(sir);
58
59         }
60
61         @Test
62         public void testParseV3VnfCreate() throws JsonParseException, JsonMappingException, IOException, ValidationException{
63                 String requestJSON;
64                  try {
65                           requestJSON = IOUtils.toString (ClassLoader.class.getResourceAsStream ("/v3VnfCreate.json"));
66
67                 } catch (IOException e) {
68                     fail ("Exception caught");
69                     e.printStackTrace ();
70                     return;
71                 }
72                         ObjectMapper mapper = new ObjectMapper();
73                          HashMap<String, String> instanceIdMap = new HashMap<String,String>();
74                         instanceIdMap.put("serviceInstanceId", "3eecada1-83a4-4f33-9ed2-7937e7b8dbbc");
75                         ServiceInstancesRequest sir  = mapper.readValue(requestJSON, ServiceInstancesRequest.class);
76                         MsoRequest msoRequest = new MsoRequest ("1234");
77                         msoRequest.parse(sir, instanceIdMap, Action.createInstance, "v3");
78                         assertEquals(msoRequest.getRequestInfo().getSource(),"VID");
79                         assertFalse(msoRequest.getALaCarteFlag());
80                         assertEquals(msoRequest.getReqVersion(),3);
81                         boolean testIsALaCarteSet = msoRequest.getServiceInstancesRequest().getRequestDetails().getRequestParameters().isALaCarteSet();
82                         assertFalse(testIsALaCarteSet);
83
84         }
85
86         @Test(expected = ValidationException.class)
87         public void testParseV3VolumeGroupFail() throws JsonParseException, JsonMappingException, IOException, ValidationException{
88                 String requestJSON;
89                  try {
90                           requestJSON = IOUtils.toString (ClassLoader.class.getResourceAsStream ("/v3VolumeGroupBad.json"));
91
92                 } catch (IOException e) {
93                     fail ("Exception caught");
94                     e.printStackTrace ();
95                     return;
96                 }
97                         ObjectMapper mapper = new ObjectMapper();
98                          HashMap<String, String> instanceIdMap = new HashMap<String,String>();
99                         instanceIdMap.put("serviceInstanceId", "3eecada1-83a4-4f33-9ed2-7937e7b8dbbc");
100                         ServiceInstancesRequest sir  = mapper.readValue(requestJSON, ServiceInstancesRequest.class);
101                         MsoRequest msoRequest = new MsoRequest ("1234");
102                         msoRequest.parse(sir, instanceIdMap, Action.updateInstance, "v3");
103
104         }
105
106         @Test
107         public void testParseV3UpdateNetwork() throws JsonParseException, JsonMappingException, IOException, ValidationException{
108                 String requestJSON;
109                  try {
110                           requestJSON = IOUtils.toString (ClassLoader.class.getResourceAsStream ("/v3UpdateNetwork.json"));
111
112                 } catch (IOException e) {
113                     fail ("Exception caught");
114                     e.printStackTrace ();
115                     return;
116                 }
117                         ObjectMapper mapper = new ObjectMapper();
118                          HashMap<String, String> instanceIdMap = new HashMap<String,String>();
119                         instanceIdMap.put("serviceInstanceId", "3eecada1-83a4-4f33-9ed2-7937e7b8dbbc");
120                         ServiceInstancesRequest sir  = mapper.readValue(requestJSON, ServiceInstancesRequest.class);
121                         MsoRequest msoRequest = new MsoRequest ("1234");
122                         msoRequest.parse(sir, instanceIdMap, Action.updateInstance, "v3");
123
124         }
125
126         @Test(expected = ValidationException.class)
127         public void testParseV3UpdateNetworkFail() throws JsonParseException, JsonMappingException, IOException, ValidationException{
128                 String requestJSON;
129                  try {
130                           requestJSON = IOUtils.toString (ClassLoader.class.getResourceAsStream ("/v3UpdateNetworkBad.json"));
131
132                 } catch (IOException e) {
133                     fail ("Exception caught");
134                     e.printStackTrace ();
135                     return;
136                 }
137                         ObjectMapper mapper = new ObjectMapper();
138                          HashMap<String, String> instanceIdMap = new HashMap<String,String>();
139                         instanceIdMap.put("serviceInstanceId", "3eecada1-83a4-4f33-9ed2-7937e7b8dbbc");
140                         ServiceInstancesRequest sir  = mapper.readValue(requestJSON, ServiceInstancesRequest.class);
141                         MsoRequest msoRequest = new MsoRequest ("1234");
142                         msoRequest.parse(sir, instanceIdMap, Action.updateInstance, "v3");
143
144         }
145
146         @Test
147         public void testParseV3DeleteNetwork() throws JsonParseException, JsonMappingException, IOException, ValidationException{
148                 String requestJSON;
149                  try {
150                           requestJSON = IOUtils.toString (ClassLoader.class.getResourceAsStream ("/v3DeleteNetwork.json"));
151
152                 } catch (IOException e) {
153                     fail ("Exception caught");
154                     e.printStackTrace ();
155                     return;
156                 }
157                         ObjectMapper mapper = new ObjectMapper();
158                          HashMap<String, String> instanceIdMap = new HashMap<String,String>();
159                         instanceIdMap.put("serviceInstanceId", "3eecada1-83a4-4f33-9ed2-7937e7b8dbbc");
160                         ServiceInstancesRequest sir  = mapper.readValue(requestJSON, ServiceInstancesRequest.class);
161                         MsoRequest msoRequest = new MsoRequest ("1234");
162                         msoRequest.parse(sir, instanceIdMap, Action.deleteInstance, "v3");
163         }
164
165         @Test
166         public void testParseV3ServiceInstanceDelete() throws JsonParseException, JsonMappingException, IOException, ValidationException{
167                 String requestJSON1, requestJSON2;
168                  try {
169                           requestJSON1 = IOUtils.toString (ClassLoader.class.getResourceAsStream ("/v3DeleteServiceInstance.json"));
170                           requestJSON2 = IOUtils.toString (ClassLoader.class.getResourceAsStream ("/v3DeleteServiceInstanceALaCarte.json"));
171
172                 } catch (IOException e) {
173                     fail ("Exception caught");
174                     e.printStackTrace ();
175                     return;
176                 }
177                         ObjectMapper mapper = new ObjectMapper();
178                          HashMap<String, String> instanceIdMap = new HashMap<String,String>();
179                         instanceIdMap.put("serviceInstanceId", "3eecada1-83a4-4f33-9ed2-7937e7b8dbbc");
180                         ServiceInstancesRequest sir  = mapper.readValue(requestJSON1, ServiceInstancesRequest.class);
181                         MsoRequest msoRequest = new MsoRequest ("1234");
182                         msoRequest.parse(sir, instanceIdMap, Action.deleteInstance, "v3");
183                         boolean testIsALaCarteSet = msoRequest.getServiceInstancesRequest().getRequestDetails().getRequestParameters().isALaCarteSet();
184                         assertTrue(testIsALaCarteSet);
185                         assertFalse(msoRequest.getALaCarteFlag());
186                         sir  = mapper.readValue(requestJSON2, ServiceInstancesRequest.class);
187                         msoRequest = new MsoRequest ("12345");
188                         msoRequest.parse(sir, instanceIdMap, Action.deleteInstance, "v3");
189                         testIsALaCarteSet = msoRequest.getServiceInstancesRequest().getRequestDetails().getRequestParameters().isALaCarteSet();
190                         assertTrue(testIsALaCarteSet);
191                         assertTrue(msoRequest.getALaCarteFlag());
192
193         }
194
195         @Test(expected = ValidationException.class)
196         public void testParseV3ServiceInstanceCreateFail() throws JsonParseException, JsonMappingException, IOException, ValidationException{
197                 String requestJSON2;
198                  try {
199                           requestJSON2 = IOUtils.toString (ClassLoader.class.getResourceAsStream ("/v3DeleteServiceInstanceALaCarte.json"));
200
201                 } catch (IOException e) {
202                     fail ("Exception caught");
203                     e.printStackTrace ();
204                     return;
205                 }
206                         ObjectMapper mapper = new ObjectMapper();
207                          HashMap<String, String> instanceIdMap = new HashMap<String,String>();
208                         instanceIdMap.put("serviceInstanceId", "3eecada1-83a4-4f33-9ed2-7937e7b8dbbc");
209                         ServiceInstancesRequest sir  = mapper.readValue(requestJSON2, ServiceInstancesRequest.class);
210                         MsoRequest msoRequest = new MsoRequest ("1234");
211                         msoRequest.parse(sir, instanceIdMap, Action.createInstance, "v3");
212
213         }
214
215         @Test(expected = ValidationException.class)
216         public void testParseV3ServiceInstanceDeleteMacroFail() throws JsonParseException, JsonMappingException, IOException, ValidationException{
217                 String requestJSON;
218                  try {
219                           requestJSON = IOUtils.toString (ClassLoader.class.getResourceAsStream ("/v3DeleteServiceInstanceBad.json"));
220
221                 } catch (IOException e) {
222                     fail ("Exception caught");
223                     e.printStackTrace ();
224                     return;
225                 }
226                         ObjectMapper mapper = new ObjectMapper();
227                          HashMap<String, String> instanceIdMap = new HashMap<String,String>();
228                         instanceIdMap.put("serviceInstanceId", "3eecada1-83a4-4f33-9ed2-7937e7b8dbbc");
229                         ServiceInstancesRequest sir  = mapper.readValue(requestJSON, ServiceInstancesRequest.class);
230                         MsoRequest msoRequest = new MsoRequest ("1234");
231                         msoRequest.parse(sir, instanceIdMap, Action.deleteInstance, "v3");
232
233         }
234
235 }