aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/test/java/org/onap/cli/fw/error/OnapCommandErrorTest.java
blob: 45560c4a73bf54c92d199b337667db712a70d1c2 (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
296
297
298
299
300
/*
 * 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 oclipCommandDiscoveryFailedTest() {
        OnapCommandDiscoveryFailed failed = new OnapCommandDiscoveryFailed("name");
        assertEquals("0x1001::Failed auto discover schema files from name under class path, ", failed.getMessage());
        failed = new OnapCommandDiscoveryFailed("directory", "name");
        assertEquals("0x1001::Failed auto generate json file 'name' under class path directory 'directory'",
                failed.getMessage());
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        assertEquals("0x2001::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 oclipCommandInvalidResultAttributeScopeTest() {
        OnapCommandInvalidResultAttributeScope failed = new OnapCommandInvalidResultAttributeScope("Attribute");

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

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

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

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

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

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

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

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

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

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

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

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

        assertEquals("0x6003::Command Test is not available for product version 1.0", failed.getMessage());
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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


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

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

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

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

    @Test
    public void oclipCommandTypeInvalidTest() {
        OnapCommandInvalidCommandType failed = new OnapCommandInvalidCommandType("test");

        assertEquals("0x3003::Command type test is invalid", failed.getMessage());
    }    
}