01: /*
02: * ImportFileHandlerTest.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.db.importer;
13:
14: import java.io.BufferedReader;
15: import java.io.File;
16: import java.io.PrintWriter;
17: import java.io.Reader;
18: import java.nio.CharBuffer;
19: import workbench.TestUtil;
20: import workbench.util.ZipOutputFactory;
21:
22: /**
23: *
24: * @author support@sql-workbench.net
25: */
26: public class ImportFileHandlerTest extends junit.framework.TestCase {
27:
28: public ImportFileHandlerTest(String testName) {
29: super (testName);
30: }
31:
32: public void testHandler() {
33: try {
34: TestUtil util = new TestUtil("outputFactoryTest");
35: File importFile = new File(util.getBaseDir(),
36: "datafile.txt");
37:
38: File archive = new File(util.getBaseDir(), "archive.zip");
39: ZipOutputFactory zout = new ZipOutputFactory(archive);
40: PrintWriter out = new PrintWriter(zout.createWriter(
41: importFile, "UTF-8"));
42:
43: String firstline = "nr\tfirstname\tlastname";
44: out.println(firstline);
45: out.print(Integer.toString(1));
46: out.print('\t');
47: out.println("First\t\"Last");
48: out.println("name\"");
49: out.close();
50:
51: zout.done();
52:
53: ImportFileHandler handler = new ImportFileHandler();
54: handler.setMainFile(archive, "UTF-8");
55: assertEquals("ZIP Archive not recognized", true, handler
56: .isZip());
57:
58: BufferedReader br = handler.getMainFileReader();
59: String line = br.readLine();
60:
61: assertEquals("Wrong data read", firstline, line);
62:
63: handler.done();
64: handler.setMainFile(archive, "UTF-8");
65: handler.done();
66: if (!archive.delete()) {
67: fail("Could not delete archive!");
68: }
69: } catch (Exception e) {
70: e.printStackTrace();
71: fail(e.getMessage());
72: }
73: }
74:
75: }
|