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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.core.protocols.engdep.messages;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertTrue;
27 import java.net.UnknownHostException;
29 import org.junit.Test;
30 import org.onap.policy.apex.core.protocols.engdep.messages.Response;
31 import org.onap.policy.apex.core.protocols.engdep.messages.UpdateModel;
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 assertTrue(message.hashCode() != 0);
70 message = new Response(responseKey, false, null);
71 assertTrue(message.hashCode() != 0);
72 message = new Response(responseKey, true, null);
73 assertTrue(message.hashCode() != 0);
74 message = new Response(responseKey, true, new UpdateModel(null));
75 assertTrue(message.hashCode() != 0);
77 assertTrue(message.equals(message));
78 assertFalse(message.equals(null));
79 assertFalse(message.equals(new StartEngine(new AxArtifactKey())));
81 message = new Response(null, false, responseTo);
82 Response otherMessage = new Response(null, false, null);
83 assertFalse(message.equals(otherMessage));
84 otherMessage = new Response(null, false, responseTo);
85 assertTrue(message.equals(otherMessage));
86 message = new Response(null, false, null);
87 assertFalse(message.equals(otherMessage));
88 otherMessage = new Response(null, false, null);
89 assertTrue(message.equals(otherMessage));
91 message = new Response(null, false, null);
92 otherMessage = new Response(null, true, null);
93 assertFalse(message.equals(otherMessage));
94 otherMessage = new Response(null, false, null);
95 assertTrue(message.equals(otherMessage));