aboutsummaryrefslogtreecommitdiffstats
path: root/PolicyEngineAPI/src/test/java/org/onap
diff options
context:
space:
mode:
authorpa834y <pa834y@att.com>2018-04-26 15:26:26 -0400
committerpa834y <pa834y@att.com>2018-04-26 15:27:12 -0400
commit3eab022023bd68eee6743e30dd7db21c256bf00b (patch)
treeec29335476ae24e37298158a6d49de984baf2fec /PolicyEngineAPI/src/test/java/org/onap
parent9562f3b5dfc5613629b5119cb629c81005d93431 (diff)
Incorporate Liam code review
Change-Id: I387a54b8bd8c619c521c512258928669a8c1b791 Issue-ID: POLICY-756 Signed-off-by: pa834y <pa834y@att.com>
Diffstat (limited to 'PolicyEngineAPI/src/test/java/org/onap')
-rw-r--r--PolicyEngineAPI/src/test/java/org/onap/policy/std/test/AutoClientEndTest.java37
-rw-r--r--PolicyEngineAPI/src/test/java/org/onap/policy/std/test/ManualClientEndTest.java16
2 files changed, 29 insertions, 24 deletions
diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/std/test/AutoClientEndTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/std/test/AutoClientEndTest.java
index 4f1ce6f59..5056fceb7 100644
--- a/PolicyEngineAPI/src/test/java/org/onap/policy/std/test/AutoClientEndTest.java
+++ b/PolicyEngineAPI/src/test/java/org/onap/policy/std/test/AutoClientEndTest.java
@@ -21,12 +21,11 @@
package org.onap.policy.std.test;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
import org.java_websocket.WebSocket;
import org.java_websocket.handshake.ClientHandshake;
import org.java_websocket.server.WebSocketServer;
@@ -37,7 +36,6 @@ import org.onap.policy.api.NotificationHandler;
import org.onap.policy.api.NotificationScheme;
import org.onap.policy.api.PDPNotification;
import org.onap.policy.std.AutoClientEnd;
-import org.onap.policy.std.StdPDPNotification;
import org.springframework.util.SocketUtils;
/**
@@ -47,9 +45,9 @@ import org.springframework.util.SocketUtils;
public class AutoClientEndTest {
private static WebSocketServer ws;
- private static int port = 18080;
+ private static int port = SocketUtils.findAvailableTcpPort();
private static CountDownLatch countServerDownLatch = null;
- private StdPDPNotification notification = null;
+ private static PDPNotification notification = null;
/**
* Start server.
@@ -58,8 +56,8 @@ public class AutoClientEndTest {
*/
@BeforeClass
public static void startServer() throws Exception {
- port = SocketUtils.findAvailableTcpPort();
- ws = new WebSocketServer(new InetSocketAddress(port), 16) {
+ notification = null;
+ ws = new WebSocketServer(new InetSocketAddress(port), 1) {
@Override
public void onOpen(WebSocket conn, ClientHandshake handshake) {
conn.send("{\"removedPolicies\": [],\"loadedPolicies\": "
@@ -91,7 +89,7 @@ public class AutoClientEndTest {
};
- ws.setConnectionLostTimeout(30);
+ ws.setConnectionLostTimeout(0);
ws.start();
}
@@ -102,8 +100,8 @@ public class AutoClientEndTest {
NotificationHandler handler = new NotificationHandler() {
@Override
- public void notificationReceived(PDPNotification notifi) {
- notification = (StdPDPNotification) notifi;
+ public void notificationReceived(PDPNotification notify) {
+ notification = notify;
countServerDownLatch.countDown();
}
@@ -113,17 +111,26 @@ public class AutoClientEndTest {
countServerDownLatch = new CountDownLatch(1);
AutoClientEnd.start("http://localhost:" + port + "/");
- countServerDownLatch.await();
+ countServerDownLatch.await(45, TimeUnit.SECONDS);
+
+ assertNotNull(notification);
+
+ // simulate a server restart and verify client reconnects
+ countServerDownLatch = new CountDownLatch(1);
+ ws.stop(30000);
+ startServer();
+ countServerDownLatch.await(60+10, TimeUnit.SECONDS);
assertNotNull(notification);
- assertTrue(AutoClientEnd.getStatus());
+
+ AutoClientEnd.stop();
+
}
@AfterClass
- public static void successTests() throws InterruptedException, IOException {
- AutoClientEnd.stop();
- ws.stop();
+ public static void stopServer() throws InterruptedException, IOException {
+ ws.stop(30000);
}
diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/std/test/ManualClientEndTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/std/test/ManualClientEndTest.java
index 4a09164b5..252fa7e70 100644
--- a/PolicyEngineAPI/src/test/java/org/onap/policy/std/test/ManualClientEndTest.java
+++ b/PolicyEngineAPI/src/test/java/org/onap/policy/std/test/ManualClientEndTest.java
@@ -27,6 +27,7 @@ import static org.junit.Assert.fail;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
import org.java_websocket.WebSocket;
import org.java_websocket.handshake.ClientHandshake;
import org.java_websocket.server.WebSocketServer;
@@ -40,13 +41,11 @@ import org.springframework.util.SocketUtils;
/**
* The class <code>ManualClientEndTest</code> contains tests for the class <code>{@link ManualClientEnd}</code>.
*
- * @generatedBy CodePro at 6/1/16 1:41 PM
- * @version $Revision: 1.0 $
*/
public class ManualClientEndTest {
private static WebSocketServer ws;
- private static int port = 18080;
+ private static int port = SocketUtils.findAvailableTcpPort();
private static CountDownLatch countServerDownLatch = null;
private static String recvMsg = null;
@@ -57,8 +56,7 @@ public class ManualClientEndTest {
*/
@BeforeClass
public static void startServer() throws Exception {
- port = SocketUtils.findAvailableTcpPort();
- ws = new WebSocketServer(new InetSocketAddress(port), 16) {
+ ws = new WebSocketServer(new InetSocketAddress(port), 1) {
@Override
public void onOpen(WebSocket conn, ClientHandshake handshake) {
@@ -93,16 +91,16 @@ public class ManualClientEndTest {
};
- ws.setConnectionLostTimeout(30);
+ ws.setConnectionLostTimeout(0);
ws.start();
}
@Test
- public void testAutoClient() throws Exception {
+ public void testManualClient() throws Exception {
countServerDownLatch = new CountDownLatch(1);
ManualClientEnd.start("http://localhost:" + port + "/");
- countServerDownLatch.await();
+ countServerDownLatch.await(45, TimeUnit.SECONDS);
assertNotNull(ManualClientEnd.result(NotificationScheme.MANUAL_ALL_NOTIFICATIONS));
assertTrue("Manual".equalsIgnoreCase(recvMsg));
@@ -110,6 +108,6 @@ public class ManualClientEndTest {
@AfterClass
public static void successTests() throws InterruptedException, IOException {
- ws.stop();
+ ws.stop(30000);
}
}