1 package org.ogf.saga.namespace.abstracts;
2
3 import org.junit.After;
4 import org.junit.Before;
5 import org.ogf.saga.buffer.Buffer;
6 import org.ogf.saga.buffer.BufferFactory;
7 import org.ogf.saga.file.File;
8 import org.ogf.saga.logicalfile.LogicalFile;
9 import org.ogf.saga.namespace.*;
10 import org.ogf.saga.session.SessionFactory;
11 import org.ogf.saga.url.URL;
12 import org.ogf.saga.url.URLFactory;
13
14 import java.util.List;
15
16
17
18
19
20
21
22
23
24
25
26
27
28 public abstract class AbstractDataMovement extends AbstractDirectory {
29 protected static final int FLAGS_BYPASSEXIST = 4096;
30
31
32 protected static final String DEFAULT_DIRNAME_2 = "dir2/";
33 protected static final String DEFAULT_FILENAME_2 = "file2.txt";
34 protected static final String DEFAULT_CONTENT_2 = "Content of file 2 on base2.url...\n";
35
36
37 protected URL m_dirUrl2;
38 protected URL m_subDirUrl2;
39 protected URL m_fileUrl2;
40
41
42 protected NSDirectory m_dir2;
43
44 public AbstractDataMovement(String protocol, String targetProtocol) throws Exception {
45 super(protocol);
46 URL baseUrl2;
47 if (protocol.equals(targetProtocol)) {
48 if (getOptionalProperty(protocol, CONFIG_BASE2_URL) != null) {
49 baseUrl2 = URLFactory.createURL(getOptionalProperty(protocol, CONFIG_BASE2_URL));
50 } else {
51 baseUrl2 = URLFactory.createURL(getRequiredProperty(protocol, CONFIG_BASE_URL));
52 }
53 } else {
54 baseUrl2 = URLFactory.createURL(getRequiredProperty(targetProtocol, CONFIG_BASE_URL));
55 }
56 m_dirUrl2 = createURL(baseUrl2, DEFAULT_DIRNAME_2);
57 m_subDirUrl2 = createURL(m_dirUrl2, DEFAULT_SUBDIRNAME);
58 m_fileUrl2 = createURL(m_subDirUrl2, DEFAULT_FILENAME_2);
59 if (m_session==null && baseUrl2.getFragment()!=null) {
60 m_session = SessionFactory.createSession(true);
61 }
62 if (m_physicalDirUrl ==null && getOptionalProperty(targetProtocol, CONFIG_PHYSICAL_PROTOCOL) != null) {
63 String physicalProtocol = getOptionalProperty(targetProtocol, CONFIG_PHYSICAL_PROTOCOL);
64 URL basePhysicalUrl = URLFactory.createURL(getRequiredProperty(physicalProtocol, CONFIG_BASE_URL));
65 m_physicalDirUrl = createURL(basePhysicalUrl, DEFAULT_DIRNAME);
66 m_physicalFileUrl = createURL(m_physicalDirUrl, DEFAULT_PHYSICAL);
67 m_physicalFileUrl2 = createURL(m_physicalDirUrl, DEFAULT_PHYSICAL2);
68 }
69 }
70
71 @Before
72 public void setUp() throws Exception {
73 super.setUp();
74 try {
75 if (m_physicalFileUrl2 != null) {
76
77 File physicalFile = (File) m_physicalDir.open(m_physicalFileUrl2, FLAGS_FILE);
78 Buffer buffer = BufferFactory.createBuffer(DEFAULT_CONTENT_2.getBytes());
79 physicalFile.write(buffer);
80 physicalFile.close();
81 }
82 if (m_dirUrl2 != null) {
83
84 m_dir2 = NSFactory.createNSDirectory(m_session, m_dirUrl2, FLAGS_DIR);
85 if (m_fileUrl2 != null) {
86 NSEntry file2 = m_dir2.open(m_fileUrl2, FLAGS_FILE);
87 if (file2 instanceof File) {
88 Buffer buffer = BufferFactory.createBuffer(DEFAULT_CONTENT_2.getBytes());
89 ((File)file2).write(buffer);
90 } else if (file2 instanceof LogicalFile) {
91 ((LogicalFile)file2).addLocation(m_physicalFileUrl2);
92 }
93 file2.close();
94 }
95 }
96 } catch(Exception e) {
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138