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;
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));
72 String[] portBlankValue0 = {"", ""};
73 parameterMap.put("port", portBlankValue0);
74 assertEquals(-1, ParameterCheck.getPort(parameterMap));
76 String[] portBlankValue1 = {" ", " "};
77 parameterMap.put("port", portBlankValue1);
78 assertEquals(-1, ParameterCheck.getPort(parameterMap));
80 String[] portValueBad = {"port", "value"};
81 parameterMap.put("port", portValueBad);
82 assertEquals(-1, ParameterCheck.getPort(parameterMap));
84 String[] portValueRange0 = {"-1", "-1"};
85 parameterMap.put("port", portValueRange0);
86 assertEquals(-1, ParameterCheck.getPort(parameterMap));
88 String[] portValueRange1 = {"65536", "65536"};
89 parameterMap.put("port", portValueRange1);
90 assertEquals(-1, ParameterCheck.getPort(parameterMap));
92 String[] portValue = {"12344", "23221"};
93 parameterMap.put("port", portValue);
94 assertEquals(12344, ParameterCheck.getPort(parameterMap));
98 public void testEngineKey() {
99 assertEquals(null, ParameterCheck.getEngineKey(null));
101 Map<String, String[]> parameterMap = new LinkedHashMap<>();
102 parameterMap.put("Zooby", null);
103 assertEquals(null, ParameterCheck.getEngineKey(parameterMap));
105 parameterMap.put("AxArtifactKey", null);
106 assertEquals(null, ParameterCheck.getEngineKey(parameterMap));
107 parameterMap.remove("AxArtifactKey");
109 parameterMap.put("AxArtifactKey#zooby", null);
110 assertEquals(null, ParameterCheck.getEngineKey(parameterMap));
111 parameterMap.remove("AxArtifactKey#zooby");
113 parameterMap.put("AxArtifactKey#zooby#looby", null);
114 assertEquals(null, ParameterCheck.getEngineKey(parameterMap));
115 parameterMap.remove("AxArtifactKey#zooby#looby");
117 parameterMap.put("AxArtifactKey#Name:0.0.1", null);
118 assertEquals(new AxArtifactKey("Name", "0.0.1"), ParameterCheck.getEngineKey(parameterMap));
122 public void testStartStopValue() {
123 assertEquals(null, ParameterCheck.getStartStop(null, null));
125 Map<String, String[]> parameterMap = new LinkedHashMap<>();
126 assertEquals(null, ParameterCheck.getStartStop(parameterMap, null));
128 parameterMap.put("Zooby", null);
129 assertEquals(null, ParameterCheck.getStartStop(parameterMap, null));
131 AxArtifactKey engineKey = new AxArtifactKey("Engine", "0.0.1");
133 parameterMap.put("Zooby", null);
134 assertEquals(null, ParameterCheck.getStartStop(parameterMap, engineKey));
136 String key = "AxArtifactKey#" + engineKey.getId();
138 parameterMap.put(key, null);
139 assertEquals(null, ParameterCheck.getStartStop(parameterMap, engineKey));
141 String[] startStopBlankValue0 = {"", ""};
142 parameterMap.put(key, startStopBlankValue0);
143 assertEquals(null, ParameterCheck.getStartStop(parameterMap, engineKey));
145 String[] startStopBlankValue1 = {" ", " "};
146 parameterMap.put(key, startStopBlankValue1);
147 assertEquals(null, ParameterCheck.getStartStop(parameterMap, engineKey));
149 String[] startStopValueBad = {key, "value"};
150 parameterMap.put(key, startStopValueBad);
151 assertEquals(null, ParameterCheck.getStartStop(parameterMap, engineKey));
153 String[] startValue = {"START", "STOP"};
154 parameterMap.put(key, startValue);
155 assertEquals(ParameterCheck.StartStop.START, ParameterCheck.getStartStop(parameterMap, engineKey));
157 String[] stopValue = {"STOP", "START"};
158 parameterMap.put(key, stopValue);
159 assertEquals(ParameterCheck.StartStop.STOP, ParameterCheck.getStartStop(parameterMap, engineKey));
163 public void testLong() {
164 assertEquals(-1, ParameterCheck.getLong(null, null));
166 Map<String, String[]> parameterMap = new LinkedHashMap<>();
167 assertEquals(-1, ParameterCheck.getLong(parameterMap, null));
169 parameterMap.put("long0", null);
170 assertEquals(-1, ParameterCheck.getLong(parameterMap, "longx"));
171 assertEquals(-1, ParameterCheck.getLong(parameterMap, "long0"));
173 String[] longBlankValue0 = {"", ""};
174 parameterMap.put("long1", longBlankValue0);
175 assertEquals(-1, ParameterCheck.getLong(parameterMap, "long1"));
177 String[] longBlankValue1 = {" ", " "};
178 parameterMap.put("long2", longBlankValue1);
179 assertEquals(-1, ParameterCheck.getLong(parameterMap, "long2"));
181 String[] longValueBad = {"long", "value"};
182 parameterMap.put("long3", longValueBad);
183 assertEquals(-1, ParameterCheck.getLong(parameterMap, "long3"));
185 String[] longValue = {"12345", "6789"};
186 parameterMap.put("long4", longValue);
187 assertEquals(12345, ParameterCheck.getLong(parameterMap, "long4"));