Skip to content

Commit 088d8bd

Browse files
committed
ADAP-98 WIP expand junit test cases.
1 parent f6b5774 commit 088d8bd

10 files changed

Lines changed: 318 additions & 103 deletions

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

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
package com.openfin.desktop;
22

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;
3+
import static org.junit.Assert.assertEquals;
94

105
import java.util.List;
116
import java.util.concurrent.CountDownLatch;
127
import java.util.concurrent.TimeUnit;
138

14-
import static junit.framework.Assert.assertEquals;
9+
import org.junit.AfterClass;
10+
import org.junit.BeforeClass;
11+
import org.junit.Test;
12+
import org.slf4j.Logger;
13+
import org.slf4j.LoggerFactory;
1514

1615
/**
1716
*
@@ -256,4 +255,37 @@ public void onError(Ack ack) {
256255
TestUtils.closeApplication(application1);
257256
TestUtils.closeApplication(application2);
258257
}
258+
259+
@Test
260+
public void addEventListener() throws Exception {
261+
ApplicationOptions options = TestUtils.getAppOptions(null);
262+
Application application = TestUtils.createApplication(options, desktopConnection);
263+
CountDownLatch latch = new CountDownLatch(1);
264+
application.addEventListener("started", event -> {
265+
latch.countDown();
266+
}, new AckListener() {
267+
@Override
268+
public void onSuccess(Ack ack) {
269+
}
270+
271+
@Override
272+
public void onError(Ack ack) {
273+
}
274+
});
275+
276+
application.run(new AckListener() {
277+
@Override
278+
public void onSuccess(Ack ack) {
279+
}
280+
281+
@Override
282+
public void onError(Ack ack) {
283+
}
284+
});
285+
286+
latch.await(5, TimeUnit.SECONDS);
287+
assertEquals("eventListener test timeout", 0, latch.getCount());
288+
289+
TestUtils.closeApplication(application);
290+
}
259291
}

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

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

3+
import static org.junit.Assert.assertEquals;
4+
5+
import java.util.concurrent.CountDownLatch;
6+
import java.util.concurrent.TimeUnit;
7+
import java.util.concurrent.atomic.AtomicReference;
8+
39
import org.json.JSONObject;
410
import org.junit.AfterClass;
511
import org.junit.BeforeClass;
@@ -8,12 +14,6 @@
814
import org.slf4j.Logger;
915
import org.slf4j.LoggerFactory;
1016

11-
import java.util.concurrent.CountDownLatch;
12-
import java.util.concurrent.TimeUnit;
13-
import java.util.concurrent.atomic.AtomicReference;
14-
15-
import static junit.framework.Assert.assertEquals;
16-
1717
/**
1818
* JUnit tests for com.openfin.desktop.InterApplicationBus class
1919
*
@@ -317,4 +317,28 @@ public void wildCardTopicSelf() throws Exception {
317317
assertEquals(latch.getCount(), 0);
318318
}
319319

320+
@Ignore
321+
@Test
322+
public void topicWithSpecialCharacters() throws Exception {
323+
final String topic = ":/\\;@#[]{}<>+=&^%$£\"?¬";
324+
//final String topic = "whatever";
325+
326+
CountDownLatch latch = new CountDownLatch(1);
327+
BusListener busListener = (sourceUuid, receivingTopic, payload) -> {
328+
logger.debug(String.format("Receiving %s", payload.toString()));
329+
if (receivingTopic.equals(topic)) {
330+
latch.countDown();
331+
}
332+
};
333+
subscribeToTopic("*", topic, busListener);
334+
335+
JSONObject msg = new JSONObject();
336+
msg.put("name", "topicWithSpecialCharacters");
337+
desktopConnection.getInterApplicationBus().publish(topic, msg);
338+
339+
latch.await(5, TimeUnit.SECONDS);
340+
assertEquals(latch.getCount(), 0);
341+
}
342+
343+
320344
}

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

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

3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.fail;
5+
6+
import java.util.concurrent.CountDownLatch;
7+
import java.util.concurrent.TimeUnit;
8+
9+
import org.json.JSONObject;
310
import org.junit.AfterClass;
411
import org.junit.BeforeClass;
512
import org.junit.Test;
613
import org.slf4j.Logger;
714
import org.slf4j.LoggerFactory;
815

9-
import java.util.concurrent.CountDownLatch;
10-
import java.util.concurrent.TimeUnit;
11-
import java.util.concurrent.atomic.AtomicReference;
12-
13-
import static junit.framework.Assert.assertEquals;
14-
import static junit.framework.Assert.fail;
15-
1616
/**
1717
* Tests for com.openfin.desktop.Notification class
1818
*
@@ -104,4 +104,71 @@ public void onError(Ack ack) {
104104
assertEquals(onShowLatch.getCount(), 0);
105105
assertEquals(onCloseLatch.getCount(), 0);
106106
}
107+
108+
@Test
109+
public void sendMessage() throws Exception {
110+
CountDownLatch latch = new CountDownLatch(1);
111+
NotificationOptions options = new NotificationOptions(notification_url);
112+
options.setMessage(new JSONObject("{message: \"JSONMessage\"}"));
113+
//options.setMessageText("Notification Text");
114+
options.setTimeout(1000);
115+
116+
NotificationListener nListener = new NotificationListener() {
117+
118+
@Override
119+
public void onClick(Ack ack) {
120+
}
121+
122+
@Override
123+
public void onClose(Ack ack) {
124+
}
125+
126+
@Override
127+
public void onDismiss(Ack ack) {
128+
}
129+
130+
@Override
131+
public void onError(Ack ack) {
132+
logger.error("onError for notification");
133+
}
134+
135+
@Override
136+
public void onMessage(Ack ack) {
137+
logger.info("onMessage");
138+
latch.countDown();
139+
}
140+
141+
@Override
142+
public void onShow(Ack ack) {
143+
}
144+
};
145+
146+
AckListener ackListener = new AckListener() {
147+
@Override
148+
public void onSuccess(Ack ack) {
149+
}
150+
151+
@Override
152+
public void onError(Ack ack) {
153+
logger.error(ack.getReason());
154+
}
155+
};
156+
157+
Notification n = new Notification(options, nListener, desktopConnection, ackListener);
158+
n.sendMessage(new JSONObject("{message: \"JSONMessage2\"}"), new AckListener() {
159+
160+
@Override
161+
public void onSuccess(Ack ack) {
162+
latch.countDown();
163+
}
164+
165+
@Override
166+
public void onError(Ack ack) {
167+
logger.error("onError for sendMessage");
168+
}
169+
});
170+
latch.await(10, TimeUnit.SECONDS);
171+
assertEquals(0, latch.getCount());
172+
173+
}
107174
}

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

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

3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.fail;
5+
6+
import java.util.UUID;
7+
import java.util.concurrent.CountDownLatch;
8+
import java.util.concurrent.TimeUnit;
9+
import java.util.concurrent.atomic.AtomicReference;
10+
311
import org.json.JSONArray;
412
import org.json.JSONObject;
513
import org.junit.AfterClass;
614
import org.junit.BeforeClass;
7-
import org.junit.Ignore;
815
import org.junit.Test;
916
import org.slf4j.Logger;
1017
import org.slf4j.LoggerFactory;
1118

12-
import java.util.UUID;
13-
import java.util.concurrent.CountDownLatch;
14-
import java.util.concurrent.TimeUnit;
15-
import java.util.concurrent.atomic.AtomicReference;
16-
17-
import static junit.framework.Assert.assertEquals;
18-
import static junit.framework.Assert.fail;
19-
2019
/**
2120
*
2221
* JUnit tests for com.openfin.desktop.OpenFinRuntime class
Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
package com.openfin.desktop;
22

3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertTrue;
5+
6+
import java.net.Socket;
7+
import java.util.UUID;
8+
import java.util.concurrent.CountDownLatch;
9+
import java.util.concurrent.TimeUnit;
10+
import java.util.concurrent.atomic.AtomicReference;
11+
312
import org.json.JSONArray;
413
import org.json.JSONObject;
514
import org.junit.AfterClass;
@@ -8,32 +17,21 @@
817
import org.slf4j.Logger;
918
import org.slf4j.LoggerFactory;
1019

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-
1820
/**
1921
* Created by richard on 4/1/2016.
2022
*/
2123
public class RuntimeConfigTest {
2224
private static Logger logger = LoggerFactory.getLogger(RuntimeConfigTest.class.getName());
2325

2426
private static final String DESKTOP_UUID = RuntimeConfigTest.class.getName();
25-
private static DesktopConnection desktopConnection;
2627
private static RuntimeConfiguration configuration;
2728
private static String appUUID = UUID.randomUUID().toString();
2829

29-
@BeforeClass
3030
public static void setup() throws Exception {
3131
logger.debug("starting");
32-
configuration = getRuntimeConfiguration();
33-
desktopConnection = TestUtils.setupConnection(DESKTOP_UUID, configuration);
3432
}
3533

36-
private static RuntimeConfiguration getRuntimeConfiguration() {
34+
private static RuntimeConfiguration getDefaultRuntimeConfiguration() {
3735
RuntimeConfiguration configuration = new RuntimeConfiguration();
3836
configuration.setRuntimeVersion(TestUtils.getRuntimeVersion());
3937
configuration.setDevToolsPort(9090);
@@ -57,45 +55,19 @@ private static RuntimeConfiguration getRuntimeConfiguration() {
5755
return configuration;
5856
}
5957

60-
@AfterClass
61-
public static void teardown() throws Exception {
62-
TestUtils.teardownDesktopConnection(desktopConnection);
63-
}
64-
6558
@Test
6659
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);
60+
RuntimeConfiguration configuration = getDefaultRuntimeConfiguration();
61+
DesktopConnection conn = TestUtils.setupConnection(DESKTOP_UUID, configuration);
62+
assertTrue(isWindowCreated(appUUID, conn));
63+
TestUtils.teardownDesktopConnection(conn);
9264
}
9365

94-
private boolean isWindowCreated(String uuid) throws Exception {
66+
private boolean isWindowCreated(String uuid, DesktopConnection conn) throws Exception {
9567
CountDownLatch latch = new CountDownLatch(1);
9668
AtomicReference<Boolean> atomicReference = new AtomicReference<>();
9769
atomicReference.set(false);
98-
OpenFinRuntime runtime = new OpenFinRuntime(desktopConnection);
70+
OpenFinRuntime runtime = new OpenFinRuntime(conn);
9971
runtime.getAllWindows(new AckListener() {
10072
@Override
10173
public void onSuccess(Ack ack) {
@@ -119,5 +91,37 @@ public void onError(Ack ack) {
11991
latch.await(5, TimeUnit.SECONDS);
12092
return atomicReference.get();
12193
}
94+
95+
private static boolean serverListening(int port)
96+
{
97+
Socket s = null;
98+
try
99+
{
100+
s = new Socket("localhost", port);
101+
return true;
102+
}
103+
catch (Exception e)
104+
{
105+
return false;
106+
}
107+
finally
108+
{
109+
if(s != null)
110+
try {s.close();}
111+
catch(Exception e){}
112+
}
113+
}
114+
115+
116+
@Test
117+
public void setDevToolsPort() throws Exception {
118+
int devPort = 7777;
119+
120+
RuntimeConfiguration configuration = getDefaultRuntimeConfiguration();
121+
configuration.setDevToolsPort(devPort);
122+
DesktopConnection conn = TestUtils.setupConnection(DESKTOP_UUID, configuration);
123+
assertTrue(serverListening(devPort));
124+
TestUtils.teardownDesktopConnection(conn);
125+
}
122126
}
123127

0 commit comments

Comments
 (0)