summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorHenry.Sun <henry.a.sun@est.tech>2020-03-02 15:47:09 +0800
committerHenry.Sun <henry.a.sun@est.tech>2020-03-04 12:02:42 +0800
commit153ad0056c3928116d28eb7e1bb14c4a04a76fc2 (patch)
tree00f973c22492c89633723dcb5f09b448973e9ba4 /services
parent27dcbd57cc04c45ba85ff6f4008ef2c1d8f7c050 (diff)
replace test sleep() with awaitality package
Signed-off-by: Henry.Sun <henry.a.sun@est.tech> Change-Id: I305771ddef42bd3032ad52f4c5ecd55b01ed5a1a Issue-ID: POLICY-1914 Signed-off-by: Henry.Sun <henry.a.sun@est.tech>
Diffstat (limited to 'services')
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexMainTest.java48
1 files changed, 16 insertions, 32 deletions
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexMainTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexMainTest.java
index 86ae99ec7..4b05c525c 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexMainTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexMainTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 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.
@@ -20,6 +21,7 @@
package org.onap.policy.apex.service.engine.main;
+import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -28,9 +30,10 @@ import java.io.OutputStream;
import java.io.PrintStream;
import java.util.HashMap;
import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
import org.junit.After;
import org.junit.Test;
-import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
import org.onap.policy.apex.service.parameters.ApexParameters;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier;
@@ -57,11 +60,8 @@ public class ApexMainTest {
System.setOut(new PrintStream(outContent));
ApexMain.main(null);
- ThreadUtilities.sleep(200);
-
- final String outString = outContent.toString();
-
- assertTrue(outString.contains("Apex configuration file was not specified as an argument"));
+ await().atMost(200, TimeUnit.MILLISECONDS).until(() -> outContent.toString()
+ .contains("Apex configuration file was not specified as an argument"));
}
@Test
@@ -72,12 +72,9 @@ public class ApexMainTest {
String[] args = { "-whee" };
final ApexMain apexMain = new ApexMain(args);
- ThreadUtilities.sleep(200);
+ await().atMost(200, TimeUnit.MILLISECONDS).until(() -> outContent.toString()
+ .contains("invalid command line arguments specified : Unrecognized option: -whee"));
apexMain.shutdown();
-
- final String outString = outContent.toString();
-
- assertTrue(outString.contains("invalid command line arguments specified : Unrecognized option: -whee"));
}
@Test
@@ -88,12 +85,9 @@ public class ApexMainTest {
String[] args = { "-h" };
final ApexMain apexMain = new ApexMain(args);
- ThreadUtilities.sleep(200);
+ await().atMost(200, TimeUnit.MILLISECONDS).until(() -> outContent.toString()
+ .contains("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
apexMain.shutdown();
-
- final String outString = outContent.toString();
-
- assertTrue(outString.contains("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
}
@Test
@@ -104,12 +98,9 @@ public class ApexMainTest {
String[] args = { "-c", "src/test/resources/parameters/badParams.json" };
final ApexMain apexMain = new ApexMain(args);
- ThreadUtilities.sleep(200);
+ await().atMost(200, TimeUnit.MILLISECONDS).until(() -> outContent.toString()
+ .contains("parameter group has status INVALID"));
apexMain.shutdown();
-
- final String outString = outContent.toString();
-
- assertTrue(outString.contains("parameter group has status INVALID"));
}
@Test
@@ -122,12 +113,9 @@ public class ApexMainTest {
final ApexMain apexMain = new ApexMain(args);
assertEquals("MyApexEngine",
apexMain.getApexParametersMap().values().iterator().next().getEngineServiceParameters().getName());
- ThreadUtilities.sleep(200);
+ await().atMost(200, TimeUnit.MILLISECONDS).until(() -> outContent.toString()
+ .contains("Added the action listener to the engine"));
apexMain.shutdown();
-
- final String outString = outContent.toString();
-
- assertTrue(outString.contains("Added the action listener to the engine"));
}
@Test
@@ -143,13 +131,9 @@ public class ApexMainTest {
assertEquals("trust-store-file", System.getProperty("javax.net.ssl.trustStore"));
assertEquals("Pol1cy_0nap", System.getProperty("javax.net.ssl.trustStorePassword"));
- ThreadUtilities.sleep(200);
+ await().atMost(10000, TimeUnit.MILLISECONDS).until(() -> outContent.toString()
+ .contains("Added the action listener to the engine"));
apexMain.shutdown();
-
- ThreadUtilities.sleep(10000);
- final String outString = outContent.toString();
-
- assertTrue(outString.contains("Added the action listener to the engine"));
}
@Test