2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2018 Ericsson. All rights reserved.
4 * Modifications Copyright (C) 2019-2020 Nordix Foundation.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.apex.core.protocols.engdep.messages;
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;
30 import java.net.UnknownHostException;
31 import org.junit.Test;
32 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
33 import org.slf4j.ext.XLogger;
34 import org.slf4j.ext.XLoggerFactory;
37 * The Class ResponseTest.
39 * @author Liam Fallon (liam.fallon@ericsson.com)
41 public class ResponseTest {
42 // Logger for this class
43 private static final XLogger logger = XLoggerFactory.getXLogger(ResponseTest.class);
48 * @throws UnknownHostException the unknown host exception
51 public void testResponse() throws UnknownHostException {
52 final AxArtifactKey responseKey = new AxArtifactKey("ResponseTest", "0.0.1");
53 final AxArtifactKey responseToKey = new AxArtifactKey("ResponseTestTo", "0.0.1");
54 UpdateModel responseTo = new UpdateModel(responseToKey);
56 Response message = new Response(responseKey, false, responseTo);
57 logger.debug(message.toString());
58 assertTrue(message.toString().contains("ResponseTest"));
59 assertFalse(message.isSuccessful());
61 message = new Response(responseKey, true, responseTo);
62 logger.debug(message.toString());
63 assertTrue(message.toString().contains("ResponseTest"));
64 assertTrue(message.isSuccessful());
65 assertEquals(responseTo, message.getResponseTo());
67 message = new Response(null, false, null);
68 assertNotEquals(0, message.hashCode());
69 message = new Response(responseKey, false, null);
70 assertNotEquals(0, message.hashCode());
71 message = new Response(responseKey, true, null);
72 assertNotEquals(0, message.hashCode());
73 message = new Response(responseKey, true, new UpdateModel(null));
74 assertNotEquals(0, message.hashCode());
75 // disabling sonar because this code tests the equals() method
76 assertEquals(message, message); // NOSONAR
77 assertNotNull(message);
78 assertNotEquals(message, (Object) new StartEngine(new AxArtifactKey()));
80 message = new Response(null, false, responseTo);
81 Response otherMessage = new Response(null, false, null);
82 assertNotEquals(message, otherMessage);
83 otherMessage = new Response(null, false, responseTo);
84 assertEquals(message, otherMessage);
85 message = new Response(null, false, null);
86 assertNotEquals(message, otherMessage);
87 otherMessage = new Response(null, false, null);
88 assertEquals(message, (otherMessage));
90 message = new Response(null, false, null);
91 otherMessage = new Response(null, true, null);
92 assertNotEquals(message, otherMessage);
93 otherMessage = new Response(null, false, null);
94 assertEquals(message, otherMessage);