summaryrefslogtreecommitdiffstats
path: root/services
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 /services
parent9f17d75f75dd087a58822dcc5aa2821267aa2193 (diff)
parent153ad0056c3928116d28eb7e1bb14c4a04a76fc2 (diff)
Merge "replace test sleep() with awaitality package"
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