1 19 20 package org.netbeans.modules.editor.mimelookup.impl; 21 22 import java.io.IOException ; 23 import java.util.Collection ; 24 import java.util.Iterator ; 25 import org.netbeans.api.editor.mimelookup.MimeLookup; 26 import org.netbeans.junit.NbTestCase; 27 import org.openide.util.Lookup; 28 import org.openide.util.Lookup.Result; 29 import org.openide.util.Lookup.Template; 30 import org.openide.util.LookupEvent; 31 import org.openide.util.LookupListener; 32 33 38 public class IssuesTest extends NbTestCase { 39 40 private static final int WAIT_TIME = 5000; 41 private static final int WAIT_TIME_FIRING = 1500; 42 final int resultChangedCount[] = new int[1]; 43 44 public IssuesTest(java.lang.String testName) { 45 super(testName); 46 } 47 48 protected void setUp() throws java.lang.Exception { 49 String fsstruct [] = new String [] { 50 "Editors/text/jsp/testLookup/org-netbeans-modules-editor-mimelookup-impl-TestLookupObject.instance", "Editors/text/x-java/testLookupTwo/org-netbeans-modules-editor-mimelookup-impl-TestLookupObjectTwo.instance", "Editors/testLookupTwo/org-netbeans-modules-editor-mimelookup-impl-TestLookupObjectTwo.instance", }; 54 55 EditorTestLookup.setLookup(fsstruct, getWorkDir(), new Object [] {}, 56 getClass().getClassLoader()); 57 58 } 59 60 private void createFile(String file) throws IOException { 61 TestUtilities.createFile(getWorkDir(), file); } 63 64 private void checkResultChange(final int count) throws IOException { 65 TestUtilities.waitMaxMilisForValue(WAIT_TIME_FIRING, new TestUtilities.ValueResolver(){ 67 public Object getValue(){ 68 return Boolean.FALSE; 69 } 70 }, Boolean.TRUE); 71 assertTrue(("resultChangedCount is:"+resultChangedCount[0]+" instead of "+count), resultChangedCount[0] == count); 72 } 73 74 77 public void testForChangeInLayer() throws IOException { 78 79 MimeLookup lookup = MimeLookup.getMimeLookup("text/jsp"); Result result = lookup.lookup(new Template(TestLookupObject.class)); 86 result.allInstances(); LookupListener listener = new LookupListener(){ 88 public void resultChanged(LookupEvent ev){ 89 resultChangedCount[0]++; 90 } 91 }; 92 result.addLookupListener(listener); 93 94 createFile("Editors/text/jsp/testLookup/org-openide-actions-PasteAction.instance"); 97 checkResultChange(0); 98 99 TestUtilities.deleteFile(getWorkDir(), 100 "Editors/text/jsp/testLookup/org-netbeans-modules-editor-mimelookup-impl-TestLookupObject.instance"); 101 102 checkResultChange(1); 103 104 result.removeLookupListener(listener); 105 resultChangedCount[0] = 0; 106 108 109 110 } 111 112 115 public void testDoubleItems(){ 116 MimeLookup lookup = MimeLookup.getMimeLookup("text/x-java"); Result result = lookup.lookup(new Template(TestLookupObjectTwo.class)); 118 Collection col = result.allInstances(); 119 assertTrue(col.size() == 1); 120 121 lookup = MimeLookup.getMimeLookup(""); result = lookup.lookup(new Template(TestLookupObjectTwo.class)); 123 col = result.allInstances(); 124 assertTrue(col.size() == 1); 125 126 } 127 128 129 private void checkLookupObject(final MimeLookup lookup, final Class clazz, final boolean shouldBePresent){ 130 TestUtilities.waitMaxMilisForValue(WAIT_TIME, new TestUtilities.ValueResolver(){ 131 public Object getValue(){ 132 Object obj = lookup.lookup(clazz); 133 boolean bool = (shouldBePresent) ? obj != null : obj == null; 134 return Boolean.valueOf(bool); 135 } 136 }, Boolean.TRUE); 137 Object obj = lookup.lookup(clazz); 138 if (shouldBePresent){ 139 assertTrue("Object should be present in the lookup",obj!=null); 140 } else { 141 assertTrue("Object should NOT be present in the lookup",obj==null); 142 } 143 } 144 145 private void checkLookupTemplate(final MimeLookup lookup, final Class clazz, final int instCount){ 146 TestUtilities.waitMaxMilisForValue(WAIT_TIME, new TestUtilities.ValueResolver(){ 147 public Object getValue(){ 148 Lookup.Result result = lookup.lookup(new Lookup.Template(clazz)); 149 boolean bool = result.allInstances().size() == instCount; 150 return Boolean.valueOf(bool); 151 } 152 }, Boolean.TRUE); 153 Lookup.Result result = lookup.lookup(new Lookup.Template(clazz)); 154 int size = result.allInstances().size(); 155 boolean bool = (size == instCount); 156 assertTrue("Number of instances doesn't match. Found:"+size+". Should be presented:"+instCount+".", bool); 157 } 158 159 } 160 | Popular Tags |