1 package org.ogf.saga.logicalfile;
2
3 import java.util.List;
4 import org.junit.Assert;
5 import org.junit.Test;
6 import org.ogf.saga.namespace.Flags;
7 import org.ogf.saga.namespace.NSDirectory;
8 import org.ogf.saga.namespace.NSEntry;
9 import org.ogf.saga.namespace.abstracts.AbstractDirectory;
10 import org.ogf.saga.namespace.base.DirectoryBaseTest;
11 import org.ogf.saga.url.URL;
12 import org.ogf.saga.url.URLFactory;
13
14
15
16
17
18
19
20
21
22
23
24
25
26 public abstract class LogicalDirTest extends DirectoryBaseTest {
27 protected LogicalDirTest(String protocol) throws Exception {
28 super(protocol);
29 }
30
31 @Test
32 public void test_open() throws Exception {
33 NSDirectory dir = m_subDir.openDir(URLFactory.createURL(".."), Flags.NONE.getValue());
34 Assert.assertTrue(
35 dir instanceof LogicalDirectory);
36 Assert.assertEquals(
37 DEFAULT_DIRNAME,
38 dir.getName().getPath()+"/");
39 NSEntry entry = m_subDir.open(URLFactory.createURL(DEFAULT_FILENAME), Flags.NONE.getValue());
40 Assert.assertTrue(
41 entry instanceof LogicalFile);
42 Assert.assertEquals(
43 DEFAULT_FILENAME,
44 entry.getName().getPath());
45 }
46
47 @Override
48 @Test
49 public void test_find() throws Exception {
50 if (m_subDir instanceof LogicalDirectory) {
51 List<URL> list = ((LogicalDirectory) m_subDir).find(DEFAULT_FILEPATTERN, null, Flags.NONE.getValue());
52 Assert.assertEquals(
53 1,
54 list.size());
55 Assert.assertEquals(
56 DEFAULT_FILENAME,
57 list.get(0).toString());
58 } else {
59 Assert.fail("Not an instance of class: LogicalDirectory");
60 }
61 }
62
63 @Test
64 public void test_find_norecurse() throws Exception {
65 if (m_dir instanceof LogicalDirectory) {
66 List<URL> list = ((LogicalDirectory) m_dir).find(DEFAULT_FILEPATTERN, null, Flags.NONE.getValue());
67 Assert.assertEquals(
68 0,
69 list.size());
70 } else {
71 Assert.fail("Not an instance of class: LogicalDirectory");
72 }
73 }
74
75 @Override
76 @Test
77 public void test_find_recurse() throws Exception {
78 if (m_dir instanceof LogicalDirectory) {
79 List<URL> list = ((LogicalDirectory) m_dir).find(DEFAULT_FILEPATTERN, null, Flags.RECURSIVE.getValue());
80 Assert.assertEquals(
81 1,
82 list.size());
83 Assert.assertEquals(
84 DEFAULT_SUBDIRNAME +DEFAULT_FILENAME,
85 list.get(0).toString());
86 } else {
87 Assert.fail("Not an instance of class: LogicalDirectory");
88 }
89 }
90
91 @Test
92 public void test_isFile() throws Exception {
93 if (m_subDir instanceof LogicalDirectory) {
94 Assert.assertFalse(((LogicalDirectory) m_subDir).isFile(URLFactory.createURL("..")));
95 Assert.assertTrue(((LogicalDirectory) m_subDir).isFile(URLFactory.createURL(DEFAULT_FILENAME)));
96 } else {
97 Assert.fail("Not an instance of class: LogicalDirectory");
98 }
99 }
100
101 }