@Test
 public void testRunModalWithErrorDialogThrowsException() {
   final CountDownLatch latch = new CountDownLatch(1);
   final AtomicBoolean result = new AtomicBoolean();
   final I18NBoundMessage mockFailureMessage = mock(I18NBoundMessage.class);
   final Exception exception = new Exception("Failure");
   AbstractUIRunner.asyncRun(
       new ThrowableRunnable() {
         @Override
         public void run() throws Throwable {
           result.set(
               ProgressUtils.runModalWithErrorDialog(
                   PlatformUI.getWorkbench().getActiveWorkbenchWindow(),
                   JFaceUtils.wrap(
                       new Callable<Void>() {
                         @Override
                         public Void call() throws Exception {
                           latch.await();
                           throw exception;
                         }
                       },
                       "Test operation"),
                   mockFailureMessage));
         }
       });
   ProgressDialogFixture fixture = new ProgressDialogFixture();
   fixture.assertTask("Test operation");
   latch.countDown();
   fixture.waitForClose();
   verify(mockFailureMessage).error(JFaceUtils.class, exception);
   assertThat(result.get(), is(false));
 }
 @Test
 public void testProgressAndErrorReported() throws Exception {
   openDialog();
   final CountDownLatch latch = new CountDownLatch(1);
   try {
     AbstractUIRunner.syncRun(
         new ThrowableRunnable() {
           @Override
           public void run() throws Throwable {
             mEngine.setConnection(
                 new MockUIConnection() {
                   @Override
                   public void update(DeployedStrategy strategy, Strategy newConfiguration)
                       throws Exception {
                     latch.await();
                     throw new Exception("Update Failed");
                   }
                 });
           }
         });
     mBot.button("OK").click();
     ProgressDialogFixture fixture = new ProgressDialogFixture();
     fixture.assertTask("Updating strategy configuration on 'Engine'...");
     latch.countDown();
     ErrorDialogFixture errorDialog = new ErrorDialogFixture();
     errorDialog.assertError("Update Failed");
     errorDialog.dismiss();
   } finally {
     latch.countDown();
   }
 }
 private void openDialog() throws Exception {
   AbstractUIRunner.syncRun(
       new ThrowableRunnable() {
         @Override
         public void run() throws Throwable {
           mStrategy = createDeployedStrategy("Strategy1");
           mStrategy.setUrn(new ModuleURN("metc:strategy:system:Strategy1"));
           mStrategy.setClassName("Claz");
           mStrategy.setLanguage("Lang");
           mStrategy.setScriptPath("c:\\path");
           mStrategy.setRouteOrdersToServer(true);
           mEngine = createEngine("Engine");
           mEngine.setConnection(new MockUIConnection());
           mEngine.getDeployedStrategies().add(mStrategy);
           mDialog =
               PropertyDialog.createDialogOn(
                   PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                   StrategyEngineWorkbenchUI.DEPLOYED_STRATEGY_CONFIGURATION_PROPERTY_PAGE_ID,
                   mStrategy);
           mDialog.setBlockOnOpen(false);
           mDialog.open();
         }
       });
   mBot.shell("Properties for Strategy1 on Engine");
   SWTTestUtil.assertButtonDoesNotExist("Apply");
   SWTTestUtil.assertButtonDoesNotExist("Restore Defaults");
   SWTTestUtil.testReadOnlyText(mBot.textWithLabel("Instance Name:"), "Strategy1");
   SWTTestUtil.testReadOnlyText(mBot.textWithLabel("Class:"), "Claz");
   SWTTestUtil.testReadOnlyText(mBot.textWithLabel("Language:"), "Lang");
   SWTTestUtil.testReadOnlyText(mBot.textWithLabel("Script:"), "c:\\path");
 }
 @Test
 public void testPropertiesContextMenu() throws Exception {
   openDialog();
   // use index 1 since first tree is property page navigation tree
   SWTBotTree tree = mBot.tree(1);
   ContextMenuHelper.clickContextMenu(tree, "Add");
   new NewPropertyInputDialogTestFixture("keyx", "valuex").inputData();
   ContextMenuHelper.clickContextMenu(tree, "Add");
   new NewPropertyInputDialogTestFixture("keyz", "valuez").inputData();
   tree.getTreeItem("keyz").select();
   ContextMenuHelper.clickContextMenu(tree, "Delete");
   tree.unselect();
   // delete should not show up when the selection is empty
   assertThat(SWTTestUtil.getMenuItems(tree).get("Delete"), nullValue());
   mBot.button("OK").click();
   Thread.sleep(WAIT_TIME);
   AbstractUIRunner.syncRun(
       new ThrowableRunnable() {
         @Override
         public void run() throws Throwable {
           assertDeployedStrategy(
               mStrategy,
               mEngine,
               StrategyState.STOPPED,
               "Strategy1",
               "Claz",
               "Lang",
               "c:\\path",
               true,
               ImmutableMap.of("keyx", "valuex"));
         }
       });
 }
 @Test
 public void testInlineEditing() throws Exception {
   openDialog();
   mBot.button("Add New Property").click();
   new NewPropertyInputDialogTestFixture("key2", "value2").inputData();
   // use index 1 since first tree is property page navigation tree
   CustomTree tree = new CustomTree(mBot.tree(1).widget);
   tree.click(0, 1);
   mBot.sleep(500);
   mBot.text("value2").setText("value3");
   mBot.button("OK").click();
   Thread.sleep(WAIT_TIME);
   AbstractUIRunner.syncRun(
       new ThrowableRunnable() {
         @Override
         public void run() throws Throwable {
           assertDeployedStrategy(
               mStrategy,
               mEngine,
               StrategyState.STOPPED,
               "Strategy1",
               "Claz",
               "Lang",
               "c:\\path",
               true,
               ImmutableMap.of("key2", "value3"));
         }
       });
 }
 @Test
 public void testCancelChange() throws Exception {
   openDialog();
   mBot.checkBox("Route orders to server").click();
   mBot.button("Add New Property").click();
   new NewPropertyInputDialogTestFixture("key2", "value2").inputData();
   mBot.button("Cancel").click();
   Thread.sleep(WAIT_TIME);
   AbstractUIRunner.syncRun(
       new ThrowableRunnable() {
         @Override
         public void run() throws Throwable {
           assertDeployedStrategy(
               mStrategy,
               mEngine,
               StrategyState.STOPPED,
               "Strategy1",
               "Claz",
               "Lang",
               "c:\\path",
               true,
               null);
         }
       });
 }
 @Test
 public void testDisabledForRunningStrategy() throws Exception {
   AbstractUIRunner.syncRun(
       new ThrowableRunnable() {
         @Override
         public void run() throws Throwable {
           mStrategy = createDeployedStrategy("Strategy1");
           mStrategy.setClassName("Claz");
           mStrategy.setLanguage("Lang");
           mStrategy.setScriptPath("c:\\path");
           mStrategy.setRouteOrdersToServer(true);
           mStrategy.setState(StrategyState.RUNNING);
           mEngine = createEngine("Engine");
           mEngine.setConnection(new MockUIConnection());
           mEngine.getDeployedStrategies().add(mStrategy);
           mDialog =
               PropertyDialog.createDialogOn(
                   PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                   StrategyEngineWorkbenchUI.DEPLOYED_STRATEGY_CONFIGURATION_PROPERTY_PAGE_ID,
                   mStrategy);
           mDialog.setBlockOnOpen(false);
           mDialog.open();
         }
       });
   mBot.shell("Properties for Strategy1 on Engine");
   testDisabled(mBot.textWithLabel("Instance Name:"), "Strategy1");
   testDisabled(mBot.textWithLabel("Class:"), "Claz");
   testDisabled(mBot.textWithLabel("Language:"), "Lang");
   testDisabled(mBot.textWithLabel("Script:"), "c:\\path");
   assertThat(mBot.checkBox("Route orders to server").isEnabled(), is(false));
   assertThat(mBot.checkBox("Route orders to server").isChecked(), is(true));
   // use index 1 since first tree is property page navigation tree
   assertThat(mBot.tree(1).isEnabled(), is(false));
   assertThat(mBot.button("Add New Property").isEnabled(), is(false));
 }
 @Test
 public void testChangeProperties() throws Exception {
   openDialog();
   SWTBotCheckBox checkBox = mBot.checkBox("Route orders to server");
   assertThat(checkBox.isChecked(), is(true));
   checkBox.click();
   mBot.button("Add New Property").click();
   new NewPropertyInputDialogTestFixture("key", "value").inputData();
   mBot.button("Add New Property").click();
   new NewPropertyInputDialogTestFixture("key2", "value2").inputData();
   mBot.button("OK").click();
   Thread.sleep(WAIT_TIME);
   AbstractUIRunner.syncRun(
       new ThrowableRunnable() {
         @Override
         public void run() throws Throwable {
           assertDeployedStrategy(
               mStrategy,
               mEngine,
               StrategyState.STOPPED,
               "Strategy1",
               "Claz",
               "Lang",
               "c:\\path",
               false,
               ImmutableMap.of("key", "value", "key2", "value2"));
         }
       });
 }
 public static NewStrategyAgentWizardFixture create(
     final Shell shell, final IStrategyEngines engines, final StrategyAgentEngine engine)
     throws Exception {
   NewStrategyAgentWizard wizard =
       AbstractUIRunner.syncCall(
           new Callable<NewStrategyAgentWizard>() {
             @Override
             public NewStrategyAgentWizard call() {
               NewStrategyAgentWizard wizard = new NewStrategyAgentWizard(engines, engine);
               WizardDialog dialog = new WizardDialog(shell, wizard);
               dialog.setBlockOnOpen(false);
               dialog.open();
               return wizard;
             }
           });
   return new NewStrategyAgentWizardFixture(wizard);
 }
 @Test
 public void testSeededValues() throws Exception {
   StrategyAgentEngine engine =
       AbstractUIRunner.syncCall(
           new Callable<StrategyAgentEngine>() {
             @Override
             public StrategyAgentEngine call() {
               StrategyAgentEngine engine =
                   StrategyAgentEngineTestUtil.createStrategyAgentEngine(
                       "abc", "xyz", "tcp://abc", "host", 8080);
               engine.setConnectionState(ConnectionState.CONNECTED);
               return engine;
             }
           });
   NewStrategyAgentWizardFixture fixture =
       NewStrategyAgentWizardFixture.create(mShell, mMockService, engine);
   fixture.finish();
   StrategyAgentEngineTestUtil.assertStrategyAgentEngine(
       fixture.waitForClose(), "abc", "xyz", "tcp://abc", "host", 8080, ConnectionState.CONNECTED);
   verify(mMockService).addEngine((StrategyEngine) anyObject());
 }