aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test
diff options
context:
space:
mode:
authorLiam Fallon <liam.fallon@est.tech>2020-03-04 13:32:27 +0000
committerGerrit Code Review <gerrit@onap.org>2020-03-04 13:32:27 +0000
commita9b60303e7e3699cc4df904144592ea6a9b6c586 (patch)
tree1b710f2f899598d3032a6485db54c2e4a8cc92a2 /plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test
parent9f17d75f75dd087a58822dcc5aa2821267aa2193 (diff)
parent153ad0056c3928116d28eb7e1bb14c4a04a76fc2 (diff)
Merge "replace test sleep() with awaitality package"
Diffstat (limited to 'plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test')
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConusmerTest.java29
1 files changed, 13 insertions, 16 deletions
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConusmerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConusmerTest.java
index 6face9e50..3341082c0 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConusmerTest.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConusmerTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@
package org.onap.policy.apex.plugins.event.carrier.restclient;
+import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -28,6 +29,7 @@ import static org.junit.Assert.fail;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
+import java.util.concurrent.TimeUnit;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.Invocation.Builder;
@@ -39,7 +41,6 @@ import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
-import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
import org.onap.policy.apex.service.engine.event.ApexEventException;
import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters;
import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode;
@@ -119,7 +120,7 @@ public class ApexRestClientConusmerTest {
// We have not set the URL, this test should not receive any events
arcc.start();
- ThreadUtilities.sleep(200);
+ await().atMost(200, TimeUnit.MILLISECONDS).until(() -> incomingEventReceiver.getEventCount() == 0);
arcc.stop();
assertEquals(0, incomingEventReceiver.getEventCount());
@@ -127,7 +128,7 @@ public class ApexRestClientConusmerTest {
// We have not set the URL, this test should not receive any events
arcc.start();
- ThreadUtilities.sleep(200);
+ await().atMost(200, TimeUnit.MILLISECONDS).until(() -> incomingEventReceiver.getEventCount() == 0);
arcc.stop();
assertEquals(0, incomingEventReceiver.getEventCount());
}
@@ -169,7 +170,7 @@ public class ApexRestClientConusmerTest {
// We have not set the URL, this test should not receive any events
arcc.start();
- ThreadUtilities.sleep(200);
+ await().atMost(200, TimeUnit.MILLISECONDS).until(() -> incomingEventReceiver.getEventCount() == 0);
arcc.stop();
assertEquals(0, incomingEventReceiver.getEventCount());
}
@@ -214,14 +215,10 @@ public class ApexRestClientConusmerTest {
// We have not set the URL, this test should not receive any events
arcc.start();
- ThreadUtilities.sleep(200);
+ await().atMost(400, TimeUnit.MILLISECONDS).until(() -> outContent.toString()
+ .contains("received an empty event from URL \"http://some.place.that.does.not/exist\""));
arcc.stop();
-
assertEquals(0, incomingEventReceiver.getEventCount());
-
- final String outString = outContent.toString();
-
- assertTrue(outString.contains("received an empty event from URL \"http://some.place.that.does.not/exist\""));
}
@Test
@@ -261,7 +258,8 @@ public class ApexRestClientConusmerTest {
// We have not set the URL, this test should not receive any events
arcc.start();
- ThreadUtilities.sleep(200);
+ await().atMost(200, TimeUnit.MILLISECONDS).until(() -> outContent.toString()
+ .contains("received an empty event from URL \"http://some.place.that.does.not/exist\""));
arcc.stop();
assertEquals(0, incomingEventReceiver.getEventCount());
@@ -305,10 +303,9 @@ public class ApexRestClientConusmerTest {
// We have not set the URL, this test should not receive any events
arcc.start();
- ThreadUtilities.sleep(200);
+ await().atMost(400, TimeUnit.MILLISECONDS).until(
+ () -> incomingEventReceiver.getLastEvent().equals("This is an event"));
arcc.stop();
-
- assertEquals("This is an event", incomingEventReceiver.getLastEvent());
}
@Test
@@ -349,7 +346,7 @@ public class ApexRestClientConusmerTest {
try {
// We have not set the URL, this test should not receive any events
arcc.start();
- ThreadUtilities.sleep(200);
+ await().atMost(200, TimeUnit.MILLISECONDS).until(() -> incomingEventReceiver.getEventCount() == 0);
arcc.stop();
} catch (Exception e) {
// test invalid status code