2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.openecomp.sdnc.sli.SliPluginUtils;
24 import java.util.HashMap;
27 import org.junit.Test;
28 import org.openecomp.sdnc.sli.SvcLogicContext;
29 import org.openecomp.sdnc.sli.SvcLogicException;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
33 public class CheckParametersTest {
36 public void nullRequiredParameters() throws Exception {
37 Map<String, String> parametersMap = new HashMap<String, String>();
38 String[] requiredParams = null;
39 Logger Log = LoggerFactory.getLogger(SliPluginUtils.class);
40 SliPluginUtils.checkParameters(parametersMap, requiredParams, Log);
43 @Test(expected = SvcLogicException.class)
44 public void emptyParametersMap() throws Exception {
45 Map<String, String> parametersMap = new HashMap<String, String>();
46 String[] requiredParams = new String[] { "param1", "param2", "param3" };
47 Logger Log = LoggerFactory.getLogger(SliPluginUtils.class);
48 SliPluginUtils.checkParameters(parametersMap, requiredParams, Log);
51 @Test(expected = SvcLogicException.class)
52 public void paramNotFound() throws Exception {
53 Map<String, String> parametersMap = new HashMap<String, String>();
54 parametersMap.put("tst", "me");
55 String[] requiredParams = new String[] { "param1", "parm2", "param3" };
56 Logger Log = LoggerFactory.getLogger(SliPluginUtils.class);
57 SliPluginUtils.checkParameters(parametersMap, requiredParams, Log);
61 public void testSunnyRequiredParameters() throws Exception {
62 SvcLogicContext ctx = new SvcLogicContext();
63 ctx.setAttribute("param1", "hello");
64 ctx.setAttribute("param2", "world");
65 ctx.setAttribute("param3", "!");
67 Map<String, String> parameters = new HashMap<String, String>();
68 parameters.put("param1", "dog");
69 parameters.put("param2", "cat");
70 parameters.put("param3", "fish");
72 SliPluginUtils.requiredParameters(parameters, ctx);
76 public void testSunnyRequiredParametersWithPrefix() throws Exception {
77 String prefixValue = "my.unique.path.";
78 SvcLogicContext ctx = new SvcLogicContext();
79 ctx.setAttribute(prefixValue + "param1", "hello");
80 ctx.setAttribute(prefixValue + "param2", "world");
81 ctx.setAttribute(prefixValue + "param3", "!");
83 Map<String, String> parameters = new HashMap<String, String>();
84 parameters.put("prefix", prefixValue);
85 parameters.put("param1", "dog");
86 parameters.put("param2", "cat");
87 parameters.put("param3", "fish");
89 SliPluginUtils.requiredParameters(parameters, ctx);
92 @Test(expected = SvcLogicException.class)
93 public void testRainyMissingRequiredParameters() throws Exception {
94 SvcLogicContext ctx = new SvcLogicContext();
95 ctx.setAttribute("param1", "hello");
96 ctx.setAttribute("param3", "!");
98 Map<String, String> parameters = new HashMap<String, String>();
99 parameters.put("param1", null);
100 parameters.put("param2", null);
101 parameters.put("param3", null);
103 SliPluginUtils.requiredParameters(parameters, ctx);
106 @Test(expected = SvcLogicException.class)
107 public void testEmptyRequiredParameters() throws Exception {
108 SvcLogicContext ctx = new SvcLogicContext();
109 ctx.setAttribute("param1", "hello");
110 ctx.setAttribute("param3", "!");
112 Map<String, String> parameters = new HashMap<String, String>();
114 SliPluginUtils.requiredParameters(parameters, ctx);