2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * Modifications Copyright (C) 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.infrastructure.messaging;
24 import static org.awaitility.Awaitility.await;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertNotNull;
28 import java.util.concurrent.TimeUnit;
30 import org.junit.Test;
31 import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WsStringMessageClient;
32 import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WsStringMessageListener;
33 import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WsStringMessageServer;
34 import org.slf4j.ext.XLogger;
35 import org.slf4j.ext.XLoggerFactory;
38 * The Class EndToEndMessagingTest.
40 * @author Liam Fallon (liam.fallon@ericsson.com)
42 public class EndToEndStringMessagingTest {
43 // Logger for this class
44 private static final XLogger logger = XLoggerFactory.getXLogger(EndToEndStringMessagingTest.class);
46 private WsStringMessageServer server;
47 private WsStringMessageClient client;
49 private boolean finished = false;
52 public void testEndToEndMessaging() throws MessagingException {
53 logger.debug("end to end messaging test starting . . .");
54 server = new WsStringMessageServer(44441);
55 assertNotNull(server);
56 server.start(new WsStringServerMessageListener());
58 await().atMost(2, TimeUnit.SECONDS).until(() -> server.isStarted());
61 client = new WsStringMessageClient("localhost", 44441);
62 assertNotNull(client);
63 client.start(new WsStringClientMessageListener());
65 client.sendString("Hello, client here");
67 await().atLeast(50, TimeUnit.MILLISECONDS).until(() -> finished);
78 logger.debug("end to end messaging test finished");
81 private class WsStringServerMessageListener implements WsStringMessageListener {
83 public void receiveString(final String stringMessage) {
84 logger.debug(stringMessage);
85 assertEquals("Hello, client here", stringMessage);
86 server.sendString("Hello back from server");
90 private class WsStringClientMessageListener implements WsStringMessageListener {
92 public void receiveString(final String stringMessage) {
93 logger.debug(stringMessage);
94 assertEquals("Hello back from server", stringMessage);