1 /*
2 * Copyright (c) 2003
3 * Information Desire GmbH
4 * All rights reserved.
5 */
6 package com.infodesire.infobit;
7
8 import com.infodesire.infobit.data.Acl;
9 import com.infodesire.infobit.data.Infobit;
10
11 import com.infodesire.infobit.external.InfobitExporter;
12 import com.infodesire.infobit.external.InfobitImporter;
13
14 import com.infodesire.infobit.external.impl.ImporterImpl;
15 // import com.infodesire.infobit.external.impl.VelocityExporter;
16 import com.infodesire.infobit.external.impl.SimpleExporter;
17
18 import junit.framework.TestCase;
19 import junit.framework.TestSuite;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23
24 import java.io.BufferedReader;
25 import java.io.IOException;
26 import java.io.InputStream;
27 import java.io.InputStreamReader;
28 import java.io.Reader;
29 import java.io.StringReader;
30 import java.io.StringWriter;
31
32 import java.util.ArrayList;
33 import java.util.Collection;
34 import java.util.HashMap;
35 import java.util.HashSet;
36 import java.util.List;
37 import java.util.Map;
38 import java.util.Set;
39
40 /***
41 * Test cases asserting the XML representation of infobits
42 *
43 * @author peter
44 * @created August 27, 2003
45 * @version $Revision: 1.1 $
46 */
47 public class XMLImportTest extends XMLTestBase {
48
49 /***
50 * The infobit importer being part of the fixture
51 */
52 protected InfobitImporter _importer;
53
54
55 /***
56 * Initializes the test cases.
57 *
58 * @param name Test name
59 */
60 public XMLImportTest(String name) {
61 super(name);
62 }
63
64
65 /***
66 * Common test case fixture.
67 *
68 * @exception Exception Description of Exception
69 */
70 public void setUp() throws Exception {
71 super.setUp();
72 _importer = new ImporterImpl();
73 _importer.setManager(_manager);
74 _importer.setAcl(_defaultAcl);
75 _importer.init();
76 }
77
78
79 /***
80 * Common teardown of test case fixtures.
81 *
82 * @exception Exception Description of Exception
83 */
84 public void tearDown() throws Exception {
85 }
86
87
88 /***
89 * Checks export of an empty infobit.
90 *
91 * @exception Exception Description of Exception
92 */
93 public void testEmptyInfobitImport() throws Exception {
94 String path = "/com/infodesire/infobit/external/emptyInfobit.xml";
95 performImportTest("testEmptyInfobitImport", path);
96 }
97
98
99 /***
100 * Checks the import of an infobit with multiple (text content) versions
101 * attached.
102 *
103 * @exception Exception Generic error
104 */
105 public void testMultiVersionInfobitImport() throws Exception {
106 String path =
107 "/com/infodesire/infobit/external/multiVersionInfobit.xml";
108 performImportTest("testMultiVersionInfobitImport", path);
109 }
110
111
112 /***
113 * Checks the import of an infobit with a binary content version attached.
114 *
115 * @exception Exception Description of Exception
116 */
117 public void testBinaryContentInfobitImport() throws Exception {
118 String path =
119 "/com/infodesire/infobit/external/binaryContentInfobit.xml";
120 performImportTest("testBinaryContentInfobitImport", path);
121 }
122
123
124 /***
125 * Checks the XML representation of multiple unrelated infobits.
126 *
127 * @exception Exception Description of Exception
128 */
129 public void testMultipleInfobitsImport() throws Exception {
130 String path = "/com/infodesire/infobit/external/multipleInfobits.xml";
131 performImportTest("testMultipleInfobitsImport", path);
132 }
133
134
135 /***
136 * Checks the import of a template content infobit.
137 *
138 * @exception Exception Description of Exception
139 */
140 public void testTemplateInfobitImport() throws Exception {
141 String path = "/com/infodesire/infobit/external/templateInfobit.xml";
142 performImportTest("testTemplateInfobitImport", path);
143 }
144
145
146 /***
147 * Checks the XML representation of a set of script with its referred
148 * template infobit.
149 *
150 * @exception Exception Description of Exception
151 */
152 public void testScriptSetImport() throws Exception {
153 String path = "/com/infodesire/infobit/external/scriptSet.xml";
154 performImportTest("testScriptSetImport", path);
155 }
156
157
158 /***
159 * Executes a test to successfully import an infobit. The Test consists in
160 * importing (with import already validated) an infobit, re-exporting it and
161 * assuring that the re-exported representation coincides with the initial
162 * one.
163 *
164 * @param name Descriptive name of the test, used for tracing only
165 * @param path Path to the XML representation (to be located in
166 * the classpath) which to test export for.
167 * @exception Exception Description of Exception
168 */
169 private void performImportTest(String name, String path)
170 throws Exception {
171
172 InputStream is = getClass().getResourceAsStream(path);
173 InputStreamReader source = new InputStreamReader(is);
174
175 List diag = new ArrayList();
176 List infobits = _importer.importInfobits(source, path, diag);
177 assertTrue("import errors", diag.size() == 0);
178
179 StringWriter dest = new StringWriter();
180 _exporter.export(infobits, dest);
181 dest.close();
182 String reexport = dest.toString();
183 Reader reexReader = new StringReader(reexport);
184
185 // DEBUG
186 System.out.println("Import: " + name);
187 System.out.print(reexport);
188
189 is = getClass().getResourceAsStream(path);
190 source = new InputStreamReader(is);
191
192 BufferedReader obtained = new BufferedReader(reexReader);
193 BufferedReader expected = new BufferedReader(source);
194 checkDocument(obtained, expected);
195 }
196
197 }
This page was automatically generated by Maven