Merge "Fix the bug of cannot return multiple versions of particular tosca policy...
[policy/models.git] / models-interactions / model-impl / appc / src / test / java / org / onap / policy / appc / ResponseStatusTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * appc
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
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  */
21
22 package org.onap.policy.appc;
23
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;
29
30 import org.junit.Test;
31
32 public class ResponseStatusTest {
33
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";
36
37     @Test
38     public void testResonseStatus() {
39         ResponseStatus status = new ResponseStatus();
40         assertNotNull(status);
41         assertNotEquals(0, status.hashCode());
42
43         status.setCode(1234);
44         assertEquals(1234, status.getCode());
45
46         status.setDescription(THE_WONDERFUL_LAND_OF_OZ);
47         assertEquals(THE_WONDERFUL_LAND_OF_OZ, status.getDescription());
48
49         status.setValue(THERE_S_NO_PLACE_LIKE_HOME);
50         assertEquals(THERE_S_NO_PLACE_LIKE_HOME, status.getValue());
51         assertNotEquals(0, status.hashCode());
52
53         assertEquals("ResponseStatus [Code=1234, Value=There's no pla", status.toString().substring(0, 47));
54
55         ResponseStatus copiedStatus = new ResponseStatus();
56         copiedStatus.setCode(status.getCode());
57         copiedStatus.setDescription(status.getDescription());
58         copiedStatus.setValue(status.getValue());
59
60         assertTrue(status.equals(status));
61         assertTrue(status.equals(copiedStatus));
62         assertFalse(status.equals(null));
63         assertFalse(status.equals("Hello"));
64
65         status.setCode(-1);
66         assertFalse(status.equals(copiedStatus));
67         copiedStatus.setCode(-1);
68         assertTrue(status.equals(copiedStatus));
69         status.setCode(1234);
70         assertFalse(status.equals(copiedStatus));
71         copiedStatus.setCode(1234);
72         assertTrue(status.equals(copiedStatus));
73
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));
82
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));
91     }
92 }