2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-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.infrastructure.messaging;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
26 import org.junit.Test;
27 import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WsStringMessageClient;
28 import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WsStringMessageListener;
29 import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WsStringMessageServer;
30 import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
31 import org.slf4j.ext.XLogger;
32 import org.slf4j.ext.XLoggerFactory;
35 * The Class EndToEndMessagingTest.
37 * @author Liam Fallon (liam.fallon@ericsson.com)
39 public class EndToEndStringMessagingTest {
40 // Logger for this class
41 private static final XLogger logger = XLoggerFactory.getXLogger(EndToEndStringMessagingTest.class);
43 private WsStringMessageServer server;
44 private WsStringMessageClient client;
46 private boolean finished = false;
49 public void testEndToEndMessaging() throws MessagingException {
50 logger.debug("end to end messaging test starting . . .");
51 server = new WsStringMessageServer(44441);
52 assertNotNull(server);
53 server.start(new WsStringServerMessageListener());
56 client = new WsStringMessageClient("localhost", 44441);
57 assertNotNull(client);
58 client.start(new WsStringClientMessageListener());
60 client.sendString("Hello, client here");
63 ThreadUtilities.sleep(50);
74 logger.debug("end to end messaging test finished");
77 private class WsStringServerMessageListener implements WsStringMessageListener {
79 public void receiveString(final String stringMessage) {
80 logger.debug(stringMessage);
81 assertEquals("Hello, client here", stringMessage);
82 server.sendString("Hello back from server");
86 private class WsStringClientMessageListener implements WsStringMessageListener {
88 public void receiveString(final String stringMessage) {
89 logger.debug(stringMessage);
90 assertEquals("Hello back from server", stringMessage);