KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > jsf > editor > JSFEditorUtilitiesTest


1 package org.netbeans.modules.web.jsf.editor;
2 import java.io.File JavaDoc;
3 import java.io.FileReader JavaDoc;
4 import java.io.IOException JavaDoc;
5 import javax.swing.text.BadLocationException JavaDoc;
6 import org.netbeans.editor.BaseDocument;
7 import org.netbeans.junit.NbTestCase;
8 import org.openide.filesystems.FileObject;
9 import org.openide.filesystems.FileUtil;
10 import org.netbeans.modules.xml.text.syntax.XMLKit;
11
12 /**
13  *
14  * @author petr
15  */

16 public class JSFEditorUtilitiesTest extends NbTestCase {
17     
18     File JavaDoc testDir;
19     FileObject testDirFO;
20     
21     public JSFEditorUtilitiesTest(String JavaDoc testName) {
22         super(testName);
23     }
24
25     protected void setUp() throws Exception JavaDoc {
26         super.setUp();
27         testDir = new File JavaDoc (this.getDataDir().getPath());
28         assertTrue("have a dir " + testDir, testDir.isDirectory());
29         testDirFO = FileUtil.toFileObject(testDir);
30         assertNotNull("testDirFO is null", testDirFO);
31     }
32     
33     /**
34      * Test of getNavigationRuleDefinition method, of class org.netbeans.modules.web.jsf.editor.JSFEditorUtilities.
35      */

36     public void testGetNavigationRuleDefinition() {
37         //System.out.println("getNavigationRuleDefinition");
38
BaseDocument doc = createBaseDocument(new File JavaDoc(testDir, "faces-config1.xml"));
39         String JavaDoc ruleName = "/searchSciname.jsp";
40         int[] expResult = new int[]{1541,1964};
41         int[] result = JSFEditorUtilities.getNavigationRuleDefinition(doc, ruleName);
42         //System.out.println("result: " + result[0] + " | " + result [1]);
43
assertEquals(expResult[0], result[0]);
44         assertEquals(expResult[1], result[1]);
45     }
46
47     private BaseDocument createBaseDocument(File JavaDoc file){
48         BaseDocument doc = new BaseDocument(XMLKit.class, false);
49         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
50         try {
51             FileReader JavaDoc reader = new FileReader JavaDoc (file);
52             char[] buf = new char [100];
53             int count = -1;
54             while ((count = reader.read(buf)) != -1){
55                 buffer.append(buf, 0, count);
56             }
57             reader.close();
58             doc.insertString(0, buffer.toString(), null);
59             return doc;
60         } catch (IOException JavaDoc ex) {
61             fail("Exception occured during createBaseDocument: " + ex.toString());
62         }
63         catch (BadLocationException JavaDoc ex) {
64             fail("Exception occured during createBaseDocument: " + ex.toString());
65         }
66         return null;
67     }
68     
69 }
70
Popular Tags