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;
29 import org.junit.Test;
30 import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WsStringMessageClient;
31 import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WsStringMessageListener;
32 import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WsStringMessageServer;
33 import org.slf4j.ext.XLogger;
34 import org.slf4j.ext.XLoggerFactory;
37 * The Class EndToEndMessagingTest.
39 * @author Liam Fallon (liam.fallon@ericsson.com)
41 public class EndToEndStringMessagingTest {
42 // Logger for this class
43 private static final XLogger logger = XLoggerFactory.getXLogger(EndToEndStringMessagingTest.class);
45 private WsStringMessageServer server;
46 private WsStringMessageClient client;
48 private boolean finished = false;
51 public void testEndToEndMessaging() throws MessagingException {
52 logger.debug("end to end messaging test starting . . .");
53 server = new WsStringMessageServer(44441);
54 assertNotNull(server);
55 server.start(new WsStringServerMessageListener());
57 await().atMost(2, TimeUnit.SECONDS).until(() -> server.isStarted());
60 client = new WsStringMessageClient("localhost", 44441);
61 assertNotNull(client);
62 client.start(new WsStringClientMessageListener());
64 client.sendString("Hello, client here");
66 await().atLeast(50, TimeUnit.MILLISECONDS).until(() -> finished);
77 logger.debug("end to end messaging test finished");
80 private class WsStringServerMessageListener implements WsStringMessageListener {
82 public void receiveString(final String stringMessage) {
83 logger.debug(stringMessage);
84 assertEquals("Hello, client here", stringMessage);
85 server.sendString("Hello back from server");
89 private class WsStringClientMessageListener implements WsStringMessageListener {
91 public void receiveString(final String stringMessage) {
92 logger.debug(stringMessage);
93 assertEquals("Hello back from server", stringMessage);