Пример #1
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();
  }
 /**
  * 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();
 }