1 7 8 package org.netbeans.test.junit.testcase; 9 10 import java.io.BufferedWriter ; 11 import java.io.File ; 12 import java.io.FileWriter ; 13 import java.io.IOException ; 14 import java.io.PrintStream ; 15 import java.io.PrintWriter ; 16 import java.util.ArrayList ; 17 import org.netbeans.jellytools.Bundle; 18 import org.netbeans.jellytools.EditorOperator; 19 import org.netbeans.jellytools.util.StringFilter; 20 import org.netbeans.jemmy.JemmyProperties; 21 import org.netbeans.jemmy.TestOut; 22 import org.netbeans.junit.NbTestCase; 23 import org.netbeans.test.junit.utils.Utilities; 24 25 29 public class JunitTestCase extends NbTestCase { 30 31 32 private static boolean CREATE_GOLDENFILES = false; 33 34 35 protected static final String CREATE_TESTS_DIALOG = Bundle.getString( 36 "org.netbeans.modules.junit.Bundle", "JUnitCfgOfCreate.Title"); 37 38 39 protected static PrintWriter goldenWriter = null; 40 41 42 protected static PrintStream err; 43 44 45 protected static PrintStream log; 46 47 48 private String workDir = "/tmp"; 49 50 51 protected StringFilter filter; 52 53 static { 54 if (System.getProperty("create.goldenfiles") != null && 55 System.getProperty("create.goldenfiles").equals("true")) { 56 CREATE_GOLDENFILES=true; 57 } 58 } 59 60 61 public JunitTestCase(String testName) { 62 super(testName); 63 } 64 65 68 public void setUp() { 69 System.out.println("######## " + getName() + " #######"); 70 err = getLog(); 71 log = getRef(); 72 JemmyProperties.getProperties().setOutput(new TestOut(null, 73 new PrintWriter (err, true), new PrintWriter (err, false), null)); 74 try { 75 File wd = getWorkDir(); 76 workDir = wd.toString(); 77 } catch (IOException e) { } 78 filter = new StringFilter(); 80 filter.addReplaceFilter("@author ", "\n", "@author Tester\n"); 81 filter.addReplaceFilter("Created on ", "\n", "Created on Date\n"); 82 } 83 84 87 protected void tearDown() { 88 if(CREATE_GOLDENFILES) { 89 File f; 90 f = getDataDir().getParentFile(); ArrayList names = new ArrayList (); 93 names.add("goldenfiles"); names.add("data"); names.add("qa-functional"); while (!f.getName().equals("test")) { 97 if (!f.getName().equals("sys") && !f.getName().equals("work") &&!f.getName().equals("tests")) { 98 names.add(f.getName()); 99 } 100 f = f.getParentFile(); 101 } 102 for (int i = names.size()-1;i > -1;i--) { 103 f = new File (f,(String )(names.get(i))); 104 } 105 f = new File (f, getClass().getName().replace('.', File.separatorChar)); 106 f = new File (f, getName()+".pass"); 107 if (!f.getParentFile().exists()) { 108 f.getParentFile().mkdirs(); 109 } 110 try { 111 goldenWriter = new PrintWriter (new BufferedWriter (new FileWriter (f))); 112 System.out.println("Class name"+ Utilities.TEST_CLASS_NAME + "Test.java"); 113 EditorOperator op = new EditorOperator(Utilities.TEST_CLASS_NAME + "Test.java"); 114 goldenWriter.print(filter.filter(op.getText())); goldenWriter.println(); goldenWriter.close(); 117 } catch (IOException ex) { 118 ex.printStackTrace(); 119 } 120 log("Passive mode: generate golden file into "+f.getAbsolutePath()); 121 122 } else { 123 } 126 log.close(); 127 err.close(); 128 } 129 130 } 131 | Popular Tags |