1 package gate.xml;
2
3
10
11 import junit.framework.*;
12 import gate.*;
13 import gate.creole.*;
14 import gate.corpora.*;
15 import java.net.*;
16 import java.io.*;
17
18
28 public class TestRepositioningInfo
29 extends TestCase {
30
31
32 public TestRepositioningInfo(String dummy) {
33 super(dummy);
34 }
35
36
39 protected void setUp() {
40
41 testFile = TestDocument.getTestServerName() + "tests/test-inline.xml";
42
43 try {
45 FeatureMap params = Factory.newFeatureMap();
46 params.put("sourceUrl",new URL(testFile));
47 params.put("preserveOriginalContent", new Boolean("true"));
48 params.put("collectRepositioningInfo", new Boolean("true"));
49 doc = (Document) Factory.createResource("gate.corpora.DocumentImpl",params);
50 }
51 catch (MalformedURLException murle) {
52 fail("Document cannot be created ");
53 }
54 catch (ResourceInstantiationException rie) {
55 fail("Resources cannot be created for the test document");
56 }
57 }
58
59
60 public void tearDown() throws Exception {
61 Factory.deleteResource(doc);
62 }
64
65
76 public void testRepositioningInfo() throws Exception {
77
78 String encoding = ((DocumentImpl)doc).getEncoding();
80 File outputFile = File.createTempFile("test-inline1","xml");
81 OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(outputFile),encoding);
82 writer.write(((gate.Document)doc).toXml(null, true));
83 writer.flush();
84 writer.close();
85 InputStreamReader readerForSource = new InputStreamReader(new URL(testFile).openStream(),encoding);
86 InputStreamReader readerForDesti = new InputStreamReader(new FileInputStream(outputFile),encoding);
87 while(true) {
88 int input1 = readerForSource.read();
89 int input2 = readerForDesti.read();
90 if(input1 < 0 || input2 < 0) {
91 assertTrue(input1 < 0 && input2 < 0);
92 readerForSource.close();
93 readerForDesti.close();
94 outputFile.delete();
95 return;
96 } else {
97 assertEquals(input1,input2);
98 }
99 }
100 }
101
102
103 public static Test suite() {
104 return new TestSuite(TestRepositioningInfo.class);
105 }
107
108
109 private String testFile = "";
110
111
112 private Document doc = null;
113
114 }