finished new testng suite creation and recognition
authorLukas Jungmann <jungi@netbeans.org>
Sun, 01 Jan 2012 17:11:55 +0100
changeset 17718ad280c1919b9
parent 17717 1d8f42f57d13
child 17719 58431eb125a1
finished new testng suite creation and recognition
testng/src/org/netbeans/modules/contrib/testng/NewTestSuiteWizardIterator.java
testng/src/org/netbeans/modules/contrib/testng/TestNGSuiteDataEditor.java
testng/src/org/netbeans/modules/contrib/testng/TestNGSuiteDataNode.java
testng/src/org/netbeans/modules/contrib/testng/TestNGSuiteDataObject.java
testng/src/org/netbeans/modules/contrib/testng/resources/testng-suite.template
testng/src/org/netbeans/modules/contrib/testng/resources/testng.xml.template
     1.1 --- a/testng/src/org/netbeans/modules/contrib/testng/NewTestSuiteWizardIterator.java	Sun Jan 01 13:06:37 2012 +0100
     1.2 +++ b/testng/src/org/netbeans/modules/contrib/testng/NewTestSuiteWizardIterator.java	Sun Jan 01 17:11:55 2012 +0100
     1.3 @@ -1,7 +1,7 @@
     1.4  /*
     1.5   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     1.6   *
     1.7 - * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
     1.8 + * Copyright 2011-2012 Oracle and/or its affiliates. All rights reserved.
     1.9   *
    1.10   * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
    1.11   * Other names may be trademarks of their respective owners.
    1.12 @@ -50,7 +50,6 @@
    1.13  import org.netbeans.api.project.*;
    1.14  import org.netbeans.api.templates.TemplateRegistration;
    1.15  import org.netbeans.modules.contrib.testng.api.TestNGSupport;
    1.16 -import org.netbeans.spi.java.project.support.ui.templates.JavaTemplates;
    1.17  import org.netbeans.spi.project.ui.templates.support.Templates;
    1.18  import org.openide.WizardDescriptor;
    1.19  import org.openide.filesystems.FileObject;
    1.20 @@ -59,7 +58,8 @@
    1.21  import org.openide.loaders.DataObject;
    1.22  
    1.23  @TemplateRegistration(folder = "TestNG", position = 2000,
    1.24 -        content= "resources/testng-suite.template",
    1.25 +        content = "resources/testng.xml.template",
    1.26 +        scriptEngine = "freemarker",
    1.27          displayName = "#Templates/TestNG/TestNGTestSuite.xml",
    1.28          description = "/org/netbeans/modules/contrib/testng/resources/newTestSuite.html",
    1.29          iconBase = "org/netbeans/modules/contrib/testng/resources/testng.gif")
    1.30 @@ -69,6 +69,10 @@
    1.31      private transient WizardDescriptor.Panel[] panels;
    1.32      private transient WizardDescriptor wiz;
    1.33  
    1.34 +    public NewTestSuiteWizardIterator() {
    1.35 +    }
    1.36 +
    1.37 +    
    1.38      private WizardDescriptor.Panel[] createPanels(final WizardDescriptor wizardDescriptor) {
    1.39          // Ask for Java folders
    1.40          Project project = Templates.getProject(wizardDescriptor);
    1.41 @@ -81,14 +85,10 @@
    1.42          }
    1.43          if (groups.length == 0) {
    1.44              groups = sources.getSourceGroups(Sources.TYPE_GENERIC);
    1.45 -            return new WizardDescriptor.Panel[]{
    1.46 -                        Templates.buildSimpleTargetChooser(project, groups).create()
    1.47 -                    };
    1.48 -        } else {
    1.49 -            return new WizardDescriptor.Panel[]{
    1.50 -                        JavaTemplates.createPackageChooser(project, groups)
    1.51 -                    };
    1.52          }
    1.53 +        return new WizardDescriptor.Panel[]{
    1.54 +                    Templates.buildSimpleTargetChooser(project, groups).create()
    1.55 +                };
    1.56      }
    1.57  
    1.58      private String[] createSteps(String[] before, WizardDescriptor.Panel[] panels) {
    1.59 @@ -111,7 +111,7 @@
    1.60          return res;
    1.61      }
    1.62  
    1.63 -    public Set<FileObject> instantiate() throws IOException {
    1.64 +    public Set<DataObject> instantiate() throws IOException {
    1.65          FileObject dir = Templates.getTargetFolder(wiz);
    1.66          String targetName = Templates.getTargetName(wiz);
    1.67  
    1.68 @@ -120,16 +120,23 @@
    1.69  
    1.70          DataObject dTemplate = DataObject.find(template);
    1.71          String pkgName = getSelectedPackageName(dir);
    1.72 -        DataObject dobj;
    1.73 -        if (pkgName == null) {
    1.74 -            dobj = dTemplate.createFromTemplate(df, targetName);
    1.75 -        } else {
    1.76 -            dobj = dTemplate.createFromTemplate(df, targetName, Collections.singletonMap("name", targetName)); // NOI18N
    1.77 +        String suiteName = pkgName + " suite";
    1.78 +        String projectName = ProjectUtils.getInformation(FileOwnerQuery.getOwner(dir)).getName();
    1.79 +        if (pkgName == null || pkgName.trim().length() < 1) {
    1.80 +            pkgName = ".*"; //NOI18N
    1.81 +            suiteName = "All tests for " + projectName;
    1.82          }
    1.83 +        
    1.84 +        Map<String, String> props = new HashMap<String, String>();
    1.85 +        props.put("name", projectName);
    1.86 +        props.put("suiteName", suiteName);
    1.87 +        props.put("pkg", pkgName);
    1.88  
    1.89 -        FileObject createdFile = dobj.getPrimaryFile();
    1.90 +        DataObject dobj = dTemplate.createFromTemplate(df, targetName, props);
    1.91 +
    1.92 +        FileObject createdFile = DataObject.find(dobj.getPrimaryFile()).getPrimaryFile();
    1.93          TestNGSupport.findTestNGSupport(FileOwnerQuery.getOwner(createdFile)).configureProject(createdFile);
    1.94 -        return Collections.singleton(createdFile);
    1.95 +        return Collections.singleton(dobj);
    1.96      }
    1.97  
    1.98      public void initialize(WizardDescriptor wiz) {
     2.1 --- a/testng/src/org/netbeans/modules/contrib/testng/TestNGSuiteDataEditor.java	Sun Jan 01 13:06:37 2012 +0100
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,135 +0,0 @@
     2.4 -/*
     2.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     2.6 - *
     2.7 - * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
     2.8 - *
     2.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
    2.10 - * Other names may be trademarks of their respective owners.
    2.11 - *
    2.12 - * The contents of this file are subject to the terms of either the GNU
    2.13 - * General Public License Version 2 only ("GPL") or the Common
    2.14 - * Development and Distribution License("CDDL") (collectively, the
    2.15 - * "License"). You may not use this file except in compliance with the
    2.16 - * License. You can obtain a copy of the License at
    2.17 - * http://www.netbeans.org/cddl-gplv2.html
    2.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    2.19 - * specific language governing permissions and limitations under the
    2.20 - * License.  When distributing the software, include this License Header
    2.21 - * Notice in each file and include the License file at
    2.22 - * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
    2.23 - * particular file as subject to the "Classpath" exception as provided
    2.24 - * by Oracle in the GPL Version 2 section of the License file that
    2.25 - * accompanied this code. If applicable, add the following below the
    2.26 - * License Header, with the fields enclosed by brackets [] replaced by
    2.27 - * your own identifying information:
    2.28 - * "Portions Copyrighted [year] [name of copyright owner]"
    2.29 - *
    2.30 - * If you wish your version of this file to be governed by only the CDDL
    2.31 - * or only the GPL Version 2, indicate your decision by adding
    2.32 - * "[Contributor] elects to include this software in this distribution
    2.33 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
    2.34 - * single choice of license, a recipient has the option to distribute
    2.35 - * your version of this file under either the CDDL, the GPL Version 2 or
    2.36 - * to extend the choice of license to its licensees as provided above.
    2.37 - * However, if you add GPL Version 2 code and therefore, elected the GPL
    2.38 - * Version 2 license, then the option applies only if the new code is
    2.39 - * made subject to such option by the copyright holder.
    2.40 - *
    2.41 - * Contributor(s):
    2.42 - *
    2.43 - * Portions Copyrighted 2011 Sun Microsystems, Inc.
    2.44 - */
    2.45 -package org.netbeans.modules.contrib.testng;
    2.46 -
    2.47 -import java.io.IOException;
    2.48 -import javax.swing.event.ChangeEvent;
    2.49 -import javax.swing.event.ChangeListener;
    2.50 -import org.netbeans.core.api.multiview.MultiViews;
    2.51 -import org.openide.cookies.*;
    2.52 -import org.openide.filesystems.FileLock;
    2.53 -import org.openide.filesystems.FileObject;
    2.54 -import org.openide.nodes.FilterNode;
    2.55 -import org.openide.nodes.Node;
    2.56 -import org.openide.text.CloneableEditor;
    2.57 -import org.openide.text.CloneableEditorSupport;
    2.58 -import org.openide.text.DataEditorSupport;
    2.59 -import org.openide.windows.CloneableOpenSupport;
    2.60 -
    2.61 -/**
    2.62 - *
    2.63 - * @author lukas
    2.64 - */
    2.65 -final class TestNGSuiteDataEditor extends DataEditorSupport implements OpenCookie, EditCookie, EditorCookie.Observable, PrintCookie, ChangeListener {
    2.66 -
    2.67 -    private boolean addedChangeListener = false;
    2.68 -
    2.69 -    public TestNGSuiteDataEditor(TestNGSuiteDataObject obj) {
    2.70 -        super(obj, null, new TestNGEnv(obj));
    2.71 -        setMIMEType(TestNGSuiteDataObject.MIME_TYPE);
    2.72 -    }
    2.73 -
    2.74 -    @Override
    2.75 -    protected Pane createPane() {
    2.76 -        return (CloneableEditorSupport.Pane) MultiViews.createCloneableMultiView(TestNGSuiteDataObject.MIME_TYPE, getDataObject());
    2.77 -    }
    2.78 -
    2.79 -    @Override
    2.80 -    protected boolean notifyModified() {
    2.81 -        if (!super.notifyModified()) {
    2.82 -            return false;
    2.83 -        } else {
    2.84 -            TestNGEnv e = (TestNGEnv) env;
    2.85 -            e.getTestNGSuiteDataObject().addSaveCookie(e);
    2.86 -            return true;
    2.87 -        }
    2.88 -    }
    2.89 -
    2.90 -    @Override
    2.91 -    protected void notifyUnmodified() {
    2.92 -        super.notifyUnmodified();
    2.93 -        TestNGEnv e = (TestNGEnv) env;
    2.94 -        e.getTestNGSuiteDataObject().removeSaveCookie(e);
    2.95 -    }
    2.96 -
    2.97 -    @Override
    2.98 -    protected boolean asynchronousOpen() {
    2.99 -        return true;
   2.100 -    }
   2.101 -
   2.102 -    public void stateChanged(ChangeEvent e) {
   2.103 -        updateTitles();
   2.104 -    }
   2.105 -
   2.106 -    private static class TestNGEnv extends DataEditorSupport.Env implements SaveCookie {
   2.107 -
   2.108 -        private static final long serialVersionUID = 6587342954372956374L;
   2.109 -
   2.110 -        public TestNGEnv(TestNGSuiteDataObject obj) {
   2.111 -            super(obj);
   2.112 -        }
   2.113 -
   2.114 -        @Override
   2.115 -        public CloneableOpenSupport findCloneableOpenSupport() {
   2.116 -            return (CloneableOpenSupport) getDataObject().getLookup().lookup(EditCookie.class);
   2.117 -        }
   2.118 -
   2.119 -        @Override
   2.120 -        protected FileObject getFile() {
   2.121 -            return getDataObject().getPrimaryFile();
   2.122 -        }
   2.123 -
   2.124 -        @Override
   2.125 -        protected FileLock takeLock() throws IOException {
   2.126 -            return ((TestNGSuiteDataObject) getDataObject()).getPrimaryEntry().takeLock();
   2.127 -        }
   2.128 -
   2.129 -        public void save() throws IOException {
   2.130 -            ((TestNGSuiteDataEditor) findCloneableOpenSupport()).saveDocument();
   2.131 -            getDataObject().setModified(false);
   2.132 -        }
   2.133 -
   2.134 -        TestNGSuiteDataObject getTestNGSuiteDataObject() {
   2.135 -            return (TestNGSuiteDataObject) getDataObject();
   2.136 -        }
   2.137 -    }
   2.138 -}
     3.1 --- a/testng/src/org/netbeans/modules/contrib/testng/TestNGSuiteDataNode.java	Sun Jan 01 13:06:37 2012 +0100
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,73 +0,0 @@
     3.4 -/*
     3.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     3.6 - *
     3.7 - * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
     3.8 - *
     3.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
    3.10 - * Other names may be trademarks of their respective owners.
    3.11 - *
    3.12 - * The contents of this file are subject to the terms of either the GNU
    3.13 - * General Public License Version 2 only ("GPL") or the Common
    3.14 - * Development and Distribution License("CDDL") (collectively, the
    3.15 - * "License"). You may not use this file except in compliance with the
    3.16 - * License. You can obtain a copy of the License at
    3.17 - * http://www.netbeans.org/cddl-gplv2.html
    3.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    3.19 - * specific language governing permissions and limitations under the
    3.20 - * License.  When distributing the software, include this License Header
    3.21 - * Notice in each file and include the License file at
    3.22 - * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
    3.23 - * particular file as subject to the "Classpath" exception as provided
    3.24 - * by Oracle in the GPL Version 2 section of the License file that
    3.25 - * accompanied this code. If applicable, add the following below the
    3.26 - * License Header, with the fields enclosed by brackets [] replaced by
    3.27 - * your own identifying information:
    3.28 - * "Portions Copyrighted [year] [name of copyright owner]"
    3.29 - *
    3.30 - * If you wish your version of this file to be governed by only the CDDL
    3.31 - * or only the GPL Version 2, indicate your decision by adding
    3.32 - * "[Contributor] elects to include this software in this distribution
    3.33 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
    3.34 - * single choice of license, a recipient has the option to distribute
    3.35 - * your version of this file under either the CDDL, the GPL Version 2 or
    3.36 - * to extend the choice of license to its licensees as provided above.
    3.37 - * However, if you add GPL Version 2 code and therefore, elected the GPL
    3.38 - * Version 2 license, then the option applies only if the new code is
    3.39 - * made subject to such option by the copyright holder.
    3.40 - *
    3.41 - * Contributor(s):
    3.42 - *
    3.43 - * Portions Copyrighted 2011 Sun Microsystems, Inc.
    3.44 - */
    3.45 -package org.netbeans.modules.contrib.testng;
    3.46 -
    3.47 -import org.openide.loaders.DataNode;
    3.48 -import org.openide.nodes.Children;
    3.49 -import org.openide.util.Lookup;
    3.50 -
    3.51 -public class TestNGSuiteDataNode extends DataNode {
    3.52 -
    3.53 -    private static final String IMAGE_ICON_BASE = "org/netbeans/modules/contrib/testng/resources/testng.gif";
    3.54 -
    3.55 -    public TestNGSuiteDataNode(TestNGSuiteDataObject obj) {
    3.56 -        super(obj, Children.LEAF);
    3.57 -        setIconBaseWithExtension(IMAGE_ICON_BASE);
    3.58 -    }
    3.59 -
    3.60 -    TestNGSuiteDataNode(TestNGSuiteDataObject obj, Lookup lookup) {
    3.61 -        super(obj, Children.LEAF, lookup);
    3.62 -        setIconBaseWithExtension(IMAGE_ICON_BASE);
    3.63 -    }
    3.64 -//    /** Creates a property sheet. */
    3.65 -//    @Override
    3.66 -//    protected Sheet createSheet() {
    3.67 -//        Sheet s = super.createSheet();
    3.68 -//        Sheet.Set ss = s.get(Sheet.PROPERTIES);
    3.69 -//        if (ss == null) {
    3.70 -//            ss = Sheet.createPropertiesSet();
    3.71 -//            s.put(ss);
    3.72 -//        }
    3.73 -//        // TODO add some relevant properties: ss.put(...)
    3.74 -//        return s;
    3.75 -//    }
    3.76 -}
     4.1 --- a/testng/src/org/netbeans/modules/contrib/testng/TestNGSuiteDataObject.java	Sun Jan 01 13:06:37 2012 +0100
     4.2 +++ b/testng/src/org/netbeans/modules/contrib/testng/TestNGSuiteDataObject.java	Sun Jan 01 17:11:55 2012 +0100
     4.3 @@ -1,7 +1,7 @@
     4.4  /*
     4.5   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     4.6   *
     4.7 - * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
     4.8 + * Copyright 2011-2012 Oracle and/or its affiliates. All rights reserved.
     4.9   *
    4.10   * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
    4.11   * Other names may be trademarks of their respective owners.
    4.12 @@ -47,13 +47,11 @@
    4.13  import org.netbeans.spi.xml.cookies.CheckXMLSupport;
    4.14  import org.netbeans.spi.xml.cookies.DataObjectAdapters;
    4.15  import org.netbeans.spi.xml.cookies.ValidateXMLSupport;
    4.16 -import org.openide.cookies.SaveCookie;
    4.17  import org.openide.filesystems.FileObject;
    4.18  import org.openide.loaders.DataObjectExistsException;
    4.19  import org.openide.loaders.MultiDataObject;
    4.20  import org.openide.loaders.MultiFileLoader;
    4.21  import org.openide.nodes.CookieSet;
    4.22 -import org.openide.nodes.Node;
    4.23  import org.openide.util.Lookup;
    4.24  import org.openide.util.NbBundle;
    4.25  import org.openide.windows.TopComponent;
    4.26 @@ -67,17 +65,12 @@
    4.27          CookieSet cookies = getCookieSet();
    4.28          cookies.add(new CheckXMLSupport(DataObjectAdapters.inputSource(this)));
    4.29          cookies.add(new ValidateXMLSupport(DataObjectAdapters.inputSource(this)));
    4.30 -        cookies.add(new TestNGSuiteDataEditor(this));
    4.31 +        registerEditor(MIME_TYPE, true);
    4.32      }
    4.33  
    4.34      @Override
    4.35 -    protected Node createNodeDelegate() {
    4.36 -        return new TestNGSuiteDataNode(this, getLookup());
    4.37 -    }
    4.38 -
    4.39 -    @Override
    4.40 -    public Lookup getLookup() {
    4.41 -        return getCookieSet().getLookup();
    4.42 +    protected int associateLookup() {
    4.43 +        return 1;
    4.44      }
    4.45  
    4.46      @MultiViewElement.Registration(displayName = "#CTL_SourceTabCaption",
    4.47 @@ -91,18 +84,4 @@
    4.48      public static MultiViewEditorElement createMultiViewEditorElement(Lookup context) {
    4.49          return new MultiViewEditorElement(context);
    4.50      }
    4.51 -
    4.52 -    void addSaveCookie(final SaveCookie save) {
    4.53 -        if (getLookup().lookup(SaveCookie.class) == null) {
    4.54 -            getCookieSet().add(save);
    4.55 -            setModified(true);
    4.56 -        }
    4.57 -    }
    4.58 -
    4.59 -    void removeSaveCookie(final SaveCookie save) {
    4.60 -        if (getLookup().lookup(SaveCookie.class) == save) {
    4.61 -            getCookieSet().remove(save);
    4.62 -            setModified(false);
    4.63 -        }
    4.64 -    }
    4.65  }
     5.1 --- a/testng/src/org/netbeans/modules/contrib/testng/resources/testng-suite.template	Sun Jan 01 13:06:37 2012 +0100
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,23 +0,0 @@
     5.4 -<?xml version='1.0' encoding='UTF-8' ?>
     5.5 -<#assign licenseFirst = "<!--">
     5.6 -<#assign licensePrefix = "">
     5.7 -<#assign licenseLast = "-->">
     5.8 -<#include "../Licenses/license-${project.license}.txt">
     5.9 -<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
    5.10 -<suite name="${name}">
    5.11 -
    5.12 -    <!--
    5.13 -    <suite-files>
    5.14 -        <suite-file path="./junit-suite.xml" />
    5.15 -    </suite-files>
    5.16 -
    5.17 -    <test name="TimeOut">
    5.18 -        <classes>
    5.19 -            <class name="test.timeout.TimeOutTest" />
    5.20 -            <class name="test.timeout.TimeOutFromXmlTest"/>
    5.21 -            <class name="test.timeout.TimeOutThreadLocalSampleTest"/>
    5.22 -        </classes>
    5.23 -    </test>
    5.24 -    -->
    5.25 -
    5.26 -</suite>
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/testng/src/org/netbeans/modules/contrib/testng/resources/testng.xml.template	Sun Jan 01 17:11:55 2012 +0100
     6.3 @@ -0,0 +1,28 @@
     6.4 +<?xml version='1.0' encoding='UTF-8' ?>
     6.5 +<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
     6.6 +<suite name="${name}">
     6.7 +
     6.8 +    <!--
     6.9 +    see examples at http://testng.org/doc/documentation-main.html#testng-xml
    6.10 +
    6.11 +    <suite-files>
    6.12 +        <suite-file path="./junit-suite.xml" />
    6.13 +    </suite-files>
    6.14 +
    6.15 +    <test name="TimeOut">
    6.16 +        <classes>
    6.17 +            <class name="test.timeout.TimeOutTest" />
    6.18 +            <class name="test.timeout.TimeOutFromXmlTest"/>
    6.19 +            <class name="test.timeout.TimeOutThreadLocalSampleTest"/>
    6.20 +        </classes>
    6.21 +    </test>
    6.22 +    -->
    6.23 +    
    6.24 +    <test name="${suiteName}">
    6.25 +        <parameter name="param-name" value="param-value" />
    6.26 +        <packages>
    6.27 +            <package name="${pkg}"/>
    6.28 +        </packages>
    6.29 +    </test>
    6.30 +
    6.31 +</suite>