2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Modifications Copyright (C) 2018 IBM.
9 * ================================================================================
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 * ============LICENSE_END=========================================================
24 package org.onap.ccsdk.sli.core.slipluginutils;
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertNull;
29 import java.util.HashMap;
32 import org.junit.Test;
33 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
34 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
38 public class CheckParametersTest {
41 public void nullRequiredParameters() throws Exception {
42 Map<String, String> parametersMap = new HashMap<String, String>();
43 String[] requiredParams = null;
44 Logger Log = LoggerFactory.getLogger(SliPluginUtils.class);
45 SliPluginUtils.checkParameters(parametersMap, requiredParams, Log);
48 @Test(expected = SvcLogicException.class)
49 public void emptyParametersMap() throws Exception {
50 Map<String, String> parametersMap = new HashMap<String, String>();
51 String[] requiredParams = new String[] { "param1", "param2", "param3" };
52 Logger Log = LoggerFactory.getLogger(SliPluginUtils.class);
53 SliPluginUtils.checkParameters(parametersMap, requiredParams, Log);
56 @Test(expected = SvcLogicException.class)
57 public void paramNotFound() throws Exception {
58 Map<String, String> parametersMap = new HashMap<String, String>();
59 parametersMap.put("tst", "me");
60 String[] requiredParams = new String[] { "param1", "parm2", "param3" };
61 Logger Log = LoggerFactory.getLogger(SliPluginUtils.class);
62 SliPluginUtils.checkParameters(parametersMap, requiredParams, Log);
66 public void testSunnyRequiredParameters() throws Exception {
67 SvcLogicContext ctx = new SvcLogicContext();
68 ctx.setAttribute("param1", "hello");
69 ctx.setAttribute("param2", "world");
70 ctx.setAttribute("param3", "!");
72 Map<String, String> parameters = new HashMap<String, String>();
73 parameters.put("param1", "dog");
74 parameters.put("param2", "cat");
75 parameters.put("param3", "fish");
77 SliPluginUtils.requiredParameters(parameters, ctx);
81 public void testSunnyRequiredParametersWithPrefix() throws Exception {
82 String prefixValue = "my.unique.path.";
83 SvcLogicContext ctx = new SvcLogicContext();
84 ctx.setAttribute(prefixValue + "param1", "hello");
85 ctx.setAttribute(prefixValue + "param2", "world");
86 ctx.setAttribute(prefixValue + "param3", "!");
88 Map<String, String> parameters = new HashMap<String, String>();
89 parameters.put("prefix", prefixValue);
90 parameters.put("param1", "dog");
91 parameters.put("param2", "cat");
92 parameters.put("param3", "fish");
94 SliPluginUtils.requiredParameters(parameters, ctx);
97 @Test(expected = SvcLogicException.class)
98 public void testRainyMissingRequiredParameters() throws Exception {
99 SvcLogicContext ctx = new SvcLogicContext();
100 ctx.setAttribute("param1", "hello");
101 ctx.setAttribute("param3", "!");
103 Map<String, String> parameters = new HashMap<String, String>();
104 parameters.put("param1", null);
105 parameters.put("param2", null);
106 parameters.put("param3", null);
108 SliPluginUtils.requiredParameters(parameters, ctx);
111 @Test(expected = SvcLogicException.class)
112 public void testEmptyRequiredParameters() throws Exception {
113 SvcLogicContext ctx = new SvcLogicContext();
114 ctx.setAttribute("param1", "hello");
115 ctx.setAttribute("param3", "!");
117 Map<String, String> parameters = new HashMap<String, String>();
119 SliPluginUtils.requiredParameters(parameters, ctx);
122 @Test(expected = SvcLogicException.class)
123 public void testJsonStringToCtx() throws Exception {
124 SvcLogicContext ctx = new SvcLogicContext();
125 Map<String, String> parameters = new HashMap<String, String>();
126 parameters.put("outputPath", "testPath");
127 parameters.put("isEscaped", "true");
128 parameters.put("source", "//{/name1/:value1/}//");
129 SliPluginUtils.jsonStringToCtx(parameters, ctx);
133 public void testGetAttributeValue() throws Exception {
134 SvcLogicContext ctx = new SvcLogicContext();
135 Map<String, String> parameters = new HashMap<String, String>();
136 parameters.put("outputPath", "testPath");
137 parameters.put("source", "testSource");
138 SliPluginUtils.getAttributeValue(parameters, ctx);
139 assertNull(ctx.getAttribute(parameters.get("outputPath")));
143 public void testCtxListContains() throws Exception {
144 SvcLogicContext ctx = new SvcLogicContext();
145 Map<String, String> parameters = new HashMap<String, String>();
146 parameters.put("list", "10_length");
147 parameters.put("keyName", "testName");
148 parameters.put("keyValue", "testValue");
149 ctx.setAttribute("10_length", "10");
150 assertEquals("false", SliPluginUtils.ctxListContains(parameters, ctx));