Package com.google.gdt.eclipse.designer.uibinder.gef

Source Code of com.google.gdt.eclipse.designer.uibinder.gef.UiBinderJavaParseValidatorTest

/*******************************************************************************
* Copyright 2011 Google Inc. All Rights Reserved.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
package com.google.gdt.eclipse.designer.uibinder.gef;

import com.google.gdt.eclipse.designer.uibinder.parser.UiBinderJavaParseValidator;

import org.eclipse.wb.core.editor.IDesignerEditor;
import org.eclipse.wb.internal.core.DesignerPlugin;
import org.eclipse.wb.internal.core.EnvironmentUtils;
import org.eclipse.wb.internal.core.editor.actions.SwitchAction;
import org.eclipse.wb.internal.core.editor.errors.WarningComposite;
import org.eclipse.wb.tests.gef.UiContext;

import org.eclipse.core.resources.IFile;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.ide.IDE;

/**
* Test for {@link UiBinderJavaParseValidator}.
*
* @author scheglov_ke
*/
public class UiBinderJavaParseValidatorTest extends UiBinderGefTest {
  ////////////////////////////////////////////////////////////////////////////
  //
  // Life cycle
  //
  ////////////////////////////////////////////////////////////////////////////
  @Override
  protected void tearDown() throws Exception {
    DesignerPlugin.setDisplayExceptionOnConsole(true);
    EnvironmentUtils.setTestingTime(true);
    super.tearDown();
  }

  ////////////////////////////////////////////////////////////////////////////
  //
  // Exit zone :-) XXX
  //
  ////////////////////////////////////////////////////////////////////////////
  public void _test_exit() throws Exception {
    System.exit(0);
  }

  ////////////////////////////////////////////////////////////////////////////
  //
  // Tests
  //
  ////////////////////////////////////////////////////////////////////////////
  /**
   * If Java source works with UiBinder, then ui.xml should be designed instead.
   */
  public void test_showWarning() throws Exception {
    removeExceptionsListener();
    DesignerPlugin.setDisplayExceptionOnConsole(false);
    //
    IFile javaFile = getFileSrc("test/client/Test.java");
    assertTrue(javaFile.exists());
    // open Java
    IEditorPart javaEditor = openJavaDesignEditor(javaFile);
    switchToDesign(javaEditor);
    // prepare UIContext
    UiContext context = new UiContext();
    // WarningComposite is visible
    Composite warningComposite = context.findFirstWidget(WarningComposite.class);
    assertNotNull(warningComposite);
    assertTrue(warningComposite.isVisible());
  }

  ////////////////////////////////////////////////////////////////////////////
  //
  // Utils
  //
  ////////////////////////////////////////////////////////////////////////////
  private static IEditorPart openJavaDesignEditor(IFile javaFile) throws PartInitException {
    return IDE.openEditor(DesignerPlugin.getActivePage(), javaFile, IDesignerEditor.ID);
  }

  private static void switchToDesign(IEditorPart javaEditor) {
    SwitchAction switchAction = new SwitchAction();
    switchAction.setActiveEditor(null, javaEditor);
    switchAction.run();
  }
}
TOP

Related Classes of com.google.gdt.eclipse.designer.uibinder.gef.UiBinderJavaParseValidatorTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.