ensure data for si matches on macro requests
[so.git] / mso-api-handlers / mso-api-handler-infra / src / test / java / org / onap / so / apihandlerinfra / validation / UserParamsValidationTest.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.apihandlerinfra.validation;
22
23 import java.io.IOException;
24 import java.nio.file.Files;
25 import java.nio.file.Paths;
26 import java.util.Map;
27
28 import org.junit.Rule;
29 import org.junit.Test;
30 import org.junit.rules.ExpectedException;
31 import org.onap.so.apihandlerinfra.Action;
32 import org.onap.so.exceptions.ValidationException;
33 import org.onap.so.serviceinstancebeans.Service;
34 import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
35
36 import com.fasterxml.jackson.databind.ObjectMapper;
37
38 public class UserParamsValidationTest{
39         
40         UserParamsValidation validation = new UserParamsValidation();
41         
42         @Rule
43         public ExpectedException thrown = ExpectedException.none();
44         
45         public ValidationInformation setupValidationInformation(String path) throws IOException{
46                 String jsonInput = new String(Files.readAllBytes(Paths.get(path)));
47                 ObjectMapper mapper = new ObjectMapper();
48                 ServiceInstancesRequest sir = mapper.readValue(jsonInput, ServiceInstancesRequest.class);
49                 ValidationInformation info = new ValidationInformation(sir, null, Action.createInstance, 7, false, sir.getRequestDetails().getRequestParameters());
50         for(Map<String, Object> params : sir.getRequestDetails().getRequestParameters().getUserParams()){
51                         ObjectMapper obj = new ObjectMapper();
52                         String input = obj.writeValueAsString(params.get("service"));
53                         Service validate = obj.readValue(input, Service.class);
54                         info.setUserParams(validate);
55                         break;
56             }
57         info.setRequestInfo(sir.getRequestDetails().getRequestInfo());
58                 return info;
59         }
60         
61         @Test
62         public void validateModelTypeExceptionTest() throws IOException, ValidationException{
63         thrown.expect(ValidationException.class);
64                 thrown.expectMessage("No valid modelType in userParams service modelInfo is specified");
65         validation.validate(setupValidationInformation("src/test/resources/Validation/UserParamsValidation/ModelInfoNoModelType.json"));
66         }
67         @Test
68         public void validateInstanceNameExceptionTest() throws IOException, ValidationException{
69         thrown.expect(ValidationException.class);
70                 thrown.expectMessage("instanceName in requestInfo does not match instanceName in userParams service");
71         validation.validate(setupValidationInformation("src/test/resources/Validation/UserParamsValidation/MacroRequest.json"));
72         }
73         @Test
74         public void validateModelTypeTest() throws ValidationException, IOException{
75         thrown.expect(ValidationException.class);
76                 thrown.expectMessage("modelType in modelInfo does not match modelType in userParams service");
77         validation.validate(setupValidationInformation("src/test/resources/Validation/UserParamsValidation/ModelType.json"));
78         }
79         @Test
80         public void validateModelInvariantIdTest() throws ValidationException, IOException{
81         thrown.expect(ValidationException.class);
82                 thrown.expectMessage("modelInvariantId in modelInfo does not match modelInvariantId in userParams service");
83         validation.validate(setupValidationInformation("src/test/resources/Validation/UserParamsValidation/ModelInvariantId.json"));
84         }
85         @Test
86         public void validateModelVersionIdTest() throws ValidationException, IOException{
87         thrown.expect(ValidationException.class);
88                 thrown.expectMessage("modelVersionId in modelInfo does not match modelVersionId in userParams service");
89         validation.validate(setupValidationInformation("src/test/resources/Validation/UserParamsValidation/ModelVersionId.json"));
90         }
91         @Test
92         public void validateModelNameTest() throws ValidationException, IOException{
93         thrown.expect(ValidationException.class);
94                 thrown.expectMessage("modelName in modelInfo does not match modelName in userParams service");
95         validation.validate(setupValidationInformation("src/test/resources/Validation/UserParamsValidation/ModelName.json"));
96         }
97         @Test
98         public void validateModelVersionTest() throws ValidationException, IOException{
99         thrown.expect(ValidationException.class);
100                 thrown.expectMessage("modelVersion in modelInfo does not match modelVersion in userParams service");
101         validation.validate(setupValidationInformation("src/test/resources/Validation/UserParamsValidation/ModelVersion.json"));
102         }
103         @Test
104         public void validateModelCustomizationIdTest() throws ValidationException, IOException{
105         thrown.expect(ValidationException.class);
106                 thrown.expectMessage("modelCustomizationId in modelInfo does not match modelCustomizationId in userParams service");
107         validation.validate(setupValidationInformation("src/test/resources/Validation/UserParamsValidation/ModelCustomizationId.json"));
108         }
109 }