01: package liquibase;
02:
03: import liquibase.FileOpener;
04: import liquibase.FileSystemFileOpener;
05: import static org.junit.Assert.*;
06: import org.junit.Before;
07: import org.junit.Test;
08:
09: import java.io.File;
10: import java.io.IOException;
11: import java.net.URI;
12: import java.net.URISyntaxException;
13: import java.net.URL;
14: import java.util.Enumeration;
15:
16: public class FileSystemFileOpenerTest {
17: FileSystemFileOpener opener;
18:
19: @Before
20: public void createFileOpener() throws URISyntaxException {
21: File this ClassFile = new File(new URI(this .getClass()
22: .getClassLoader().getResource(
23: "liquibase/FileSystemFileOpener.class")
24: .toExternalForm()));
25: String packageDirectory = this ClassFile.getParent();
26:
27: opener = new FileSystemFileOpener(packageDirectory);
28: }
29:
30: @Test(expected=IllegalArgumentException.class)
31: public void onlyAcceptsDirectories() throws URISyntaxException {
32: File this ClassFile = new File(new URI(this .getClass()
33: .getClassLoader().getResource(
34: "liquibase/FileSystemFileOpener.class")
35: .toExternalForm()));
36:
37: FileOpener o = new FileSystemFileOpener(this ClassFile
38: .getAbsolutePath());
39: }
40:
41: @Test
42: public void singleFileTest() throws IOException {
43: assertNotNull(opener
44: .getResourceAsStream("FileSystemFileOpener.class"));
45: }
46:
47: @Test
48: public void multipleFileTest() throws IOException {
49: Enumeration<URL> files = opener.getResources(".");
50: boolean found = false;
51: while (files.hasMoreElements()) {
52: URL u = files.nextElement();
53: found |= u.getFile().lastIndexOf("FileSystemFileOpener") > -1;
54: }
55: assertTrue(found);
56: }
57: }
|