01: /*
02: * The contents of this file are subject to the terms of the Common Development
03: * and Distribution License (the License). You may not use this file except in
04: * compliance with the License.
05: *
06: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
07: * or http://www.netbeans.org/cddl.txt.
08: *
09: * 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-2007 Sun
17: * Microsystems, Inc. All Rights Reserved.
18: */
19:
20: package org.netbeans.test.lib;
21:
22: import java.io.File;
23: import java.io.FileWriter;
24: import java.io.IOException;
25: import org.netbeans.jellytools.JellyTestCase;
26:
27: /**
28: *
29: * @author Jindrich Sedek
30: */
31: public abstract class BasicTokensTest extends JellyTestCase {
32:
33: private String goldenFilePath;
34:
35: public BasicTokensTest(String name) {
36: super (name);
37: }
38:
39: abstract protected boolean generateGoldenFiles();
40:
41: public void tearDown() {
42: if (generateGoldenFiles()) {
43: fail("GENERATING GOLDEN FILES TO " + goldenFilePath);
44: } else {
45: compareReferenceFiles();
46: }
47: }
48:
49: protected void testRun(String fileName) {
50: String result = null;
51: File dir = new File(getDataDir(), "tokens");
52: File file = new File(dir, fileName);
53: try {
54: result = new DumpTokens(file).getTokenString();
55: } catch (Throwable t) {
56: System.out.println(t);
57: t.printStackTrace();
58: }
59: if (generateGoldenFiles()) {
60: try {
61: goldenFilePath = getGoldenFile().getPath().replace(
62: "work/sys", "qa-functional");
63: File gFile = new File(goldenFilePath);
64: gFile.createNewFile();
65: FileWriter writer = new FileWriter(gFile);
66: writer.write(result + "\n");
67: writer.close();
68: } catch (IOException ioe) {
69: ioe.printStackTrace(System.err);
70: fail("IO EXCEPTION");
71: }
72: } else {
73: ref(result);
74: }
75: }
76: }
|