1 package org.ogf.saga.file;
2
3 import java.io.BufferedReader;
4 import java.io.ByteArrayOutputStream;
5 import java.io.InputStreamReader;
6
7 import org.junit.Ignore;
8 import org.junit.Test;
9 import org.ogf.saga.buffer.Buffer;
10 import org.ogf.saga.buffer.BufferFactory;
11 import org.ogf.saga.namespace.Flags;
12 import org.ogf.saga.namespace.NSFactory;
13 import org.ogf.saga.namespace.base.ReadBaseTest;
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 public abstract class ReadTest extends ReadBaseTest {
29 protected ReadTest(String protocol) throws Exception {
30 super(protocol);
31 }
32
33 @Test
34 public void test_getSize() throws Exception {
35 if (m_file instanceof File) {
36 assertEquals(
37 DEFAULT_CONTENT.length(),
38 ((File)m_file).getSize());
39 } else {
40 fail("Not an instance of class: File");
41 }
42 }
43
44 @Test
45 public void test_read_applicationManagedBuffer() throws Exception {
46 if (m_file instanceof File) {
47 Buffer buffer = BufferFactory.createBuffer(new byte[1024]);
48 File reader = (File) NSFactory.createNSEntry(m_session, m_fileUrl, Flags.READ.getValue());
49 reader.read(buffer);
50 byte[] bytes = new byte[DEFAULT_CONTENT.length()];
51 System.arraycopy(buffer.getData(), 0, bytes, 0, DEFAULT_CONTENT.length());
52 assertEquals(
53 DEFAULT_CONTENT,
54 new String(bytes));
55 reader.close();
56 } else {
57 fail("Not an instance of class: File");
58 }
59 }
60
61 @Test
62 public void test_read() throws Exception {
63 if (m_file instanceof File) {
64 checkWrited(m_fileUrl, DEFAULT_CONTENT);
65 } else {
66 fail("Not an instance of class: File");
67 }
68 }
69
70 @Test
71 public void test_inputStream() throws Exception {
72 FileInputStream fis = FileFactory.createFileInputStream(m_session, m_fileUrl);
73 ByteArrayOutputStream baos = new ByteArrayOutputStream();
74 int read;
75 while ((read=fis.read()) != -1) {
76 baos.write(read);
77 }
78 fis.close();
79 assertEquals(
80 DEFAULT_CONTENT,
81 baos.toString());
82 baos.close();
83 }
84
85 @Test
86 @Ignore
87 public void test_seek() throws Exception {
88
89 }
90 }