diff --git a/pom.xml b/pom.xml index 8015952..d5e3e4c 100644 --- a/pom.xml +++ b/pom.xml @@ -58,12 +58,7 @@ co.openfin openfin-desktop-java-adapter - 9.0.1-SNAPSHOT - - - co.openfin - openfin-snap-dock - 1.0.0.1 + 9.2.0 tablelayout diff --git a/release/fdc3.bat b/release/fdc3.bat deleted file mode 100644 index 17628cc..0000000 --- a/release/fdc3.bat +++ /dev/null @@ -1,2 +0,0 @@ -java -cp lib/hamcrest-core-1.3.jar;lib/hamcrest-library-1.1.jar;lib/jetty-client-9.4.18.v20190429.jar;lib/jetty-http-9.4.18.v20190429.jar;lib/jetty-io-9.4.18.v20190429.jar;lib/jetty-util-9.4.18.v20190429.jar;lib/jetty-xml-9.4.18.v20190429.jar;lib/jna-4.5.1.jar;lib/jna-platform-4.5.1.jar;lib/json-20160810.jar;lib/junit-4.11.jar;lib/mockito-core-1.9.5.jar;lib/objenesis-1.0.jar;lib/openfin-desktop-java-adapter-8.0.8.jar;lib/openfin-desktop-java-example-7.1.1-tests.jar;lib/openfin-desktop-java-example-7.1.1.jar;lib/openfin-snap-dock-1.0.0.1.jar;lib/slf4j-api-1.7.21.jar;lib/slf4j-jdk14-1.6.1.jar;lib/slf4j-log4j12-1.7.18.jar;lib/TableLayout-20050920.jar;lib/websocket-api-9.4.18.v20190429.jar;lib/websocket-client-9.4.18.v20190429.jar;lib/websocket-common-9.4.18.v20190429.jar -Djava.util.logging.config.file=logging.properties -Dcom.openfin.temp=%LocalAppData%\OpenFin\temp -Dcom.openfin.demo.version=stable com.openfin.desktop.demo.FDC3Example - diff --git a/release/junit.bat b/release/junit.bat index bdd58e8..b79d81f 100644 --- a/release/junit.bat +++ b/release/junit.bat @@ -6,4 +6,4 @@ set RuntimeVersion="stable" set RuntimeVersion="%1" ) -java -cp lib/hamcrest-core-1.3.jar;lib/hamcrest-library-1.1.jar;lib/jetty-client-9.4.18.v20190429.jar;lib/jetty-http-9.4.18.v20190429.jar;lib/jetty-io-9.4.18.v20190429.jar;lib/jetty-util-9.4.18.v20190429.jar;lib/jetty-xml-9.4.18.v20190429.jar;lib/jna-4.5.1.jar;lib/jna-platform-4.5.1.jar;lib/json-20160810.jar;lib/junit-4.11.jar;lib/log4j-1.2.17.jar;lib/mockito-core-1.9.5.jar;lib/objenesis-1.0.jar;lib/openfin-desktop-java-adapter-9.0.1-SNAPSHOT.jar;lib/openfin-desktop-java-example-9.0.1-tests.jar;lib/openfin-snap-dock-1.0.0.1.jar;lib/slf4j-api-1.7.21.jar;lib/slf4j-jdk14-1.6.1.jar;lib/slf4j-log4j12-1.7.18.jar;lib/TableLayout-20050920.jar;lib/websocket-api-9.4.18.v20190429.jar;lib/websocket-client-9.4.18.v20190429.jar;lib/websocket-common-9.4.18.v20190429.jar -Djava.util.logging.config.file=logging.properties -Dcom.openfin.test.runtime.version=%RuntimeVersion% org.junit.runner.JUnitCore com.openfin.desktop.AllTests +java -cp lib/hamcrest-core-1.3.jar;lib/hamcrest-library-1.1.jar;lib/jetty-client-9.4.18.v20190429.jar;lib/jetty-http-9.4.18.v20190429.jar;lib/jetty-io-9.4.18.v20190429.jar;lib/jetty-util-9.4.18.v20190429.jar;lib/jetty-xml-9.4.18.v20190429.jar;lib/jna-4.5.1.jar;lib/jna-platform-4.5.1.jar;lib/json-20160810.jar;lib/junit-4.11.jar;lib/log4j-1.2.17.jar;lib/mockito-core-1.9.5.jar;lib/objenesis-1.0.jar;lib/openfin-desktop-java-adapter-9.2.0.jar;lib/openfin-desktop-java-example-9.2.1-tests.jar;lib/slf4j-api-1.7.21.jar;lib/slf4j-jdk14-1.6.1.jar;lib/slf4j-log4j12-1.7.18.jar;lib/TableLayout-20050920.jar;lib/websocket-api-9.4.18.v20190429.jar;lib/websocket-client-9.4.18.v20190429.jar;lib/websocket-common-9.4.18.v20190429.jar -Djava.util.logging.config.file=logging.properties -Dcom.openfin.test.runtime.version=%RuntimeVersion% org.junit.runner.JUnitCore com.openfin.desktop.AllTests diff --git a/release/lib/openfin-desktop-java-adapter-8.0.11-SNAPSHOT.jar b/release/lib/openfin-desktop-java-adapter-8.0.11-SNAPSHOT.jar deleted file mode 100644 index ddaa903..0000000 Binary files a/release/lib/openfin-desktop-java-adapter-8.0.11-SNAPSHOT.jar and /dev/null differ diff --git a/release/lib/openfin-desktop-java-adapter-8.0.8.jar b/release/lib/openfin-desktop-java-adapter-8.0.8.jar deleted file mode 100644 index d50704b..0000000 Binary files a/release/lib/openfin-desktop-java-adapter-8.0.8.jar and /dev/null differ diff --git a/release/lib/openfin-desktop-java-adapter-9.0.1-SNAPSHOT.jar b/release/lib/openfin-desktop-java-adapter-9.0.1-SNAPSHOT.jar deleted file mode 100644 index feaff7a..0000000 Binary files a/release/lib/openfin-desktop-java-adapter-9.0.1-SNAPSHOT.jar and /dev/null differ diff --git a/release/lib/openfin-desktop-java-adapter-9.2.0.jar b/release/lib/openfin-desktop-java-adapter-9.2.0.jar new file mode 100644 index 0000000..8e5fff9 Binary files /dev/null and b/release/lib/openfin-desktop-java-adapter-9.2.0.jar differ diff --git a/release/lib/openfin-desktop-java-example-9.0.1-tests.jar b/release/lib/openfin-desktop-java-example-9.0.1-tests.jar deleted file mode 100644 index a6229c4..0000000 Binary files a/release/lib/openfin-desktop-java-example-9.0.1-tests.jar and /dev/null differ diff --git a/release/lib/openfin-desktop-java-example-9.0.1.jar b/release/lib/openfin-desktop-java-example-9.0.1.jar index 0f7e627..e4c2bae 100644 Binary files a/release/lib/openfin-desktop-java-example-9.0.1.jar and b/release/lib/openfin-desktop-java-example-9.0.1.jar differ diff --git a/release/lib/openfin-desktop-java-example-9.2.1-tests.jar b/release/lib/openfin-desktop-java-example-9.2.1-tests.jar new file mode 100644 index 0000000..2611d69 Binary files /dev/null and b/release/lib/openfin-desktop-java-example-9.2.1-tests.jar differ diff --git a/release/lib/openfin-desktop-java-example-9.2.2.jar b/release/lib/openfin-desktop-java-example-9.2.2.jar new file mode 100644 index 0000000..dea5aac Binary files /dev/null and b/release/lib/openfin-desktop-java-example-9.2.2.jar differ diff --git a/release/lib/openfin-snap-dock-1.0.0.1.jar b/release/lib/openfin-snap-dock-1.0.0.1.jar deleted file mode 100644 index 89e1c0f..0000000 Binary files a/release/lib/openfin-snap-dock-1.0.0.1.jar and /dev/null differ diff --git a/release/profile.bat b/release/profile.bat new file mode 100644 index 0000000..9e1cf11 --- /dev/null +++ b/release/profile.bat @@ -0,0 +1,2 @@ +java -Xmx100m -Xms100m -cp lib/hamcrest-core-1.3.jar;lib/hamcrest-library-1.1.jar;lib/jetty-client-9.4.18.v20190429.jar;lib/jetty-http-9.4.18.v20190429.jar;lib/jetty-io-9.4.18.v20190429.jar;lib/jetty-util-9.4.18.v20190429.jar;lib/jetty-xml-9.4.18.v20190429.jar;lib/jna-4.5.1.jar;lib/jna-platform-4.5.1.jar;lib/json-20160810.jar;lib/junit-4.11.jar;lib/mockito-core-1.9.5.jar;lib/objenesis-1.0.jar;lib/openfin-desktop-java-adapter-9.2.3-SNAPSHOT.jar;lib/openfin-desktop-java-example-9.0.1-tests.jar;lib/openfin-desktop-java-example-9.2.2.jar;lib/slf4j-api-1.7.21.jar;lib/slf4j-jdk14-1.6.1.jar;lib/slf4j-log4j12-1.7.18.jar;lib/TableLayout-20050920.jar;lib/websocket-api-9.4.18.v20190429.jar;lib/websocket-client-9.4.18.v20190429.jar;lib/websocket-common-9.4.18.v20190429.jar -Djava.util.logging.config.file=logging.properties -Dcom.openfin.temp=%LocalAppData%\OpenFin\temp -Dcom.openfin.demo.version=stable -Dcom.openfin.demo.licenseKey=123456 com.openfin.desktop.demo.MemoryProfile + diff --git a/src/main/java/com/openfin/desktop/demo/ChannelExample.java b/src/main/java/com/openfin/desktop/demo/ChannelExample.java index 40edf04..0eba6b6 100644 --- a/src/main/java/com/openfin/desktop/demo/ChannelExample.java +++ b/src/main/java/com/openfin/desktop/demo/ChannelExample.java @@ -47,52 +47,114 @@ public ChannelExample() { * Create a provider that supports "getValue", "increment" and "incrementBy n" actions */ public void createChannelProvider() { - desktopConnection.getChannel(CHANNEL_NAME).addChannelListener(new ChannelListener() { - @Override - public void onChannelConnect(ConnectionEvent connectionEvent) { - logger.info(String.format("provider receives channel connect event from %s ", connectionEvent.getUuid())); - } - @Override - public void onChannelDisconnect(ConnectionEvent connectionEvent) { - logger.info(String.format("provider receives channel disconnect event from %s ", connectionEvent.getUuid())); - } - }); - desktopConnection.getChannel(CHANNEL_NAME).create(new AsyncCallback() { - @Override - public void onSuccess(ChannelProvider provider) { - //provider created, register actions. - AtomicInteger x = new AtomicInteger(0); - - provider.register("getValue", new ChannelAction() { - @Override - public JSONObject invoke(String action, Object payload, JSONObject senderIdentity) { - logger.info(String.format("provider processing action %s, payload=%s", action, payload.toString())); - JSONObject obj = new JSONObject(); - obj.put("value", x.get()); - return obj; - } - }); - provider.register("increment", new ChannelAction() { - @Override - public JSONObject invoke(String action, Object payload, JSONObject senderIdentity) { - logger.info(String.format("provider processing action %s, payload=%s", action, payload.toString())); - JSONObject obj = new JSONObject(); - obj.put("value", x.incrementAndGet()); - provider.publish("event", obj, null); - return obj; - } - }); - provider.register("incrementBy", new ChannelAction() { - @Override - public JSONObject invoke(String action, Object payload, JSONObject senderIdentity) { - logger.info(String.format("provider processing action %s, payload=%s", action, payload.toString())); - int delta = ((JSONObject)payload).getInt("delta"); - JSONObject obj = new JSONObject(); - obj.put("value", x.addAndGet(delta)); - return obj; + + // Create the channel provider. + desktopConnection.getChannel(CHANNEL_NAME).createAsync().thenAccept(provider -> { + provider.addProviderListener(new ChannelProviderListener() { + + // Create the onChannelConnect event handler. + @Override + public void onClientConnect(ChannelClientConnectEvent connectionEvent) throws Exception { + + // Add a line to the log file to identify the UUID of the caller. + logger.info(String.format("provider receives client connect event from %s ", connectionEvent.getUuid())); + + // Extract the JSON payload. + JSONObject payload = (JSONObject) connectionEvent.getPayload(); + + // If the "name" element of the payload says the client is invalid, reject the request. + if (payload != null) { + String name = payload.optString("name"); + if ("Invalid Client".equals(name)) { + throw new Exception("request rejected"); + } } - }); - } + } + + // Create the onChannelDisconnect event handler. + @Override + public void onClientDisconnect(ChannelClientConnectEvent connectionEvent) { + + // Add a line to the log file identifying the UUID of the caller. + logger.info(String.format("provider receives channel disconnect event from %s ", connectionEvent.getUuid())); + } + }); + + // The provider was created. Now to register the actions. + // ------------------------------------------------------ + + // This variable is used as the "value" element for the getValue, increment, and incrementBy actions. + AtomicInteger localInteger = new AtomicInteger(0); + + // Register the "getValue" action. + // This action will return the value of the localInteger variable. + provider.register("getValue", new ChannelAction() { + + // This is the logic for the "getValue" action. + @Override + public JSONObject invoke(String action, Object payload, JSONObject senderIdentity) { + + // Write a string to the logfile that shows the requested action and payload. + logger.info(String.format("provider processing action %s, payload=%s", action, payload.toString())); + + // Create a JSON object to return to the channel client. + JSONObject obj = new JSONObject(); + + // Set the "value" JSON element to the value of the localInteger variable. + obj.put("value", localInteger.get()); + + // Return the JSON object to the channel client. + return obj; + } + }); + + // Register the "increment" action. + // This action will increment the value of the localInteger variable by one. + provider.register("increment", new ChannelAction() { + + // This is the logic for the "increment" action. + @Override + public JSONObject invoke(String action, Object payload, JSONObject senderIdentity) { + + // Write a string to the logfile that identifies the action and payload. + logger.info(String.format("provider processing action %s, payload=%s", action, payload.toString())); + + // Create a JSON object to return to the channel client. + JSONObject obj = new JSONObject(); + + // Increment localInteger and set the "value" JSON element to the new value of localInteger. + obj.put("value", localInteger.incrementAndGet()); + provider.publish("event", obj, null); + + // Return the JSON object to the channel client. + return obj; + } + }); + + // Register the "incrementBy" action. + // This action will increment the value of the localInteger variable by a specified amount. + provider.register("incrementBy", new ChannelAction() { + + // This is the logic for the "incrementBy" action. + @Override + public JSONObject invoke(String action, Object payload, JSONObject senderIdentity) { + + // Write a string to the logfile that identifies the action and payload. + logger.info(String.format("provider processing action %s, payload=%s", action, payload.toString())); + + // Extract the increment amount (delta) from the payload JSON object. + int delta = ((JSONObject)payload).getInt("delta"); + + // Create a new JSON object to return to the channel client. + JSONObject obj = new JSONObject(); + + // Increase localInteger by the delta amount and set the "value" JSON element to the new value of localInteger. + obj.put("value", localInteger.addAndGet(delta)); + + // Return the new JSON object to the channel client. + return obj; + } + }); }); } @@ -100,64 +162,68 @@ public JSONObject invoke(String action, Object payload, JSONObject senderIdentit * Create a channel client that invokes "getValue", "increment" and "incrementBy n" actions */ public void createChannelClient() { - desktopConnection.getChannel(CHANNEL_NAME).connect(new AsyncCallback() { - @Override - public void onSuccess(ChannelClient client) { - // register a channel event - client.register("event", new ChannelAction() { - @Override - public JSONObject invoke(String action, Object payload, JSONObject senderIdentity) { - logger.info("channel event {}", action); - return null; - } - }); - - //connected to provider, invoke actions provided by the provider. - //get current value - client.dispatch("getValue", null, new AckListener() { - @Override - public void onSuccess(Ack ack) { - logger.info("current value={}", ack.getJsonObject().getJSONObject("data").getJSONObject("result").getInt("value")); - - //got current value, do increment - client.dispatch("increment", null, new AckListener() { - @Override - public void onSuccess(Ack ack) { - logger.info("after invoking increment, value={}", ack.getJsonObject().getJSONObject("data").getJSONObject("result").getInt("value")); - - //let's do increatmentBy 10 - JSONObject payload = new JSONObject(); - payload.put("delta", 10); - client.dispatch("incrementBy", payload, new AckListener() { - @Override - public void onSuccess(Ack ack) { - logger.info("after invoking incrementBy, value={}", ack.getJsonObject().getJSONObject("data").getJSONObject("result").getInt("value")); - - try { - desktopConnection.disconnect(); - } - catch (DesktopException e) { - e.printStackTrace(); - } - } + JSONObject payload = new JSONObject(); + payload.put("name", "java example"); + desktopConnection.getChannel(CHANNEL_NAME).connectAsync(false, payload).thenAccept(client -> { + client.addChannelListener(new ChannelListener() { + @Override + public void onChannelConnect(ConnectionEvent connectionEvent) { + } + @Override + public void onChannelDisconnect(ConnectionEvent connectionEvent) { + logger.info("channel disconnected {}", connectionEvent.getChannelId()); + } + }); + client.register("event", new ChannelAction() { + @Override + public JSONObject invoke(String action, Object payload, JSONObject senderIdentity) { + logger.info("channel event {}", action); + return null; + } + }); + + client.dispatch("getValue", null, new AckListener() { + @Override + public void onSuccess(Ack ack) { + logger.info("current value={}", ack.getJsonObject().getJSONObject("data").getJSONObject("result").getInt("value")); + + //got current value, do increment + client.dispatch("increment", null, new AckListener() { + @Override + public void onSuccess(Ack ack) { + logger.info("after invoking increment, value={}", ack.getJsonObject().getJSONObject("data").getJSONObject("result").getInt("value")); - @Override - public void onError(Ack ack) { + //let's do increatmentBy 10 + JSONObject payload = new JSONObject(); + payload.put("delta", 10); + client.dispatch("incrementBy", payload, new AckListener() { + @Override + public void onSuccess(Ack ack) { + logger.info("after invoking incrementBy, value={}", ack.getJsonObject().getJSONObject("data").getJSONObject("result").getInt("value")); + + try { + desktopConnection.disconnect(); + } catch (DesktopException e) { + e.printStackTrace(); } - }); - } + } - @Override - public void onError(Ack ack) { - } - }); - } + @Override + public void onError(Ack ack) { + } + }); + } - @Override - public void onError(Ack ack) { - } - }); - } + @Override + public void onError(Ack ack) { + } + }); + } + + @Override + public void onError(Ack ack) { + } + }); }); } @@ -207,4 +273,4 @@ public static void main(String[] args) { java.lang.System.exit(0); } -} \ No newline at end of file +} diff --git a/src/main/java/com/openfin/desktop/demo/DockingDemo2.java b/src/main/java/com/openfin/desktop/demo/DockingDemo2.java deleted file mode 100644 index cf6589c..0000000 --- a/src/main/java/com/openfin/desktop/demo/DockingDemo2.java +++ /dev/null @@ -1,289 +0,0 @@ -package com.openfin.desktop.demo; - -import com.openfin.desktop.*; -import com.openfin.desktop.win32.ExternalWindowObserver; -import info.clearthought.layout.TableLayout; -import org.json.JSONObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.swing.*; -import java.awt.*; -import java.awt.event.ActionListener; -import java.awt.event.WindowEvent; -import java.awt.event.WindowListener; - -/** - * This app works with OpenFinDockingDemo as another dockable Java window - * - * Created by wche on 3/9/2016. - */ -public class DockingDemo2 extends JPanel implements ActionListener, WindowListener { - private final static Logger logger = LoggerFactory.getLogger(DockingDemo2.class.getName()); - - protected String javaParentAppUuid = "Java Parent App"; // Its value must match OpenFinDockingDemo. Please see OpenFinDockingDemo for comments - - protected String appUuid = "AnotherJavaDocking"; // UUID for desktopConnection - protected String javaWindowName = "Another Java Dock Window"; - - protected DesktopConnection desktopConnection; - protected ExternalWindowObserver externalWindowObserver; - - private static JFrame jFrame; - protected JButton undockButton; - protected JTextField dockStatus; // show Ready to dock message - - public DockingDemo2() { - try { - this.desktopConnection = new DesktopConnection(appUuid); - startOpenFinRuntime(); - } catch (DesktopException desktopError) { - desktopError.printStackTrace(); - } - setLayout(new BorderLayout()); - add(layoutCenterPanel(), BorderLayout.CENTER); - add(layoutLeftPanel(), BorderLayout.WEST); - setBorder(BorderFactory.createEmptyBorder(20,20,20,20)); - } - - private JPanel layoutLeftPanel() { - JPanel panel = new JPanel(); - double size[][] = {{410}, {120, 30, TableLayout.FILL}}; - panel.setLayout(new TableLayout(size)); - panel.add(layoutActionButtonPanel(), "0,0,0,0"); - panel.add(layoutDockStatus(), "0,1,0,1"); - return panel; - } - - private JTextField layoutDockStatus() { - this.dockStatus = new JTextField(); - return this.dockStatus; - } - - private JPanel layoutActionButtonPanel() { - JPanel buttonPanel = new JPanel(); - JPanel topPanel = new JPanel(); - double size[][] = {{10, 190, 20, 190, 10}, {25, 10, 25, 10}}; - topPanel.setLayout(new TableLayout(size)); - topPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createBevelBorder(2), "Desktop")); - undockButton = new JButton("Undock"); - undockButton.setActionCommand("undock-window"); - undockButton.setEnabled(false); - topPanel.add(undockButton, "1,0,1,0"); - undockButton.addActionListener(this); - buttonPanel.add(topPanel, "0,0"); - return buttonPanel; - } - - private JPanel layoutCenterPanel() { - JPanel panel = new JPanel(); - double size[][] = {{TableLayout.FILL}, {150, 150, TableLayout.FILL}}; - panel.setLayout(new TableLayout(size)); - - return panel; - } - - private void undockFromOtherWindows() { - try { - // send message to Docking Manager to undock me - JSONObject msg = new JSONObject(); - msg.put("applicationUuid", javaParentAppUuid); - msg.put("windowName", javaWindowName); - desktopConnection.getInterApplicationBus().publish("undock-window", msg); - - } catch (Exception e) { - e.printStackTrace(); - } - undockButton.setEnabled(false); - } - - private void startOpenFinRuntime() { - try { - DesktopStateListener listener = new DesktopStateListener() { - @Override - public void onReady() { - onRuntimeReady(); - } - - @Override - public void onClose(String error) { - } - @Override - public void onError(String reason) { - logger.error("Connection failed: " + reason); - java.lang.System.exit(0); - } - @Override - public void onMessage(String message) { - } - @Override - public void onOutgoingMessage(String message) { - } - }; - desktopConnection.setAdditionalRuntimeArguments(" --v=1"); // enable additional logging from Runtime - - String desktopVersion = java.lang.System.getProperty("com.openfin.demo.version"); - if (desktopVersion == null) { - desktopVersion = "stable"; - } - desktopConnection.connectToVersion(desktopVersion, listener, 60); // 5.44.10.26 has fix for cross-app docking, which is required for windowsInShameGroupMoveTogether - - } catch (Exception e) { - e.printStackTrace(); - } - } - private void onRuntimeReady() { - try { - this.desktopConnection.getInterApplicationBus().subscribe("*", "window-docked", (uuid, topic, data) -> { - JSONObject event = (JSONObject) data; - String appUuid = event.getString("applicationUuid"); - String windowName = event.getString("windowName"); - if (javaParentAppUuid.equals(appUuid) && javaWindowName.equals(windowName)) { - updateUndockButton(true); - } - }); - this.desktopConnection.getInterApplicationBus().subscribe("*", "window-undocked", (uuid, topic, data) -> { - JSONObject event = (JSONObject) data; - String appUuid = event.getString("applicationUuid"); - String windowName = event.getString("windowName"); - if (javaParentAppUuid.equals(appUuid) && javaWindowName.equals(windowName)) { - updateUndockButton(false); - } - }); - registerJavaWindow(); - Application javaParentApp = Application.wrap(javaParentAppUuid, desktopConnection); - javaParentApp.addEventListener("closed", actionEvent -> { shutdown(); }, null); - } catch (Exception e) { - logger.error("Error creating DockingManager", e); - } - } - - private void registerJavaWindow() { - try { - externalWindowObserver = new ExternalWindowObserver(desktopConnection.getPort(), javaParentAppUuid, javaWindowName, jFrame, - new AckListener() { - @Override - public void onSuccess(Ack ack) { - try { - if (ack.isSuccessful()) { - JSONObject request = new JSONObject(); - request.put("applicationUuid", javaParentAppUuid); - request.put("windowName", javaWindowName); - desktopConnection.getInterApplicationBus().publish("register-docking-window", request); - } - } catch (Exception ex) { - logger.error("Error registering window", ex); - } - } - @Override - public void onError(Ack ack) { - logger.error("Error registering java window ", ack.getReason()); - } - }); - } catch (Exception e) { - logger.error("Error registering external window", e); - } - } - - public void actionPerformed(java.awt.event.ActionEvent e) { - if ("undock-window".equals(e.getActionCommand())) { - undockFromOtherWindows(); - } - } - private void updateUndockButton(boolean enabled) { - this.undockButton.setEnabled(enabled); - if (enabled) { - this.dockStatus.setText("Docked. Click Unlock button to undock"); - } else { - this.dockStatus.setText(""); - } - } - - private static void createAndShowGUI() { - //Create and set up the window. - jFrame = new JFrame("Another Java Docking Demo"); - jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - - //Create and set up the content pane. - DockingDemo2 newContentPane = new DockingDemo2(); - newContentPane.setOpaque(true); //content panes must be opaque - jFrame.setContentPane(newContentPane); - jFrame.addWindowListener(newContentPane); - - //Display the window. - jFrame.pack(); - jFrame.setSize(470, 300); - jFrame.setLocation(600, 400); -// jFrame.setLocationRelativeTo(null); - jFrame.setResizable(false); - jFrame.setVisible(true); - } - - private void shutdown() { - logger.debug("shutting down"); - if (externalWindowObserver != null) { - logger.debug("Closing"); - try { - JSONObject request = new JSONObject(); - request.put("applicationUuid", javaParentAppUuid); - request.put("windowName", javaWindowName); - desktopConnection.getInterApplicationBus().publish("unregister-docking-window", request); - Thread.sleep(2000); // give time to flush messages to Runtime - externalWindowObserver.dispose(); - desktopConnection.disconnect(); - Thread.sleep(1000); // give time to flush messages to Runtime - } catch (Exception ex) { - logger.error("Error existing", ex); - } - } - } - - /** - * - * @param args - */ - public static void main(String[] args) { - javax.swing.SwingUtilities.invokeLater(new Runnable() { - public void run() { - createAndShowGUI(); - } - }); - } - - @Override - public void windowOpened(WindowEvent e) { - - } - - @Override - public void windowClosing(WindowEvent e) { - shutdown(); - } - - @Override - public void windowClosed(WindowEvent e) { - - } - - @Override - public void windowIconified(WindowEvent e) { - - } - - @Override - public void windowDeiconified(WindowEvent e) { - - } - - @Override - public void windowActivated(WindowEvent e) { - - } - - @Override - public void windowDeactivated(WindowEvent e) { - - } -} - - diff --git a/src/main/java/com/openfin/desktop/demo/FDC3Example.java b/src/main/java/com/openfin/desktop/demo/FDC3Example.java deleted file mode 100644 index 9f10972..0000000 --- a/src/main/java/com/openfin/desktop/demo/FDC3Example.java +++ /dev/null @@ -1,361 +0,0 @@ -package com.openfin.desktop.demo; - -import com.openfin.desktop.*; -import com.openfin.desktop.fdc3.*; -import org.json.JSONArray; -import org.json.JSONObject; - -import javax.swing.*; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.io.IOException; -import java.lang.System; -import java.util.List; -import java.util.UUID; - -public class FDC3Example implements DesktopStateListener { - - private final static String javaConnectUuid = "JavaFDC3Demo"; - - private DesktopConnection desktopConnection; - private JFrame mainWindow; - private JButton btnLaunchRed; - private JButton btnTickerToRed; - private JButton btnFindIntent; - private JButton btnFindContextIntent; - private JButton btnBroadcast; - private JButton btnJoinRed; - private JButton btnIntentListener; - - private JTextArea output; // show output of API - private String ticker = "AAPL"; - - private FDC3Client fdc3Client; - - private JSONArray serviceConfig = new JSONArray(); - - FDC3Example() { - try { - this.createMainWindow(); - this.launchOpenfin(); - } - catch (Exception e) { - e.printStackTrace(); - } - } - - void createMainWindow() { - this.mainWindow = new JFrame("FDC3 Demo"); - this.mainWindow.setResizable(false); - this.mainWindow.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); - this.mainWindow.addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(WindowEvent we) { - try { -// application.close(); - Thread.sleep(1000); - java.lang.System.exit(0); - } - catch (Exception de) { - de.printStackTrace(); - } - } - }); - - JPanel contentPnl = new JPanel(new BorderLayout(10, 10)); - contentPnl.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); - JPanel pnl = new JPanel(); - pnl.setLayout(new BoxLayout(pnl, BoxLayout.Y_AXIS)); - - this.btnLaunchRed = new JButton("Start Charts: Red"); - this.btnLaunchRed.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - startReds(); - } - }); - this.btnLaunchRed.setEnabled(false); - pnl.add(btnLaunchRed); - - this.btnTickerToRed = new JButton("Send ticker to Red"); - this.btnTickerToRed.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - sendTickerToReds(); - } - }); - this.btnTickerToRed.setEnabled(false); - pnl.add(btnTickerToRed); - - this.btnFindIntent = new JButton("Find intent of ViewChart"); - this.btnFindIntent.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - findIntent(); - } - }); - this.btnFindIntent.setEnabled(false); - pnl.add(btnFindIntent); - - this.btnFindContextIntent = new JButton("Find intent of fdc3.instrument context"); - this.btnFindContextIntent.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - findContextIntent(); - } - }); - this.btnFindContextIntent.setEnabled(false); - pnl.add(btnFindContextIntent); - - this.btnBroadcast = new JButton("Broadcast to default channel"); - this.btnBroadcast.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - broadcast(); - } - }); - this.btnBroadcast.setEnabled(false); - pnl.add(btnBroadcast); - - this.btnJoinRed = new JButton("Join Red channel"); - this.btnJoinRed.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - joinRed(); - } - }); - this.btnJoinRed.setEnabled(false); - pnl.add(btnJoinRed); - - this.btnIntentListener = new JButton("Register an intent listener"); - this.btnIntentListener.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - addIntentListener(); - } - }); - this.btnIntentListener.setEnabled(false); - pnl.add(btnIntentListener); - - pnl.add(layoutOutputPanel()); - - contentPnl.add(pnl, BorderLayout.CENTER); - - this.mainWindow.getContentPane().add(contentPnl); - this.mainWindow.setLocationRelativeTo(null); - this.mainWindow.setSize(400, 400); - this.mainWindow.setVisible(true); - } - - protected JScrollPane layoutOutputPanel() { - output = new JTextArea(100, 40); - output.setEditable(false); - output.setAutoscrolls(true); - output.setLineWrap(true); - output.setMinimumSize(new Dimension(40, 100)); - output.setPreferredSize(new Dimension(40, 100)); - JScrollPane statusPane = new JScrollPane(output); - statusPane.setVerticalScrollBarPolicy( - JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); - statusPane.setPreferredSize(new Dimension(500, 650)); - return statusPane; - } - - void launchOpenfin() throws DesktopException, DesktopIOException, IOException, InterruptedException { - RuntimeConfiguration config = new RuntimeConfiguration(); - config.setRuntimeVersion("alpha"); -// config.setRuntimeVersion("10.66.41.18"); - config.setAdditionalRuntimeArguments("--v=1 "); -// serviceConfig = new JSONArray(); -// JSONObject layout = new JSONObject(); -// layout.put("name", "fdc3"); -// serviceConfig.put(0, layout); -// config.addConfigurationItem("services", serviceConfig); - - this.desktopConnection = new DesktopConnection(javaConnectUuid); - this.desktopConnection.connect(config, this, 60); - } - - @Override - public void onReady() { - this.fdc3Client = FDC3Client.getInstance(this.desktopConnection); - this.fdc3Client.connect(new AckListener() { - @Override - public void onSuccess(Ack ack) { - btnLaunchRed.setEnabled(true); - btnTickerToRed.setEnabled(true); - btnFindIntent.setEnabled(true); - btnFindContextIntent.setEnabled(true); - btnBroadcast.setEnabled(true); - btnJoinRed.setEnabled(true); - btnIntentListener.setEnabled(true); - addContextListener(); - output.setText(String.format("Connected to FDC3 service")); - } - @Override - public void onError(Ack ack) { - output.setText(String.format("Failed to Connect to FDC3 service")); - } - }); - } - - private void startReds() { - fdc3Client.open("fdc3-charts-red", null, new AckListener() { - @Override - public void onSuccess(Ack ack) { - output.setText(String.format("FDC3 started %b", ack.isSuccessful())); - } - @Override - public void onError(Ack ack) { - output.setText(String.format("FDC3 started failed %s", ack.getReason())); - } - }); - } - - private void sendTickerToReds() { - String ticker = getTicker(); - Context context = new Context("fdc3.instrument", ticker); - JSONObject id = new JSONObject(); - id.put("ticker", ticker.toLowerCase()); - context.setId(id); - fdc3Client.raiseIntent("ViewChart", context, "fdc3-charts-red", new AsyncCallback() { - @Override - public void onSuccess(IntentResolution result) { - output.setText(String.format("IntentResolution source=%s, version=%s", result.getSource(), result.getVersion())); - } - }); - } - - private void findIntent() { - fdc3Client.findIntent("ViewChart", null, new AsyncCallback() { - @Override - public void onSuccess(AppIntent result) { - output.setText(result.toString()); - - } - }); - } - - private void findContextIntent() { - String ticker = getTicker(); - Context context = new Context("fdc3.instrument", ticker); - - fdc3Client.findIntentsByContext(context, new AsyncCallback>() { - - @Override - public void onSuccess(List result) { - for (int i=0; i() { - @Override - public void onSuccess(Channel channel) { - if (channel != null) { - channel.join(new AckListener() { - @Override - public void onSuccess(Ack ack) { - if (ack.isSuccessful()) { - output.setText(String.format("Joined red channel")); - } else { - output.setText(String.format("Failed to join red channel %s", ack.getReason())); - } - } - @Override - public void onError(Ack ack) { - output.setText(String.format("Failed to join red channel %s", ack.getReason())); - } - }); - } - } - }); - } - - private void addIntentListener() { - fdc3Client.addIntentListener("ViewChartByJava", new IntentListener() { - @Override - public JSONObject onIntent(Context context) { - output.setText(String.format("Received Intent: %s", context.toString())); - context.put("comment", "Java rules"); - return context; - } - }, new AckListener() { - @Override - public void onSuccess(Ack ack) { - if (ack.isSuccessful()) { - output.setText("Registered intent listener"); - } else { - output.setText(String.format("Failed to register intent listener %s", ack.getReason())); - } - } - - @Override - public void onError(Ack ack) { - output.setText(String.format("Failed to register intent listener %s", ack.getReason())); - } - }); - } - - private void addContextListener() { - fdc3Client.addContextListener(new ContextListener() { - @Override - public JSONObject onContext(Context result) { - output.setText(String.format("Received context: %s", result.toString())); - return null; - } - }, null); - } - - private String getTicker() { - this.ticker = this.ticker.equals("AAPL") ? "MSFT" : "AAPL"; - return this.ticker; - } - - @Override - public void onClose(String error) { - - } - - @Override - public void onError(String reason) { - } - - @Override - public void onMessage(String message) { - } - - @Override - public void onOutgoingMessage(String message) { - } - - public static void main(String[] args) { - new FDC3Example(); - } - -} diff --git a/src/main/java/com/openfin/desktop/demo/JNLPExample.java b/src/main/java/com/openfin/desktop/demo/JNLPExample.java index ce8a612..646a244 100644 --- a/src/main/java/com/openfin/desktop/demo/JNLPExample.java +++ b/src/main/java/com/openfin/desktop/demo/JNLPExample.java @@ -63,7 +63,9 @@ public JNLPExample() throws DesktopException { startButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { - desktopConnection.connectToVersion("stable", listener, 100000); + RuntimeConfiguration cfg = new RuntimeConfiguration(); + cfg.setRuntimeVersion("stable"); + desktopConnection.connect(cfg, listener, 30); } catch (Exception ex) { ex.printStackTrace(); } diff --git a/src/main/java/com/openfin/desktop/demo/LauncherBusDemo.java b/src/main/java/com/openfin/desktop/demo/LauncherBusDemo.java index fbbf36d..58d2cf3 100644 --- a/src/main/java/com/openfin/desktop/demo/LauncherBusDemo.java +++ b/src/main/java/com/openfin/desktop/demo/LauncherBusDemo.java @@ -9,8 +9,6 @@ import com.openfin.desktop.*; import com.openfin.desktop.Window; import com.openfin.desktop.channel.*; -import com.openfin.desktop.channel.NotificationListener; -import com.openfin.desktop.channel.NotificationOptions; import com.openfin.desktop.win32.ExternalWindowObserver; import com.sun.jna.Native; import info.clearthought.layout.TableLayout; @@ -30,10 +28,8 @@ public class LauncherBusDemo extends JFrame { private DesktopConnection desktopConnection; private InterApplicationBus interApplicationBus; - private NotificationClient notificationClient; private JButton btnOFApp1, btnOFApp2; private JButton btnTabOFApp1; - private JButton btnNotification, btnToggleNotification; // button to create notifications private JButton btnUndock; // button to undock this Java window private JButton btnOFSendApp1, btnOFSendApp2; // send messages to OpenFin app via Inter App Bus private JButton btnGenerateWorkSpace, btnRestoreWorkSpace; @@ -104,26 +100,6 @@ public void actionPerformed(java.awt.event.ActionEvent e) { } }); - btnNotification = new JButton(); - btnNotification.setText("Notification"); - btnNotification.setEnabled(false); - btnNotification.addActionListener(new ActionListener() { - @Override - public void actionPerformed(java.awt.event.ActionEvent e) { - createNotification(); - } - }); - - btnToggleNotification = new JButton(); - btnToggleNotification.setText("Toggle Notification CENTER"); - btnToggleNotification.setEnabled(false); - btnToggleNotification.addActionListener(new ActionListener() { - @Override - public void actionPerformed(java.awt.event.ActionEvent e) { - toggleNotificationCenter(); - } - }); - btnGenerateWorkSpace = new JButton(); btnGenerateWorkSpace.setText("Generate WorkSpace"); btnGenerateWorkSpace.setEnabled(false); @@ -157,8 +133,6 @@ public void actionPerformed(java.awt.event.ActionEvent e) { topPanel.add(btnOFApp2, "1,4,1,4"); topPanel.add(btnOFSendApp1, "1,6,1,6"); topPanel.add(btnOFSendApp2, "1,8,1,8"); - topPanel.add(btnNotification, "1,10,1,10"); - topPanel.add(btnToggleNotification, "1,12,1,12"); topPanel.add(btnGenerateWorkSpace, "1,14,1,14"); topPanel.add(btnRestoreWorkSpace, "1,16,1,16"); topPanel.add(btnUndock, "1,18,1,18"); @@ -242,7 +216,6 @@ public void onReady() { configAppEventListener(); createEmbddedApp(); createLayoutClient(); - createNotificationClient(); } @Override @@ -468,47 +441,6 @@ public void onError(Ack ack) { } }); } - private void createNotificationClient() { - this.notificationClient = new NotificationClient(this.desktopConnection, new AckListener() { - @Override - public void onSuccess(Ack ack) { - btnNotification.setEnabled(true); - btnToggleNotification.setEnabled(true); - LauncherBusDemo.this.notificationClient.addNotificationListener(new NotificationListener() { - @Override - public void onClick(NotificationOptions options) { - logger.info(String.format("Notification clicked %s", options.getId())); - } - @Override - public void onButtonClick(NotificationOptions options) { - logger.info(String.format("Notification button clicked %s button index %d", options.getId(), - options.getButtonIndex())); - } - @Override - public void onClose(NotificationOptions options) { - logger.info(String.format("Notification closed %s", options.getId())); - } - }); - } - @Override - public void onError(Ack ack) { - - } - }); - } - private void createNotification() { - NotificationOptions options = new NotificationOptions(); - options.setId(UUID.randomUUID().toString()); - options.setBody("Hello From Java app"); - options.setTitle("Java Demo"); - options.setIcon("https://openfin.co/favicon.ico"); - options.addButton(null, "button1"); - options.addButton(null, "button2"); - this.notificationClient.create(options, null); - } - private void toggleNotificationCenter() { - this.notificationClient.toggleNotificationCenter(null); - } private void generateWorkSpace() { this.layoutClient.generateWorkspace(new AsyncCallback() { diff --git a/src/main/java/com/openfin/desktop/demo/MemoryProfile.java b/src/main/java/com/openfin/desktop/demo/MemoryProfile.java new file mode 100644 index 0000000..0b22811 --- /dev/null +++ b/src/main/java/com/openfin/desktop/demo/MemoryProfile.java @@ -0,0 +1,96 @@ +package com.openfin.desktop.demo; + +import com.openfin.desktop.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; + + +/** + * This class can be used to profile memory usage of Java Adapter for communicating with Runtime. The initial version + * just keeps calling getMachineId API. It can easily extended to test other APIs. + * + * VisualVM, available from https://visualvm.github.io/, can be used to monitor memory usgage while this code is running + */ + +public class MemoryProfile { + private final static Logger logger = LoggerFactory.getLogger(MemoryProfile.class.getName()); + + public static void main(String[] args) { + RuntimeConfiguration runtimeConfiguration = new RuntimeConfiguration(); + String connectionUuid = MemoryProfile.class.getName(); + String desktopVersion = java.lang.System.getProperty("com.openfin.demo.version"); + if (desktopVersion == null) { + desktopVersion = "stable"; + } + runtimeConfiguration.setRuntimeVersion(desktopVersion); + try { + final DesktopConnection desktopConnection = new DesktopConnection(connectionUuid); + DesktopStateListener listener = new DesktopStateListener() { + @Override + public void onReady() { + launchThread(desktopConnection); + } + @Override + public void onClose(String error) { + + } + @Override + public void onError(String reason) { + logger.error(String.format("onError %s", reason)); + } + + @Override + public void onMessage(String message) { + } + @Override + public void onOutgoingMessage(String message) { + } + }; + desktopConnection.connect(runtimeConfiguration, listener, 50); + } catch (Exception e) { + logger.error("", e); + } + } + + private static void launchThread(DesktopConnection desktopConnection) { + Thread t = new Thread() { + @Override + public void run() { + OpenFinRuntime openfinSystem = new OpenFinRuntime(desktopConnection); + AtomicInteger callCount = new AtomicInteger(); + AtomicBoolean shouldRun = new AtomicBoolean(true); + while (shouldRun.get()) { + try { + CountDownLatch latch = new CountDownLatch(1); + openfinSystem.getMachineId(new AckListener() { + @Override + public void onSuccess(Ack ack) { + if (ack.isSuccessful()) { + logger.info(String.format("API call count %d", callCount.incrementAndGet())); + latch.countDown(); + } else { + logger.error(String.format("API failed %s", ack.getReason())); + shouldRun.set(false); + } + } + @Override + public void onError(Ack ack) { + logger.error(String.format("API failed %s", ack.getReason())); + shouldRun.set(false); + } + }); + latch.await(1, TimeUnit.SECONDS); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + } + }; + t.start(); + } +} diff --git a/src/main/java/com/openfin/desktop/demo/NoGui.java b/src/main/java/com/openfin/desktop/demo/NoGui.java index 9b9d625..3076fff 100644 --- a/src/main/java/com/openfin/desktop/demo/NoGui.java +++ b/src/main/java/com/openfin/desktop/demo/NoGui.java @@ -76,7 +76,9 @@ public void onOutgoingMessage(String message) { System.out.println("Main.onOutgoingMessage"); } }; - desktopConnection.connectToVersion("6.49.12.17", listener, 5000); + RuntimeConfiguration cfg = new RuntimeConfiguration(); + cfg.setRuntimeVersion("stable"); + desktopConnection.connect(cfg, listener, 50); try { // keep Runtime running for 10 seconds diff --git a/src/main/java/com/openfin/desktop/demo/NotificationServiceDemo.java b/src/main/java/com/openfin/desktop/demo/NotificationServiceDemo.java index 9d40d6f..30d5c3f 100644 --- a/src/main/java/com/openfin/desktop/demo/NotificationServiceDemo.java +++ b/src/main/java/com/openfin/desktop/demo/NotificationServiceDemo.java @@ -157,8 +157,8 @@ private JPanel createCreateNotificationPanel() { JTextField tfBody = new JTextField("Body"); JTextField tfCategory = new JTextField("Category"); JTextField tfIcon = new JTextField("https://openfin.co/favicon-32x32.png"); - JTextField tfIndicatorText = new JTextField(""); - JTextField tfExpiresInSecs = new JTextField("5"); + JTextField tfIndicatorText = new JTextField("Hello From Java"); + JTextField tfExpiresInSecs = new JTextField("60"); JComboBox cbSticky = new JComboBox<>(); cbSticky.addItem(NotificationOptions.STICKY_STICKY); @@ -168,6 +168,7 @@ private JPanel createCreateNotificationPanel() { cbIndicator.addItem(NotificationIndicator.TYPE_FAILURE); cbIndicator.addItem(NotificationIndicator.TYPE_WARNING); cbIndicator.addItem(NotificationIndicator.TYPE_SUCCESS); + cbIndicator.setSelectedIndex(2); JPanel pnlCenter = new JPanel(new GridBagLayout()); GridBagConstraints gbConst = new GridBagConstraints(); diff --git a/src/main/java/com/openfin/desktop/demo/OpenFinDockingDemo.java b/src/main/java/com/openfin/desktop/demo/OpenFinDockingDemo.java deleted file mode 100644 index 57da058..0000000 --- a/src/main/java/com/openfin/desktop/demo/OpenFinDockingDemo.java +++ /dev/null @@ -1,516 +0,0 @@ -package com.openfin.desktop.demo; - -import com.openfin.desktop.DockingManager; -import com.openfin.desktop.*; -import info.clearthought.layout.TableLayout; -import org.json.JSONObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.swing.*; -import java.awt.*; -import java.awt.event.*; -import java.io.*; -import java.lang.System; -import java.util.Arrays; - -/** - * Example of snap&dock Java window with OpenFin html5 window - * - * Move windows close to each other so they snap, and release mouse to dock 2 windows. - * - * This example use snap and dock library at https://github.com/openfin/java-snap-and-dock. - * - * Steps to implement snap&dock in this example - * - * 1. Launch OpenFin Runtime, as in startOpenFinRuntime - * 2. Create an instance of DockingManager - * 2. Launch a HTML5 app and register with DockingManager as in launchHTMLApps - * 3. Register Java window as in DockingManager registerJavaWindow - * - * All windows can receive notification when it is docked by subscribing to 'window-docked' topic. It can also request to be undocked - * by sending a message to Docking Manager. Please refer to document of Snap&Dock library for more into - * - * Created by wche on 2/28/15. - * - */ -public class OpenFinDockingDemo extends JPanel implements ActionListener, WindowListener { - private final static Logger logger = LoggerFactory.getLogger(OpenFinDockingDemo.class.getName()); - - private static JFrame jFrame; - protected JButton launch; - protected JButton close; - - protected JButton undockButton; - - // For a Java window to be dockable, it must be registered with Runtime as a child window of a HTML5 app. We are going to create - // a hidden HTML5 app, with javaParentAppUuid as UUID, as the parent app of all Java windows - protected String javaParentAppUuid = "Java Parent App"; - - protected String appUuid = "JavaDocking"; // UUID for desktopConnection - protected String javaWindowName = "Java Dock Window"; - protected String openfin_app_url = "https://cdn.openfin.co/examples/junit/SimpleDockingExample.html"; // source is in release/SimpleDockingExample.html - - protected DesktopConnection desktopConnection; - protected DockingManager dockingManager; - protected JTextField dockStatus; // show Ready to dock message - protected JTextArea status; - - public OpenFinDockingDemo() { - try { - this.desktopConnection = new DesktopConnection(appUuid); - } catch (DesktopException desktopError) { - desktopError.printStackTrace(); - } - setLayout(new BorderLayout()); - add(layoutCenterPanel(), BorderLayout.CENTER); - add(layoutLeftPanel(), BorderLayout.WEST); - setBorder(BorderFactory.createEmptyBorder(20,20,20,20)); - setMainButtonsEnabled(false); - setAppButtonsEnabled(false); - } - - private JPanel layoutLeftPanel() { - JPanel panel = new JPanel(); - double size[][] = {{410}, {120, 30, TableLayout.FILL}}; - panel.setLayout(new TableLayout(size)); - panel.add(layoutActionButtonPanel(), "0,0,0,0"); - panel.add(layoutDockStatus(), "0,1,0,1"); - panel.add(layoutStatusPanel(), "0, 2, 0, 2"); - return panel; - } - - private JTextField layoutDockStatus() { - this.dockStatus = new JTextField(); - this.dockStatus.setForeground(Color.RED); - return this.dockStatus; - } - - private JPanel layoutActionButtonPanel() { - JPanel buttonPanel = new JPanel(); - - JPanel topPanel = new JPanel(); - double size[][] = {{10, 190, 20, 190, 10}, {25, 10, 25, 10}}; - topPanel.setLayout(new TableLayout(size)); - topPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createBevelBorder(2), "Desktop")); - - launch = new JButton("Launch OpenFin"); - launch.setActionCommand("start"); - close = new JButton("Shutdown OpenFin"); - close.setActionCommand("close"); - topPanel.add(launch, "1,0,1,0"); - topPanel.add(close, "3,0,3,0"); - - undockButton = new JButton("Undock"); - undockButton.setActionCommand("undock-window"); - undockButton.setEnabled(false); - topPanel.add(undockButton, "1,2,1,2"); - - close.addActionListener(this); - launch.addActionListener(this); - undockButton.addActionListener(this); - - buttonPanel.add(topPanel, "0,0"); - return buttonPanel; - } - - private JPanel layoutCenterPanel() { - JPanel panel = new JPanel(); - double size[][] = {{TableLayout.FILL}, {150, 150, TableLayout.FILL}}; - panel.setLayout(new TableLayout(size)); - - return panel; - } - - protected JPanel layoutStatusPanel() { - //Simple status console - status = new JTextArea(); - status.setEditable(false); - status.setAutoscrolls(true); - status.setLineWrap(true); - JScrollPane statusPane = new JScrollPane(status); - statusPane.setVerticalScrollBarPolicy( - JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); - statusPane.getViewport().setOpaque(false); - statusPane.setOpaque(false); - statusPane.setBorder(BorderFactory.createEmptyBorder(5,15,15,15)); - - - - JPanel panel = new JPanel(); - panel.setLayout(new BorderLayout()); - panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createBevelBorder(2), "Status")); - panel.add(statusPane, BorderLayout.CENTER); - - return panel; - } - - @Override - public void windowOpened(WindowEvent e) { - } - - @Override - public void windowClosing(WindowEvent e) { - closeDesktop(); - } - - @Override - public void windowClosed(WindowEvent e) { - } - - @Override - public void windowIconified(WindowEvent e) { - } - - @Override - public void windowDeiconified(WindowEvent e) { - } - - @Override - public void windowActivated(WindowEvent e) { - } - - @Override - public void windowDeactivated(WindowEvent e) { - } - - private void updateMessagePanel(final String msg) { - if (SwingUtilities.isEventDispatchThread()) { - String t = ""; - if (status.getText().length() > 0) { - t = status.getText(); - } - StringBuilder b = new StringBuilder(); - b.append(msg).append("\n").append(t); - status.setText(b.toString()); - status.setCaretPosition(0); - } else { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - updateMessagePanel(msg); - } - }); - } - } - - - private void closeDesktop() { - if (desktopConnection != null && desktopConnection.isConnected()) { - try { - Application javaParentApp = Application.wrap(javaParentAppUuid, desktopConnection); - javaParentApp.close(); - dockingManager.dispose(); - Thread.sleep(2000); - desktopConnection.exit(); - desktopConnection = null; - } catch (Exception e) { - e.printStackTrace(); - } - } - - try { - Thread.sleep(2000); - System.exit(0); - } catch (InterruptedException e) { - e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. - } - } - - private void undockFromOtherWindows() { - try { - // send message to Docking Manager to undock me - JSONObject msg = new JSONObject(); - msg.put("applicationUuid", javaParentAppUuid); - msg.put("windowName", javaWindowName); - desktopConnection.getInterApplicationBus().publish("undock-window", msg); - - } catch (Exception e) { - e.printStackTrace(); - } - undockButton.setEnabled(false); - } - - /** - * - * Start OpenFin Runtime - * - */ - private void startOpenFinRuntime() { - try { - DesktopStateListener listener = new DesktopStateListener() { - @Override - public void onReady() { - onRuntimeReady(); - } - - @Override - public void onClose(String error) { - updateMessagePanel(String.format("Connection closed %s", error)); - } - @Override - public void onError(String reason) { - updateMessagePanel("Connection failed: " + reason); - } - @Override - public void onMessage(String message) { - } - @Override - public void onOutgoingMessage(String message) { - } - }; - RuntimeConfiguration configuration = new RuntimeConfiguration(); - configuration.setDevToolsPort(9090); - configuration.setAdditionalRuntimeArguments(" --v=1 "); // enable additional logging from Runtime - String desktopVersion = java.lang.System.getProperty("com.openfin.demo.version"); - if (desktopVersion == null) { - desktopVersion = "stable"; - } - configuration.setRuntimeVersion(desktopVersion); - desktopConnection.connect(configuration, listener, 60); - - } catch (Exception e) { - e.printStackTrace(); - } - } - - private void onRuntimeReady() { - try { - updateMessagePanel("Connection authorized."); - setMainButtonsEnabled(true); - this.dockingManager = new DockingManager(this.desktopConnection, this.javaParentAppUuid); - this.desktopConnection.getInterApplicationBus().subscribe("*", "window-docked", (uuid, topic, data) -> { - JSONObject event = (JSONObject) data; - String appUuid = event.getString("applicationUuid"); - String windowName = event.getString("windowName"); - updateMessagePanel(String.format("Window docked %s %s", appUuid, windowName)); - if (javaParentAppUuid.equals(appUuid) && javaWindowName.equals(windowName)) { - updateUndockButton(true); - } - }); - this.desktopConnection.getInterApplicationBus().subscribe("*", "window-undocked", (uuid, topic, data) -> { - JSONObject event = (JSONObject) data; - String appUuid = event.getString("applicationUuid"); - String windowName = event.getString("windowName"); - updateMessagePanel(String.format("Window undocked %s %s", appUuid, windowName)); - if (javaParentAppUuid.equals(appUuid) && javaWindowName.equals(windowName)) { - updateUndockButton(false); - } - }); - registerJavaWindow(); - launchHTMLApps(); - launchAnotherJavaApp(); - } catch (Exception e) { - logger.error("Error creating DockingManager", e); - } - } - - public void actionPerformed(java.awt.event.ActionEvent e) { - if ("start".equals(e.getActionCommand())) { - startOpenFinRuntime(); - } else if ("close".equals(e.getActionCommand())) { - closeDesktop(); - } else if ("undock-window".equals(e.getActionCommand())) { - undockFromOtherWindows(); - } - } - - - private void setMainButtonsEnabled(boolean enabled) { - launch.setEnabled(!enabled); - close.setEnabled(enabled); - } - - private void setAppButtonsEnabled(boolean enabled) { - } - - /** - * Register Java window with OpenFin Runtime - * - */ - private void registerJavaWindow() { - try { - // Java window needs to be assigned a HTML5 app as parent app in order for Runtime to control it. - // now we are creating a HTML5 app aith autoShow = false so it is hidden. - ApplicationOptions options = new ApplicationOptions(javaParentAppUuid, javaParentAppUuid, openfin_app_url); - options.setApplicationIcon("http://openfin.github.io/snap-and-dock/openfin.ico"); - WindowOptions mainWindowOptions = new WindowOptions(); - mainWindowOptions.setAutoShow(false); - mainWindowOptions.setDefaultHeight(50); - mainWindowOptions.setDefaultLeft(50); - mainWindowOptions.setDefaultTop(50); - mainWindowOptions.setDefaultWidth(50); - mainWindowOptions.setShowTaskbarIcon(false); - mainWindowOptions.setSaveWindowState(false); // set to false so all windows start at same initial positions for each run - options.setMainWindowOptions(mainWindowOptions); - launchHTMLApp(options, new AckListener() { - @Override - public void onSuccess(Ack ack) { - Application app = (Application) ack.getSource(); - logger.debug("Registering java window"); - dockingManager.registerJavaWindow(javaWindowName, jFrame, - new AckListener() { - @Override - public void onSuccess(Ack ack) { - if (ack.isSuccessful()) { - undockButton.setEnabled(false); - } - } - @Override - public void onError(Ack ack) { - logger.error("Error registering Java window " + ack.getReason()); - } - }); - } - @Override - public void onError(Ack ack) { - logger.error("Error launching " + javaParentAppUuid); - } - }); - } catch (Exception e) { - e.printStackTrace(); - } - } - - /** - * - * Launching HTML5 apps and register docking manager - * - */ - private void launchHTMLApps() { - // launch 5 instances of same example app - int width = 300, height=200; - int gap = 50; // gap between windows at initial positions - for (int i = 0; i < 2; i++) { - try { - String uuid = String.format("docking-html-%d", i); - ApplicationOptions options = new ApplicationOptions(uuid, uuid, openfin_app_url); - options.setApplicationIcon("http://openfin.github.io/snap-and-dock/openfin.ico"); - WindowOptions mainWindowOptions = new WindowOptions(); - mainWindowOptions.setAutoShow(true); - mainWindowOptions.setDefaultHeight(height); - mainWindowOptions.setDefaultLeft(10 + i * (width + gap)); - mainWindowOptions.setDefaultTop(50); - mainWindowOptions.setDefaultWidth(width); - mainWindowOptions.setShowTaskbarIcon(true); - mainWindowOptions.setSaveWindowState(false); // set to false so all windows start at same initial positions for each run - options.setMainWindowOptions(mainWindowOptions); - launchHTMLApp(options, new AckListener() { - @Override - public void onSuccess(Ack ack) { - logger.debug(String.format("Successful launching %s", options.getUUID())); - Application app = (Application) ack.getSource(); - dockingManager.registerWindow(app.getWindow()); - } - @Override - public void onError(Ack ack) { - logger.error(String.format("Error launching %s %s", options.getUUID(), ack.getReason())); - } - }); - } catch (Exception e) { - logger.error("Error launching app", e); - } - } - } - - private void launchHTMLApp(ApplicationOptions options, AckListener ackListener) throws Exception { - logger.debug(String.format("Launching %s", options.getUUID())); - DemoUtils.runApplication(options, this.desktopConnection, ackListener); - } - - - private void launchAnotherJavaApp() { - Thread launchThread = new Thread() { - public void run() { - logger.debug(String.format("Launching docking.bat %s", DockingDemo2.class.getName())); - String[] command = {"docking.bat", DockingDemo2.class.getName()}; - ProcessBuilder probuilder = new ProcessBuilder( command ); - //You can set up your work directory - probuilder.directory(new File(".")); - try { -// Process process = probuilder.start(); -// //Read out dir output -// InputStream is = process.getInputStream(); -// InputStreamReader isr = new InputStreamReader(is); -// BufferedReader br = new BufferedReader(isr); -// String line; -// while ((line = br.readLine()) != null) { -// logger.debug(String.format("Java App output: %s", line)); -// } -// int exitValue = process.waitFor(); -// logger.debug(String.format("Java app exit code %d", exitValue)); - - Process process = Runtime.getRuntime().exec("cmd"); - OutputStream stdin = process.getOutputStream(); - InputStream stderr = process.getErrorStream(); - InputStream stdout = process.getInputStream(); - String line = "start docking.bat " + DockingDemo2.class.getName() + "\n"; - stdin.write(line.getBytes()); - stdin.flush(); - stdin.close(); - // clean up if any output in stdout - BufferedReader brCleanUp = - new BufferedReader(new InputStreamReader(stdout)); - while ((line = brCleanUp.readLine()) != null) { - logger.debug("[Stdout] " + line); - } - brCleanUp.close(); - // clean up if any output in stderr - brCleanUp = - new BufferedReader(new InputStreamReader(stderr)); - while ((line = brCleanUp.readLine()) != null) { - logger.info("[Stderr] " + line); - } - brCleanUp.close(); - } catch (Exception ex) { - logger.error("Error launch java app", ex); - } - } - }; - launchThread.start(); - } - - private void updateUndockButton(boolean enabled) { - this.undockButton.setEnabled(enabled); - if (enabled) { - this.dockStatus.setText("Docked. Click Unlock button to undock"); - } else { - this.dockStatus.setText(""); - } - } - - - private static void createAndShowGUI() { - //Create and set up the window. - jFrame = new JFrame("Java Docking Demo"); - jFrame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); - - //Create and set up the content pane. - OpenFinDockingDemo newContentPane = new OpenFinDockingDemo(); - newContentPane.setOpaque(true); //content panes must be opaque - jFrame.setContentPane(newContentPane); - jFrame.addWindowListener(newContentPane); - - //Display the window. - jFrame.pack(); - jFrame.setSize(470, 300); - jFrame.setLocation(100, 400); -// jFrame.setLocationRelativeTo(null); - jFrame.setResizable(false); - jFrame.setVisible(true); - } - - - /** - * - * @param args - */ - public static void main(String[] args) { - javax.swing.SwingUtilities.invokeLater(new Runnable() { - public void run() { - createAndShowGUI(); - } - }); - } - -} diff --git a/src/test/java/com/openfin/desktop/ChannelTest.java b/src/test/java/com/openfin/desktop/ChannelTest.java index 7741654..e8009de 100644 --- a/src/test/java/com/openfin/desktop/ChannelTest.java +++ b/src/test/java/com/openfin/desktop/ChannelTest.java @@ -2,34 +2,21 @@ import static org.junit.Assert.assertEquals; +import java.util.Objects; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicReference; +import com.openfin.desktop.channel.*; import org.json.JSONObject; import org.junit.AfterClass; import org.junit.BeforeClass; -import org.junit.Ignore; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.openfin.desktop.channel.ChannelAction; -import com.openfin.desktop.channel.ChannelClient; -import com.openfin.desktop.channel.ChannelListener; -import com.openfin.desktop.channel.ChannelProvider; -import com.openfin.desktop.channel.ConnectionEvent; -import com.openfin.desktop.channel.Middleware; - /** - * JUnit tests for com.openfin.desktop.InterApplicationBus class - * - * Test cases in this class need to have access to an OpenFin HTML5 app to - * verify sub/pub workflow. Sources for the app can be found in release - * directory: PubSubExample.html. It is hosted by OpenFin at - * https://cdn.openfin.co/examples/junit/PubSubExample.html + * JUnit tests for OpenFin Channel API * * Created by wche on 1/27/16. * @@ -54,15 +41,25 @@ public static void teardown() throws Exception { @Test public void createChannelProvider() throws Exception { CountDownLatch latch = new CountDownLatch(1); - desktopConnection.getChannel("createChannelProviderTest").create(new AsyncCallback() { + desktopConnection.getChannel("createChannelProvider").create(new AsyncCallback() { @Override public void onSuccess(ChannelProvider provider) { latch.countDown(); } }); - latch.await(10, TimeUnit.SECONDS); + assertEquals(0, latch.getCount()); + } + @Test + public void createChannelProviderAsync() throws Exception { + CountDownLatch latch = new CountDownLatch(1); + desktopConnection.getChannel("createChannelProviderAsync").createAsync().thenAccept(provider -> { + if (Objects.nonNull(provider)) { + latch.countDown(); + } + }); + latch.await(10, TimeUnit.SECONDS); assertEquals(0, latch.getCount()); } @@ -81,12 +78,24 @@ public void onSuccess(ChannelClient result) { }); } }); - latch.await(10, TimeUnit.SECONDS); - assertEquals(0, latch.getCount()); } - + @Test + public void createChannelClientAsync() throws Exception { + CountDownLatch latch = new CountDownLatch(1); + final String channelName = "createChannelClientAsync"; + desktopConnection.getChannel(channelName).createAsync().thenAccept(provider -> { + desktopConnection.getChannel(channelName).connectAsync().thenAccept(client -> { + if (Objects.nonNull(client)) { + latch.countDown(); + } + }); + }); + latch.await(10, TimeUnit.SECONDS); + assertEquals(0, latch.getCount()); + } + @Test public void multipleChannelClients() throws Exception { CountDownLatch latch1 = new CountDownLatch(1); @@ -97,9 +106,7 @@ public void multipleChannelClients() throws Exception { desktopConnection.getChannel(channelName).create(new AsyncCallback() { @Override public void onSuccess(ChannelProvider provider) { - provider.register(providerActionName, new ChannelAction() { - @Override public JSONObject invoke(String action, Object payload, JSONObject senderIdentity) { return null; @@ -111,7 +118,6 @@ public JSONObject invoke(String action, Object payload, JSONObject senderIdentit @Override public void onSuccess(ChannelClient client) { client.dispatch(providerActionName, new JSONObject(), null); - client.register(clientActionName, new ChannelAction() { @Override public JSONObject invoke(String action, Object payload, JSONObject senderIdentity) { @@ -132,7 +138,6 @@ public JSONObject invoke(String action, Object payload, JSONObject senderIdentit return null; } }); - provider.publish(clientActionName, new JSONObject(), null); } }); @@ -297,35 +302,32 @@ public JSONObject invoke(String action, Object payload, JSONObject senderIdentit @Test public void connectionListener() throws Exception { final String channelName = "connectionListenerTest"; - CountDownLatch latch = new CountDownLatch(2); - - desktopConnection.getChannel(channelName).create(new AsyncCallback() { - @Override - public void onSuccess(ChannelProvider provider) { - desktopConnection.getChannel(channelName).addChannelListener(new ChannelListener() { + CountDownLatch latch = new CountDownLatch(3); + desktopConnection.getChannel(channelName).createAsync().thenAccept(provider -> { + provider.addProviderListener(new ChannelProviderListener() { + @Override + public void onClientConnect(ChannelClientConnectEvent connectionEvent) throws Exception { + latch.countDown(); + } + @Override + public void onClientDisconnect(ChannelClientConnectEvent connectionEvent) { + latch.countDown(); + } + }); + + desktopConnection.getChannel(channelName).connectAsync().thenAccept(client -> { + client.disconnect(new AckListener() { @Override - public void onChannelConnect(ConnectionEvent connectionEvent) { + public void onSuccess(Ack ack) { latch.countDown(); } - @Override - public void onChannelDisconnect(ConnectionEvent connectionEvent) { - latch.countDown(); + public void onError(Ack ack) { } }); - - desktopConnection.getChannel(channelName).connect(new AsyncCallback() { - @Override - public void onSuccess(ChannelClient client) { - client.disconnect(null); - } - - }); - } + }); }); - latch.await(10, TimeUnit.SECONDS); - assertEquals(0, latch.getCount()); } @@ -390,4 +392,38 @@ public void onError(Ack ack) { assertEquals(initValue + 3, resultValue.get()); } + @Test + public void rejectConnection() throws Exception { + final String channelName = "rejectConnectionTest"; + final String payloadValue = "reject me"; + final String rejectReason = "not allowed"; + + CountDownLatch latch = new CountDownLatch(1); + + desktopConnection.getChannel(channelName).createAsync().thenAccept(provider -> { + provider.addProviderListener(new ChannelProviderListener() { + @Override + public void onClientConnect(ChannelClientConnectEvent connectionEvent) throws Exception { + String payload = (String) connectionEvent.getPayload(); + if (payloadValue.equals(payload)) { + throw new Exception(rejectReason); + } + } + @Override + public void onClientDisconnect(ChannelClientConnectEvent connectionEvent) { + } + }); + + desktopConnection.getChannel(channelName).connectAsync(payloadValue).thenAccept(client -> { + }).exceptionally(ex -> { + if (ex.getMessage().contains(rejectReason)) { + latch.countDown(); + } + return null; + }); + }); + + latch.await(10, TimeUnit.SECONDS); + assertEquals(0, latch.getCount()); + } } diff --git a/src/test/java/com/openfin/desktop/InteropTest.java b/src/test/java/com/openfin/desktop/InteropTest.java index a9d2662..7b412c3 100644 --- a/src/test/java/com/openfin/desktop/InteropTest.java +++ b/src/test/java/com/openfin/desktop/InteropTest.java @@ -35,12 +35,12 @@ public static void setup() throws Exception { cfg.setManifestLocation("https://testing-assets.openfin.co/adapters/interop/app.json"); // cfg.setManifestLocation("http://localhost:5555/app.json"); desktopConnection = TestUtils.setupConnection(DESKTOP_UUID, cfg); + Thread.sleep(3000); // give time for the js app to start up and configure everything properly } @AfterClass public static void teardown() throws Exception { - OpenFinRuntime runtime = new OpenFinRuntime(desktopConnection); - runtime.exit(); + TestUtils.teardownDesktopConnection(desktopConnection); } @Test @@ -153,6 +153,15 @@ public void clientFireIntent() throws Exception { CompletionStage fireIntentFuture = desktopConnection.getInterop().connect(BROKER_NANE).thenCompose(client->{ return client.fireIntent(intent); }); + desktopConnection.getInterop().connect(BROKER_NANE).thenCompose(client->{ + return client.registerIntentListener("JavaIntent", intentReceived->{ + String ticker = intentReceived.getContext().getId().optString("ticker", ""); + StringBuilder sb = new StringBuilder(context.getId().getString("ticker")); + }).thenCompose(v -> { + return client.fireIntent(intent); + }); + }); + fireIntentFuture.toCompletableFuture().get(10, TimeUnit.SECONDS); } diff --git a/src/test/java/com/openfin/desktop/NotificationTest.java b/src/test/java/com/openfin/desktop/NotificationTest.java index 44f5765..eeb0fbf 100644 --- a/src/test/java/com/openfin/desktop/NotificationTest.java +++ b/src/test/java/com/openfin/desktop/NotificationTest.java @@ -47,128 +47,4 @@ public static void teardown() throws Exception { TestUtils.teardownDesktopConnection(desktopConnection); } - @Test - public void notificationEventListenersWork() throws Exception { - CountDownLatch onShowLatch = new CountDownLatch(1); - CountDownLatch onCloseLatch = new CountDownLatch(1); - - NotificationOptions options = new NotificationOptions(notification_url); - options.setTimeout(1000); - options.setMessageText("Unit test for notification"); - new Notification(options, new NotificationListener() { - @Override - public void onClick(Ack ack) { - logger.debug("onClick for notification"); - } - - @Override - public void onClose(Ack ack) { - logger.debug("onClose for notification"); - onCloseLatch.countDown(); - } - - @Override - public void onDismiss(Ack ack) { - logger.debug("onDismiss for notification"); - onCloseLatch.countDown(); - } - - @Override - public void onError(Ack ack) { - logger.error("onError for notification"); - } - - @Override - public void onMessage(Ack ack) { - logger.debug("onMessage for notification"); - } - - @Override - public void onShow(Ack ack) { - logger.debug("onShow for notification"); - onShowLatch.countDown(); - } - }, desktopConnection, new AckListener() { - @Override - public void onSuccess(Ack ack) { - } - @Override - public void onError(Ack ack) { - logger.error(ack.getReason()); - fail("onError"); - } - }); - - onShowLatch.await(5, TimeUnit.SECONDS); - onCloseLatch.await(5, TimeUnit.SECONDS); - assertEquals(onShowLatch.getCount(), 0); - assertEquals(onCloseLatch.getCount(), 0); - } - - @Test - public void sendMessage() throws Exception { - CountDownLatch latch = new CountDownLatch(1); - NotificationOptions options = new NotificationOptions(notification_url); - options.setMessage(new JSONObject("{message: \"JSONMessage\"}")); - //options.setMessageText("Notification Text"); - options.setTimeout(1000); - - NotificationListener nListener = new NotificationListener() { - - @Override - public void onClick(Ack ack) { - } - - @Override - public void onClose(Ack ack) { - } - - @Override - public void onDismiss(Ack ack) { - } - - @Override - public void onError(Ack ack) { - logger.error("onError for notification"); - } - - @Override - public void onMessage(Ack ack) { - logger.info("onMessage"); - latch.countDown(); - } - - @Override - public void onShow(Ack ack) { - } - }; - - AckListener ackListener = new AckListener() { - @Override - public void onSuccess(Ack ack) { - } - - @Override - public void onError(Ack ack) { - logger.error(ack.getReason()); - } - }; - - Notification n = new Notification(options, nListener, desktopConnection, ackListener); - n.sendMessage(new JSONObject("{message: \"JSONMessage2\"}"), new AckListener() { - - @Override - public void onSuccess(Ack ack) { - latch.countDown(); - } - - @Override - public void onError(Ack ack) { - logger.error("onError for sendMessage"); - } - }); - latch.await(10, TimeUnit.SECONDS); - assertEquals(0, latch.getCount()); - - } } diff --git a/src/test/java/com/openfin/desktop/OpenFinRuntimeTest.java b/src/test/java/com/openfin/desktop/OpenFinRuntimeTest.java index c9b593a..a741f7a 100644 --- a/src/test/java/com/openfin/desktop/OpenFinRuntimeTest.java +++ b/src/test/java/com/openfin/desktop/OpenFinRuntimeTest.java @@ -12,6 +12,7 @@ import org.json.JSONObject; import org.junit.AfterClass; import org.junit.BeforeClass; +import org.junit.Ignore; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -48,7 +49,7 @@ public static void teardown() throws Exception { public void getDeviceId() throws Exception { logger.debug("start getDeviceId"); CountDownLatch latch = new CountDownLatch(1); - runtime.getDeviceId(new AckListener() { + runtime.getMachineId(new AckListener() { @Override public void onSuccess(Ack ack) { if (ack.isSuccessful()) { @@ -398,6 +399,8 @@ public void onError(Ack ack) { } } + // this test does not work anymore with Secure By Default in place + @Ignore @Test public void startAndTerminateExternalProcess() throws Exception { CountDownLatch startLatch = new CountDownLatch(1); diff --git a/src/test/java/com/openfin/desktop/SnapshotTest.java b/src/test/java/com/openfin/desktop/SnapshotTest.java index fc8c676..d3513e1 100644 --- a/src/test/java/com/openfin/desktop/SnapshotTest.java +++ b/src/test/java/com/openfin/desktop/SnapshotTest.java @@ -1,9 +1,6 @@ package com.openfin.desktop; -import com.openfin.desktop.snapshot.SnapshotSource; import com.openfin.desktop.snapshot.SnapshotSourceProvider; -import com.sun.xml.internal.bind.v2.runtime.unmarshaller.LocatorEx; -import org.json.JSONArray; import org.json.JSONObject; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -16,7 +13,6 @@ import java.util.concurrent.TimeUnit; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; public class SnapshotTest implements SnapshotSourceProvider { diff --git a/src/test/java/com/openfin/desktop/SystemTest.java b/src/test/java/com/openfin/desktop/SystemTest.java index 9519b8f..135e02d 100644 --- a/src/test/java/com/openfin/desktop/SystemTest.java +++ b/src/test/java/com/openfin/desktop/SystemTest.java @@ -50,7 +50,7 @@ public static void teardown() throws Exception { @Test public void getDeviceId() throws Exception { CountDownLatch latch = new CountDownLatch(1); - runtime.getDeviceId(new AckListener() { + runtime.getMachineId(new AckListener() { @Override public void onSuccess(Ack ack) { if (ack.isSuccessful()) { @@ -393,6 +393,8 @@ public void onError(Ack ack) { } } + // this test does not work anymore with Secure By Default in place + @Ignore @Test public void startAndTerminateExternalProcess() throws Exception { CountDownLatch startLatch = new CountDownLatch(1); diff --git a/src/test/java/com/openfin/desktop/TestUtils.java b/src/test/java/com/openfin/desktop/TestUtils.java index d5cb4b3..a60b4c8 100644 --- a/src/test/java/com/openfin/desktop/TestUtils.java +++ b/src/test/java/com/openfin/desktop/TestUtils.java @@ -110,6 +110,7 @@ public static DesktopConnection setupConnection(String connectionUuid) throws Ex DesktopConnection desktopConnection = new DesktopConnection(connectionUuid); RuntimeConfiguration configuration = new RuntimeConfiguration(); configuration.setRuntimeVersion(runtimeVersion); + configuration.setMaxMessageSize(738320); String args = java.lang.System.getProperty("com.openfin.test.runtime.additionalRuntimeArguments"); if (args != null) { configuration.setAdditionalRuntimeArguments(args); @@ -298,15 +299,7 @@ public void eventReceived(ActionEvent actionEvent) { }; addEventListener(application, "closed", listener); - application.close(new AckListener() { - @Override - public void onSuccess(Ack ack) { - } - @Override - public void onError(Ack ack) { - logger.error(ack.getReason()); - } - }); + application.close(); stoppedLatch.await(5, TimeUnit.SECONDS); assertEquals("Close application timeout " + application.getUuid(), stoppedLatch.getCount(), 0); }