Changes for checkstyle 8.32
[policy/apex-pdp.git] / core / core-protocols / src / test / java / org / onap / policy / apex / core / protocols / engdep / messages / ResponseTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2018 Ericsson. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.apex.core.protocols.engdep.messages;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertTrue;
26
27 import java.net.UnknownHostException;
28 import org.junit.Test;
29 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
30 import org.slf4j.ext.XLogger;
31 import org.slf4j.ext.XLoggerFactory;
32
33 /**
34  * The Class ResponseTest.
35  *
36  * @author Liam Fallon (liam.fallon@ericsson.com)
37  */
38 public class ResponseTest {
39     // Logger for this class
40     private static final XLogger logger = XLoggerFactory.getXLogger(ResponseTest.class);
41
42     /**
43      * Test response.
44      *
45      * @throws UnknownHostException the unknown host exception
46      */
47     @SuppressWarnings("unlikely-arg-type")
48     @Test
49     public void testResponse() throws UnknownHostException {
50         final AxArtifactKey responseKey = new AxArtifactKey("ResponseTest", "0.0.1");
51         final AxArtifactKey responseToKey = new AxArtifactKey("ResponseTestTo", "0.0.1");
52         UpdateModel responseTo = new UpdateModel(responseToKey);
53         
54         Response message = new Response(responseKey, false, responseTo);
55         logger.debug(message.toString());
56         assertTrue(message.toString().contains("ResponseTest"));
57         assertFalse(message.isSuccessful());
58
59         message = new Response(responseKey, true, responseTo);
60         logger.debug(message.toString());
61         assertTrue(message.toString().contains("ResponseTest"));
62         assertTrue(message.isSuccessful());
63         assertEquals(responseTo, message.getResponseTo());
64
65         message = new Response(null, false, null);
66         assertTrue(message.hashCode() != 0);
67         message = new Response(responseKey, false, null);
68         assertTrue(message.hashCode() != 0);
69         message = new Response(responseKey, true, null);
70         assertTrue(message.hashCode() != 0);
71         message = new Response(responseKey, true, new UpdateModel(null));
72         assertTrue(message.hashCode() != 0);
73         
74         assertTrue(message.equals(message));
75         assertFalse(message.equals(null));
76         assertFalse(message.equals(new StartEngine(new AxArtifactKey())));
77
78         message = new Response(null, false, responseTo);
79         Response otherMessage = new Response(null, false, null);
80         assertFalse(message.equals(otherMessage));
81         otherMessage = new Response(null, false, responseTo);
82         assertTrue(message.equals(otherMessage));
83         message = new Response(null, false, null);
84         assertFalse(message.equals(otherMessage));
85         otherMessage = new Response(null, false, null);
86         assertTrue(message.equals(otherMessage));
87         
88         message = new Response(null, false, null);
89         otherMessage = new Response(null, true, null);
90         assertFalse(message.equals(otherMessage));
91         otherMessage = new Response(null, false, null);
92         assertTrue(message.equals(otherMessage));
93     }
94 }