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;
28 import org.junit.Test;
29 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
32 * Test the parameter check class.
35 public class ParameterCheckTest {
38 public void testStartStop() {
39 assertEquals("START", ParameterCheck.StartStop.START.name());
40 assertEquals("STOP", ParameterCheck.StartStop.STOP.name());
44 public void testHostName() {
45 assertNull(ParameterCheck.getHostName(null));
47 Map<String, String[]> parameterMap = new LinkedHashMap<>();
48 assertNull(ParameterCheck.getHostName(parameterMap));
49 parameterMap.put("hostname", null);
50 assertNull(ParameterCheck.getHostName(parameterMap));
52 String[] hostnameBlankValue0 = {"", ""};
53 parameterMap.put("hostname", hostnameBlankValue0);
54 assertNull(ParameterCheck.getHostName(parameterMap));
56 String[] hostnameBlankValue1 = {" ", " "};
57 parameterMap.put("hostname", hostnameBlankValue1);
58 assertNull(ParameterCheck.getHostName(parameterMap));
60 String[] hostnameValue = {"hostname0", "hostname1"};
61 parameterMap.put("hostname", hostnameValue);
62 assertEquals("hostname0", ParameterCheck.getHostName(parameterMap));
66 public void testPort() {
67 assertEquals(-1, ParameterCheck.getPort(null));
69 Map<String, String[]> parameterMap = new LinkedHashMap<>();
70 assertEquals(-1, ParameterCheck.getPort(parameterMap));
71 parameterMap.put("port", null);
72 assertEquals(-1, ParameterCheck.getPort(parameterMap));
74 String[] portBlankValue0 = {"", ""};
75 parameterMap.put("port", portBlankValue0);
76 assertEquals(-1, ParameterCheck.getPort(parameterMap));
78 String[] portBlankValue1 = {" ", " "};
79 parameterMap.put("port", portBlankValue1);
80 assertEquals(-1, ParameterCheck.getPort(parameterMap));
82 String[] portValueBad = {"port", "value"};
83 parameterMap.put("port", portValueBad);
84 assertEquals(-1, ParameterCheck.getPort(parameterMap));
86 String[] portValueRange0 = {"-1", "-1"};
87 parameterMap.put("port", portValueRange0);
88 assertEquals(-1, ParameterCheck.getPort(parameterMap));
90 String[] portValueRange1 = {"65536", "65536"};
91 parameterMap.put("port", portValueRange1);
92 assertEquals(-1, ParameterCheck.getPort(parameterMap));
94 String[] portValue = {"12344", "23221"};
95 parameterMap.put("port", portValue);
96 assertEquals(12344, ParameterCheck.getPort(parameterMap));
100 public void testEngineKey() {
101 assertEquals(null, ParameterCheck.getEngineKey(null));
103 Map<String, String[]> parameterMap = new LinkedHashMap<>();
104 parameterMap.put("Zooby", null);
105 assertEquals(null, ParameterCheck.getEngineKey(parameterMap));
107 parameterMap.put("AxArtifactKey", null);
108 assertEquals(null, ParameterCheck.getEngineKey(parameterMap));
109 parameterMap.remove("AxArtifactKey");
111 parameterMap.put("AxArtifactKey#zooby", null);
112 assertEquals(null, ParameterCheck.getEngineKey(parameterMap));
113 parameterMap.remove("AxArtifactKey#zooby");
115 parameterMap.put("AxArtifactKey#zooby#looby", null);
116 assertEquals(null, ParameterCheck.getEngineKey(parameterMap));
117 parameterMap.remove("AxArtifactKey#zooby#looby");
119 parameterMap.put("AxArtifactKey#Name:0.0.1", null);
120 assertEquals(new AxArtifactKey("Name", "0.0.1"), ParameterCheck.getEngineKey(parameterMap));
124 public void testStartStopValue() {
125 assertEquals(null, ParameterCheck.getStartStop(null, null));
127 Map<String, String[]> parameterMap = new LinkedHashMap<>();
128 assertEquals(null, ParameterCheck.getStartStop(parameterMap, null));
130 parameterMap.put("Zooby", null);
131 assertEquals(null, ParameterCheck.getStartStop(parameterMap, null));
133 AxArtifactKey engineKey = new AxArtifactKey("Engine", "0.0.1");
135 parameterMap.put("Zooby", null);
136 assertEquals(null, ParameterCheck.getStartStop(parameterMap, engineKey));
138 String key = "AxArtifactKey#" + engineKey.getId();
140 parameterMap.put(key, null);
141 assertEquals(null, ParameterCheck.getStartStop(parameterMap, engineKey));
143 String[] startStopBlankValue0 = {"", ""};
144 parameterMap.put(key, startStopBlankValue0);
145 assertEquals(null, ParameterCheck.getStartStop(parameterMap, engineKey));
147 String[] startStopBlankValue1 = {" ", " "};
148 parameterMap.put(key, startStopBlankValue1);
149 assertEquals(null, ParameterCheck.getStartStop(parameterMap, engineKey));
151 String[] startStopValueBad = {key, "value"};
152 parameterMap.put(key, startStopValueBad);
153 assertEquals(null, ParameterCheck.getStartStop(parameterMap, engineKey));
155 String[] startValue = {"START", "STOP"};
156 parameterMap.put(key, startValue);
157 assertEquals(ParameterCheck.StartStop.START, ParameterCheck.getStartStop(parameterMap, engineKey));
159 String[] stopValue = {"STOP", "START"};
160 parameterMap.put(key, stopValue);
161 assertEquals(ParameterCheck.StartStop.STOP, ParameterCheck.getStartStop(parameterMap, engineKey));
165 public void testLong() {
166 assertEquals(-1, ParameterCheck.getLong(null, null));
168 Map<String, String[]> parameterMap = new LinkedHashMap<>();
169 assertEquals(-1, ParameterCheck.getLong(parameterMap, null));
171 parameterMap.put("long0", null);
172 assertEquals(-1, ParameterCheck.getLong(parameterMap, "longx"));
173 assertEquals(-1, ParameterCheck.getLong(parameterMap, "long0"));
175 String[] longBlankValue0 = {"", ""};
176 parameterMap.put("long1", longBlankValue0);
177 assertEquals(-1, ParameterCheck.getLong(parameterMap, "long1"));
179 String[] longBlankValue1 = {" ", " "};
180 parameterMap.put("long2", longBlankValue1);
181 assertEquals(-1, ParameterCheck.getLong(parameterMap, "long2"));
183 String[] longValueBad = {"long", "value"};
184 parameterMap.put("long3", longValueBad);
185 assertEquals(-1, ParameterCheck.getLong(parameterMap, "long3"));
187 String[] longValue = {"12345", "6789"};
188 parameterMap.put("long4", longValue);
189 assertEquals(12345, ParameterCheck.getLong(parameterMap, "long4"));