Skip to content

Commit 64f7ee5

Browse files
author
Wenjun Che
committed
ADAP-44: create JUNIT tests
1 parent 9e12eb0 commit 64f7ee5

File tree

4 files changed

+828
-0
lines changed

4 files changed

+828
-0
lines changed

pom.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,21 @@
114114
<manifestFile>${basedir}/target/classes/META-INF/MANIFEST.MF</manifestFile>
115115
</archive>
116116
</configuration>
117+
<executions>
118+
<execution>
119+
<goals>
120+
<goal>test-jar</goal>
121+
</goals>
122+
</execution>
123+
</executions>
124+
</plugin>
125+
126+
<plugin>
127+
<groupId>org.apache.maven.plugins</groupId>
128+
<artifactId>maven-surefire-plugin</artifactId>
129+
<configuration>
130+
<skipTests>true</skipTests>
131+
</configuration>
117132
</plugin>
118133

119134
</plugins>
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
package com.openfin.desktop;
2+
3+
import org.junit.AfterClass;
4+
import org.junit.BeforeClass;
5+
import org.junit.Ignore;
6+
import org.junit.Test;
7+
import org.slf4j.Logger;
8+
import org.slf4j.LoggerFactory;
9+
10+
import java.util.concurrent.CountDownLatch;
11+
import java.util.concurrent.TimeUnit;
12+
13+
import static junit.framework.Assert.assertEquals;
14+
15+
/**
16+
*
17+
* JUnit tests for Application class
18+
*
19+
* Created by wche on 1/22/16.
20+
*
21+
*/
22+
public class ApplicationTest {
23+
private static Logger logger = LoggerFactory.getLogger(ApplicationTest.class.getName());
24+
25+
private static final String DESKTOP_UUID = ApplicationTest.class.getName();
26+
private static DesktopConnection desktopConnection;
27+
28+
@BeforeClass
29+
public static void setup() throws Exception {
30+
logger.debug("starting");
31+
desktopConnection = TestUtils.setupConnection(DESKTOP_UUID);
32+
}
33+
34+
@AfterClass
35+
public static void teardown() throws Exception {
36+
TestUtils.teardownDesktopConnection(desktopConnection);
37+
}
38+
39+
40+
41+
42+
@Test
43+
public void runAndClose() throws Exception {
44+
logger.debug("runAndClose");
45+
ApplicationOptions options = TestUtils.getAppOptions();
46+
Application application = TestUtils.runApplication(options, desktopConnection);
47+
TestUtils.closeApplication(application);
48+
}
49+
50+
@Test
51+
public void runAndTerminate() throws Exception {
52+
logger.debug("runAndTerminate");
53+
ApplicationOptions options = TestUtils.getAppOptions();
54+
Application application = TestUtils.createApplication(options, desktopConnection);
55+
56+
CountDownLatch stoppedLatch = new CountDownLatch(1);
57+
EventListener listener = new EventListener() {
58+
@Override
59+
public void eventReceived(ActionEvent actionEvent) {
60+
if (actionEvent.getType().equals("closed")) {
61+
stoppedLatch.countDown();
62+
}
63+
}
64+
};
65+
TestUtils.addEventListener(application, "closed", listener);
66+
TestUtils.runApplication(application);
67+
application.terminate();
68+
stoppedLatch.await(5, TimeUnit.SECONDS);
69+
assertEquals("Terminate application timeout " + options.getUUID(), stoppedLatch.getCount(), 0);
70+
}
71+
72+
@Test
73+
public void getApplicationManifest() throws Exception {
74+
logger.debug("getApplicationManifest");
75+
ApplicationOptions options = TestUtils.getAppOptions();
76+
Application application = TestUtils.runApplication(options, desktopConnection);
77+
CountDownLatch latch = new CountDownLatch(1);
78+
application.getManifest(new AckListener() {
79+
@Override
80+
public void onSuccess(Ack ack) {
81+
}
82+
@Override
83+
public void onError(Ack ack) {
84+
logger.debug(ack.getJsonObject().toString());
85+
if (ack.getReason().contains(" was not created from a manifest")) {
86+
latch.countDown();
87+
}
88+
}
89+
});
90+
latch.await(5, TimeUnit.SECONDS);
91+
assertEquals("getApplicationManifest timeout " + options.getUUID(), latch.getCount(), 0);
92+
TestUtils.closeApplication(application);
93+
}
94+
95+
@Ignore("restart does not fire started event")
96+
@Test
97+
public void restartApplication() throws Exception {
98+
ApplicationOptions options = TestUtils.getAppOptions();
99+
Application application = TestUtils.runApplication(options, desktopConnection);
100+
CountDownLatch latch = new CountDownLatch(1);
101+
TestUtils.addEventListener(application, "started", actionEvent -> {
102+
if (actionEvent.getType().equals("started")) {
103+
latch.countDown();
104+
}
105+
});
106+
application.restart();
107+
latch.await(5, TimeUnit.SECONDS);
108+
assertEquals("restartApplication timeout " + options.getUUID(), latch.getCount(), 0);
109+
}
110+
111+
@Test
112+
public void runReqestedEventListeners() throws Exception {
113+
ApplicationOptions options = TestUtils.getAppOptions();
114+
Application application = TestUtils.createApplication(options, desktopConnection);
115+
CountDownLatch latch = new CountDownLatch(1);
116+
TestUtils.addEventListener(application, "run-requested", actionEvent -> {
117+
if (actionEvent.getType().equals("run-requested")) {
118+
logger.info(String.format("%s", actionEvent.getEventObject().toString()));
119+
latch.countDown();
120+
}
121+
});
122+
123+
TestUtils.runApplication(application);
124+
// run-requested is generated when Application.run is called on an active application
125+
application.run();
126+
latch.await(5, TimeUnit.SECONDS);
127+
assertEquals("run-requested timeout " + options.getUUID(), latch.getCount(), 0);
128+
TestUtils.closeApplication(application);
129+
}
130+
}

0 commit comments

Comments
 (0)