|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.test.java.compilation; import java.io.File; import junit.textui.TestRunner; import org.netbeans.jellytools.Bundle; import org.netbeans.jellytools.JellyTestCase; import org.netbeans.jellytools.MainWindowOperator; import org.netbeans.jellytools.OptionsOperator; import org.netbeans.jellytools.actions.*; import org.netbeans.jellytools.nodes.FolderNode; import org.netbeans.jellytools.nodes.JavaNode; import org.netbeans.jellytools.properties.Property; import org.netbeans.jellytools.properties.PropertySheetOperator; import org.netbeans.jemmy.EventTool; import org.netbeans.junit.NbTestSuite; import org.netbeans.modules.java.JavaExternalCompilerType; import org.netbeans.modules.java.JavaProcessExecutor; import org.netbeans.modules.java.settings.JavaSettings; import org.netbeans.test.java.Utilities; import org.openide.actions.SaveAllAction; import org.openide.filesystems.Repository; public class Compilation extends JellyTestCase { private String sampleDir = Utilities.getSampleDir().getDisplayName(); /** Need to be defined because of JUnit */ public Compilation(String name) { super(name); } public static NbTestSuite suite() { NbTestSuite suite = new NbTestSuite(); suite.addTest(new Compilation("test1")); suite.addTest(new Compilation("test2")); suite.addTest(new Compilation("test3")); suite.addTest(new Compilation("test4")); suite.addTest(new Compilation("test5")); return suite; } /** Use for execution inside IDE */ public static void main(java.lang.String[] args) { // run whole suite TestRunner.run(suite()); // run only selected test case //junit.textui.TestRunner.run(new BeansTemplates("testJavaBean")); } public void setUp() { System.out.println("######## "+getName()+" #######"); } public void tearDown() { ((SaveAllAction) SaveAllAction.findObject(SaveAllAction.class, true)).performAction(); } public void test1() { JavaSettings javaSettings = (JavaSettings) JavaSettings.findObject(JavaSettings.class, true); assertEquals(javaSettings.getCompiler().getClass(), JavaExternalCompilerType.class); assertEquals(javaSettings.getExecutor().getClass(), JavaProcessExecutor.class); } public void test2() { JavaNode colorPickerNode = new JavaNode(sampleDir + "|examples|colorpicker|ColorPicker"); colorPickerNode.select(); new CleanAction().perform(); waitFinished("Finished ColorPicker"); assertTrue("ColorPicker.class not found", !isCompiled("examples.colorpicker.ColorPicker")); FolderNode examplesFolderNode = new FolderNode(sampleDir + "|examples"); examplesFolderNode.select(); new CleanAllAction().perform(); waitFinished("Finished"); assertEquals("No classes should be in sampledir after CleanAllAction", 0, Utilities.getAllFilenames(new File(sampleDir), true, ".class").length); } public void test3() { JavaNode colorPickerNode = new JavaNode(sampleDir + "|examples|colorpicker|ColorPicker"); colorPickerNode.select(); new CompileAction().perform(); waitFinished("Finished ColorPicker"); //new EventTool().waitNoEvent(1000); assertTrue("ColorPicker is not compiled",isCompiled("examples.colorpicker.ColorPicker")); FolderNode examplesFolderNode = new FolderNode(sampleDir + "|examples"); examplesFolderNode.select(); new CompileAllAction().perform(); waitFinished("Finished examples"); assertEquals("All classes should be compiled", 29, Utilities.getAllFilenames(new File(sampleDir), true, ".class").length); } public void test4() { final String EXTERNAL_COMPILATION = Bundle.getString("org.netbeans.core.Bundle", "UI/Services/Building") + "|" + Bundle.getString("org.netbeans.core.Bundle", "Templates/Services/CompilerType") + "|" + Bundle.getString("org.netbeans.modules.java.Bundle", "Templates/Services/CompilerType/JavaExternalCompiler.settings"); final String TARGET = Bundle.getString("org.netbeans.modules.java.Bundle", "TARGET_PROP"); String fsName = Utilities.findFileSystem("testfs").getDisplayName(); OptionsOperator options = OptionsOperator.invoke(); options.selectOption(EXTERNAL_COMPILATION); PropertySheetOperator pso = options.getPropertySheet(EXTERNAL_COMPILATION); Property target = new Property(pso, TARGET); target.setValue(fsName); FolderNode examplesFolderNode = new FolderNode(sampleDir + "|examples"); examplesFolderNode.select(); new CompileAllAction().perform(); waitFinished("Finished examples"); assertEquals("All classes should be compiled", 29, Utilities.getAllFilenames(new File(fsName + "/examples"), true, ".class").length); new CleanAllAction().perform(); waitFinished("Finished examples"); assertEquals("No classes should be in sampledir after CleanAllAction", 0, Utilities.getAllFilenames(new File(fsName + "/examples"), true, ".class").length); options = OptionsOperator.invoke(); pso = options.getPropertySheet(EXTERNAL_COMPILATION); target = new Property(pso, TARGET); target.setValue(Bundle.getString("org.netbeans.modules.java.Bundle", "LABEL_TargetDefault")); } public void test5() { FolderNode examplesNode = new FolderNode(sampleDir + "|examples"); examplesNode.select(); new CleanAllAction().perform(); waitFinished("Finished examples"); FolderNode colorpickerNode = new FolderNode(sampleDir + "|examples|colorpicker"); colorpickerNode.select(); FolderNode texteditorNode = new FolderNode(sampleDir + "|examples|texteditor"); texteditorNode.addSelectionPath(); new BuildAction().perform(); waitFinished("Finished two objects"); assertEquals("Compilation failed", 23, Utilities.getAllFilenames(new File(sampleDir), true, ".class").length); examplesNode.select(); new BuildAllAction().perform(); waitFinished("Finished examples"); assertEquals("All classes should be compiled", 29, Utilities.getAllFilenames(new File(sampleDir), true, ".class").length); } private boolean isCompiled(String name) { return (Repository.getDefault().findResource(name.replace('.', '/') + ".class")!= null); } private void waitFinished(String text) { MainWindowOperator.getDefault().waitStatusText(text); new EventTool().waitNoEvent(500); } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.