1 19 20 package org.netbeans.modules.junit; 21 22 import org.openide.*; 23 import org.openide.nodes.*; 24 import org.openide.util.HelpCtx; 25 import org.openide.util.NbBundle; 26 import org.openide.util.actions.CookieAction; 27 import org.openide.loaders.*; 28 import org.openide.src.*; 29 import org.openide.filesystems.*; 30 import org.openide.cookies.*; 31 import java.lang.reflect.*; 32 import java.util.*; 33 import java.io.*; 34 import junit.framework.*; 35 import org.netbeans.junit.*; 36 37 public class CreateTestActionTest extends NbTestCase { 38 39 public CreateTestActionTest(java.lang.String testName) { 40 super(testName); 41 } 42 43 public static void main(java.lang.String [] args) { 44 junit.textui.TestRunner.run(suite()); 45 } 46 47 public static Test suite() { 48 TestSuite suite = new TestSuite(CreateTestActionTest.class); 49 50 return suite; 51 } 52 53 54 public void testGetName() { 55 System.out.println("testGetName"); 56 String name = TO.getName(); 57 assertTrue(null != name); 58 } 59 60 61 public void testGetHelpCtx() { 62 System.out.println("testGetHelpCtx"); 63 HelpCtx hc = TO.getHelpCtx(); 64 assertTrue(null != hc); 65 } 66 67 68 public void testCookieClasses() { 69 System.out.println("testCookieClasses"); 70 Class [] c = TO.cookieClasses(); 71 assertTrue(null != c); 72 } 73 74 75 public void testIconResource() { 76 System.out.println("testIconResource"); 77 String icon = TO.iconResource(); 78 assertTrue(null != icon); 79 } 80 81 82 public void testMode() { 83 System.out.println("testMode"); 84 TO.mode(); 85 } 86 87 88 public void testPerformAction() throws Exception { 89 System.out.println("testPerformAction"); 90 91 if (null == System.getProperty("netbeans.home")) { 93 fail("This tast can run within the IDE only."); 94 } 95 96 LocalFileSystem fsPass = new LocalFileSystem(); 97 LocalFileSystem fsTest = new LocalFileSystem(); 98 LocalFileSystem fsSrc = new LocalFileSystem(); 99 fsPass.setRootDirectory(new File(appendSlash(m_pathData) + "CreateTestAction/pass")); 100 fsTest.setRootDirectory(new File(appendSlash(m_pathData) + "CreateTestAction/test")); 101 fsSrc.setRootDirectory(new File(appendSlash(m_pathData) + "CreateTestAction/src")); 102 TopManager.getDefault().getRepository().addFileSystem(fsPass); 103 TopManager.getDefault().getRepository().addFileSystem(fsTest); 104 TopManager.getDefault().getRepository().addFileSystem(fsSrc); 105 106 JUnitSettings js = JUnitSettings.getDefault(); 107 setGenerateFlags(js, true); 108 js.setFileSystem(fsTest.getSystemName()); 109 110 assertTrue("Can't clean up the test directory.", delete(fsTest.getRoot(), false)); 111 TO.performAction(new Node[] { DataObject.find(fsTest.getRoot()).getNodeDelegate() }); 112 113 assertDirectories(fsTest.getRootDirectory(), fsPass.getRootDirectory()); 114 } 115 116 117 protected CreateTestAction TO = null; 118 protected String m_pathData = null; 119 120 protected void setUp() { 121 if (null == TO) 122 TO = (CreateTestAction)CreateTestAction.findObject(CreateTestAction.class, true); 123 124 if (null == m_pathData) 125 m_pathData = System.getProperty("xdata"); 126 } 127 128 protected void tearDown() { 129 } 130 131 private String appendSlash(String path) { 133 if (null == path) 134 return new String (); 135 136 if (!path.endsWith("\\") && !path.endsWith("/")) 137 return path + "\\"; 138 139 return path; 140 } 141 142 private final void assertDirectories(File test, File pass) { 143 File fKids[]; 144 145 fKids = test.listFiles(); 147 for(int i = 0; i < fKids.length; i++) { 148 assertDirectories(fKids[i], new File(pass, fKids[i].getName())); 149 } 150 151 if (!test.isDirectory()) { 152 assertFile(test, new File(pass, test.getName()), new File(System.getProperty("xresults"))); 153 } 154 else { 155 File fPassKids[] = pass.listFiles(); 157 for(int i = 0; i < fPassKids.length; i++) { 158 if (!new File(test, fPassKids[i].getName()).exists()) 159 fail("The file or directory '" + fPassKids[i].getAbsolutePath() + "' is missing."); 160 } 161 } 162 } 163 164 private final boolean delete(FileObject fo, boolean deleteCurrent) { 165 FileObject foKids[]; 166 FileLock lock = null; 167 168 foKids = fo.getChildren(); 170 for(int i = 0; i < foKids.length; i++) { 171 if (!delete(foKids[i], true)) 172 return false; 173 } 174 175 if (!deleteCurrent) 176 return true; 177 178 try { 179 lock = fo.lock(); 180 fo.delete(lock); 181 } 182 catch (IOException e) { 183 return false; 184 } 185 finally { 186 if (null != lock) 187 lock.releaseLock(); 188 } 189 return true; 190 } 191 192 private void setGenerateFlags(JUnitSettings js, boolean flag) { 193 js.setMembersPublic(flag); assertTrue(flag == js.isMembersPublic()); 194 js.setMembersProtected(flag); assertTrue(flag == js.isMembersProtected()); 195 js.setMembersPackage(flag); assertTrue(flag == js.isMembersPackage()); 196 js.setBodyComments(flag); assertTrue(flag == js.isBodyComments()); 197 js.setBodyContent(flag); assertTrue(flag == js.isBodyContent()); 198 js.setJavaDoc(flag); assertTrue(flag == js.isJavaDoc()); 199 } 200 } 201 | Popular Tags |