Skip to content

Commit e89aa48

Browse files
author
Wenjun Che
committed
ADAP-44: create JUNIT tests
1 parent 2a6fddc commit e89aa48

4 files changed

Lines changed: 55 additions & 5 deletions

File tree

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,23 @@ public void runReqestedEventListeners() throws Exception {
130130
CountDownLatch latch = new CountDownLatch(1);
131131
TestUtils.addEventListener(application, "run-requested", actionEvent -> {
132132
if (actionEvent.getType().equals("run-requested")) {
133-
logger.info(String.format("%s", actionEvent.getEventObject().toString()));
133+
logger.debug(String.format("%s", actionEvent.getEventObject().toString()));
134134
latch.countDown();
135135
}
136136
});
137-
138137
TestUtils.runApplication(application);
139138
// run-requested is generated when Application.run is called on an active application
140139
application.run();
141140
latch.await(5, TimeUnit.SECONDS);
142141
assertEquals("run-requested timeout " + options.getUUID(), latch.getCount(), 0);
143142
TestUtils.closeApplication(application);
144143
}
144+
145+
@Test
146+
public void createChildWindow() throws Exception {
147+
Application application = TestUtils.runApplication(TestUtils.getAppOptions(), desktopConnection);
148+
WindowOptions childOptions = TestUtils.getWindowOptions("child1", TestUtils.openfin_app_url); // use same URL as main app
149+
Window childWindow = TestUtils.createChildWindow(application, childOptions, desktopConnection);
150+
TestUtils.closeApplication(application);
151+
}
145152
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
public class SystemTest {
2929
private static Logger logger = LoggerFactory.getLogger(SystemTest.class.getName());
3030

31-
private static final String DESKTOP_UUID = ApplicationTest.class.getName();
31+
private static final String DESKTOP_UUID = SystemTest.class.getName();
3232
private static DesktopConnection desktopConnection;
3333
private static System runtimeSystem;
3434
private static final String openfin_app_url = "http://test.openf.in/test.html";

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class TestUtils {
2020
private static boolean connectionClosing;
2121
private static String runtimeVersion;
2222
private static CountDownLatch disconnectedLatch;
23-
private static final String openfin_app_url = "http://test.openf.in/test.html"; // simple test app
23+
public static final String openfin_app_url = "http://test.openf.in/test.html"; // simple test app
2424

2525
public static DesktopConnection setupConnection(String connectionUuid) throws Exception {
2626
logger.debug("starting");
@@ -200,5 +200,33 @@ public void eventReceived(ActionEvent actionEvent) {
200200
assertEquals("Close application timeout " + application.getUuid(), stoppedLatch.getCount(), 0);
201201
}
202202

203+
public static WindowOptions getWindowOptions(String name, String url) throws Exception {
204+
WindowOptions options = new WindowOptions(name, url);
205+
options.setDefaultWidth(200);
206+
options.setDefaultHeight(200);
207+
options.setDefaultTop(200);
208+
options.setDefaultLeft(200);
209+
options.setSaveWindowState(false); // so the window opens with the same default bounds every time
210+
options.setAutoShow(true);
211+
options.setFrame(true);
212+
options.setResizable(true);
213+
return options;
214+
}
215+
216+
public static Window createChildWindow(Application application, WindowOptions childOptions, DesktopConnection desktopConnection) throws Exception {
203217

218+
final CountDownLatch windowCreatedLatch = new CountDownLatch(1);
219+
// use window-end-load event to wait for the window to finish loading
220+
application.addEventListener("window-end-load", actionEvent -> {
221+
if (actionEvent.getEventObject().has("name")) {
222+
if (childOptions.getName().equals(actionEvent.getEventObject().getString("name"))) {
223+
windowCreatedLatch.countDown();
224+
}
225+
}
226+
}, null);
227+
application.createChildWindow(childOptions, null);
228+
windowCreatedLatch.await(10, TimeUnit.SECONDS);
229+
assertEquals("createChildWindow timeout", windowCreatedLatch.getCount(), 0);
230+
return Window.wrap(application.getOptions().getUUID(), childOptions.getName(), desktopConnection);
231+
}
204232
}
Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
11
package com.openfin.desktop;
22

3+
import org.junit.Test;
4+
import org.slf4j.Logger;
5+
import org.slf4j.LoggerFactory;
6+
37
/**
4-
* Created by richard on 1/25/16.
8+
* Created by wche on 1/25/16.
9+
*
510
*/
611
public class WindowTest {
12+
private static Logger logger = LoggerFactory.getLogger(WindowTest.class.getName());
13+
14+
private static final String DESKTOP_UUID = WindowTest.class.getName();
15+
private static DesktopConnection desktopConnection;
16+
private static final String child_window_url = "http://test.openf.in/test.html"; // simple test app
17+
18+
@Test
19+
public void hideAndShow() throws Exception {
20+
21+
}
722
}

0 commit comments

Comments
 (0)