1 package test.xmldb.levelzero; 8 9 import junit.framework.*; 10 import test.xmldb.*; 11 12 import java.io.BufferedReader ; 13 import java.io.FileReader ; 14 15 import org.xml.sax.InputSource ; 16 import org.apache.xerces.parsers.DOMParser; 17 import org.apache.log4j.Logger; 18 19 import org.xmldb.api.modules.XMLResource; 20 23 public class StringTest extends XMLDBTestCase implements LevelZeroTestConstants { 24 25 Logger logger = Logger.getLogger(StringTest.class); 26 27 28 public StringTest(String name) { 29 super(name); 30 } 31 32 public static Test suite() { 33 return new TestSuite(StringTest.class); 34 } 35 36 39 public void testString() { 40 try { 41 logger.debug("\nLevelZeroTest.testString() - started\n"); 42 43 BufferedReader in = new BufferedReader (new FileReader (xmlFileName)); 45 InputSource source = new InputSource (in); 46 DOMParser parser = new DOMParser(); 47 parser.parse(source); 48 String xmlString = toString(parser.getDocument()).trim(); 49 XMLResource res = insertStringDocument(id, super.toString(document)); 50 51 String result = retrieveTextDocument(id).trim(); 52 53 super.assertNotNull("LevelZeroTest.testString() - result", result); 54 super.assertEquals("LevelZeroTest.testString() - length", xmlString.length(), result.length()); 55 56 updateStringDocument(id); 59 60 } catch (Exception e) { 61 e.printStackTrace(); 62 fail( e.getMessage( ) ); 63 } 64 } 65 66 private XMLResource insertStringDocument(String id, String document) throws Exception { 67 XMLResource res = (XMLResource) col.createResource(id, XMLResource.RESOURCE_TYPE); 68 super.assertEquals("LevelZeroTest.testString() - id",res.getId(), id); 69 super.assertSame(res.getParentCollection(),col); 70 res.setContent(document); 71 col.storeResource(res); 72 return res; 73 } 74 75 private String retrieveTextDocument(String id) throws Exception { 76 XMLResource resource = (XMLResource) col.getResource(id); 77 return (String )resource.getContent(); 78 } 79 80 private void updateStringDocument(String id) throws Exception { 81 XMLResource resource = (XMLResource) col.getResource(id); 82 String document = (String )resource.getContent(); 83 84 document = document.toLowerCase(); 86 87 resource.setContent(document); 88 col.storeResource(resource); 89 } 90 } 91 | Popular Tags |