From 780268ec538e303bc5bd5c93e2b813e0d3dcbcc7 Mon Sep 17 00:00:00 2001 From: Joseph Chou Date: Tue, 17 Mar 2020 18:29:53 -0400 Subject: ONAP junit code update M2 junit failed on AppcLcmTest Issue-ID: POLICY-2435 Change-Id: I30a2db72b6b127857dc3db2aeda75e46fa919dcd Signed-off-by: Joseph Chou --- .../java/org/onap/policy/m2/test/AppcLcmTest.java | 33 ++++++++++++++++------ 1 file changed, 25 insertions(+), 8 deletions(-) (limited to 'controlloop/m2/test') 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 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(); -- cgit 1.2.3-korg