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=========================================================
21 package org.onap.so.apihandlerinfra.validation;
23 import java.io.IOException;
24 import java.nio.file.Files;
25 import java.nio.file.Paths;
27 import org.junit.Rule;
28 import org.junit.Test;
29 import org.junit.rules.ExpectedException;
30 import org.onap.so.apihandlerinfra.Action;
31 import org.onap.so.exceptions.ValidationException;
32 import org.onap.so.serviceinstancebeans.Service;
33 import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
34 import com.fasterxml.jackson.databind.ObjectMapper;
36 public class UserParamsValidationTest {
38 UserParamsValidation validation = new UserParamsValidation();
41 public ExpectedException thrown = ExpectedException.none();
43 public ValidationInformation setupValidationInformation(String path) throws IOException {
44 String jsonInput = new String(Files.readAllBytes(Paths.get(path)));
45 ObjectMapper mapper = new ObjectMapper();
46 ServiceInstancesRequest sir = mapper.readValue(jsonInput, ServiceInstancesRequest.class);
47 ValidationInformation info = new ValidationInformation(sir, null, Action.createInstance, 7, false,
48 sir.getRequestDetails().getRequestParameters());
49 for (Map<String, Object> params : sir.getRequestDetails().getRequestParameters().getUserParams()) {
50 ObjectMapper obj = new ObjectMapper();
51 String input = obj.writeValueAsString(params.get("service"));
52 Service validate = obj.readValue(input, Service.class);
53 info.setUserParams(validate);
56 info.setRequestInfo(sir.getRequestDetails().getRequestInfo());
61 public void validateModelTypeExceptionTest() throws IOException, ValidationException {
62 thrown.expect(ValidationException.class);
63 thrown.expectMessage("No valid modelType in userParams service modelInfo is specified");
64 validation.validate(setupValidationInformation(
65 "src/test/resources/Validation/UserParamsValidation/ModelInfoNoModelType.json"));
69 public void validateInstanceNameExceptionTest() throws IOException, ValidationException {
70 thrown.expect(ValidationException.class);
71 thrown.expectMessage("instanceName in requestInfo does not match instanceName in userParams service");
73 setupValidationInformation("src/test/resources/Validation/UserParamsValidation/MacroRequest.json"));
77 public void validateModelTypeTest() throws ValidationException, IOException {
78 thrown.expect(ValidationException.class);
79 thrown.expectMessage("modelType in modelInfo does not match modelType in userParams service");
81 setupValidationInformation("src/test/resources/Validation/UserParamsValidation/ModelType.json"));
85 public void validateModelInvariantIdTest() throws ValidationException, IOException {
86 thrown.expect(ValidationException.class);
87 thrown.expectMessage("modelInvariantId in modelInfo does not match modelInvariantId in userParams service");
89 setupValidationInformation("src/test/resources/Validation/UserParamsValidation/ModelInvariantId.json"));
93 public void validateModelVersionIdTest() throws ValidationException, IOException {
94 thrown.expect(ValidationException.class);
95 thrown.expectMessage("modelVersionId in modelInfo does not match modelVersionId in userParams service");
97 setupValidationInformation("src/test/resources/Validation/UserParamsValidation/ModelVersionId.json"));
101 public void validateModelNameTest() throws ValidationException, IOException {
102 thrown.expect(ValidationException.class);
103 thrown.expectMessage("modelName in modelInfo does not match modelName in userParams service");
105 setupValidationInformation("src/test/resources/Validation/UserParamsValidation/ModelName.json"));
109 public void validateModelVersionTest() throws ValidationException, IOException {
110 thrown.expect(ValidationException.class);
111 thrown.expectMessage("modelVersion in modelInfo does not match modelVersion in userParams service");
113 setupValidationInformation("src/test/resources/Validation/UserParamsValidation/ModelVersion.json"));
117 public void validateModelCustomizationIdTest() throws ValidationException, IOException {
118 thrown.expect(ValidationException.class);
119 thrown.expectMessage(
120 "modelCustomizationId in modelInfo does not match modelCustomizationId in userParams service");
121 validation.validate(setupValidationInformation(
122 "src/test/resources/Validation/UserParamsValidation/ModelCustomizationId.json"));