Eliminate ranges
[sdnc/core.git] / sliPluginUtils / provider / src / test / java / org / openecomp / sdnc / sli / SliPluginUtils / CheckParametersTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : SDN-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                                              reserved.
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
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
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=========================================================
20  */
21
22 package org.openecomp.sdnc.sli.SliPluginUtils;
23
24 import java.util.HashMap;
25 import java.util.Map;
26
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;
32
33 public class CheckParametersTest {
34
35     @Test
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);
41     }
42
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);
49     }
50
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);
58     }
59
60     @Test
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", "!");
66
67         Map<String, String> parameters = new HashMap<String, String>();
68         parameters.put("param1", "dog");
69         parameters.put("param2", "cat");
70         parameters.put("param3", "fish");
71
72         SliPluginUtils.requiredParameters(parameters, ctx);
73     }
74
75     @Test
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", "!");
82
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");
88
89         SliPluginUtils.requiredParameters(parameters, ctx);
90     }
91
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", "!");
97
98         Map<String, String> parameters = new HashMap<String, String>();
99         parameters.put("param1", null);
100         parameters.put("param2", null);
101         parameters.put("param3", null);
102
103         SliPluginUtils.requiredParameters(parameters, ctx);
104     }
105
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", "!");
111
112         Map<String, String> parameters = new HashMap<String, String>();
113
114         SliPluginUtils.requiredParameters(parameters, ctx);
115     }
116 }