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
50 @SuppressWarnings("unlikely-arg-type")
52 public void testResponse() throws UnknownHostException {
53 final AxArtifactKey responseKey = new AxArtifactKey("ResponseTest", "0.0.1");
54 final AxArtifactKey responseToKey = new AxArtifactKey("ResponseTestTo", "0.0.1");
55 UpdateModel responseTo = new UpdateModel(responseToKey);
57 Response message = new Response(responseKey, false, responseTo);
58 logger.debug(message.toString());
59 assertTrue(message.toString().contains("ResponseTest"));
60 assertFalse(message.isSuccessful());
62 message = new Response(responseKey, true, responseTo);
63 logger.debug(message.toString());
64 assertTrue(message.toString().contains("ResponseTest"));
65 assertTrue(message.isSuccessful());
66 assertEquals(responseTo, message.getResponseTo());
68 message = new Response(null, false, null);
69 assertNotEquals(0, message.hashCode());
70 message = new Response(responseKey, false, null);
71 assertNotEquals(0, message.hashCode());
72 message = new Response(responseKey, true, null);
73 assertNotEquals(0, message.hashCode());
74 message = new Response(responseKey, true, new UpdateModel(null));
75 assertNotEquals(0, message.hashCode());
76 // disabling sonar because this code tests the equals() method
77 assertEquals(message, message); // NOSONAR
78 assertNotNull(message);
79 assertNotEquals(message, new StartEngine(new AxArtifactKey()));
81 message = new Response(null, false, responseTo);
82 Response otherMessage = new Response(null, false, null);
83 assertNotEquals(message, otherMessage);
84 otherMessage = new Response(null, false, responseTo);
85 assertEquals(message, otherMessage);
86 message = new Response(null, false, null);
87 assertNotEquals(message, otherMessage);
88 otherMessage = new Response(null, false, null);
89 assertEquals(message, (otherMessage));
91 message = new Response(null, false, null);
92 otherMessage = new Response(null, true, null);
93 assertNotEquals(message, otherMessage);
94 otherMessage = new Response(null, false, null);
95 assertEquals(message, otherMessage);