KickJava   Java API By Example, From Geeks To Geeks.

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


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.QueryType;
11 import org.exoplatform.services.xml.querying.impl.xtas.SimpleStatement;
12 import org.exoplatform.services.xml.querying.impl.xtas.XTASMLStatement;
13
14 //import org.exoplatform.services.xml.querying.impl.xtas.BaseStatement;
15
//import org.exoplatform.services.xml.querying.impl.xtas.XTASMLStatement;
16
//import org.exoplatform.services.xml.querying.impl.xtas.SimpleStatement;
17
//import org.exoplatform.services.xml.querying.impl.xtas.QueryType;
18

19 /**
20  * Test Case for QueryContent related things
21  * @version $Id: TestQueryContent.java 566 2005-01-25 12:50:49Z kravchuk $
22  */

23 public class TestQueryContent extends TestCase
24 {
25     protected BaseStatement qc = null;
26
27     public TestQueryContent(String JavaDoc name)
28     {
29         super(name);
30     }
31
32     public static Test suite()
33     {
34         return new TestSuite(TestQueryContent.class);
35     }
36
37     public void testLocalFileContent()
38     {
39
40         String JavaDoc f1 = "tmp/query.xml";
41
42         try {
43
44             qc = new XTASMLStatement (f1);
45             // Just see how it works :)
46
assertNotNull( qc );
47 // assertEquals( "Local file content Not equal ", util.getFileContent(f1), qc.getStatementAsString() );
48

49         } catch ( Exception JavaDoc e) {
50             fail( "Could not create QueryContent: "+e.toString());
51         }
52
53     }
54
55
56     public void testUrlContent()
57     {
58
59     }
60
61     public void testSimpleStatement()
62     {
63
64         BaseStatement qc = null;
65
66         try {
67
68 // qc = new SimpleStatement("select", "//security-identity/*");
69
qc = SimpleStatement.select("//security-identity/*", "tmp/ejb-jar.xml");
70
71             assertEquals( QueryType.SELECT, qc.getInstructions()[0].getType() );
72
73             assertEquals( true , qc.getInstructions()[0].isAtXml() );
74             assertEquals( false , qc.getInstructions()[0].isAtResource() );
75
76 // System.out.println(qc);
77

78             qc = null;
79             String JavaDoc f1 = "tmp/created-xml.xml";
80             qc = new SimpleStatement ("create", "tmp/created-xml.xml", "<test/>", null, null);
81
82 // System.out.println(qc);
83

84
85             assertNotNull( qc.toString() );
86             assertEquals( QueryType.CREATE, qc.getInstructions()[0].getType() );
87             assertEquals( qc.toString()+" isAtXml(): ", false , qc.getInstructions()[0].isAtXml() );
88             assertEquals( qc.toString()+" isAtResource(): ", true , qc.getInstructions()[0].isAtResource() );
89
90
91         } catch ( Exception JavaDoc e) {
92             fail( "Could not create Query Statement: "+e.toString()+"("+qc+")");
93         }
94
95
96
97         try {
98
99             // Must not be created! Bad query type
100
qc = new SimpleStatement ("bad", "//security-identity/*");
101 // assertNull( qc.toString() );
102

103             fail( "Query Statement created ! " +qc.toString());
104
105         } catch ( Exception JavaDoc e) {
106 // fail( "Could not create Query Statement: "+e.toString());
107
}
108
109         try {
110
111             qc = new SimpleStatement ("create", null, null);
112 // assertNull( qc.toString() );
113

114 // System.out.println(qc.getNewValue().toString().length());
115
// System.out.println(qc.getNewValue().isEmpty());
116

117             fail( "Query Statement created ! " +qc.toString());
118
119         } catch ( Exception JavaDoc e) {
120 // fail( "Could not create Query Statement: "+e.toString());
121
}
122
123
124     }
125
126
127 }
128
Popular Tags