KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > ant > freeform > ui > UnboundTargetAlertTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.ant.freeform.ui;
21
22 import java.util.Arrays JavaDoc;
23 import java.util.Collections JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.List JavaDoc;
26 import java.util.Set JavaDoc;
27 import java.util.TreeSet JavaDoc;
28 import org.netbeans.modules.ant.freeform.FreeformProject;
29 import org.netbeans.modules.ant.freeform.FreeformProjectGenerator;
30 import org.netbeans.modules.ant.freeform.FreeformProjectType;
31 import org.netbeans.modules.ant.freeform.TestBase;
32 import org.netbeans.modules.ant.freeform.spi.support.Util;
33 import org.w3c.dom.Element JavaDoc;
34
35 /**
36  * Test non-GUI functionality of the unbound target alert: binding creation etc.
37  * @author Jesse Glick
38  */

39 public class UnboundTargetAlertTest extends TestBase {
40     
41     public UnboundTargetAlertTest(String JavaDoc name) {
42         super(name);
43     }
44
45     private FreeformProject prj;
46     private UnboundTargetAlert uta;
47     
48     protected void setUp() throws Exception JavaDoc {
49         super.setUp();
50         prj = copyProject(simple);
51         uta = new UnboundTargetAlert(prj, "debug");
52     }
53     
54     public void testGenerateBindingAndAddContextMenuItem() throws Exception JavaDoc {
55         uta.simulateTargetSelection("twiddle-this");
56         uta.generateBindingAndAddContextMenuItem();
57         List JavaDoc<FreeformProjectGenerator.TargetMapping> mappings = FreeformProjectGenerator.getTargetMappings(prj.helper());
58         // Will add it to the end, so just look there.
59
FreeformProjectGenerator.TargetMapping lastMapping = mappings.get(mappings.size() - 1);
60         assertEquals("debug", lastMapping.name);
61         assertEquals(null, lastMapping.script);
62         assertEquals(Collections.singletonList("twiddle-this"), lastMapping.targets);
63         assertEquals(null, lastMapping.properties);
64         assertEquals(null, lastMapping.context);
65         // Check also making a binding for multiple targets, which is permitted.
66
mappings.remove(lastMapping);
67         FreeformProjectGenerator.putTargetMappings(prj.helper(), mappings);
68         uta.simulateTargetSelection(" twiddle-this extra-step ");
69         uta.generateBindingAndAddContextMenuItem();
70         mappings = FreeformProjectGenerator.getTargetMappings(prj.helper());
71         lastMapping = mappings.get(mappings.size() - 1);
72         assertEquals("debug", lastMapping.name);
73         assertEquals(null, lastMapping.script);
74         assertEquals(Arrays.asList("twiddle-this", "extra-step"), lastMapping.targets);
75         assertEquals(null, lastMapping.properties);
76         assertEquals(null, lastMapping.context);
77         // Also check the context menu.
78
Element JavaDoc data = prj.getPrimaryConfigurationData();
79         Element JavaDoc view = Util.findElement(data, "view", FreeformProjectType.NS_GENERAL);
80         assertNotNull(view);
81         Element JavaDoc contextMenu = Util.findElement(view, "context-menu", FreeformProjectType.NS_GENERAL);
82         assertNotNull(contextMenu);
83         Set JavaDoc<String JavaDoc> actionNames = new TreeSet JavaDoc<String JavaDoc>();
84         for (Element JavaDoc action : Util.findSubElements(contextMenu)) {
85             if (action.getLocalName().equals("ide-action")) {
86                 actionNames.add(action.getAttribute("name"));
87             }
88         }
89         assertEquals("Correct context menu IDE actions",
90             new TreeSet JavaDoc<String JavaDoc>(Arrays.asList("build", "clean", "rebuild", "run", "javadoc", /*added*/ "debug")),
91             actionNames);
92     }
93     
94 }
95
Popular Tags