public void testJbide() throws Throwable {

    // get test page path
    IFile file =
        (IFile) TestUtil.getComponentPath(TEST_PAGE_NAME, RichFacesAllTests.IMPORT_PROJECT_NAME);

    assertNotNull(
        "Could not open specified file. componentPage = "
            + TEST_PAGE_NAME
            + ";projectName = "
            + RichFacesAllTests.IMPORT_PROJECT_NAME,
        file); //$NON-NLS-1$

    IEditorInput input = new FileEditorInput(file);

    assertNotNull("Editor input is null", input);
    // open and get editor
    JSPMultiPageEditor part = openEditor(input);

    // get dom document
    nsIDOMDocument document = TestUtil.getVpeVisualDocument(part);
    nsIDOMElement element = document.getDocumentElement();

    assertNotNull(element);

    // get root node
    nsIDOMNode node = queryInterface(element, nsIDOMNode.class);

    List<nsIDOMNode> elements = new ArrayList<nsIDOMNode>();

    // find "table" elements
    TestUtil.findElementsByName(node, elements, HTML.TAG_TABLE);

    assertEquals(2, elements.size());

    // get first table. It has default attributes (minValue=0, maxValue=100)
    nsIDOMNode defaultInputSlider = elements.get(0);
    // check min-,max- values
    checkMinMaxValue(defaultInputSlider, 0, 100);

    // get first table. It has edited attributes (minValue=-10,
    // maxValue=200)
    nsIDOMNode editedInputSlider = elements.get(1);
    // check min-,max- values
    checkMinMaxValue(editedInputSlider, -10, 200);

    // check exception
    if (getException() != null) {
      throw getException();
    }
  }
Exemplo n.º 2
0
  @Test
  public void testJBIDE1479() throws Throwable {
    // wait
    setException(null);
    // get test page path
    final IFile file =
        (IFile) TestUtil.getComponentPath(TEST_PAGE_NAME, JsfAllTests.IMPORT_PROJECT_NAME);

    assertNotNull(
        "Could not open specified file " + TEST_PAGE_NAME, // $NON-NLS-1$
        file);

    IEditorInput input = new FileEditorInput(file);

    assertNotNull("Editor input is null", input); // $NON-NLS-1$

    JSPMultiPageEditor part = openEditor(input);
    TestUtil.waitForIdle(120 * 1000);
    assertNotNull(part);

    Job job = new WorkspaceJob("Test JBIDE-1479") { // $NON-NLS-1$

          @Override
          public IStatus runInWorkspace(IProgressMonitor monitor) {
            try {
              new FormatProcessorXML().formatFile(file);
            } catch (CoreException e) {
              TestUtil.fail(e);
            } catch (IOException e) {
              TestUtil.fail(e);
            }
            return Status.OK_STATUS;
          }
        };
    job.setPriority(Job.SHORT);
    job.schedule(0L);
    job.join();
    TestUtil.waitForIdle(15 * 1000 * 60);
    TestUtil.delay(1000L);
    closeEditors();

    /*
     * we ignore this code, because we are testint JBIDE-1479,
     * it's test fot crash of eclipse.And if we modifying content from non-ui thread, we almost
     * always will get SWTException 'access violation'.
     */
    //		if(getException()!=null) {
    //			throw getException();
    //		}
  }
  public void testNoDefaultLocaleForChangeAndRefresh() throws Throwable {
    VpeController controller =
        openInVpe(JsfAllTests.IMPORT_JSF_LOCALES_PROJECT_NAME, NO_DEFLOC_CHANGE_REFRESH_PAGE);
    nsIDOMDocument doc = controller.getXulRunnerEditor().getDOMDocument();

    nsIDOMElement localeText = doc.getElementById(LOCALE_TEXT_ID);
    String localizedText = getLocalizedText(localeText);
    assertTrue(
        "Text is '" + localizedText + "', but should be in 'de' locale",
        HELLO2_DE.equalsIgnoreCase(localizedText)); // $NON-NLS-1$ //$NON-NLS-2$
    /*
     * Change the locale
     */
    Element fViewElement =
        controller.getSourceBuilder().getSourceDocument().getElementById(FVIEW_ID);
    int offset = controller.getSourceBuilder().getPosition(fViewElement, 0, false);
    assertTrue(
        "Previous locale should be 'de'",
        "de"
            .equalsIgnoreCase(
                fViewElement.getAttribute("locale"))); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

    IRegion reg =
        new FindReplaceDocumentAdapter(
                controller.getSourceBuilder().getStructuredTextViewer().getDocument())
            .find(offset, "de", true, true, false, false);
    controller
        .getSourceBuilder()
        .getStructuredTextViewer()
        .getDocument()
        .replace(reg.getOffset(), reg.getLength(), "en_GB");
    /*
     * Wait until new value is applied and children are refreshed.
     * Wait while all deferred events are processed
     */
    while (Display.getCurrent().readAndDispatch()) ;
    /*
     * Wait while all jobs including started through deferred events are ended
     */
    JobUtils.delay(VpeController.DEFAULT_UPDATE_DELAY_TIME * 4);
    TestUtil.waitForIdle();
    fViewElement = controller.getSourceBuilder().getSourceDocument().getElementById(FVIEW_ID);
    assertTrue(
        "Current locale should be 'en_GB'",
        "en_GB"
            .equalsIgnoreCase(
                fViewElement.getAttribute("locale"))); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

    doc = controller.getXulRunnerEditor().getDOMDocument();
    localeText = doc.getElementById(LOCALE_TEXT_ID);
    localizedText = getLocalizedText(localeText);

    /*
     * Check the new localized message.
     */
    assertTrue(
        "Text is '" + localizedText + "', but should be in 'en_GB' locale",
        HELLO_EN_GB.equalsIgnoreCase(localizedText)); // $NON-NLS-1$ //$NON-NLS-2$
    closeEditors();
  }
  /**
   * Checks if the first element in the test file is selected in the VPE when the VPE is just
   * loaded.
   *
   * @throws Throwable
   */
  public void testJBIDE4037Test() throws Throwable {
    setException(null);
    IFile ifile = (IFile) TestUtil.getComponentPath(FILE_PATH, JsfAllTests.IMPORT_PROJECT_NAME);
    IEditorInput input = new FileEditorInput(ifile);
    JSPMultiPageEditor part = openEditor(input);

    TestUtil.waitForJobs();
    nsIDOMElement rootElement =
        TestUtil.getVpeController(part).getXulRunnerEditor().getSelectedElement();

    // check if something selected
    assertNotNull(rootElement);
    // check if the selected element is the first element on the page (we know its ID)
    assertEquals(ROOT_ELEMENT_ID, rootElement.getAttribute(HTML.ATTR_ID));

    if (getException() != null) {
      throw getException();
    }
  }
  /**
   * If there are several f:views on the page. Only the last f:view one should be applied on server,
   * but each f:view should have its own locale.
   *
   * @throws Throwable
   */
  public void testSeveralFViewsWithLocales() throws Throwable {

    IFile file =
        (IFile)
            TestUtil.getComponentPath(SEVERAL_FVIEWS_PAGE, JsfAllTests.IMPORT_JSF_20_PROJECT_NAME);
    assertNotNull(
        "Could not open specified file." //$NON-NLS-1$
            + " componentPage = "
            + SEVERAL_FVIEWS_PAGE //$NON-NLS-1$
            + ";projectName = "
            + JsfAllTests.IMPORT_JSF_20_PROJECT_NAME,
        file); //$NON-NLS-1$
    IEditorInput input = new FileEditorInput(file);
    assertNotNull("Editor input is null", input); // $NON-NLS-1$
    /*
     * open and get the editor
     */
    JSPMultiPageEditor part = openEditor(input);
    VpeController controller = TestUtil.getVpeController(part);

    javaSources = EclipseResourceUtil.getJavaProjectSrcLocations(file.getProject());
    nsIDOMDocument doc = controller.getXulRunnerEditor().getDOMDocument();
    nsIDOMElement localeText = doc.getElementById(LOCALE_TEXT0_ID);
    String localizedText = getLocalizedText(localeText);
    checkLocaleStrings(file, "en", localizedText); // $NON-NLS-1$

    localeText = doc.getElementById(LOCALE_TEXT1_ID);
    localizedText = getLocalizedText(localeText);
    checkLocaleStrings(file, "de", localizedText); // $NON-NLS-1$

    localeText = doc.getElementById(LOCALE_TEXT2_ID);
    localizedText = getLocalizedText(localeText);
    /*
     * f:view will use default locale if nothing is specified.
     */
    checkLocaleStrings(file, "en_US", localizedText); // $NON-NLS-1$

    localeText = doc.getElementById(LOCALE_TEXT_ID);
    localizedText = getLocalizedText(localeText);
    checkLocaleStrings(file, "en_GB", localizedText); // $NON-NLS-1$

    closeEditors();
  }
 /**
  * After the locale attribute value has been changed and Refresh button is clicked - the correct
  * locale should be applied, bundle messages should be updated and showed in the correct locale.
  *
  * @throws Throwable
  */
 public void testChangeLocaleAndRefresh() throws Throwable {
   VpeController controller =
       openInVpe(JsfAllTests.IMPORT_JSF_20_PROJECT_NAME, CHANGE_LOCALE_AND_REFRESH_PAGE);
   nsIDOMDocument doc = controller.getXulRunnerEditor().getDOMDocument();
   nsIDOMElement localeText = doc.getElementById(LOCALE_TEXT_ID);
   String localizedText = getLocalizedText(localeText);
   assertTrue(
       "Text is '" + localizedText + "', but should be in 'de' locale",
       HELLO2_DE.equalsIgnoreCase(localizedText)); // $NON-NLS-1$ //$NON-NLS-2$
   /*
    * Change the locale
    */
   Element fViewElement =
       controller.getSourceBuilder().getSourceDocument().getElementById(FVIEW_ID);
   assertTrue(
       "Previous locale should be 'de'",
       "de"
           .equalsIgnoreCase(
               fViewElement.getAttribute("locale"))); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
   fViewElement.setAttribute("locale", "en_GB"); // $NON-NLS-1$ //$NON-NLS-2$
   /*
    * Wait until new value is applied and children are refreshed.
    */
   TestUtil.delay(500);
   TestUtil.waitForIdle();
   assertTrue(
       "Current locale should be 'en_GB'",
       "en_GB"
           .equalsIgnoreCase(
               fViewElement.getAttribute("locale"))); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
   doc = controller.getXulRunnerEditor().getDOMDocument();
   localeText = doc.getElementById(LOCALE_TEXT_ID);
   localizedText = getLocalizedText(localeText);
   /*
    * Check the new localized message.
    */
   assertTrue(
       "Text is '" + localizedText + "', but should be in 'en_GB' locale",
       HELLO_EN_GB.equalsIgnoreCase(localizedText)); // $NON-NLS-1$ //$NON-NLS-2$
   closeEditors();
 }
 @Override
 protected void setUp() throws Exception {
   super.setUp();
   setException(null);
   this.file =
       (IFile)
           TestUtil.getComponentPath(
               TEST_FILE_NAME, //$NON-NLS-1$
               JsfAllTests.IMPORT_PROJECT_NAME);
   ResourceReference[] entries = new ResourceReference[1];
   entries[0] = new ResourceReference("request.contextPath", ResourceReference.FILE_SCOPE);
   entries[0].setProperties("contextPathFolder");
   ELReferenceList.getInstance().setAllResources(this.file, entries);
 }