Ejemplo n.º 1
0
  @Test
  public void testNormal() throws Exception {
    // create a context
    URL url =
        new URL(
            "http://demo.opengeo.org/geoserver/wms?Service=WMS&Version=1.1.1&Request=GetCapabilities"); //$NON-NLS-1$
    workflow.setContext(url);

    Assertion a1 =
        new Assertion() {
          @Override
          public void run() {
            fail = page.getViewer().getTree().getItemCount() != 1;
            if (!fail) {
              fail = page.getViewer().getTree().getItem(0).getItemCount() < 1;
            }
            if (!fail) fail = page.getViewer().getCheckedElements().length != 0;
          }
        };
    Object[] actions = new Object[] {IDialogConstants.NEXT_ID, a1, IDialogConstants.CANCEL_ID};

    DialogDriver driver = new DialogDriver(dialog, actions);
    driver.schedule();

    dialog.open();

    assertFalse(a1.fail);
    driver.cancel();
  }
  public void testSelection() {
    // turn on and off a viewer selection
    Runnable r1 =
        new Runnable() {
          public void run() {
            page.getViewer().setSelection(new StructuredSelection());

            SelectionChangedEvent event =
                new SelectionChangedEvent(page.getViewer(), new StructuredSelection());
            page.selectionChanged(event);
          }
        };

    Assertion a1 =
        new Assertion() {
          @Override
          public void run() {
            Button next = DialogDriver.findButton(dialog, IDialogConstants.NEXT_ID);
            fail = next.isEnabled();
          }
        };
    Runnable r2 =
        new Runnable() {

          public void run() {
            List l = page.getDescriptors();
            page.getViewer().setSelection(new StructuredSelection(l.get(0)));
          }
        };
    Assertion a2 =
        new Assertion() {
          @Override
          public void run() {
            Button next = DialogDriver.findButton(dialog, IDialogConstants.NEXT_ID);
            fail = !next.isEnabled();
          }
        };
    Object[] actions = new Object[] {r1, a1, r2, a2, IDialogConstants.CANCEL_ID};
    DialogDriver driver = new DialogDriver(dialog, actions);
    driver.schedule();

    dialog.open();
    driver.cancel();
    driver.cancel();

    assertFalse(a1.fail);
    assertFalse(a2.fail);
  }
  public void testWorkbenchSelection() {
    try {
      URL url =
          new URL(
              "http://wms.jpl.nasa.gov/wms.cgi?Service=WMS&Version=1.1.1&Request=GetCapabilities"); //$NON-NLS-1$
      workflow.setContext(url);
    } catch (Exception e) {
      e.printStackTrace();
      fail();
    }

    Assertion a1 =
        new Assertion() {
          @Override
          public void run() {
            IStructuredSelection sselection =
                (IStructuredSelection) page.getViewer().getSelection();
            UDIGConnectionFactoryDescriptor d =
                (UDIGConnectionFactoryDescriptor) sselection.getFirstElement();

            fail = !d.getId().equals("net.refractions.udig.catalog.ui.WMS"); // $NON-NLS-1$
            if (!fail) {
              Button button = DialogDriver.findButton(dialog, IDialogConstants.NEXT_ID);
              fail = !button.isEnabled();
            }
          }
        };
    Object[] actions = new Object[] {a1, IDialogConstants.CANCEL_ID};

    DialogDriver driver = new DialogDriver(dialog, actions);
    driver.schedule();

    dialog.open();
    driver.cancel();

    assertFalse(a1.fail);
  }