7583ee0c428ceb3b9b5e2393229ce5642f9d2c96
[policy/drools-applications.git] / controlloop / common / model-impl / appclcm / src / test / java / org / onap / policy / appclcm / LcmResponseTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * appclcm
4  * ================================================================================
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.appclcm;
22
23 import static org.junit.Assert.assertFalse;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertNull;
26 import static org.junit.Assert.assertTrue;
27
28 import org.junit.Test;
29
30 public class LcmResponseTest {
31
32     private static final String PAYLOAD = "payload";
33
34     @Test
35     public void testHashCode() {
36         LcmResponse response = new LcmResponse();
37         assertTrue(response.hashCode() != 0);
38         response.setCommonHeader(new LcmCommonHeader());
39         assertTrue(response.hashCode() != 0);
40         response.setPayload(PAYLOAD);
41         assertTrue(response.hashCode() != 0);
42         response.setStatus(null);
43         assertTrue(response.hashCode() != 0);
44     }
45
46     @Test
47     public void testLcmResponse() {
48         LcmResponse response = new LcmResponse();
49         assertNull(response.getCommonHeader());
50         assertNull(response.getPayload());
51         assertNotNull(response.getStatus());
52     }
53
54     @Test
55     public void testToString() {
56         LcmResponse response = new LcmResponse();
57         assertFalse(response.toString().isEmpty());
58     }
59
60     @Test
61     public void testEqualsObject() {
62         LcmResponse response = new LcmResponse();
63         assertTrue(response.equals(response));
64         assertFalse(response.equals(null));
65         assertFalse(response.equals(new Object()));
66
67         LcmResponse response2 = new LcmResponse();
68         assertTrue(response.equals(response2));
69
70         response.setCommonHeader(new LcmCommonHeader());
71         assertFalse(response.equals(response2));
72         response2.setCommonHeader(response.getCommonHeader());
73         assertTrue(response.equals(response2));
74
75         response.setPayload(PAYLOAD);
76         assertFalse(response.equals(response2));
77         response2.setPayload(response.getPayload());
78         assertTrue(response.equals(response2));
79
80         response.setCommonHeader(null);
81         assertFalse(response.equals(response2));
82         response2.setCommonHeader(null);
83         assertTrue(response.equals(response2));
84
85         response.setPayload(null);
86         assertFalse(response.equals(response2));
87         response2.setPayload(response.getPayload());
88         assertTrue(response.equals(response2));
89
90         response.setStatus(null);
91         assertFalse(response.equals(response2));
92         response2.setStatus(response.getStatus());
93         assertTrue(response.equals(response2));
94
95         LcmResponseStatus status = new LcmResponseStatus();
96         status.setCode(5);
97         response.setStatus(status);
98         response2.setStatus(new LcmResponseStatus());
99         assertFalse(response.equals(response2));
100     }
101
102     @Test
103     public void testResponseRequest() {
104         LcmRequest request = new LcmRequest();
105         request.setCommonHeader(new LcmCommonHeader());
106         request.setPayload(PAYLOAD);
107
108         LcmResponse response = new LcmResponse(request);
109
110         assertTrue(response.getPayload().equals(PAYLOAD));
111     }
112
113 }