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 java.util.HashMap;
28 import org.junit.Test;
29 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
30 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
34 public class SliPluginUtils_checkParametersTest {
37 public void nullRequiredParameters() throws Exception {
38 Map<String, String> parametersMap = new HashMap<String, String>();
39 String[] requiredParams = null;
40 Logger Log = LoggerFactory.getLogger(SliPluginUtils.class);
41 SliPluginUtils.checkParameters(parametersMap, requiredParams, Log);
44 @Test(expected = SvcLogicException.class)
45 public void emptyParametersMap() throws Exception {
46 Map<String, String> parametersMap = new HashMap<String, String>();
47 String[] requiredParams = new String[] { "param1", "param2", "param3" };
48 Logger Log = LoggerFactory.getLogger(SliPluginUtils.class);
49 SliPluginUtils.checkParameters(parametersMap, requiredParams, Log);
52 @Test(expected = SvcLogicException.class)
53 public void paramNotFound() throws Exception {
54 Map<String, String> parametersMap = new HashMap<String, String>();
55 parametersMap.put("tst", "me");
56 String[] requiredParams = new String[] { "param1", "parm2", "param3" };
57 Logger Log = LoggerFactory.getLogger(SliPluginUtils.class);
58 SliPluginUtils.checkParameters(parametersMap, requiredParams, Log);
62 public void testSunnyRequiredParameters() throws Exception {
63 SvcLogicContext ctx = new SvcLogicContext();
64 ctx.setAttribute("param1", "hello");
65 ctx.setAttribute("param2", "world");
66 ctx.setAttribute("param3", "!");
68 Map<String, String> parameters = new HashMap<String, String>();
69 parameters.put("param1", "dog");
70 parameters.put("param2", "cat");
71 parameters.put("param3", "fish");
73 SliPluginUtils.requiredParameters(parameters, ctx);
77 public void testSunnyRequiredParametersWithPrefix() throws Exception {
78 String prefixValue = "my.unique.path.";
79 SvcLogicContext ctx = new SvcLogicContext();
80 ctx.setAttribute(prefixValue + "param1", "hello");
81 ctx.setAttribute(prefixValue + "param2", "world");
82 ctx.setAttribute(prefixValue + "param3", "!");
84 Map<String, String> parameters = new HashMap<String, String>();
85 parameters.put("prefix", prefixValue);
86 parameters.put("param1", "dog");
87 parameters.put("param2", "cat");
88 parameters.put("param3", "fish");
90 SliPluginUtils.requiredParameters(parameters, ctx);
93 @Test(expected = SvcLogicException.class)
94 public void testRainyMissingRequiredParameters() throws Exception {
95 SvcLogicContext ctx = new SvcLogicContext();
96 ctx.setAttribute("param1", "hello");
97 ctx.setAttribute("param3", "!");
99 Map<String, String> parameters = new HashMap<String, String>();
100 parameters.put("param1", null);
101 parameters.put("param2", null);
102 parameters.put("param3", null);
104 SliPluginUtils.requiredParameters(parameters, ctx);
107 @Test(expected = SvcLogicException.class)
108 public void testEmptyRequiredParameters() throws Exception {
109 SvcLogicContext ctx = new SvcLogicContext();
110 ctx.setAttribute("param1", "hello");
111 ctx.setAttribute("param3", "!");
113 Map<String, String> parameters = new HashMap<String, String>();
115 SliPluginUtils.requiredParameters(parameters, ctx);