enhance SliPluginUtils
[ccsdk/sli/core.git] / sliPluginUtils / provider / src / test / java / org / onap / ccsdk / sli / core / slipluginutils / SliPluginUtils_checkParametersTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : CCSDK
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                         reserved.
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
13  * 
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  * 
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=========================================================
22  */ 
23
24 package org.onap.ccsdk.sli.core.slipluginutils;
25
26 import java.util.HashMap;
27 import java.util.Map;
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;
33
34 public class SliPluginUtils_checkParametersTest {
35
36     @Test
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);
42     }
43
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);
50     }
51
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);
59     }
60
61     @Test
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", "!");
67
68         Map<String, String> parameters = new HashMap<String, String>();
69         parameters.put("param1", "dog");
70         parameters.put("param2", "cat");
71         parameters.put("param3", "fish");
72
73         SliPluginUtils.requiredParameters(parameters, ctx);
74     }
75
76     @Test
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", "!");
83
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");
89
90         SliPluginUtils.requiredParameters(parameters, ctx);
91     }
92
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", "!");
98
99         Map<String, String> parameters = new HashMap<String, String>();
100         parameters.put("param1", null);
101         parameters.put("param2", null);
102         parameters.put("param3", null);
103
104         SliPluginUtils.requiredParameters(parameters, ctx);
105     }
106
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", "!");
112
113         Map<String, String> parameters = new HashMap<String, String>();
114
115         SliPluginUtils.requiredParameters(parameters, ctx);
116     }
117 }