269c4f81128ff6241e205d3f9201752acaaa7717
[appc.git] / appc-oam / appc-oam-bundle / src / test / java / org / openecomp / appc / oam / OAMCommandStatusTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
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
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
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.
20  * 
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.onap.appc.oam;
26
27 import org.junit.Assert;
28 import org.junit.Test;
29 import org.onap.appc.executor.objects.Params;
30
31 import java.util.HashMap;
32 import java.util.Map;
33
34 public class OAMCommandStatusTest {
35     private Map<OAMCommandStatus, Integer> CODE_MAP = new HashMap<OAMCommandStatus, Integer>() {
36         {
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);
44         }
45     };
46     private Map<OAMCommandStatus, String> MSG_MAP = new HashMap<OAMCommandStatus, String>() {
47         {
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}");
55         }
56     };
57
58     @Test
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());
64         }
65     }
66
67     @Test
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()));
73         }
74     }
75
76     @Test
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));
87         }
88     }
89
90     @Test
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());
97         }
98     }
99 }