2 * Copyright 2017 Huawei Technologies Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.cli.fw.error;
19 import static org.junit.Assert.assertEquals;
21 import org.junit.Test;
23 public class OnapCommandErrorTest {
26 public void onapCommandDiscoveryFailedTest() {
27 OnapCommandDiscoveryFailed failed = new OnapCommandDiscoveryFailed("name");
28 assertEquals("0x1001::Failed auto discover schema files from name under class path, ", failed.getMessage());
29 failed = new OnapCommandDiscoveryFailed("directory", "name");
30 assertEquals("0x1001::Failed auto generate json file 'name' under class path directory 'directory'",
35 public void onapCommandInvalidParameterValueTest() {
36 OnapCommandInvalidParameterValue failed = new OnapCommandInvalidParameterValue("name");
37 assertEquals("0x7002::Parameter name value is invalid, ", failed.getMessage());
41 public void onapCommandResultMapProcessingFailedTest() {
42 OnapCommandResultMapProcessingFailed failed = new OnapCommandResultMapProcessingFailed("name",
43 new Exception("failed"));
44 assertEquals("0x3002::Failed to parse the result format of command name, failed", failed.getMessage());
48 public void onapCommandHttpHeaderNotFoundTest() {
49 OnapCommandHttpHeaderNotFound failed = new OnapCommandHttpHeaderNotFound("name");
50 assertEquals("0x3003::Http header name is not returned from the service", failed.getMessage());
54 public void onapCommandClientInitialzationFailedTest() {
55 OnapCommandClientInitialzationFailed failed = new OnapCommandClientInitialzationFailed("Test",
56 new Exception("Test Command Failed"));
57 assertEquals("0x5001::API client for the command Test is failed, Test Command Failed", failed.getMessage());
61 public void onapCommandExceptionTest1() {
62 OnapCommandException failed = new OnapCommandException("1", "Test Command Failed");
63 assertEquals("1::Test Command Failed", failed.getMessage());
67 public void onapCommandExceptionTest2() {
68 OnapCommandException failed = new OnapCommandException("1", "Test Command Failed", 201);
69 assertEquals("201::1::Test Command Failed", failed.getMessage());
73 public void onapCommandExecutionFailedTest1() {
74 OnapCommandExecutionFailed failed = new OnapCommandExecutionFailed("Test", "Test Command Failed", 201);
75 assertEquals("201::0x6001::Command Test failed to execute, Test Command Failed", failed.getMessage());
76 failed = new OnapCommandExecutionFailed("Test", new Exception("Test Command Failed"), 201);
77 assertEquals("201::0x6001::Command Test failed to execute, Test Command Failed", failed.getMessage());
81 public void onapCommandExecutionFailedTest2() {
82 OnapCommandExecutionFailed failed = new OnapCommandExecutionFailed("Test Command Failed");
83 assertEquals("0x6001::Test Command Failed", failed.getMessage());
87 public void onapCommandExecutionFailedTest3() {
88 OnapCommandExecutionFailed failed = new OnapCommandExecutionFailed("Test", "Test Command Failed");
89 assertEquals("0x6001::Command Test failed to execute, Test Command Failed", failed.getMessage());
91 failed = new OnapCommandExecutionFailed("Test", new Exception("Test Command Failed"));
92 assertEquals("0x6001::Command Test failed to execute, Test Command Failed", failed.getMessage());
96 public void onapCommandExecutorInfoMissingTest() {
97 OnapCommandExecutorInfoMissing failed = new OnapCommandExecutorInfoMissing("Test");
99 assertEquals("0x6002::Command Test excutor info is missing from schema", failed.getMessage());
103 public void onapCommandHelpFailedTest() {
104 OnapCommandHelpFailed failed = new OnapCommandHelpFailed(new Exception("Failed"));
106 assertEquals("0x9001::Command failed to print help message, Failed", failed.getMessage());
110 public void onapCommandHttpFailureTest1() {
111 OnapCommandHttpFailure failed = new OnapCommandHttpFailure("Failed");
112 assertEquals("0x3001::Failed", failed.getMessage());
114 failed = new OnapCommandHttpFailure(new Exception("failed"), 201);
115 assertEquals("201::0x3001::failed", failed.getMessage());
119 public void onapCommandHttpFailureTest2() {
120 OnapCommandHttpFailure failed = new OnapCommandHttpFailure("Failed", 203);
122 assertEquals("203::0x3001::Failed", failed.getMessage());
126 public void onapCommandInvalidParameterTypeTest() {
127 OnapCommandInvalidParameterType failed = new OnapCommandInvalidParameterType("Failed");
129 assertEquals("0x7001::Parameter type Failed is invalid", failed.getMessage());
133 public void onapCommandInvalidPrintDirectionTest() {
134 OnapCommandInvalidPrintDirection failed = new OnapCommandInvalidPrintDirection("Direction");
136 assertEquals("0x8003::Print direction Direction is invalid", failed.getMessage());
140 public void onapCommandInvalidRegistrationTest() {
141 OnapCommandInvalidRegistration failed = new OnapCommandInvalidRegistration(OnapCommandErrorTest.class);
143 assertEquals("0x2001::Invalid commad class org.onap.cli.fw.error.OnapCommandErrorTest registration, "
144 + "it should be derived from org.onap.cli.fw.OnapCommand", failed.getMessage());
148 public void onapCommandInvalidResultAttributeScopeTest() {
149 OnapCommandInvalidResultAttributeScope failed = new OnapCommandInvalidResultAttributeScope("Attribute");
151 assertEquals("0x8002::Result atrribute Attribute is invalid", failed.getMessage());
155 public void onapCommandInvalidSchemaTest() {
156 OnapCommandInvalidSchema failed = new OnapCommandInvalidSchema("Schema", "Failed");
158 assertEquals("0xb001::Invalid command schema Schema, Failed", failed.getMessage());
162 public void onapCommandInvalidSchemaVersionTest() {
163 OnapCommandInvalidSchemaVersion failed = new OnapCommandInvalidSchemaVersion("1.0");
165 assertEquals("0xb003::Command schema open_cli_schema_version 1.0 is invalid or missing", failed.getMessage());
169 public void onapCommandLoginFailedTest1() {
170 OnapCommandLoginFailed failed = new OnapCommandLoginFailed(new Exception("Failed"));
172 assertEquals("0x4001::Login failed, Failed", failed.getMessage());
176 public void onapCommandLoginFailedTest2() {
177 OnapCommandLoginFailed failed = new OnapCommandLoginFailed("Failed", 201);
179 assertEquals("201::0x4001::Login failed, Failed", failed.getMessage());
183 public void onapCommandLogoutFailedTest() {
184 OnapCommandLogoutFailed failed = new OnapCommandLogoutFailed(new Exception("Failed"));
185 assertEquals("0x4002::Logout failed, Failed", failed.getMessage());
187 failed = new OnapCommandLogoutFailed(200);
188 assertEquals("200::0x4002::Logout failed", failed.getMessage());
192 public void onapCommandNotFoundTest() {
193 OnapCommandNotFound failed = new OnapCommandNotFound("Test", "1.0");
195 assertEquals("0x6003::Command Test is not available for product version 1.0."
196 + " so please check command name or product version set in env variable CLI_PRODUCT_VERSION or"
197 + " cli.product.version in onap.properties", failed.getMessage());
201 public void onapCommandNotInitializedTest() {
202 OnapCommandNotInitialized failed = new OnapCommandNotInitialized("Test");
204 assertEquals("0x6004::Command Test is not initialized", failed.getMessage());
208 public void onapCommandOutputPrintingFailedTest() {
209 OnapCommandOutputPrintingFailed failed = new OnapCommandOutputPrintingFailed(new Exception("error"));
211 assertEquals("0x8006::Command is failed to print the result, error", failed.getMessage());
215 public void onapCommandParameterMissingTest() {
216 OnapCommandParameterMissing failed = new OnapCommandParameterMissing("paramName");
218 assertEquals("0x7003::Parameter paramName is mandatory", failed.getMessage());
222 public void onapCommandParameterNameConflictTest() {
223 OnapCommandParameterNameConflict failed = new OnapCommandParameterNameConflict("paramName");
225 assertEquals("0x7004::Parameter name paramName is in conflict", failed.getMessage());
229 public void onapCommandParameterOptionConflictTest() {
230 OnapCommandParameterOptionConflict failed = new OnapCommandParameterOptionConflict("option");
232 assertEquals("0x7006::Parameter option option is in conflict, only one option is allowed with given name",
233 failed.getMessage());
237 public void onapCommandRegistrationFailedTest() {
238 OnapCommandRegistrationFailed failed = new OnapCommandRegistrationFailed("Test", "error");
240 assertEquals("0x2002::Failed to register the command Test, error", failed.getMessage());
244 public void onapCommandResultInitialzationFailedTest() {
245 OnapCommandResultInitialzationFailed failed = new OnapCommandResultInitialzationFailed("Test",
246 new Exception("error"));
248 assertEquals("0x8004::Failed to parse the result format of command Test, error", failed.getMessage());
252 public void onapCommandSchemaNotFoundTest() {
253 OnapCommandSchemaNotFound failed = new OnapCommandSchemaNotFound("Test");
255 assertEquals("0xb002::Command schema is missing for command Test", failed.getMessage());
259 public void onapCommandServiceNotFoundTest() {
260 OnapCommandServiceNotFound failed = new OnapCommandServiceNotFound("Service");
262 assertEquals("0xd001::Service Service is not found in MSB", failed.getMessage());
266 public void onapCommandOutputFormatNotsupportedTest() {
267 OnapCommandOutputFormatNotsupported failed = new OnapCommandOutputFormatNotsupported("Format");
269 assertEquals("0x8005::Command does not support the output format Format", failed.getMessage());
274 public void onapProfilePersistTest() {
275 OnapCommandPersistProfileFailed failed = new OnapCommandPersistProfileFailed("error");
277 assertEquals("0xc002::Failed to persist profile details, error", failed.getMessage());
279 failed = new OnapCommandPersistProfileFailed(new Exception("error"));
281 assertEquals("0xc002::Failed to persist profile details, error", failed.getMessage());
286 public void onapProfileLoadTest() {
287 OnapCommandLoadProfileFailed failed = new OnapCommandLoadProfileFailed("error");
289 assertEquals("0xc001::Failed to load profile details, error", failed.getMessage());
291 failed = new OnapCommandLoadProfileFailed(new Exception("error"));
293 assertEquals("0xc001::Failed to load profile details, error", failed.getMessage());