ce0ba90a5387eb5d93fb9b2d0ac7ba8daf7e14c2
[policy/drools-applications.git] / controlloop / common / model-impl / appc / src / test / java / org / onap / policy / appc / ResponseTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * appc
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.appc;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertNotEquals;
26 import static org.junit.Assert.assertNotNull;
27 import static org.junit.Assert.assertTrue;
28
29 import java.util.HashMap;
30 import java.util.Map;
31
32 import org.junit.Test;
33
34 public class ResponseTest {
35
36     @Test
37     public void testResonse() {
38         Response response = new Response();
39         assertNotNull(response);
40         assertNotNull(new Response(new Request()));
41         assertNotEquals(0, response.hashCode());
42
43         CommonHeader commonHeader = new CommonHeader();
44
45         Request request = new Request();
46         request.setCommonHeader(commonHeader);
47         assertNotNull(new Response(request));
48
49         response.setCommonHeader(commonHeader);
50         assertEquals(commonHeader, response.getCommonHeader());
51
52         ResponseStatus status = new ResponseStatus();
53         response.setStatus(status);
54         assertEquals(status, response.getStatus());
55
56         Map<String, Object> payload = new HashMap<>();
57         payload.put("North", "Good Witch");
58         payload.put("West", "Bad Witch");
59
60         response.setPayload(payload);
61         assertEquals(payload, response.getPayload());
62
63         assertNotEquals(0, response.hashCode());
64
65         assertEquals("Response [CommonHeader=CommonHeader [TimeStamp=", response.toString().substring(0, 47));
66
67         Response copiedResponse = new Response();
68         copiedResponse.setCommonHeader(response.getCommonHeader());
69         copiedResponse.setStatus(response.getStatus());
70         copiedResponse.setPayload(response.getPayload());
71
72         assertTrue(response.equals(response));
73         assertTrue(response.equals(copiedResponse));
74         assertFalse(response.equals(null));
75         assertFalse(response.equals("Hello"));
76
77         response.setCommonHeader(null);
78         assertFalse(response.equals(copiedResponse));
79         copiedResponse.setCommonHeader(null);
80         assertTrue(response.equals(copiedResponse));
81         response.setCommonHeader(commonHeader);
82         assertFalse(response.equals(copiedResponse));
83         copiedResponse.setCommonHeader(commonHeader);
84         assertTrue(response.equals(copiedResponse));
85
86         response.setStatus(null);
87         assertFalse(response.equals(copiedResponse));
88         copiedResponse.setStatus(null);
89         assertTrue(response.equals(copiedResponse));
90         response.setStatus(status);
91         assertFalse(response.equals(copiedResponse));
92         copiedResponse.setStatus(status);
93         assertTrue(response.equals(copiedResponse));
94
95         response.setPayload(new HashMap<String, Object>());
96         assertFalse(response.equals(copiedResponse));
97         copiedResponse.setPayload(new HashMap<String, Object>());
98         assertTrue(response.equals(copiedResponse));
99         response.setPayload(payload);
100         assertFalse(response.equals(copiedResponse));
101         copiedResponse.setPayload(payload);
102         assertTrue(response.equals(copiedResponse));
103     }
104 }