1 package org.netbeans.modules.web.jsf.editor; 2 import java.io.File ; 3 import java.io.FileReader ; 4 import java.io.IOException ; 5 import javax.swing.text.BadLocationException ; 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 16 public class JSFEditorUtilitiesTest extends NbTestCase { 17 18 File testDir; 19 FileObject testDirFO; 20 21 public JSFEditorUtilitiesTest(String testName) { 22 super(testName); 23 } 24 25 protected void setUp() throws Exception { 26 super.setUp(); 27 testDir = new File (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 36 public void testGetNavigationRuleDefinition() { 37 BaseDocument doc = createBaseDocument(new File (testDir, "faces-config1.xml")); 39 String ruleName = "/searchSciname.jsp"; 40 int[] expResult = new int[]{1541,1964}; 41 int[] result = JSFEditorUtilities.getNavigationRuleDefinition(doc, ruleName); 42 assertEquals(expResult[0], result[0]); 44 assertEquals(expResult[1], result[1]); 45 } 46 47 private BaseDocument createBaseDocument(File file){ 48 BaseDocument doc = new BaseDocument(XMLKit.class, false); 49 StringBuffer buffer = new StringBuffer (); 50 try { 51 FileReader reader = new FileReader (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 ex) { 61 fail("Exception occured during createBaseDocument: " + ex.toString()); 62 } 63 catch (BadLocationException ex) { 64 fail("Exception occured during createBaseDocument: " + ex.toString()); 65 } 66 return null; 67 } 68 69 } 70 | Popular Tags |