This is an automated email from the ASF dual-hosted git repository.
rabbah pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openwhisk.git
The following commit(s) were added to refs/heads/master by this push:
new 673d5c7 Revert "Remove unused test helpers" (#4685)
673d5c7 is described below
commit 673d5c7d4c3c50e449935482a29fbeb179d94747
Author: rodric rabbah <[email protected]>
AuthorDate: Sat Oct 12 03:49:57 2019 -0400
Revert "Remove unused test helpers" (#4685)
This reverts commit 15709b6768679e04d7cd269d99d73b52d003091a.
---
tests/src/test/scala/common/TestUtils.java | 52 ++++++++++++++++++++++++
tests/src/test/scala/common/WhiskProperties.java | 5 +++
2 files changed, 57 insertions(+)
diff --git a/tests/src/test/scala/common/TestUtils.java
b/tests/src/test/scala/common/TestUtils.java
index eb8f8cb..9fa1082 100644
--- a/tests/src/test/scala/common/TestUtils.java
+++ b/tests/src/test/scala/common/TestUtils.java
@@ -73,6 +73,7 @@ public class TestUtils {
private static final File catalogDir =
WhiskProperties.getFileRelativeToWhiskHome("catalog");
private static final File testActionsDir =
WhiskProperties.getFileRelativeToWhiskHome("tests/dat/actions");
private static final File testApiGwDir =
WhiskProperties.getFileRelativeToWhiskHome("tests/dat/apigw");
+ private static final File vcapFile = WhiskProperties.getVCAPServicesFile();
private static final String envServices = System.getenv("VCAP_SERVICES");
private static final String loggerLevel = System.getProperty("LOG_LEVEL",
Level.WARNING.toString());
@@ -112,6 +113,57 @@ public class TestUtils {
}
/**
+ * Gets the value of VCAP_SERVICES.
+ *
+ * @return VCAP_SERVICES as a JSON object
+ */
+ public static JsonObject getVCAPServices() {
+ try {
+ if (envServices != null) {
+ return new JsonParser().parse(envServices).getAsJsonObject();
+ } else {
+ return new JsonParser().parse(new
FileReader(vcapFile)).getAsJsonObject();
+ }
+ } catch (Throwable t) {
+ System.out.println("failed to parse VCAP" + t);
+ return new JsonObject();
+ }
+ }
+
+ /**
+ * Gets a VCAP_SERVICES credentials.
+ *
+ * @return VCAP credentials as a <String, String> map for each
+ * <property, value> pair in credentials
+ */
+ public static Map<String, String> getVCAPcredentials(String vcapService) {
+ try {
+ JsonObject credentials = getCredentials(vcapService);
+ Map<String, String> map = new HashMap<String, String>();
+ for (Map.Entry<String, JsonElement> entry :
credentials.entrySet()) {
+ map.put(entry.getKey(),
credentials.get(entry.getKey()).getAsString());
+ }
+
+ return map;
+ } catch (Throwable t) {
+ System.out.println("failed to parse VCAP" + t);
+ return Collections.emptyMap();
+ }
+ }
+
+ /**
+ * Gets a VCAP_SERVICES credentials as the json objects.
+ *
+ * @return VCAP credentials as a json object.
+ */
+ public static JsonObject getCredentials(String vcapService) {
+ JsonArray vcapArray =
getVCAPServices().get(vcapService).getAsJsonArray();
+ JsonObject vcapObject = vcapArray.get(0).getAsJsonObject();
+ JsonObject credentials =
vcapObject.get("credentials").getAsJsonObject();
+ return credentials;
+ }
+
+ /**
* Creates a JUnit test watcher. Use with @rule.
* @return a junit {@link TestWatcher} that prints a message when each
test starts and ends
*/
diff --git a/tests/src/test/scala/common/WhiskProperties.java
b/tests/src/test/scala/common/WhiskProperties.java
index ca08ec4..540d72c 100644
--- a/tests/src/test/scala/common/WhiskProperties.java
+++ b/tests/src/test/scala/common/WhiskProperties.java
@@ -47,6 +47,11 @@ public class WhiskProperties {
protected static final String WHISK_PROPS_FILE = "whisk.properties";
/**
+ * Default concurrency level if otherwise unspecified
+ */
+ private static final int DEFAULT_CONCURRENCY = 20;
+
+ /**
* If true, then tests will direct to the router rather than the edge
* components.
*/