1 package org.ogf.saga.namespace.base;
2
3 import org.junit.After;
4 import org.junit.Before;
5 import org.junit.Test;
6 import org.ogf.saga.error.*;
7 import org.ogf.saga.namespace.*;
8 import org.ogf.saga.namespace.abstracts.AbstractDirectory;
9 import org.ogf.saga.url.URL;
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 public abstract class MakeDirBaseTest extends AbstractDirectory {
25
26
27 protected static final String DEFAULT_SUBDIRNAME_2 = "subdir2/";
28 protected URL m_subDirUrl2;
29 protected NSDirectory m_subDir2;
30
31 public MakeDirBaseTest(String protocol) throws Exception {
32 super(protocol);
33 m_subDirUrl2 = createURL(m_subDirUrl, DEFAULT_SUBDIRNAME_2);
34 }
35
36 @Before
37 @Override
38 public void setUp() throws Exception {
39 super.setUp();
40 }
41
42 @After
43 @Override
44 public void tearDown() throws Exception {
45 if (m_subDir2 != null) {
46 m_subDir2.close();
47 }
48 super.tearDown();
49 }
50
51 @Test(expected=DoesNotExistException.class)
52 public void test_makeDir_child() throws Exception {
53 m_subDir.remove(Flags.RECURSIVE.getValue());
54 NSFactory.createNSDirectory(m_session, m_subDirUrl2, Flags.CREATE.getValue());
55 }
56
57 @Test
58 public void test_makeDir_recursive() throws Exception {
59 m_subDir.remove(Flags.RECURSIVE.getValue());
60 m_subDir2 = NSFactory.createNSDirectory(m_session, m_subDirUrl2, Flags.CREATE.or(Flags.CREATEPARENTS));
61 assertEquals(true, m_subDir2.exists(m_subDirUrl2));
62 }
63
64 @Test
65 public void test_makeDir_noexclusive() throws Exception {
66 NSFactory.createNSDirectory(m_session, m_subDirUrl, Flags.CREATE.getValue());
67 assertEquals(true, m_subDir.exists(m_subDirUrl));
68 }
69
70 @Test(expected=AlreadyExistsException.class)
71 public void test_makeDir_exclusive() throws Exception {
72 NSFactory.createNSDirectory(m_session, m_subDirUrl, Flags.CREATE.or(Flags.EXCL));
73 }
74
75
76 @Test(expected=DoesNotExistException.class)
77 public void test_remove() throws Exception {
78 m_subDir.remove(Flags.RECURSIVE.getValue());
79 NSFactory.createNSDirectory(m_session, m_subDirUrl, Flags.NONE.getValue());
80 }
81
82 @Test(expected=IncorrectStateException.class)
83 public void test_remove_notexist() throws Exception {
84 m_subDir.remove(Flags.RECURSIVE.getValue());
85 m_subDir.remove(Flags.NONE.getValue());
86 }
87
88 @Test(expected=IncorrectStateException.class)
89 public void test_remove_recursive_notexist() throws Exception {
90 m_subDir.remove(Flags.RECURSIVE.getValue());
91 m_subDir.remove(Flags.RECURSIVE.getValue());
92 }
93
94 @Test(expected=BadParameterException.class)
95 public void test_remove_norecursive() throws Exception {
96 m_subDir2 = m_dir.openDir(m_subDirUrl2, Flags.CREATE.getValue());
97 m_subDir.remove(Flags.NONE.getValue());
98 }
99 }