2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
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.testsuites.integration.uservice.adapt.websocket;
24 import static org.junit.Assert.assertEquals;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.onap.policy.apex.core.infrastructure.messaging.MessagingException;
29 import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
30 import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
31 import org.onap.policy.apex.service.engine.main.ApexMain;
33 public class TestWs2WsClient {
34 private static final long MAX_TEST_LENGTH = 10000;
36 private static final int EVENT_COUNT = 100;
37 private static final int EVENT_INTERVAL = 20;
40 * Clear relative file root environment variable.
43 public void clearRelativeFileRoot() {
44 System.clearProperty("APEX_RELATIVE_FILE_ROOT");
48 public void testJsonWsEvents() throws MessagingException, ApexException {
49 final String[] args = {"-rfr", "target", "-p", "target/examples/config/SampleDomain/Ws2WsClientJsonEvent.json"};
50 testWsEvents(args, false);
54 public void testXmlWsEvents() throws MessagingException, ApexException {
55 final String[] args = {"-rfr", "target", "-p", "target/examples/config/SampleDomain/Ws2WsClientXMLEvent.json"};
56 testWsEvents(args, true);
59 private void testWsEvents(final String[] args, final Boolean xmlEvents) throws MessagingException, ApexException {
60 final WebSocketEventSubscriberServer subServer = new WebSocketEventSubscriberServer(42453);
61 final WebSocketEventProducerServer prodServer =
62 new WebSocketEventProducerServer(42451, EVENT_COUNT, xmlEvents, EVENT_INTERVAL);
64 final ApexMain apexMain = new ApexMain(args);
66 prodServer.sendEvents();
68 final long testStartTime = System.currentTimeMillis();
70 while (System.currentTimeMillis() < testStartTime + MAX_TEST_LENGTH
71 && subServer.getEventsReceivedCount() < EVENT_COUNT) {
72 ThreadUtilities.sleep(EVENT_INTERVAL);
75 assertEquals(prodServer.getEventsSentCount(), subServer.getEventsReceivedCount());
78 prodServer.shutdown();