summaryrefslogtreecommitdiffstats
path: root/controlloop
diff options
context:
space:
mode:
authorJoseph Chou <jc2555@att.com>2020-03-17 18:29:53 -0400
committerJoseph Chou <jc2555@att.com>2020-03-18 09:08:37 -0400
commit780268ec538e303bc5bd5c93e2b813e0d3dcbcc7 (patch)
tree2f73426ebd575ad5282c8437f54b1d402a5b0b70 /controlloop
parent01cbeec256bf5ec9e3ec2e7f599aef7eb4814ae3 (diff)
ONAP junit code update
M2 junit failed on AppcLcmTest Issue-ID: POLICY-2435 Change-Id: I30a2db72b6b127857dc3db2aeda75e46fa919dcd Signed-off-by: Joseph Chou <jc2555@att.com>
Diffstat (limited to 'controlloop')
-rw-r--r--controlloop/m2/test/src/test/java/org/onap/policy/m2/test/AppcLcmTest.java33
1 files changed, 25 insertions, 8 deletions
diff --git a/controlloop/m2/test/src/test/java/org/onap/policy/m2/test/AppcLcmTest.java b/controlloop/m2/test/src/test/java/org/onap/policy/m2/test/AppcLcmTest.java
index b0e859dbf..3298d7bde 100644
--- a/controlloop/m2/test/src/test/java/org/onap/policy/m2/test/AppcLcmTest.java
+++ b/controlloop/m2/test/src/test/java/org/onap/policy/m2/test/AppcLcmTest.java
@@ -21,6 +21,7 @@
package org.onap.policy.m2.test;
+import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertNotNull;
import static org.onap.policy.guard.Util.ONAP_KEY_PASS;
import static org.onap.policy.guard.Util.ONAP_KEY_URL;
@@ -32,9 +33,13 @@ import static org.onap.policy.m2.test.Util.json;
import com.google.gson.JsonObject;
import java.io.File;
+import java.time.Duration;
import java.util.Properties;
import java.util.UUID;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+import org.awaitility.Durations;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -149,8 +154,8 @@ public class AppcLcmTest {
dcae.send(req.msg);
// receive active notification, and restart operation
- assertSubset(json("notification", "ACTIVE"),
- notification.poll());
+ awaitAndAssert(5, Durations.TWO_HUNDRED_MILLISECONDS, notification,
+ json("notification", "ACTIVE"));
appcOperation(req, "Restart", 400, "Restart Successful");
@@ -159,8 +164,8 @@ public class AppcLcmTest {
dcae.send(req.msg);
// receive final success notification
- assertSubset(json("notification", "FINAL: SUCCESS"),
- notification.poll());
+ awaitAndAssert(5, Durations.TWO_HUNDRED_MILLISECONDS, notification,
+ json("notification", "FINAL: SUCCESS"));
// sleep to allow DB update
Thread.sleep(1000);
@@ -177,8 +182,8 @@ public class AppcLcmTest {
dcae.send(req.msg);
// active notification, and restart 1 operation
- assertSubset(json("notification", "ACTIVE"),
- notification.poll());
+ awaitAndAssert(5, Durations.TWO_HUNDRED_MILLISECONDS, notification,
+ json("notification", "ACTIVE"));
appcOperation(req, "Restart", 450, "Restart 1 Failed");
appcOperation(req, "Restart", 450, "Restart 2 Failed");
@@ -191,13 +196,25 @@ public class AppcLcmTest {
dcae.send(req.msg);
// receive final success notification
- assertSubset(json("notification", "FINAL: SUCCESS"),
- notification.poll());
+ awaitAndAssert(5, Durations.TWO_HUNDRED_MILLISECONDS, notification,
+ json("notification", "FINAL: SUCCESS"));
// sleep to allow DB update
Thread.sleep(1000);
}
+ private void awaitAndAssert(int maxWaitSecond, Duration pollIntervalMilli, Input notification,
+ JsonObject jsonObj) {
+ AtomicReference<JsonObject> obj = new AtomicReference<>();
+ await().atMost(maxWaitSecond, TimeUnit.SECONDS)
+ .with().pollInterval(pollIntervalMilli)
+ .until(() -> {
+ obj.set(notification.poll());
+ return obj.get() != null;
+ });
+ assertSubset(jsonObj, obj.get());
+ }
+
private void appcOperation(Request req, String name, int responseCode, String responseMessage)
throws Exception {
String lcName = name.toLowerCase();