KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > xml > querying > impl > xtas > TestResource


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 JavaDoc;
14 /*
15 import org.exoplatform.services.xml.querying.impl.xtas.BaseStatement;
16 import org.exoplatform.services.xml.querying.impl.xtas.SimpleStatement;
17 import org.exoplatform.services.xml.querying.impl.xtas.Query;
18 import org.exoplatform.services.xml.querying.impl.xtas.XTASMLStatement;
19 import org.exoplatform.services.xml.querying.impl.xtas.resource.ResourceResolver;
20 import org.exoplatform.services.xml.querying.impl.xtas.resource.Resource;
21 */

22
23 public class TestResource extends TestCase
24 {
25    
26
27     public TestResource(String JavaDoc 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 JavaDoc f1 = "tmp/new-res.xml";
41        String JavaDoc 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 JavaDoc 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 JavaDoc e) {
65 // e.printStackTrace();
66
fail( "testLocalFile() ERROR: "+e.toString() + " "+stat);
67         }
68
69     }
70
71     public void testLocalFile1()
72     {
73
74        BaseStatement stat = null;
75        String JavaDoc 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 // q.serialize();
83
// q.serialize();
84

85 // System.out.println(q1.getResult());
86

87 // assertEquals( "", true, q.getResult().isEmpty() );
88

89
90         } catch ( Exception JavaDoc e) {
91 // e.printStackTrace();
92
fail( "testLocalFile() ERROR: "+e.toString() + " "+stat);
93         }
94     }
95
96     public void testLocalFile2()
97     {
98
99        BaseStatement stat = null;
100        String JavaDoc f1 = "tmp/new-res.xml";
101        String JavaDoc updStr = "<employee><firstname>Gennady</firstname></employee>";
102
103        try {
104
105 // stat = SimpleStatement.create( f1, updStr );
106
String JavaDoc 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 JavaDoc 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 JavaDoc e) {
125 // e.printStackTrace();
126
fail( "testLocalFile() ERROR: "+e.toString() + " "+stat);
127         }
128
129     }
130
131 /*
132     public void testDescription()
133     {
134
135
136        try {
137
138 // System.out.println(ResourceResolver.getInstance().getResource("servlet://test.xml"));
139
140           Resource res = ResourceResolver.getInstance().getResource("test.xml");
141           assertEquals( "", res.getClass().getName(), "xtas.resource.plugins.LocalFile" );
142
143           res = ResourceResolver.getInstance().getResource("servlet://test.xml");
144           assertEquals( "", res.getClass().getName(), "xtas.resource.plugins.ServletResource" );
145
146 // System.out.println();
147
148         } catch ( Exception e) {
149 // e.printStackTrace();
150             fail( "testDescription() ERROR: "+e.toString());
151         }
152
153     }
154 */

155 }
156
Popular Tags