2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2020 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.assertNotEquals;
26 import static org.junit.Assert.assertNotNull;
28 import org.junit.Test;
30 public class ResponseStatusTest {
32 private static final String THERE_S_NO_PLACE_LIKE_HOME = "There's no place like home";
33 private static final String THE_WONDERFUL_LAND_OF_OZ = "The wonderful land of Oz";
36 public void testResonseStatus() {
37 ResponseStatus status = new ResponseStatus();
38 assertNotNull(status);
39 assertNotEquals(0, status.hashCode());
42 assertEquals(1234, status.getCode());
44 status.setDescription(THE_WONDERFUL_LAND_OF_OZ);
45 assertEquals(THE_WONDERFUL_LAND_OF_OZ, status.getDescription());
47 status.setValue(THERE_S_NO_PLACE_LIKE_HOME);
48 assertEquals(THERE_S_NO_PLACE_LIKE_HOME, status.getValue());
49 assertNotEquals(0, status.hashCode());
51 assertEquals("ResponseStatus [Code=1234, Value=There's no pla", status.toString().substring(0, 47));
53 ResponseStatus copiedStatus = new ResponseStatus();
54 copiedStatus.setCode(status.getCode());
55 copiedStatus.setDescription(status.getDescription());
56 copiedStatus.setValue(status.getValue());
59 * Disabling sonar to test equals().
61 assertEquals(status, status); // NOSONAR
62 assertEquals(status, copiedStatus);
63 assertNotEquals(status, null);
64 assertNotEquals(status, "Hello"); // NOSONAR
67 assertNotEquals(status, copiedStatus);
68 copiedStatus.setCode(-1);
69 assertEquals(status, copiedStatus);
71 assertNotEquals(status, copiedStatus);
72 copiedStatus.setCode(1234);
73 assertEquals(status, copiedStatus);
75 status.setDescription(null);
76 assertNotEquals(status, copiedStatus);
77 copiedStatus.setDescription(null);
78 assertEquals(status, copiedStatus);
79 status.setDescription(THE_WONDERFUL_LAND_OF_OZ);
80 assertNotEquals(status, copiedStatus);
81 copiedStatus.setDescription(THE_WONDERFUL_LAND_OF_OZ);
82 assertEquals(status, copiedStatus);
84 status.setValue(null);
85 assertNotEquals(status, copiedStatus);
86 copiedStatus.setValue(null);
87 assertEquals(status, copiedStatus);
88 status.setValue(THERE_S_NO_PLACE_LIKE_HOME);
89 assertNotEquals(status, copiedStatus);
90 copiedStatus.setValue(THERE_S_NO_PLACE_LIKE_HOME);
91 assertEquals(status, copiedStatus);