11package 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+
312import org .json .JSONArray ;
413import org .json .JSONObject ;
514import org .junit .AfterClass ;
817import org .slf4j .Logger ;
918import 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 */
2123public 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