001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.ant.freeform.ui;
043:
044: import java.util.Arrays;
045: import java.util.Collections;
046: import java.util.Iterator;
047: import java.util.List;
048: import java.util.Set;
049: import java.util.TreeSet;
050: import org.netbeans.modules.ant.freeform.FreeformProject;
051: import org.netbeans.modules.ant.freeform.FreeformProjectGenerator;
052: import org.netbeans.modules.ant.freeform.FreeformProjectType;
053: import org.netbeans.modules.ant.freeform.TestBase;
054: import org.netbeans.modules.ant.freeform.spi.support.Util;
055: import org.w3c.dom.Element;
056:
057: /**
058: * Test non-GUI functionality of the unbound target alert: binding creation etc.
059: * @author Jesse Glick
060: */
061: public class UnboundTargetAlertTest extends TestBase {
062:
063: public UnboundTargetAlertTest(String name) {
064: super (name);
065: }
066:
067: private FreeformProject prj;
068: private UnboundTargetAlert uta;
069:
070: protected void setUp() throws Exception {
071: super .setUp();
072: prj = copyProject(simple);
073: uta = new UnboundTargetAlert(prj, "debug");
074: }
075:
076: public void testGenerateBindingAndAddContextMenuItem()
077: throws Exception {
078: uta.simulateTargetSelection("twiddle-this");
079: uta.generateBindingAndAddContextMenuItem();
080: List<FreeformProjectGenerator.TargetMapping> mappings = FreeformProjectGenerator
081: .getTargetMappings(prj.helper());
082: // Will add it to the end, so just look there.
083: FreeformProjectGenerator.TargetMapping lastMapping = mappings
084: .get(mappings.size() - 1);
085: assertEquals("debug", lastMapping.name);
086: assertEquals(null, lastMapping.script);
087: assertEquals(Collections.singletonList("twiddle-this"),
088: lastMapping.targets);
089: assertEquals(null, lastMapping.properties);
090: assertEquals(null, lastMapping.context);
091: // Check also making a binding for multiple targets, which is permitted.
092: mappings.remove(lastMapping);
093: FreeformProjectGenerator.putTargetMappings(prj.helper(),
094: mappings);
095: uta.simulateTargetSelection(" twiddle-this extra-step ");
096: uta.generateBindingAndAddContextMenuItem();
097: mappings = FreeformProjectGenerator.getTargetMappings(prj
098: .helper());
099: lastMapping = mappings.get(mappings.size() - 1);
100: assertEquals("debug", lastMapping.name);
101: assertEquals(null, lastMapping.script);
102: assertEquals(Arrays.asList("twiddle-this", "extra-step"),
103: lastMapping.targets);
104: assertEquals(null, lastMapping.properties);
105: assertEquals(null, lastMapping.context);
106: // Also check the context menu.
107: Element data = prj.getPrimaryConfigurationData();
108: Element view = Util.findElement(data, "view",
109: FreeformProjectType.NS_GENERAL);
110: assertNotNull(view);
111: Element contextMenu = Util.findElement(view, "context-menu",
112: FreeformProjectType.NS_GENERAL);
113: assertNotNull(contextMenu);
114: Set<String> actionNames = new TreeSet<String>();
115: for (Element action : Util.findSubElements(contextMenu)) {
116: if (action.getLocalName().equals("ide-action")) {
117: actionNames.add(action.getAttribute("name"));
118: }
119: }
120: assertEquals(
121: "Correct context menu IDE actions",
122: new TreeSet<String>(Arrays.asList("build", "clean",
123: "rebuild", "run", "javadoc", /*added*/"debug")),
124: actionNames);
125: }
126:
127: }
|