2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
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.deployment.rest;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNull;
25 import java.util.LinkedHashMap;
27 import org.junit.Test;
28 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
31 * Test the parameter check class.
34 public class ParameterCheckTest {
37 public void testStartStop() {
38 assertEquals("START", ParameterCheck.StartStop.START.name());
39 assertEquals("STOP", ParameterCheck.StartStop.STOP.name());
43 public void testHostName() {
44 assertNull(ParameterCheck.getHostName(null));
46 Map<String, String[]> parameterMap = new LinkedHashMap<>();
47 assertNull(ParameterCheck.getHostName(parameterMap));
48 parameterMap.put("hostname", null);
49 assertNull(ParameterCheck.getHostName(parameterMap));
51 String[] hostnameBlankValue0 = {"", ""};
52 parameterMap.put("hostname", hostnameBlankValue0);
53 assertNull(ParameterCheck.getHostName(parameterMap));
55 String[] hostnameBlankValue1 = {" ", " "};
56 parameterMap.put("hostname", hostnameBlankValue1);
57 assertNull(ParameterCheck.getHostName(parameterMap));
59 String[] hostnameValue = {"hostname0", "hostname1"};
60 parameterMap.put("hostname", hostnameValue);
61 assertEquals("hostname0", ParameterCheck.getHostName(parameterMap));
65 public void testPort() {
66 assertEquals(-1, ParameterCheck.getPort(null));
68 Map<String, String[]> parameterMap = new LinkedHashMap<>();
69 assertEquals(-1, ParameterCheck.getPort(parameterMap));
71 String[] portBlankValue0 = {"", ""};
72 parameterMap.put("port", portBlankValue0);
73 assertEquals(-1, ParameterCheck.getPort(parameterMap));
75 String[] portBlankValue1 = {" ", " "};
76 parameterMap.put("port", portBlankValue1);
77 assertEquals(-1, ParameterCheck.getPort(parameterMap));
79 String[] portValueBad = {"port", "value"};
80 parameterMap.put("port", portValueBad);
81 assertEquals(-1, ParameterCheck.getPort(parameterMap));
83 String[] portValueRange0 = {"-1", "-1"};
84 parameterMap.put("port", portValueRange0);
85 assertEquals(-1, ParameterCheck.getPort(parameterMap));
87 String[] portValueRange1 = {"65536", "65536"};
88 parameterMap.put("port", portValueRange1);
89 assertEquals(-1, ParameterCheck.getPort(parameterMap));
91 String[] portValue = {"12344", "23221"};
92 parameterMap.put("port", portValue);
93 assertEquals(12344, ParameterCheck.getPort(parameterMap));
97 public void testEngineKey() {
98 assertEquals(null, ParameterCheck.getEngineKey(null));
100 Map<String, String[]> parameterMap = new LinkedHashMap<>();
101 parameterMap.put("Zooby", null);
102 assertEquals(null, ParameterCheck.getEngineKey(parameterMap));
104 parameterMap.put("AxArtifactKey", null);
105 assertEquals(null, ParameterCheck.getEngineKey(parameterMap));
106 parameterMap.remove("AxArtifactKey");
108 parameterMap.put("AxArtifactKey#zooby", null);
109 assertEquals(null, ParameterCheck.getEngineKey(parameterMap));
110 parameterMap.remove("AxArtifactKey#zooby");
112 parameterMap.put("AxArtifactKey#zooby#looby", null);
113 assertEquals(null, ParameterCheck.getEngineKey(parameterMap));
114 parameterMap.remove("AxArtifactKey#zooby#looby");
116 parameterMap.put("AxArtifactKey#Name:0.0.1", null);
117 assertEquals(new AxArtifactKey("Name", "0.0.1"), ParameterCheck.getEngineKey(parameterMap));
121 public void testStartStopValue() {
122 assertEquals(null, ParameterCheck.getStartStop(null, null));
124 Map<String, String[]> parameterMap = new LinkedHashMap<>();
125 assertEquals(null, ParameterCheck.getStartStop(parameterMap, null));
127 parameterMap.put("Zooby", null);
128 assertEquals(null, ParameterCheck.getStartStop(parameterMap, null));
130 AxArtifactKey engineKey = new AxArtifactKey("Engine", "0.0.1");
132 parameterMap.put("Zooby", null);
133 assertEquals(null, ParameterCheck.getStartStop(parameterMap, engineKey));
135 String key = "AxArtifactKey#" + engineKey.getId();
137 parameterMap.put(key, null);
138 assertEquals(null, ParameterCheck.getStartStop(parameterMap, engineKey));
140 String[] startStopBlankValue0 = {"", ""};
141 parameterMap.put(key, startStopBlankValue0);
142 assertEquals(null, ParameterCheck.getStartStop(parameterMap, engineKey));
144 String[] startStopBlankValue1 = {" ", " "};
145 parameterMap.put(key, startStopBlankValue1);
146 assertEquals(null, ParameterCheck.getStartStop(parameterMap, engineKey));
148 String[] startStopValueBad = {key, "value"};
149 parameterMap.put(key, startStopValueBad);
150 assertEquals(null, ParameterCheck.getStartStop(parameterMap, engineKey));
152 String[] startValue = {"START", "STOP"};
153 parameterMap.put(key, startValue);
154 assertEquals(ParameterCheck.StartStop.START, ParameterCheck.getStartStop(parameterMap, engineKey));
156 String[] stopValue = {"STOP", "START"};
157 parameterMap.put(key, stopValue);
158 assertEquals(ParameterCheck.StartStop.STOP, ParameterCheck.getStartStop(parameterMap, engineKey));
162 public void testLong() {
163 assertEquals(-1, ParameterCheck.getLong(null, null));
165 Map<String, String[]> parameterMap = new LinkedHashMap<>();
166 assertEquals(-1, ParameterCheck.getLong(parameterMap, null));
168 parameterMap.put("long0", null);
169 assertEquals(-1, ParameterCheck.getLong(parameterMap, "longx"));
170 assertEquals(-1, ParameterCheck.getLong(parameterMap, "long0"));
172 String[] longBlankValue0 = {"", ""};
173 parameterMap.put("long1", longBlankValue0);
174 assertEquals(-1, ParameterCheck.getLong(parameterMap, "long1"));
176 String[] longBlankValue1 = {" ", " "};
177 parameterMap.put("long2", longBlankValue1);
178 assertEquals(-1, ParameterCheck.getLong(parameterMap, "long2"));
180 String[] longValueBad = {"long", "value"};
181 parameterMap.put("long3", longValueBad);
182 assertEquals(-1, ParameterCheck.getLong(parameterMap, "long3"));
184 String[] longValue = {"12345", "6789"};
185 parameterMap.put("long4", longValue);
186 assertEquals(12345, ParameterCheck.getLong(parameterMap, "long4"));