1 package org.ogf.saga.namespace;
2
3 import org.junit.Test;
4 import org.ogf.saga.error.*;
5 import org.ogf.saga.namespace.abstracts.AbstractDataMovement;
6 import org.ogf.saga.url.URL;
7
8
9
10
11
12
13
14
15
16
17
18
19
20 public abstract class DataReadOnlyMovementTest extends AbstractDataMovement {
21 protected DataReadOnlyMovementTest(String protocol, String targetProtocol) throws Exception {
22 super(protocol, targetProtocol);
23 }
24
25 @Test
26 public void test_copy() throws Exception {
27 URL target = createURL(m_dirUrl2, DEFAULT_FILENAME);
28 m_file.copy(m_dirUrl2, Flags.NONE.getValue());
29 checkCopied(target, DEFAULT_CONTENT);
30 }
31
32 @Test
33 public void test_copy_and_rename() throws Exception {
34 URL target = createURL(m_subDirUrl2, "copy.txt");
35 m_file.copy(target, Flags.NONE.getValue());
36 checkCopied(target, DEFAULT_CONTENT);
37 }
38
39 @Test(expected = AlreadyExistsException.class)
40 public void test_copy_nooverwrite() throws Exception {
41 URL target = createURL(m_subDirUrl2, DEFAULT_FILENAME_2);
42 m_file.copy(target, Flags.NONE.getValue());
43 }
44
45 @Test
46 public void test_copy_overwrite() throws Exception {
47 URL target = createURL(m_subDirUrl2, DEFAULT_FILENAME_2);
48 m_file.copy(target, Flags.OVERWRITE.getValue());
49 checkCopied(target, DEFAULT_CONTENT);
50 }
51
52 @Test
53 public void test_copy_lateExistenceCheck() throws Exception {
54 NSEntry entry = null;
55 try {
56 entry = NSFactory.createNSEntry(m_session, createURL(m_subDirUrl, "unexisting.txt"), FLAGS_BYPASSEXIST);
57 } catch(DoesNotExistException e) {
58 fail("Unexpected exception: "+ DoesNotExistException.class);
59 }
60 try {
61 entry.copy(m_subDirUrl2, Flags.NONE.getValue());
62 fail("Expected exception: "+ IncorrectStateException.class);
63 } catch(IncorrectStateException e) {
64 } finally {
65 entry.close();
66 }
67 try {
68 NSFactory.createNSEntry(m_session, createURL(m_subDirUrl2, "unexisting.txt"), Flags.NONE.getValue());
69 fail("Expected exception: "+ DoesNotExistException.class);
70 } catch(DoesNotExistException e) {
71 }
72 }
73
74 @Test
75 public void test_copy_norecurse() throws Exception {
76 URL target = createURL(m_subDirUrl2, DEFAULT_SUBDIRNAME);
77 try {
78 m_subDir.copy(m_subDirUrl2, Flags.NONE.getValue());
79 fail("Expected exception: "+ BadParameterException.class);
80 } catch(BadParameterException e) {
81 }
82 try {
83 NSFactory.createNSDirectory(m_session, target, Flags.NONE.getValue());
84 fail("Expected exception: "+ DoesNotExistException.class);
85 } catch(DoesNotExistException e) {
86 }
87 }
88
89 @Test
90 public void test_copy_recurse() throws Exception {
91 URL target = createURL(m_dirUrl2, DEFAULT_DIRNAME+DEFAULT_SUBDIRNAME+DEFAULT_FILENAME);
92 m_dir.copy(m_dirUrl2, Flags.RECURSIVE.getValue());
93 checkCopied(target, DEFAULT_CONTENT);
94 }
95
96 @Test
97 public void test_copy_recurse_nooverwrite() throws Exception {
98 URL target = createURL(m_dirUrl2, DEFAULT_SUBDIRNAME +DEFAULT_FILENAME);
99 try {
100 m_subDir.copy(m_dirUrl2, Flags.RECURSIVE.getValue());
101 fail("Expected exception: "+ AlreadyExistsException.class);
102 } catch(AlreadyExistsException e) {
103 }
104 try {
105 NSFactory.createNSEntry(m_session, target, Flags.NONE.getValue());
106 fail("Expected exception: "+ DoesNotExistException.class);
107 } catch(DoesNotExistException e) {
108 }
109 }
110
111 @Test
112 public void test_copy_recurse_overwrite() throws Exception {
113 URL target = createURL(m_dirUrl2, DEFAULT_SUBDIRNAME +DEFAULT_FILENAME);
114 m_subDir.copy(m_dirUrl2, Flags.RECURSIVE.or(Flags.OVERWRITE));
115 checkCopied(target, DEFAULT_CONTENT);
116 }
117
118 }