Verfiy Invalid samples
[cli.git] / framework / src / test / java / org / onap / cli / fw / error / OnapCommandErrorTest.java
1 /*
2  * Copyright 2017 Huawei Technologies Co., Ltd.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.onap.cli.fw.error;
18
19 import static org.junit.Assert.assertEquals;
20
21 import org.junit.Test;
22
23 public class OnapCommandErrorTest {
24
25     @Test
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'",
31                 failed.getMessage());
32     }
33
34     @Test
35     public void onapCommandInvalidParameterValueTest() {
36         OnapCommandInvalidParameterValue failed = new OnapCommandInvalidParameterValue("name");
37         assertEquals("0x7002::Parameter name value is invalid, ", failed.getMessage());
38     }
39
40     @Test
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());
45     }
46
47     @Test
48     public void onapCommandHttpHeaderNotFoundTest() {
49         OnapCommandHttpHeaderNotFound failed = new OnapCommandHttpHeaderNotFound("name");
50         assertEquals("0x3003::Http header name is not returned from the service", failed.getMessage());
51     }
52
53     @Test
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());
58     }
59
60     @Test
61     public void onapCommandExceptionTest1() {
62         OnapCommandException failed = new OnapCommandException("1", "Test Command Failed");
63         assertEquals("1::Test Command Failed", failed.getMessage());
64     }
65
66     @Test
67     public void onapCommandExceptionTest2() {
68         OnapCommandException failed = new OnapCommandException("1", "Test Command Failed", 201);
69         assertEquals("201::1::Test Command Failed", failed.getMessage());
70     }
71
72     @Test
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());
78     }
79
80     @Test
81     public void onapCommandExecutionFailedTest2() {
82         OnapCommandExecutionFailed failed = new OnapCommandExecutionFailed("Test Command Failed");
83         assertEquals("0x6001::Test Command Failed", failed.getMessage());
84     }
85
86     @Test
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());
90
91         failed = new OnapCommandExecutionFailed("Test", new Exception("Test Command Failed"));
92         assertEquals("0x6001::Command Test failed to execute, Test Command Failed", failed.getMessage());
93     }
94
95     @Test
96     public void onapCommandExecutorInfoMissingTest() {
97         OnapCommandExecutorInfoMissing failed = new OnapCommandExecutorInfoMissing("Test");
98
99         assertEquals("0x6002::Command Test excutor info is missing from schema", failed.getMessage());
100     }
101
102     @Test
103     public void onapCommandHelpFailedTest() {
104         OnapCommandHelpFailed failed = new OnapCommandHelpFailed(new Exception("Failed"));
105
106         assertEquals("0x9001::Command failed to print help message, Failed", failed.getMessage());
107     }
108
109     @Test
110     public void onapCommandHttpFailureTest1() {
111         OnapCommandHttpFailure failed = new OnapCommandHttpFailure("Failed");
112         assertEquals("0x3001::Failed", failed.getMessage());
113
114         failed = new OnapCommandHttpFailure(new Exception("failed"), 201);
115         assertEquals("201::0x3001::failed", failed.getMessage());
116     }
117
118     @Test
119     public void onapCommandHttpFailureTest2() {
120         OnapCommandHttpFailure failed = new OnapCommandHttpFailure("Failed", 203);
121
122         assertEquals("203::0x3001::Failed", failed.getMessage());
123     }
124
125     @Test
126     public void onapCommandInvalidParameterTypeTest() {
127         OnapCommandInvalidParameterType failed = new OnapCommandInvalidParameterType("Failed");
128
129         assertEquals("0x7001::Parameter type Failed is invalid", failed.getMessage());
130     }
131
132     @Test
133     public void onapCommandInvalidPrintDirectionTest() {
134         OnapCommandInvalidPrintDirection failed = new OnapCommandInvalidPrintDirection("Direction");
135
136         assertEquals("0x8003::Print direction Direction is invalid", failed.getMessage());
137     }
138
139     @Test
140     public void onapCommandInvalidRegistrationTest() {
141         OnapCommandInvalidRegistration failed = new OnapCommandInvalidRegistration(OnapCommandErrorTest.class);
142
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());
145     }
146
147     @Test
148     public void onapCommandInvalidResultAttributeScopeTest() {
149         OnapCommandInvalidResultAttributeScope failed = new OnapCommandInvalidResultAttributeScope("Attribute");
150
151         assertEquals("0x8002::Result atrribute Attribute is invalid", failed.getMessage());
152     }
153
154     @Test
155     public void onapCommandInvalidSchemaTest() {
156         OnapCommandInvalidSchema failed = new OnapCommandInvalidSchema("Schema", "Failed");
157
158         assertEquals("0xb001::Invalid command schema Schema, Failed", failed.getMessage());
159     }
160
161     @Test
162     public void onapCommandInvalidSchemaVersionTest() {
163         OnapCommandInvalidSchemaVersion failed = new OnapCommandInvalidSchemaVersion("1.0");
164
165         assertEquals("0xb003::Command schema open_cli_schema_version 1.0 is invalid or missing", failed.getMessage());
166     }
167
168     @Test
169     public void onapCommandLoginFailedTest1() {
170         OnapCommandLoginFailed failed = new OnapCommandLoginFailed(new Exception("Failed"));
171
172         assertEquals("0x4001::Login failed, Failed", failed.getMessage());
173     }
174
175     @Test
176     public void onapCommandLoginFailedTest2() {
177         OnapCommandLoginFailed failed = new OnapCommandLoginFailed("Failed", 201);
178
179         assertEquals("201::0x4001::Login failed, Failed", failed.getMessage());
180     }
181
182     @Test
183     public void onapCommandLogoutFailedTest() {
184         OnapCommandLogoutFailed failed = new OnapCommandLogoutFailed(new Exception("Failed"));
185         assertEquals("0x4002::Logout failed, Failed", failed.getMessage());
186
187         failed = new OnapCommandLogoutFailed(200);
188         assertEquals("200::0x4002::Logout failed", failed.getMessage());
189     }
190
191     @Test
192     public void onapCommandNotFoundTest() {
193         OnapCommandNotFound failed = new OnapCommandNotFound("Test", "1.0");
194
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());
198     }
199
200     @Test
201     public void onapCommandNotInitializedTest() {
202         OnapCommandNotInitialized failed = new OnapCommandNotInitialized("Test");
203
204         assertEquals("0x6004::Command Test is not initialized", failed.getMessage());
205     }
206
207     @Test
208     public void onapCommandOutputPrintingFailedTest() {
209         OnapCommandOutputPrintingFailed failed = new OnapCommandOutputPrintingFailed(new Exception("error"));
210
211         assertEquals("0x8006::Command is failed to print the result, error", failed.getMessage());
212     }
213
214     @Test
215     public void onapCommandParameterMissingTest() {
216         OnapCommandParameterMissing failed = new OnapCommandParameterMissing("paramName");
217
218         assertEquals("0x7003::Parameter paramName is mandatory", failed.getMessage());
219     }
220
221     @Test
222     public void onapCommandParameterNameConflictTest() {
223         OnapCommandParameterNameConflict failed = new OnapCommandParameterNameConflict("paramName");
224
225         assertEquals("0x7004::Parameter name paramName is in conflict", failed.getMessage());
226     }
227
228     @Test
229     public void onapCommandParameterOptionConflictTest() {
230         OnapCommandParameterOptionConflict failed = new OnapCommandParameterOptionConflict("option");
231
232         assertEquals("0x7006::Parameter option option is in conflict, only one option is allowed with given name",
233                 failed.getMessage());
234     }
235
236     @Test
237     public void onapCommandRegistrationFailedTest() {
238         OnapCommandRegistrationFailed failed = new OnapCommandRegistrationFailed("Test", "error");
239
240         assertEquals("0x2002::Failed to register the command Test, error", failed.getMessage());
241     }
242
243     @Test
244     public void onapCommandResultInitialzationFailedTest() {
245         OnapCommandResultInitialzationFailed failed = new OnapCommandResultInitialzationFailed("Test",
246                 new Exception("error"));
247
248         assertEquals("0x8004::Failed to parse the result format of command Test, error", failed.getMessage());
249     }
250
251     @Test
252     public void onapCommandSchemaNotFoundTest() {
253         OnapCommandSchemaNotFound failed = new OnapCommandSchemaNotFound("Test");
254
255         assertEquals("0xb002::Command schema is missing for command Test", failed.getMessage());
256     }
257
258     @Test
259     public void onapCommandSampleInvalidTest() {
260         OnapCommandInvalidSample failed = new OnapCommandInvalidSample("Test", "error");
261
262         assertEquals("0xf001::Invalid command sample Test, error", failed.getMessage());
263
264         failed = new OnapCommandInvalidSample("Test", new Exception("error"));
265
266         assertEquals("0xf001::Invalid command sample Test, error", failed.getMessage());
267     }
268
269     @Test
270     public void onapCommandServiceNotFoundTest() {
271         OnapCommandServiceNotFound failed = new OnapCommandServiceNotFound("Service");
272
273         assertEquals("0xd001::Service Service is not found in MSB", failed.getMessage());
274     }
275
276     @Test
277     public void onapCommandOutputFormatNotsupportedTest() {
278         OnapCommandOutputFormatNotsupported failed = new OnapCommandOutputFormatNotsupported("Format");
279
280         assertEquals("0x8005::Command  does not support the output format Format", failed.getMessage());
281     }
282
283
284     @Test
285     public void onapProfilePersistTest() {
286         OnapCommandPersistProfileFailed failed = new OnapCommandPersistProfileFailed("error");
287
288         assertEquals("0xc002::Failed to persist profile details, error", failed.getMessage());
289
290         failed = new OnapCommandPersistProfileFailed(new Exception("error"));
291
292         assertEquals("0xc002::Failed to persist profile details, error", failed.getMessage());
293     }
294
295
296     @Test
297     public void onapProfileLoadTest() {
298         OnapCommandLoadProfileFailed failed = new OnapCommandLoadProfileFailed("error");
299
300         assertEquals("0xc001::Failed to load profile details, error", failed.getMessage());
301
302         failed = new OnapCommandLoadProfileFailed(new Exception("error"));
303
304         assertEquals("0xc001::Failed to load profile details, error", failed.getMessage());
305     }
306 }