Refactor dblib
[ccsdk/sli/core.git] / sliPluginUtils / provider / src / test / java / org / openecomp / sdnc / sli / SliPluginUtils / CheckParametersTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : CCSDK
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdnc.sli.SliPluginUtils;
22
23 import java.util.HashMap;
24 import java.util.Map;
25
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;
31
32 public class CheckParametersTest {
33
34     @Test
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);
40     }
41
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);
48     }
49
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);
57     }
58
59     @Test
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", "!");
65
66         Map<String, String> parameters = new HashMap<String, String>();
67         parameters.put("param1", "dog");
68         parameters.put("param2", "cat");
69         parameters.put("param3", "fish");
70
71         SliPluginUtils.requiredParameters(parameters, ctx);
72     }
73
74     @Test
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", "!");
81
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");
87
88         SliPluginUtils.requiredParameters(parameters, ctx);
89     }
90
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", "!");
96
97         Map<String, String> parameters = new HashMap<String, String>();
98         parameters.put("param1", null);
99         parameters.put("param2", null);
100         parameters.put("param3", null);
101
102         SliPluginUtils.requiredParameters(parameters, ctx);
103     }
104
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", "!");
110
111         Map<String, String> parameters = new HashMap<String, String>();
112
113         SliPluginUtils.requiredParameters(parameters, ctx);
114     }
115 }