3fc5a16d9d3a3156e2b314319ecd9a55df0a9bb8
[so.git] /
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.apihandlerinfra.validation;
22
23 import static org.junit.Assert.assertFalse;
24 import static org.junit.Assert.assertTrue;
25
26 import java.io.IOException;
27 import java.nio.file.Files;
28 import java.nio.file.Paths;
29 import java.util.HashMap;
30
31 import org.junit.Test;
32 import org.onap.so.apihandlerinfra.Action;
33 import org.onap.so.apihandlerinfra.BaseTest;
34 import org.onap.so.exceptions.ValidationException;
35 import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
36
37 import com.fasterxml.jackson.databind.ObjectMapper;
38
39 public class RequestParametersValidationTest extends BaseTest{
40
41         @Test
42         public void testVfModuleWithFalseALaCarte() throws IOException, ValidationException {
43                 String requestJson = new String(Files.readAllBytes(Paths.get("src/test/resources/MsoRequestTest/RequestParameters/VfModuleModelVersionId.json")));
44                 ObjectMapper mapper = new ObjectMapper();
45                 ServiceInstancesRequest sir  = mapper.readValue(requestJson, ServiceInstancesRequest.class);    
46                 sir.getRequestDetails().getRequestParameters().setUsePreload(null);
47                 ValidationInformation info = new ValidationInformation(sir, new HashMap<String, String>(), Action.createInstance, 
48                                                                                                                                 6, false, sir.getRequestDetails().getRequestParameters());
49                 info.setRequestScope("vfModule");
50                 sir.setServiceInstanceId("0fd90c0c-0e3a-46e2-abb5-4c4820d5985b");               
51                 RequestParametersValidation validation = new RequestParametersValidation();
52                 validation.validate(info);
53                 
54                 assertFalse(info.getReqParameters().getUsePreload());           
55         }
56         
57         @Test
58         public void testVfModuleWithTrueALaCarte() throws IOException, ValidationException {
59                 String requestJson = new String(Files.readAllBytes(Paths.get("src/test/resources/MsoRequestTest/RequestParameters/VfModuleRequestParametersIsALaCarte.json")));
60                 ObjectMapper mapper = new ObjectMapper();
61                 ServiceInstancesRequest sir  = mapper.readValue(requestJson, ServiceInstancesRequest.class);
62                 sir.getRequestDetails().getRequestParameters().setUsePreload(null);
63                 ValidationInformation info = new ValidationInformation(sir, new HashMap<String, String>(), Action.createInstance, 
64                                                                                                                                 6, true, sir.getRequestDetails().getRequestParameters());
65                 info.setRequestScope("vfModule");
66                 sir.setServiceInstanceId("0fd90c0c-0e3a-46e2-abb5-4c4820d5985b");               
67                 RequestParametersValidation validation = new RequestParametersValidation();
68                 validation.validate(info);
69                 
70                 assertTrue(info.getReqParameters().getUsePreload());
71         }
72         
73         @Test
74         public void testVfModuleWithReqVersionBelow4() throws IOException, ValidationException {
75                 String requestJson = new String(Files.readAllBytes(Paths.get("src/test/resources/MsoRequestTest/RequestParameters/VfModuleModelVersionId.json")));
76                 ObjectMapper mapper = new ObjectMapper();
77                 ServiceInstancesRequest sir  = mapper.readValue(requestJson, ServiceInstancesRequest.class);            
78                 sir.getRequestDetails().getRequestParameters().setUsePreload(null);
79                 ValidationInformation info = new ValidationInformation(sir, new HashMap<String, String>(), Action.createInstance, 
80                                                                                                                                 3, false, sir.getRequestDetails().getRequestParameters());
81                 info.setRequestScope("vfModule");
82                 sir.setServiceInstanceId("0fd90c0c-0e3a-46e2-abb5-4c4820d5985b");               
83                 RequestParametersValidation validation = new RequestParametersValidation();
84                 validation.validate(info);
85                 
86                 assertTrue(info.getReqParameters().getUsePreload());
87         }
88 }