aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/test/java/org/onap/cli/fw/error/OnapCommandErrorTest.java
blob: d031cc77cd0a71259ab072942b3eea38752f423e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
/*
 * Copyright 2017 Huawei Technologies Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.onap.cli.fw.error;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

public class OnapCommandErrorTest {

    @Test
    public void onapCommandDiscoveryFailedTest() {
        OnapCommandDiscoveryFailed failed = new OnapCommandDiscoveryFailed("name");
        assertEquals("0x0010::Failed auto discover schema files from name under class path, ", failed.getMessage());
        failed = new OnapCommandDiscoveryFailed("directory", "name");
        assertEquals("0x0010::Failed auto generate json file 'name' under class path directory 'directory'",
                failed.getMessage());
    }

    @Test
    public void onapCommandInvalidParameterValueTest() {
        OnapCommandInvalidParameterValue failed = new OnapCommandInvalidParameterValue("name");
        assertEquals("0x0028::Parameter name value is invalid, ", failed.getMessage());
    }

    @Test
    public void onapCommandResultMapProcessingFailedTest() {
        OnapCommandResultMapProcessingFailed failed = new OnapCommandResultMapProcessingFailed("name",
                new Exception("failed"));
        assertEquals("0x0028::Failed to parse the result format of command name, failed", failed.getMessage());
    }

    @Test
    public void onapCommandHttpHeaderNotFoundTest() {
        OnapCommandHttpHeaderNotFound failed = new OnapCommandHttpHeaderNotFound("name");
        assertEquals("0x0027::Http header name is not returned from the service", failed.getMessage());
    }

    @Test
    public void onapCommandClientInitialzationFailedTest() {
        OnapCommandClientInitialzationFailed failed = new OnapCommandClientInitialzationFailed("Test",
                new Exception("Test Command Failed"));
        assertEquals("0x0021::API client for the command Test is failed, Test Command Failed", failed.getMessage());
    }

    @Test
    public void onapCommandExceptionTest1() {
        OnapCommandException failed = new OnapCommandException("1", "Test Command Failed");
        assertEquals("1::Test Command Failed", failed.getMessage());
    }

    @Test
    public void onapCommandExceptionTest2() {
        OnapCommandException failed = new OnapCommandException("1", "Test Command Failed", 201);
        assertEquals("201::1::Test Command Failed", failed.getMessage());
    }

    @Test
    public void onapCommandExecutionFailedTest1() {
        OnapCommandExecutionFailed failed = new OnapCommandExecutionFailed("Test", "Test Command Failed", 201);
        assertEquals("201::0x0001::Command Test failed to execute, Test Command Failed", failed.getMessage());
        failed = new OnapCommandExecutionFailed("Test", new Exception("Test Command Failed"), 201);
        assertEquals("201::0x0001::Command Test failed to execute, Test Command Failed", failed.getMessage());
    }

    @Test
    public void onapCommandExecutionFailedTest2() {
        OnapCommandExecutionFailed failed = new OnapCommandExecutionFailed("Test Command Failed");
        assertEquals("0x0001::Test Command Failed", failed.getMessage());
    }

    @Test
    public void onapCommandExecutionFailedTest3() {
        OnapCommandExecutionFailed failed = new OnapCommandExecutionFailed("Test", "Test Command Failed");
        assertEquals("0x0001::Command Test failed to execute, Test Command Failed", failed.getMessage());

        failed = new OnapCommandExecutionFailed("Test", new Exception("Test Command Failed"));
        assertEquals("0x0001::Command Test failed to execute, Test Command Failed", failed.getMessage());
    }

    @Test
    public void onapCommandExecutorInfoMissingTest() {
        OnapCommandExecutorInfoMissing failed = new OnapCommandExecutorInfoMissing("Test");

        assertEquals("0x0023::Command Test excutor info is missing from schema", failed.getMessage());
    }

    @Test
    public void onapCommandHelpFailedTest() {
        OnapCommandHelpFailed failed = new OnapCommandHelpFailed(new Exception("Failed"));

        assertEquals("0x0002::Command failed to print help message, Failed", failed.getMessage());
    }

    @Test
    public void onapCommandHttpFailureTest1() {
        OnapCommandHttpFailure failed = new OnapCommandHttpFailure("Failed");
        assertEquals("0x0025::Failed", failed.getMessage());

        failed = new OnapCommandHttpFailure(new Exception("failed"), 201);
        assertEquals("201::0x0025::failed", failed.getMessage());
    }

    @Test
    public void onapCommandHttpFailureTest2() {
        OnapCommandHttpFailure failed = new OnapCommandHttpFailure("Failed", 203);

        assertEquals("203::0x0025::Failed", failed.getMessage());
    }

    @Test
    public void onapCommandInvalidParameterTypeTest() {
        OnapCommandInvalidParameterType failed = new OnapCommandInvalidParameterType("Failed");

        assertEquals("0x0003::Parameter type Failed is invalid", failed.getMessage());
    }

    @Test
    public void onapCommandInvalidPrintDirectionTest() {
        OnapCommandInvalidPrintDirection failed = new OnapCommandInvalidPrintDirection("Direction");

        assertEquals("0x0004::Print direction Direction is invalid", failed.getMessage());
    }

    @Test
    public void onapCommandInvalidRegistrationTest() {
        OnapCommandInvalidRegistration failed = new OnapCommandInvalidRegistration(OnapCommandErrorTest.class);

        assertEquals("0x0005::Invalid commad class org.onap.cli.fw.error.OnapCommandErrorTest registration, "
                + "it should be derived from org.onap.cli.fw.OnapCommand", failed.getMessage());
    }

    @Test
    public void onapCommandInvalidResultAttributeScopeTest() {
        OnapCommandInvalidResultAttributeScope failed = new OnapCommandInvalidResultAttributeScope("Attribute");

        assertEquals("0x0006::Result atrribute Attribute is invalid", failed.getMessage());
    }

    @Test
    public void onapCommandInvalidSchemaTest() {
        OnapCommandInvalidSchema failed = new OnapCommandInvalidSchema("Schema", "Failed");

        assertEquals("0x0007::Invalid command schema Schema, Failed", failed.getMessage());
    }

    @Test
    public void onapCommandInvalidSchemaVersionTest() {
        OnapCommandInvalidSchemaVersion failed = new OnapCommandInvalidSchemaVersion("1.0");

        assertEquals("0x0008::Command schema open_cli_schema_version 1.0 is invalid or missing", failed.getMessage());
    }

    @Test
    public void onapCommandLoginFailedTest1() {
        OnapCommandLoginFailed failed = new OnapCommandLoginFailed(new Exception("Failed"));

        assertEquals("0x0009::Login failed, Failed", failed.getMessage());
    }

    @Test
    public void onapCommandLoginFailedTest2() {
        OnapCommandLoginFailed failed = new OnapCommandLoginFailed("Failed", 201);

        assertEquals("201::0x0009::Login failed, Failed", failed.getMessage());
    }

    @Test
    public void onapCommandLogoutFailedTest() {
        OnapCommandLogoutFailed failed = new OnapCommandLogoutFailed(new Exception("Failed"));
        assertEquals("0x0010::Logout failed, Failed", failed.getMessage());

        failed = new OnapCommandLogoutFailed(200);
        assertEquals("200::0x0010::Logout failed", failed.getMessage());
    }

    @Test
    public void onapCommandNotFoundTest() {
        OnapCommandNotFound failed = new OnapCommandNotFound("Test", "1.0");

        assertEquals("0x0011::Command Test is not available for product version 1.0."
                + " so please check command name or product version set in env variable CLI_PRODUCT_VERSION or"
                + " cli.product.version in onap.properties", failed.getMessage());
    }

    @Test
    public void onapCommandNotInitializedTest() {
        OnapCommandNotInitialized failed = new OnapCommandNotInitialized("Test");

        assertEquals("0x0012::Command Test is not initialized", failed.getMessage());
    }

    @Test
    public void onapCommandOutputPrintingFailedTest() {
        OnapCommandOutputPrintingFailed failed = new OnapCommandOutputPrintingFailed(new Exception("error"));

        assertEquals("0x0014::Command is failed to print the result, error", failed.getMessage());
    }

    @Test
    public void onapCommandParameterMissingTest() {
        OnapCommandParameterMissing failed = new OnapCommandParameterMissing("paramName");

        assertEquals("0x0015::Parameter paramName is mandatory", failed.getMessage());
    }

    @Test
    public void onapCommandParameterNameConflictTest() {
        OnapCommandParameterNameConflict failed = new OnapCommandParameterNameConflict("paramName");

        assertEquals("0x0016::Parameter name paramName is in conflict", failed.getMessage());
    }

    @Test
    public void onapCommandParameterOptionConflictTest() {
        OnapCommandParameterOptionConflict failed = new OnapCommandParameterOptionConflict("option");

        assertEquals("0x0017::Parameter option option is in conflict, only one option is allowed with given name",
                failed.getMessage());
    }

    @Test
    public void onapCommandRegistrationFailedTest() {
        OnapCommandRegistrationFailed failed = new OnapCommandRegistrationFailed("Test", "error");

        assertEquals("0x0018::Failed to register the command Test, error", failed.getMessage());
    }

    @Test
    public void onapCommandResultInitialzationFailedTest() {
        OnapCommandResultInitialzationFailed failed = new OnapCommandResultInitialzationFailed("Test",
                new Exception("error"));

        assertEquals("0x0022::Failed to parse the result format of command Test, error", failed.getMessage());
    }

    @Test
    public void onapCommandSchemaNotFoundTest() {
        OnapCommandSchemaNotFound failed = new OnapCommandSchemaNotFound("Test");

        assertEquals("0x0019::Command schema is missing for command Test", failed.getMessage());
    }

    @Test
    public void onapCommandServiceNotFoundTest() {
        OnapCommandServiceNotFound failed = new OnapCommandServiceNotFound("Service");

        assertEquals("0x0020::Service Service is not found in MSB", failed.getMessage());
    }

    @Test
    public void onapCommandOutputFormatNotsupportedTest() {
        OnapCommandOutputFormatNotsupported failed = new OnapCommandOutputFormatNotsupported("Format");

        assertEquals("0x0013::Command  does not support the output format Format", failed.getMessage());
    }


    @Test
    public void onapProfilePersistTest() {
        OnapCommandPersistProfileFailed failed = new OnapCommandPersistProfileFailed("error");

        assertEquals("0x1302::Failed to persist profile details, error", failed.getMessage());

        failed = new OnapCommandPersistProfileFailed(new Exception("error"));

        assertEquals("0x1302::Failed to persist profile details, error", failed.getMessage());
    }


    @Test
    public void onapProfileLoadTest() {
        OnapCommandLoadProfileFailed failed = new OnapCommandLoadProfileFailed("error");

        assertEquals("0x1301::Failed to load profile details, error", failed.getMessage());

        failed = new OnapCommandLoadProfileFailed(new Exception("error"));

        assertEquals("0x1301::Failed to load profile details, error", failed.getMessage());
    }
}