2f6c7f8ba17f5f9d69f30f2befd8791fc12077ff
[policy/models.git] / models-interactions / model-impl / sdnr / src / test / java / org / onap / policy / sdnr / PciStatusTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * sdnr
4  * ================================================================================
5  * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2019 Nordix Foundation.
7  * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
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  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.policy.sdnr;
24
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertNotEquals;
27 import static org.junit.Assert.assertNotNull;
28
29 import org.junit.Test;
30
31 public class PciStatusTest {
32
33     private static final String THE_WONDERFUL_LAND_OF_OZ = "The wonderful land of Oz";
34
35     @Test
36     public void testResponseStatus() {
37         Status status = new Status();
38         assertNotNull(status);
39         assertNotEquals(0, status.hashCode());
40
41         status.setCode(1234);
42         assertEquals(1234, status.getCode());
43
44         status.setValue(THE_WONDERFUL_LAND_OF_OZ);
45         assertEquals(THE_WONDERFUL_LAND_OF_OZ, status.getValue());
46
47         assertEquals("Status [code = 1234, value = The wonderfu", status.toString().substring(0, 41));
48
49         Status copiedStatus = new Status();
50         copiedStatus.setCode(status.getCode());
51         copiedStatus.setValue(status.getValue());
52
53         /*
54          * Disabling sonar to test equals().
55          */
56         assertEquals(status, status);           // NOSONAR
57         assertEquals(status, copiedStatus);
58         assertNotEquals(status, null);
59         assertNotEquals(status, "Hello");       // NOSONAR
60
61         status.setCode(-1);
62         assertNotEquals(status, copiedStatus);
63         copiedStatus.setCode(-1);
64         assertEquals(status, copiedStatus);
65         status.setCode(1234);
66         assertNotEquals(status, copiedStatus);
67         copiedStatus.setCode(1234);
68         assertEquals(status, copiedStatus);
69
70         status.setValue(null);
71         assertNotEquals(status, copiedStatus);
72         copiedStatus.setValue(null);
73         assertEquals(status, copiedStatus);
74         status.setValue(THE_WONDERFUL_LAND_OF_OZ);
75         assertNotEquals(status, copiedStatus);
76         copiedStatus.setValue(THE_WONDERFUL_LAND_OF_OZ);
77         assertEquals(status, copiedStatus);
78     }
79 }