2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 ONAP
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.openecomp.sdnc.sli.SliPluginUtils;
23 import java.util.HashMap;
26 import org.junit.Test;
27 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
28 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 public class CheckParametersTest {
35 public void nullRequiredParameters() throws Exception {
36 Map<String, String> parametersMap = new HashMap<String, String>();
37 String[] requiredParams = null;
38 Logger Log = LoggerFactory.getLogger(SliPluginUtils.class);
39 SliPluginUtils.checkParameters(parametersMap, requiredParams, Log);
42 @Test(expected = SvcLogicException.class)
43 public void emptyParametersMap() throws Exception {
44 Map<String, String> parametersMap = new HashMap<String, String>();
45 String[] requiredParams = new String[] { "param1", "param2", "param3" };
46 Logger Log = LoggerFactory.getLogger(SliPluginUtils.class);
47 SliPluginUtils.checkParameters(parametersMap, requiredParams, Log);
50 @Test(expected = SvcLogicException.class)
51 public void paramNotFound() throws Exception {
52 Map<String, String> parametersMap = new HashMap<String, String>();
53 parametersMap.put("tst", "me");
54 String[] requiredParams = new String[] { "param1", "parm2", "param3" };
55 Logger Log = LoggerFactory.getLogger(SliPluginUtils.class);
56 SliPluginUtils.checkParameters(parametersMap, requiredParams, Log);
60 public void testSunnyRequiredParameters() throws Exception {
61 SvcLogicContext ctx = new SvcLogicContext();
62 ctx.setAttribute("param1", "hello");
63 ctx.setAttribute("param2", "world");
64 ctx.setAttribute("param3", "!");
66 Map<String, String> parameters = new HashMap<String, String>();
67 parameters.put("param1", "dog");
68 parameters.put("param2", "cat");
69 parameters.put("param3", "fish");
71 SliPluginUtils.requiredParameters(parameters, ctx);
75 public void testSunnyRequiredParametersWithPrefix() throws Exception {
76 String prefixValue = "my.unique.path.";
77 SvcLogicContext ctx = new SvcLogicContext();
78 ctx.setAttribute(prefixValue + "param1", "hello");
79 ctx.setAttribute(prefixValue + "param2", "world");
80 ctx.setAttribute(prefixValue + "param3", "!");
82 Map<String, String> parameters = new HashMap<String, String>();
83 parameters.put("prefix", prefixValue);
84 parameters.put("param1", "dog");
85 parameters.put("param2", "cat");
86 parameters.put("param3", "fish");
88 SliPluginUtils.requiredParameters(parameters, ctx);
91 @Test(expected = SvcLogicException.class)
92 public void testRainyMissingRequiredParameters() throws Exception {
93 SvcLogicContext ctx = new SvcLogicContext();
94 ctx.setAttribute("param1", "hello");
95 ctx.setAttribute("param3", "!");
97 Map<String, String> parameters = new HashMap<String, String>();
98 parameters.put("param1", null);
99 parameters.put("param2", null);
100 parameters.put("param3", null);
102 SliPluginUtils.requiredParameters(parameters, ctx);
105 @Test(expected = SvcLogicException.class)
106 public void testEmptyRequiredParameters() throws Exception {
107 SvcLogicContext ctx = new SvcLogicContext();
108 ctx.setAttribute("param1", "hello");
109 ctx.setAttribute("param3", "!");
111 Map<String, String> parameters = new HashMap<String, String>();
113 SliPluginUtils.requiredParameters(parameters, ctx);