2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.openecomp.appc.dg.util.impl;
27 import org.junit.Assert;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
31 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
32 import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
33 import org.onap.ccsdk.sli.adaptors.aai.AAIClient;
34 import org.onap.ccsdk.sli.adaptors.aai.AAIService;
35 import org.powermock.reflect.Whitebox;
37 import java.util.HashMap;
40 public class InputParameterValidationImplTest {
41 private SvcLogicContext svcLogicContext;
43 private InputParameterValidationImpl inputParameterValidation;
46 public void setUp() throws Exception {
47 inputParameterValidation = new InputParameterValidationImpl();
48 svcLogicContext = new SvcLogicContext();
49 svcLogicContext.setAttribute("a", "b");
50 svcLogicContext.setAttribute("b", "c");
54 public void validateAttributeSuccess() throws Exception {
55 Map<String, String> params = new HashMap<>();
59 inputParameterValidation.validateAttribute(params, svcLogicContext);
61 Assert.assertEquals("true", svcLogicContext.getAttribute("validateAttribute"));
65 public void validateAttributeFailure() throws Exception {
67 Map<String, String> params = new HashMap<>();
70 inputParameterValidation.validateAttribute(params, svcLogicContext);
72 Assert.assertEquals("false", svcLogicContext.getAttribute("validateAttribute"));
75 params = new HashMap<>();
76 params.put("e", null);
78 inputParameterValidation.validateAttribute(params, svcLogicContext);
80 Assert.assertEquals("false", svcLogicContext.getAttribute("validateAttribute"));
84 public void validateAttributeNull() throws Exception {
85 inputParameterValidation.validateAttribute(null, svcLogicContext);
87 Assert.assertEquals("false", svcLogicContext.getAttribute("validateAttribute"));
91 public void validateAttributeLengthSuccess() throws Exception {
92 Map<String, String> params = new HashMap<>();
93 params.put("maximum_length_param", "2");
96 inputParameterValidation.validateAttributeLength(params, svcLogicContext);
98 Assert.assertEquals("true", svcLogicContext.getAttribute("validateAttributeLength"));
102 public void validateAttributeLengthFailure() throws Exception {
104 Map<String, String> params = new HashMap<>();
105 params.put("maximum_length_param", "2");
106 params.put("e", "1");
108 inputParameterValidation.validateAttributeLength(params, svcLogicContext);
110 Assert.assertEquals("false", svcLogicContext.getAttribute("validateAttributeLength"));
113 params = new HashMap<>();
114 params.put("maximum_length_param", "2");
115 params.put("c", "3");
117 inputParameterValidation.validateAttributeLength(params, svcLogicContext);
119 Assert.assertEquals("false", svcLogicContext.getAttribute("validateAttributeLength"));
123 public void validateAttributeLengthNull() throws Exception {
124 inputParameterValidation.validateAttributeLength(null, svcLogicContext);
126 Assert.assertEquals("false", svcLogicContext.getAttribute("validateAttributeLength"));
130 public void validateAttributeCharacterSuccess() throws Exception {
131 Map<String, String> params = new HashMap<>();
132 params.put("special_characters", "z");
133 params.put("a", "1");
135 inputParameterValidation.validateAttributeCharacter(params, svcLogicContext);
137 Assert.assertEquals("true", svcLogicContext.getAttribute("validateAttributeCharacter"));
141 public void validateAttributeCharacterFailure() throws Exception {
142 Map<String, String> params = new HashMap<>();
143 params.put("special_characters", "z");
144 params.put("d", "1");
146 inputParameterValidation.validateAttributeCharacter(params, svcLogicContext);
148 Assert.assertEquals("false", svcLogicContext.getAttribute("validateAttributeCharacter"));
152 public void validateAttributeCharacterNull() throws Exception {
153 inputParameterValidation.validateAttributeCharacter(null, svcLogicContext);
155 Assert.assertEquals("false", svcLogicContext.getAttribute("validateAttributeCharacter"));
159 public void testGetValueFromContext() throws Exception {
160 Map<String, String> result = Whitebox.invokeMethod(inputParameterValidation, "getValueFromContext",
162 Assert.assertEquals("b", result.get("a"));
163 Assert.assertEquals("c", result.get("b"));