Skip to content

Commit 015e866

Browse files
committed
RUN-1799: added RuntimeConfigTest.java
1 parent 97dbf3b commit 015e866

File tree

3 files changed

+191
-6
lines changed

3 files changed

+191
-6
lines changed

src/test/java/com/openfin/desktop/AllTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
*/
1111

1212
@RunWith(Suite.class)
13-
@Suite.SuiteClasses({ ApplicationTest.class, OpenFinRuntimeTest.class, WindowTest.class, SystemTest.class, InterApplicationBusTest.class})
13+
@Suite.SuiteClasses({ ApplicationTest.class, OpenFinRuntimeTest.class, WindowTest.class, SystemTest.class, InterApplicationBusTest.class, RuntimeConfigTest.class})
1414
public class AllTests {
1515
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
package com.openfin.desktop;
2+
3+
import org.json.JSONArray;
4+
import org.json.JSONObject;
5+
import org.junit.AfterClass;
6+
import org.junit.BeforeClass;
7+
import org.junit.Test;
8+
import org.slf4j.Logger;
9+
import org.slf4j.LoggerFactory;
10+
11+
import java.util.UUID;
12+
import java.util.concurrent.CountDownLatch;
13+
import java.util.concurrent.TimeUnit;
14+
import java.util.concurrent.atomic.AtomicReference;
15+
16+
import static junit.framework.Assert.assertEquals;
17+
18+
/**
19+
* Created by richard on 4/1/2016.
20+
*/
21+
public class RuntimeConfigTest {
22+
private static Logger logger = LoggerFactory.getLogger(RuntimeConfigTest.class.getName());
23+
24+
private static final String DESKTOP_UUID = RuntimeConfigTest.class.getName();
25+
private static DesktopConnection desktopConnection;
26+
private static RuntimeConfiguration configuration;
27+
private static String appUUID = UUID.randomUUID().toString();
28+
29+
@BeforeClass
30+
public static void setup() throws Exception {
31+
logger.debug("starting");
32+
configuration = getRuntimeConfiguration();
33+
desktopConnection = TestUtils.setupConnection(DESKTOP_UUID, configuration);
34+
}
35+
36+
private static RuntimeConfiguration getRuntimeConfiguration() {
37+
RuntimeConfiguration configuration = new RuntimeConfiguration();
38+
configuration.setRuntimeVersion(TestUtils.getRuntimeVersion());
39+
configuration.setDevToolsPort(9090);
40+
configuration.setAdditionalRuntimeArguments("--v=1");
41+
42+
JSONObject startupApp = new JSONObject();
43+
startupApp.put("name", "TVBWebTest");
44+
startupApp.put("uuid", appUUID);
45+
startupApp.put("url", TestUtils.openfin_app_url);
46+
startupApp.put("applicationIcon", TestUtils.icon_url);
47+
startupApp.put("autoShow", true);
48+
startupApp.put("defaultTop", 100);
49+
startupApp.put("defaultLeft", 100);
50+
startupApp.put("defaultWidth", 200);
51+
startupApp.put("defaultHeight", 200);
52+
startupApp.put("delay_connection", true);
53+
startupApp.put("frame", true);
54+
startupApp.put("saveWindowState", false);
55+
configuration.setStartupApp(startupApp);
56+
57+
return configuration;
58+
}
59+
60+
@AfterClass
61+
public static void teardown() throws Exception {
62+
TestUtils.teardownDesktopConnection(desktopConnection);
63+
}
64+
65+
@Test
66+
public void launchFromConfig() throws Exception {
67+
CountDownLatch latch = new CountDownLatch(1);
68+
AtomicReference<Boolean> atomicReference = new AtomicReference<>();
69+
atomicReference.set(true);
70+
// check for startup app
71+
Thread waitThread = new Thread() {
72+
public void run() {
73+
while (atomicReference.get()) {
74+
try {
75+
if (isWindowCreated(appUUID)) {
76+
latch.countDown();
77+
atomicReference.set(false);
78+
} else {
79+
Thread.sleep(1000);
80+
}
81+
} catch (Exception ex) {
82+
logger.error("Error waiting for checking window list", ex);
83+
}
84+
}
85+
}
86+
};
87+
waitThread.start();
88+
89+
latch.await(10, TimeUnit.SECONDS);
90+
atomicReference.set(false);
91+
assertEquals(latch.getCount(), 0);
92+
}
93+
94+
private boolean isWindowCreated(String uuid) throws Exception {
95+
CountDownLatch latch = new CountDownLatch(1);
96+
AtomicReference<Boolean> atomicReference = new AtomicReference<>();
97+
atomicReference.set(false);
98+
OpenFinRuntime runtime = new OpenFinRuntime(desktopConnection);
99+
runtime.getAllWindows(new AckListener() {
100+
@Override
101+
public void onSuccess(Ack ack) {
102+
if (ack.isSuccessful()) {
103+
JSONArray data = (JSONArray) ack.getData();
104+
logger.debug(String.format("All windows info %s", data.toString()));
105+
for (int i = 0; i < data.length(); i++) {
106+
JSONObject window = data.getJSONObject(i);
107+
if (window.has("uuid") && window.has("mainWindow") && window.getString("uuid").equals(uuid)) {
108+
atomicReference.set(true);
109+
}
110+
}
111+
latch.countDown();
112+
}
113+
}
114+
@Override
115+
public void onError(Ack ack) {
116+
logger.error("Connection failed: %s", ack.getReason());
117+
}
118+
});
119+
latch.await(5, TimeUnit.SECONDS);
120+
return atomicReference.get();
121+
}
122+
}
123+

src/test/java/com/openfin/desktop/TestUtils.java

Lines changed: 67 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.openfin.desktop;
22

3+
import org.json.JSONArray;
34
import org.json.JSONObject;
45
import org.slf4j.Logger;
56
import org.slf4j.LoggerFactory;
@@ -27,10 +28,75 @@ public class TestUtils {
2728
private static String runtimeVersion;
2829
private static CountDownLatch disconnectedLatch;
2930
public static final String openfin_app_url = "https://cdn.openfin.co/examples/junit/SimpleOpenFinApp.html"; // source is in release/SimpleOpenFinApp.html
31+
public static final String icon_url = "http://demoappdirectory.openf.in/desktop/config/apps/OpenFin/HelloOpenFin/img/openfin.ico";
32+
33+
static {
34+
runtimeVersion = java.lang.System.getProperty("com.openfin.test.runtime.version");
35+
if (runtimeVersion == null) {
36+
runtimeVersion = "alpha";
37+
}
38+
logger.debug(String.format("Runtime version %s", runtimeVersion));
39+
}
3040

3141
public static DesktopConnection setupConnection(String connectionUuid) throws Exception {
3242
return setupConnection(connectionUuid, null, null);
3343
}
44+
public static DesktopConnection setupConnection(String connectionUuid, RuntimeConfiguration configuration) throws Exception {
45+
logger.debug("starting from Runtime configuration");
46+
CountDownLatch connectedLatch = new CountDownLatch(1);
47+
disconnectedLatch = new CountDownLatch(1);
48+
// if RVM needs to download the version of Runtime specified, waitTime may need to be increased for slow download
49+
int waitTime = 60;
50+
String swaiTime = java.lang.System.getProperty("com.openfin.test.runtime.connect.wait.time");
51+
if (swaiTime != null) {
52+
waitTime = Integer.parseInt(swaiTime);
53+
}
54+
55+
DesktopConnection desktopConnection = new DesktopConnection(connectionUuid);
56+
desktopConnection.setAdditionalRuntimeArguments(" --v=1 "); // turn on Chromium debug log
57+
desktopConnection.connect(configuration, new DesktopStateListener() {
58+
@Override
59+
public void onReady() {
60+
logger.info("Connected to OpenFin runtime");
61+
connectionClosing = false;
62+
connectedLatch.countDown();
63+
}
64+
@Override
65+
public void onClose() {
66+
logger.debug("Connection closed");
67+
disconnectedLatch.countDown();
68+
}
69+
70+
@Override
71+
public void onError(String reason) {
72+
if (!connectionClosing) {
73+
logger.error("Connection failed: %s", reason);
74+
} else {
75+
logger.debug("Connection closed");
76+
}
77+
}
78+
79+
@Override
80+
public void onMessage(String message) {
81+
logger.debug(String.format("Runtime incoming message: %s", message));
82+
}
83+
84+
@Override
85+
public void onOutgoingMessage(String message) {
86+
logger.debug(String.format("Runtime outgoing message: %s", message));
87+
}
88+
}, waitTime);//this timeout (in 4.40.2.9) is ignored
89+
90+
logger.debug("waiting for desktop to connect");
91+
connectedLatch.await(waitTime, TimeUnit.SECONDS);
92+
if (desktopConnection.isConnected()) {
93+
logger.debug("desktop connected");
94+
} else {
95+
throw new RuntimeException("failed to initialise desktop connection");
96+
}
97+
return desktopConnection;
98+
}
99+
34100
public static DesktopConnection setupConnection(String connectionUuid, String rdmUrl, String assetsUrl) throws Exception {
35101
logger.debug("starting");
36102
CountDownLatch connectedLatch = new CountDownLatch(1);
@@ -44,10 +110,6 @@ public static DesktopConnection setupConnection(String connectionUuid, String rd
44110

45111
DesktopConnection desktopConnection = new DesktopConnection(connectionUuid);
46112
desktopConnection.setAdditionalRuntimeArguments(" --v=1 "); // turn on Chromium debug log
47-
runtimeVersion = java.lang.System.getProperty("com.openfin.test.runtime.version");
48-
if (runtimeVersion == null) {
49-
runtimeVersion = "alpha";
50-
}
51113
desktopConnection.setRdmUrl(rdmUrl);
52114
desktopConnection.setRuntimeAssetsUrl(assetsUrl);
53115
desktopConnection.connectToVersion(runtimeVersion, new DesktopStateListener() {
@@ -93,6 +155,7 @@ public void onOutgoingMessage(String message) {
93155
return desktopConnection;
94156
}
95157

158+
96159
public static void teardownDesktopConnection(DesktopConnection desktopConnection) throws Exception {
97160
if (desktopConnection.isConnected()) {
98161
connectionClosing = true;
@@ -374,5 +437,4 @@ public void onError(Ack ack) {
374437
assertEquals("getMonitorInfo timeout", latch.getCount(), 0);
375438
return windowBoundsAtomicReference.get();
376439
}
377-
378440
}

0 commit comments

Comments
 (0)