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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.client.monitoring.rest;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNull;
26 import java.util.LinkedHashMap;
29 import org.junit.Test;
30 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
33 * Test the parameter check class.
36 public class ParameterCheckTest {
39 public void testStartStop() {
40 assertEquals("START", ParameterCheck.StartStop.START.name());
41 assertEquals("STOP", ParameterCheck.StartStop.STOP.name());
45 public void testHostName() {
46 assertNull(ParameterCheck.getHostName(null));
48 Map<String, String[]> parameterMap = new LinkedHashMap<>();
49 assertNull(ParameterCheck.getHostName(parameterMap));
50 parameterMap.put("hostname", null);
51 assertNull(ParameterCheck.getHostName(parameterMap));
53 String[] hostnameBlankValue0 = {"", ""};
54 parameterMap.put("hostname", hostnameBlankValue0);
55 assertNull(ParameterCheck.getHostName(parameterMap));
57 String[] hostnameBlankValue1 = {" ", " "};
58 parameterMap.put("hostname", hostnameBlankValue1);
59 assertNull(ParameterCheck.getHostName(parameterMap));
61 String[] hostnameValue = {"hostname0", "hostname1"};
62 parameterMap.put("hostname", hostnameValue);
63 assertEquals("hostname0", ParameterCheck.getHostName(parameterMap));
67 public void testPort() {
68 assertEquals(-1, ParameterCheck.getPort(null));
70 Map<String, String[]> parameterMap = new LinkedHashMap<>();
71 assertEquals(-1, ParameterCheck.getPort(parameterMap));
72 parameterMap.put("port", null);
73 assertEquals(-1, ParameterCheck.getPort(parameterMap));
75 String[] portBlankValue0 = {"", ""};
76 parameterMap.put("port", portBlankValue0);
77 assertEquals(-1, ParameterCheck.getPort(parameterMap));
79 String[] portBlankValue1 = {" ", " "};
80 parameterMap.put("port", portBlankValue1);
81 assertEquals(-1, ParameterCheck.getPort(parameterMap));
83 String[] portValueBad = {"port", "value"};
84 parameterMap.put("port", portValueBad);
85 assertEquals(-1, ParameterCheck.getPort(parameterMap));
87 String[] portValueRange0 = {"-1", "-1"};
88 parameterMap.put("port", portValueRange0);
89 assertEquals(-1, ParameterCheck.getPort(parameterMap));
91 String[] portValueRange1 = {"65536", "65536"};
92 parameterMap.put("port", portValueRange1);
93 assertEquals(-1, ParameterCheck.getPort(parameterMap));
95 String[] portValue = {"12344", "23221"};
96 parameterMap.put("port", portValue);
97 assertEquals(12344, ParameterCheck.getPort(parameterMap));
101 public void testEngineKey() {
102 assertEquals(null, ParameterCheck.getEngineKey(null));
104 Map<String, String[]> parameterMap = new LinkedHashMap<>();
105 parameterMap.put("Zooby", null);
106 assertEquals(null, ParameterCheck.getEngineKey(parameterMap));
108 parameterMap.put("AxArtifactKey", null);
109 assertEquals(null, ParameterCheck.getEngineKey(parameterMap));
110 parameterMap.remove("AxArtifactKey");
112 parameterMap.put("AxArtifactKey#zooby", null);
113 assertEquals(null, ParameterCheck.getEngineKey(parameterMap));
114 parameterMap.remove("AxArtifactKey#zooby");
116 parameterMap.put("AxArtifactKey#zooby#looby", null);
117 assertEquals(null, ParameterCheck.getEngineKey(parameterMap));
118 parameterMap.remove("AxArtifactKey#zooby#looby");
120 parameterMap.put("AxArtifactKey#Name:0.0.1", null);
121 assertEquals(new AxArtifactKey("Name", "0.0.1"), ParameterCheck.getEngineKey(parameterMap));
125 public void testStartStopValue() {
126 assertEquals(null, ParameterCheck.getStartStop(null, null));
128 Map<String, String[]> parameterMap = new LinkedHashMap<>();
129 assertEquals(null, ParameterCheck.getStartStop(parameterMap, null));
131 parameterMap.put("Zooby", null);
132 assertEquals(null, ParameterCheck.getStartStop(parameterMap, null));
134 AxArtifactKey engineKey = new AxArtifactKey("Engine", "0.0.1");
136 parameterMap.put("Zooby", null);
137 assertEquals(null, ParameterCheck.getStartStop(parameterMap, engineKey));
139 String key = "AxArtifactKey#" + engineKey.getId();
141 parameterMap.put(key, null);
142 assertEquals(null, ParameterCheck.getStartStop(parameterMap, engineKey));
144 String[] startStopBlankValue0 = {"", ""};
145 parameterMap.put(key, startStopBlankValue0);
146 assertEquals(null, ParameterCheck.getStartStop(parameterMap, engineKey));
148 String[] startStopBlankValue1 = {" ", " "};
149 parameterMap.put(key, startStopBlankValue1);
150 assertEquals(null, ParameterCheck.getStartStop(parameterMap, engineKey));
152 String[] startStopValueBad = {key, "value"};
153 parameterMap.put(key, startStopValueBad);
154 assertEquals(null, ParameterCheck.getStartStop(parameterMap, engineKey));
156 String[] startValue = {"START", "STOP"};
157 parameterMap.put(key, startValue);
158 assertEquals(ParameterCheck.StartStop.START, ParameterCheck.getStartStop(parameterMap, engineKey));
160 String[] stopValue = {"STOP", "START"};
161 parameterMap.put(key, stopValue);
162 assertEquals(ParameterCheck.StartStop.STOP, ParameterCheck.getStartStop(parameterMap, engineKey));
166 public void testLong() {
167 assertEquals(-1, ParameterCheck.getLong(null, null));
169 Map<String, String[]> parameterMap = new LinkedHashMap<>();
170 assertEquals(-1, ParameterCheck.getLong(parameterMap, null));
172 parameterMap.put("long0", null);
173 assertEquals(-1, ParameterCheck.getLong(parameterMap, "longx"));
174 assertEquals(-1, ParameterCheck.getLong(parameterMap, "long0"));
176 String[] longBlankValue0 = {"", ""};
177 parameterMap.put("long1", longBlankValue0);
178 assertEquals(-1, ParameterCheck.getLong(parameterMap, "long1"));
180 String[] longBlankValue1 = {" ", " "};
181 parameterMap.put("long2", longBlankValue1);
182 assertEquals(-1, ParameterCheck.getLong(parameterMap, "long2"));
184 String[] longValueBad = {"long", "value"};
185 parameterMap.put("long3", longValueBad);
186 assertEquals(-1, ParameterCheck.getLong(parameterMap, "long3"));
188 String[] longValue = {"12345", "6789"};
189 parameterMap.put("long4", longValue);
190 assertEquals(12345, ParameterCheck.getLong(parameterMap, "long4"));