1 package org.ogf.saga.logicalfile;
2
3 import org.junit.Test;
4 import org.ogf.saga.buffer.Buffer;
5 import org.ogf.saga.buffer.BufferFactory;
6 import org.ogf.saga.error.DoesNotExistException;
7 import org.ogf.saga.file.File;
8 import org.ogf.saga.namespace.Flags;
9 import org.ogf.saga.namespace.base.WriteBaseTest;
10
11
12
13
14
15
16
17
18
19
20
21
22
23 public abstract class LogicalWriteTest extends WriteBaseTest {
24 protected LogicalWriteTest(String protocol) throws Exception {
25 super(protocol);
26 }
27
28 @Test
29 public void test_addLocation() throws Exception {
30 if (m_file instanceof LogicalFile) {
31
32 ((LogicalFile)m_file).addLocation(m_physicalFileUrl);
33 assertEquals(
34 1,
35 ((LogicalFile)m_file).listLocations().size());
36
37
38
39 if(m_physicalFileUrl2 != null && !new java.io.File(m_physicalFileUrl2.getString()).exists()){
40 File physicalFile = (File) m_physicalDir.open(m_physicalFileUrl2, FLAGS_FILE);
41 Buffer buffer = BufferFactory.createBuffer(DEFAULT_CONTENT2.getBytes());
42 physicalFile.write(buffer);
43 physicalFile.close();
44 }
45
46
47 ((LogicalFile)m_file).addLocation(m_physicalFileUrl2);
48 assertEquals(
49 2,
50 ((LogicalFile)m_file).listLocations().size());
51 } else {
52 fail("Not an instance of class: LogicalFile");
53 }
54 }
55
56 @Test
57 public void test_removeLocation() throws Exception {
58 if (m_file instanceof LogicalFile) {
59
60 try {
61 ((LogicalFile)m_file).removeLocation(m_physicalFileUrl2);
62 fail("Expected exception: "+ DoesNotExistException.class);
63 } catch(DoesNotExistException e) {
64 assertEquals(
65 1,
66 ((LogicalFile)m_file).listLocations().size());
67 }
68
69
70 ((LogicalFile)m_file).removeLocation(m_physicalFileUrl);
71 assertEquals(
72 0,
73 ((LogicalFile)m_file).listLocations().size());
74 } else {
75 fail("Not an instance of class: LogicalFile");
76 }
77 }
78
79 @Test
80 public void test_updateLocation() throws Exception {
81 if (m_file instanceof LogicalFile) {
82
83 if(m_physicalFileUrl2 != null && !new java.io.File(m_physicalFileUrl2.getString()).exists()){
84 File physicalFile = (File) m_physicalDir.open(m_physicalFileUrl2, FLAGS_FILE);
85 Buffer buffer = BufferFactory.createBuffer(DEFAULT_CONTENT2.getBytes());
86 physicalFile.write(buffer);
87 physicalFile.close();
88 }
89
90 ((LogicalFile)m_file).updateLocation(m_physicalFileUrl, m_physicalFileUrl2);
91 assertEquals(
92 1,
93 ((LogicalFile)m_file).listLocations().size());
94 assertEquals(
95 m_physicalFileUrl2.toString(),
96 ((LogicalFile)m_file).listLocations().get(0).toString());
97 } else {
98 fail("Not an instance of class: LogicalFile");
99 }
100 }
101
102 @Test
103 public void test_replicate() throws Exception {
104 if (m_file instanceof LogicalFile) {
105
106 ((LogicalFile)m_file).replicate(m_physicalFileUrl2, Flags.NONE.getValue());
107 assertEquals(
108 2,
109 ((LogicalFile)m_file).listLocations().size());
110
111
112 checkWrited(m_physicalFileUrl2, DEFAULT_CONTENT);
113 } else {
114 fail("Not an instance of class: LogicalFile");
115 }
116 }
117 }