1 package org.exoplatform.services.xml.querying.impl.xtas; 2 3 import junit.framework.TestCase; 4 import junit.framework.Test; 5 import junit.framework.TestSuite; 6 7 8 import java.io.*; 9 import org.exoplatform.services.xml.querying.impl.xtas.BaseStatement; 10 import org.exoplatform.services.xml.querying.impl.xtas.Query; 11 import org.exoplatform.services.xml.querying.impl.xtas.SimpleStatement; 12 import org.exoplatform.services.xml.querying.impl.xtas.XTASMLStatement; 13 import org.xml.sax.InputSource ; 14 22 23 public class TestResource extends TestCase 24 { 25 26 27 public TestResource(String name) 28 { 29 super(name); 30 } 31 public static Test suite() 32 { 33 return new TestSuite(TestResource.class); 34 } 35 36 public void testLocalFile() 37 { 38 39 BaseStatement stat = null; 40 String f1 = "tmp/new-res.xml"; 41 String updStr = "<employee><firstname>Gennady</firstname></employee>"; 42 43 try { 44 45 46 System.setProperty("xtas.xsl", "tmp/xtas-debug.xsl"); 47 48 stat = new SimpleStatement ("create", f1, updStr, null, f1); 49 Query q = new Query ( stat ); 50 q.execute(); 51 q.serialize(); 52 53 String str = util.getFileContent(f1); 54 55 stat = null; 56 stat = new SimpleStatement ("drop", f1, ""); 57 q = new Query ( stat ); 58 q.execute(); 59 60 assertEquals( "", util.XML_DECLARATION+updStr, str ); 61 62 System.setProperty("xtas.xsl", ""); 63 64 } catch ( Exception e) { 65 fail( "testLocalFile() ERROR: "+e.toString() + " "+stat); 67 } 68 69 } 70 71 public void testLocalFile1() 72 { 73 74 BaseStatement stat = null; 75 String f1 = "tmp/employees.xml"; 76 77 try { 78 79 stat = SimpleStatement.select( "/" , f1, "tmp/employees-out.xml"); 80 Query q = new Query ( stat ); 81 q.execute(); 82 85 87 89 90 } catch ( Exception e) { 91 fail( "testLocalFile() ERROR: "+e.toString() + " "+stat); 93 } 94 } 95 96 public void testLocalFile2() 97 { 98 99 BaseStatement stat = null; 100 String f1 = "tmp/new-res.xml"; 101 String updStr = "<employee><firstname>Gennady</firstname></employee>"; 102 103 try { 104 105 String s = "<query><create resource=\"tmp/new-res.xml\">"+ 107 updStr+"</create></query>"; 108 stat = new XTASMLStatement ( s.getBytes() ); 109 Query q = new Query ( stat ); 110 q.execute(); 111 q.serialize(); 112 113 String str = util.getFileContent(f1); 114 115 stat = null; 116 stat = new SimpleStatement ("drop", f1, ""); 117 q = new Query ( stat ); 118 q.execute(); 119 120 assertEquals( "", util.XML_DECLARATION+updStr, str ); 121 122 123 124 } catch ( Exception e) { 125 fail( "testLocalFile() ERROR: "+e.toString() + " "+stat); 127 } 128 129 } 130 131 155 } 156 | Popular Tags |