Changes for checkstyle 8.32
[policy/apex-pdp.git] / client / client-monitoring / src / test / java / org / onap / policy / apex / client / monitoring / rest / ParameterCheckTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2018 Ericsson. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  * 
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  * 
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  * 
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.apex.client.monitoring.rest;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNull;
25
26 import java.util.LinkedHashMap;
27 import java.util.Map;
28 import org.junit.Test;
29 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
30
31 /**
32  * Test the parameter check class.
33  *
34  */
35 public class ParameterCheckTest {
36
37     @Test
38     public void testStartStop() {
39         assertEquals("START", ParameterCheck.StartStop.START.name());
40         assertEquals("STOP", ParameterCheck.StartStop.STOP.name());
41     }
42
43     @Test
44     public void testHostName() {
45         assertNull(ParameterCheck.getHostName(null));
46         
47         Map<String, String[]> parameterMap = new LinkedHashMap<>();
48         assertNull(ParameterCheck.getHostName(parameterMap));
49         parameterMap.put("hostname", null);
50         assertNull(ParameterCheck.getHostName(parameterMap));
51         
52         String[] hostnameBlankValue0 = {"", ""};
53         parameterMap.put("hostname", hostnameBlankValue0);
54         assertNull(ParameterCheck.getHostName(parameterMap));
55         
56         String[] hostnameBlankValue1 = {" ", " "};
57         parameterMap.put("hostname", hostnameBlankValue1);
58         assertNull(ParameterCheck.getHostName(parameterMap));
59         
60         String[] hostnameValue = {"hostname0", "hostname1"};
61         parameterMap.put("hostname", hostnameValue);
62         assertEquals("hostname0", ParameterCheck.getHostName(parameterMap));
63     }
64
65     @Test
66     public void testPort() {
67         assertEquals(-1, ParameterCheck.getPort(null));
68         
69         Map<String, String[]> parameterMap = new LinkedHashMap<>();
70         assertEquals(-1, ParameterCheck.getPort(parameterMap));
71         parameterMap.put("port", null);
72         assertEquals(-1, ParameterCheck.getPort(parameterMap));
73
74         String[] portBlankValue0 = {"", ""};
75         parameterMap.put("port", portBlankValue0);
76         assertEquals(-1, ParameterCheck.getPort(parameterMap));
77
78         String[] portBlankValue1 = {" ", " "};
79         parameterMap.put("port", portBlankValue1);
80         assertEquals(-1, ParameterCheck.getPort(parameterMap));
81         
82         String[] portValueBad = {"port", "value"};
83         parameterMap.put("port", portValueBad);
84         assertEquals(-1, ParameterCheck.getPort(parameterMap));
85         
86         String[] portValueRange0 = {"-1", "-1"};
87         parameterMap.put("port", portValueRange0);
88         assertEquals(-1, ParameterCheck.getPort(parameterMap));
89
90         String[] portValueRange1 = {"65536", "65536"};
91         parameterMap.put("port", portValueRange1);
92         assertEquals(-1, ParameterCheck.getPort(parameterMap));
93
94         String[] portValue = {"12344", "23221"};
95         parameterMap.put("port", portValue);
96         assertEquals(12344, ParameterCheck.getPort(parameterMap));
97     }
98
99     @Test
100     public void testEngineKey() {
101         assertEquals(null, ParameterCheck.getEngineKey(null));
102
103         Map<String, String[]> parameterMap = new LinkedHashMap<>();
104         parameterMap.put("Zooby", null);
105         assertEquals(null, ParameterCheck.getEngineKey(parameterMap));
106         
107         parameterMap.put("AxArtifactKey", null);
108         assertEquals(null, ParameterCheck.getEngineKey(parameterMap));
109         parameterMap.remove("AxArtifactKey");
110         
111         parameterMap.put("AxArtifactKey#zooby", null);
112         assertEquals(null, ParameterCheck.getEngineKey(parameterMap));
113         parameterMap.remove("AxArtifactKey#zooby");
114
115         parameterMap.put("AxArtifactKey#zooby#looby", null);
116         assertEquals(null, ParameterCheck.getEngineKey(parameterMap));
117         parameterMap.remove("AxArtifactKey#zooby#looby");
118
119         parameterMap.put("AxArtifactKey#Name:0.0.1", null);
120         assertEquals(new AxArtifactKey("Name", "0.0.1"), ParameterCheck.getEngineKey(parameterMap));
121     }
122
123     @Test
124     public void testStartStopValue() {
125         assertEquals(null, ParameterCheck.getStartStop(null, null));
126         
127         Map<String, String[]> parameterMap = new LinkedHashMap<>();
128         assertEquals(null, ParameterCheck.getStartStop(parameterMap, null));
129
130         parameterMap.put("Zooby", null);
131         assertEquals(null, ParameterCheck.getStartStop(parameterMap, null));
132
133         AxArtifactKey engineKey = new AxArtifactKey("Engine", "0.0.1");
134
135         parameterMap.put("Zooby", null);
136         assertEquals(null, ParameterCheck.getStartStop(parameterMap, engineKey));
137
138         String key = "AxArtifactKey#" + engineKey.getId();
139         
140         parameterMap.put(key, null);
141         assertEquals(null, ParameterCheck.getStartStop(parameterMap, engineKey));
142
143         String[] startStopBlankValue0 = {"", ""};
144         parameterMap.put(key, startStopBlankValue0);
145         assertEquals(null, ParameterCheck.getStartStop(parameterMap, engineKey));
146
147         String[] startStopBlankValue1 = {" ", " "};
148         parameterMap.put(key, startStopBlankValue1);
149         assertEquals(null, ParameterCheck.getStartStop(parameterMap, engineKey));
150         
151         String[] startStopValueBad = {key, "value"};
152         parameterMap.put(key, startStopValueBad);
153         assertEquals(null, ParameterCheck.getStartStop(parameterMap, engineKey));
154         
155         String[] startValue = {"START", "STOP"};
156         parameterMap.put(key, startValue);
157         assertEquals(ParameterCheck.StartStop.START, ParameterCheck.getStartStop(parameterMap, engineKey));
158
159         String[] stopValue = {"STOP", "START"};
160         parameterMap.put(key, stopValue);
161         assertEquals(ParameterCheck.StartStop.STOP, ParameterCheck.getStartStop(parameterMap, engineKey));
162     }
163
164     @Test
165     public void testLong() {
166         assertEquals(-1, ParameterCheck.getLong(null, null));
167         
168         Map<String, String[]> parameterMap = new LinkedHashMap<>();
169         assertEquals(-1, ParameterCheck.getLong(parameterMap, null));
170         
171         parameterMap.put("long0", null);
172         assertEquals(-1, ParameterCheck.getLong(parameterMap, "longx"));
173         assertEquals(-1, ParameterCheck.getLong(parameterMap, "long0"));
174
175         String[] longBlankValue0 = {"", ""};
176         parameterMap.put("long1", longBlankValue0);
177         assertEquals(-1, ParameterCheck.getLong(parameterMap, "long1"));
178
179         String[] longBlankValue1 = {" ", " "};
180         parameterMap.put("long2", longBlankValue1);
181         assertEquals(-1, ParameterCheck.getLong(parameterMap, "long2"));
182         
183         String[] longValueBad = {"long", "value"};
184         parameterMap.put("long3", longValueBad);
185         assertEquals(-1, ParameterCheck.getLong(parameterMap, "long3"));
186         
187         String[] longValue = {"12345", "6789"};
188         parameterMap.put("long4", longValue);
189         assertEquals(12345, ParameterCheck.getLong(parameterMap, "long4"));
190     }
191 }