2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.appc.oam;
27 import org.junit.Assert;
28 import org.junit.Test;
29 import org.onap.appc.executor.objects.Params;
31 import java.util.HashMap;
34 public class OAMCommandStatusTest {
35 private Map<OAMCommandStatus, Integer> CODE_MAP = new HashMap<OAMCommandStatus, Integer>() {
37 put(OAMCommandStatus.ABORT, 304);
38 put(OAMCommandStatus.ACCEPTED, 100);
39 put(OAMCommandStatus.INVALID_PARAMETER, 302);
40 put(OAMCommandStatus.REJECTED, 300);
41 put(OAMCommandStatus.SUCCESS, 400);
42 put(OAMCommandStatus.TIMEOUT, 303);
43 put(OAMCommandStatus.UNEXPECTED_ERROR, 200);
46 private Map<OAMCommandStatus, String> MSG_MAP = new HashMap<OAMCommandStatus, String>() {
48 put(OAMCommandStatus.ABORT, "OPERATION ABORT - ${errorMsg}");
49 put(OAMCommandStatus.ACCEPTED, "ACCEPTED - request accepted");
50 put(OAMCommandStatus.INVALID_PARAMETER, "INVALID PARAMETER - ${errorMsg}");
51 put(OAMCommandStatus.REJECTED, "REJECTED - ${errorMsg}");
52 put(OAMCommandStatus.SUCCESS, "SUCCESS - request has been processed successfully");
53 put(OAMCommandStatus.TIMEOUT, "OPERATION TIMEOUT REACHED - ${errorMsg}");
54 put(OAMCommandStatus.UNEXPECTED_ERROR, "UNEXPECTED ERROR - ${errorMsg}");
59 public void testGetResponseMessage() throws Exception {
60 for (OAMCommandStatus oamCommandStatus : OAMCommandStatus.values()) {
61 String expectedMsg = MSG_MAP.get(oamCommandStatus);
62 Assert.assertEquals(String.format("Should have message (%s).", expectedMsg),
63 expectedMsg, oamCommandStatus.getResponseMessage());
68 public void testGetResponseCode() throws Exception {
69 for (OAMCommandStatus oamCommandStatus : OAMCommandStatus.values()) {
70 Integer expectedCode = CODE_MAP.get(oamCommandStatus);
71 Assert.assertEquals(String.format("Should have code (%d).", expectedCode),
72 expectedCode, Integer.valueOf(oamCommandStatus.getResponseCode()));
77 public void testGetFormattedMessage() throws Exception {
78 String message = "test message";
79 Params params = new Params().addParam("errorMsg", message);
80 for (OAMCommandStatus oamCommandStatus : OAMCommandStatus.values()) {
81 String expectedMsg1 = MSG_MAP.get(oamCommandStatus);
82 String expectedMsg2 = expectedMsg1.replaceAll("\\$\\{errorMsg\\}", message);
83 Assert.assertEquals("Should returned " + expectedMsg1,
84 expectedMsg1, oamCommandStatus.getFormattedMessage(null));
85 Assert.assertEquals("Should returned " + expectedMsg2,
86 expectedMsg2, oamCommandStatus.getFormattedMessage(params));
91 public void testToString() throws Exception {
92 for (OAMCommandStatus oamCommandStatus : OAMCommandStatus.values()) {
93 String expectedString = String.format(oamCommandStatus.TO_STRING_FORMAT,
94 CODE_MAP.get(oamCommandStatus), MSG_MAP.get(oamCommandStatus));
95 Assert.assertEquals(String.format("Should have string (%s).", expectedString),
96 expectedString, oamCommandStatus.toString());