2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2019 Nordix Foundation.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.appc;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertNotEquals;
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertTrue;
30 import org.junit.Test;
32 public class ResponseStatusTest {
34 private static final String THERE_S_NO_PLACE_LIKE_HOME = "There's no place like home";
35 private static final String THE_WONDERFUL_LAND_OF_OZ = "The wonderful land of Oz";
38 public void testResonseStatus() {
39 ResponseStatus status = new ResponseStatus();
40 assertNotNull(status);
41 assertNotEquals(0, status.hashCode());
44 assertEquals(1234, status.getCode());
46 status.setDescription(THE_WONDERFUL_LAND_OF_OZ);
47 assertEquals(THE_WONDERFUL_LAND_OF_OZ, status.getDescription());
49 status.setValue(THERE_S_NO_PLACE_LIKE_HOME);
50 assertEquals(THERE_S_NO_PLACE_LIKE_HOME, status.getValue());
51 assertNotEquals(0, status.hashCode());
53 assertEquals("ResponseStatus [Code=1234, Value=There's no pla", status.toString().substring(0, 47));
55 ResponseStatus copiedStatus = new ResponseStatus();
56 copiedStatus.setCode(status.getCode());
57 copiedStatus.setDescription(status.getDescription());
58 copiedStatus.setValue(status.getValue());
60 assertTrue(status.equals(status));
61 assertTrue(status.equals(copiedStatus));
62 assertFalse(status.equals(null));
63 assertFalse(status.equals("Hello"));
66 assertFalse(status.equals(copiedStatus));
67 copiedStatus.setCode(-1);
68 assertTrue(status.equals(copiedStatus));
70 assertFalse(status.equals(copiedStatus));
71 copiedStatus.setCode(1234);
72 assertTrue(status.equals(copiedStatus));
74 status.setDescription(null);
75 assertFalse(status.equals(copiedStatus));
76 copiedStatus.setDescription(null);
77 assertTrue(status.equals(copiedStatus));
78 status.setDescription(THE_WONDERFUL_LAND_OF_OZ);
79 assertFalse(status.equals(copiedStatus));
80 copiedStatus.setDescription(THE_WONDERFUL_LAND_OF_OZ);
81 assertTrue(status.equals(copiedStatus));
83 status.setValue(null);
84 assertFalse(status.equals(copiedStatus));
85 copiedStatus.setValue(null);
86 assertTrue(status.equals(copiedStatus));
87 status.setValue(THERE_S_NO_PLACE_LIKE_HOME);
88 assertFalse(status.equals(copiedStatus));
89 copiedStatus.setValue(THERE_S_NO_PLACE_LIKE_HOME);
90 assertTrue(status.equals(copiedStatus));