1 19 20 package org.netbeans.modules.ant.freeform.ui; 21 22 import java.util.Arrays ; 23 import java.util.Collections ; 24 import java.util.Iterator ; 25 import java.util.List ; 26 import java.util.Set ; 27 import java.util.TreeSet ; 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 ; 34 35 39 public class UnboundTargetAlertTest extends TestBase { 40 41 public UnboundTargetAlertTest(String name) { 42 super(name); 43 } 44 45 private FreeformProject prj; 46 private UnboundTargetAlert uta; 47 48 protected void setUp() throws Exception { 49 super.setUp(); 50 prj = copyProject(simple); 51 uta = new UnboundTargetAlert(prj, "debug"); 52 } 53 54 public void testGenerateBindingAndAddContextMenuItem() throws Exception { 55 uta.simulateTargetSelection("twiddle-this"); 56 uta.generateBindingAndAddContextMenuItem(); 57 List <FreeformProjectGenerator.TargetMapping> mappings = FreeformProjectGenerator.getTargetMappings(prj.helper()); 58 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 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 Element data = prj.getPrimaryConfigurationData(); 79 Element view = Util.findElement(data, "view", FreeformProjectType.NS_GENERAL); 80 assertNotNull(view); 81 Element contextMenu = Util.findElement(view, "context-menu", FreeformProjectType.NS_GENERAL); 82 assertNotNull(contextMenu); 83 Set <String > actionNames = new TreeSet <String >(); 84 for (Element 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 <String >(Arrays.asList("build", "clean", "rebuild", "run", "javadoc", "debug")), 91 actionNames); 92 } 93 94 } 95 | Popular Tags |