2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (C) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.std.test;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertNull;
27 import static org.junit.Assert.assertTrue;
28 import java.io.IOException;
29 import java.net.InetSocketAddress;
30 import java.util.concurrent.CountDownLatch;
31 import java.util.concurrent.TimeUnit;
32 import org.java_websocket.WebSocket;
33 import org.java_websocket.handshake.ClientHandshake;
34 import org.java_websocket.server.WebSocketServer;
35 import org.junit.AfterClass;
36 import org.junit.BeforeClass;
37 import org.junit.Test;
38 import org.onap.policy.api.NotificationScheme;
39 import org.onap.policy.std.ManualClientEnd;
42 * The class <code>ManualClientEndTest</code> contains tests for the class
43 * <code>{@link ManualClientEnd}</code>.
46 public class ManualClientEndTest {
47 private static WebSocketServer ws;
49 private static int port;
50 private static volatile String recvMsg = null;
51 private static volatile Exception webEx = null;
56 * @throws Exception the exception
59 public static void startServer() throws Exception {
61 CountDownLatch latch = new CountDownLatch(1);
63 ws = new WebSocketServer(new InetSocketAddress(0), 1) {
65 public void onOpen(WebSocket conn, ClientHandshake handshake) {}
68 public void onClose(WebSocket conn, int code, String reason, boolean remote) {}
71 public void onMessage(WebSocket conn, String message) {
73 // NOTE: must copy to recvMsg BEFORE invoking conn.send()
76 conn.send("{\"removedPolicies\": [],\"loadedPolicies\":"
77 + "[{\"policyName\": \"Test.Config_BRMS_Param_BrmsParamTestPa.1.xml\","
78 + "\"versionNo\": \"1\",\"matches\": {\"ECOMPName\": \"DROOLS\","
79 + "\"ONAPName\": \"DROOLS\",\"ConfigName\": \"BRMS_PARAM_RULE\","
80 + "\"guard\": \"false\",\"TTLDate\": \"NA\",\"RiskLevel\": \"5\","
81 + "\"RiskType\": \"default\"},\"updateType\": \"NEW\"}],"
82 + "\"notificationType\": \"UPDATE\"}");
86 public void onError(WebSocket conn, Exception ex) {
93 public void onStart() {
98 ws.setConnectionLostTimeout(0);
99 ws.setReuseAddr(true);
102 // ensure port connected (or error) before running the actual test
103 latch.await(20, TimeUnit.SECONDS);
105 // ensure no error during start-up
112 public void testManualClient() throws Exception {
113 ManualClientEnd.start("http://localhost:" + port + "/");
115 assertNotNull(ManualClientEnd.result(NotificationScheme.MANUAL_ALL_NOTIFICATIONS));
116 assertTrue("Manual".equalsIgnoreCase(recvMsg));
120 public static void successTests() throws InterruptedException, IOException {