View Javadoc

1   package org.ogf.saga.file;
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.namespace.Flags;
7   import org.ogf.saga.namespace.NSDirectory;
8   import org.ogf.saga.namespace.NSEntry;
9   import org.ogf.saga.namespace.abstracts.AbstractDirectory;
10  import org.ogf.saga.namespace.base.DirectoryBaseTest;
11  import org.ogf.saga.url.URL;
12  import org.ogf.saga.url.URLFactory;
13  
14  /* ***************************************************
15  * *** Centre de Calcul de l'IN2P3 - Lyon (France) ***
16  * ***             http://cc.in2p3.fr/             ***
17  * ***************************************************
18  * File:   DirectoryTest
19  * Author: lionel.Schwarz@in2p3.fr
20  * Date:   5 NOV 2013
21  * ***************************************************
22  * Description:                                      */
23  /**
24   *
25   */
26  public abstract class DirTest extends DirectoryBaseTest {
27      protected DirTest(String protocol) throws Exception {
28          super(protocol);
29      }
30  
31      @Test
32      public void test_open() throws Exception {
33          NSDirectory dir = m_subDir.openDir(URLFactory.createURL(".."), Flags.NONE.getValue());
34          assertTrue(
35                  dir instanceof Directory);
36          assertEquals(
37                  DEFAULT_DIRNAME,
38                  dir.getName().getPath()+"/");
39          NSEntry entry = m_subDir.open(URLFactory.createURL(DEFAULT_FILENAME), Flags.NONE.getValue());
40          assertTrue(
41                  entry instanceof File);
42          assertEquals(
43                  DEFAULT_FILENAME,
44                  entry.getName().getPath());
45      }
46  
47      // TODO move these tests to DirectoryBaseTest when logicaldir will support this
48      
49      @Test
50      public void test_getSizeUrl() throws Exception {
51          if (m_file instanceof File) {
52              assertEquals(
53                      DEFAULT_CONTENT.length(),
54                      ((Directory)m_subDir).getSize(m_fileUrl));
55          } else {
56              fail("Not an instance of class: File");
57          }
58      }
59  
60      @Test
61      public void test_getSizeRecursive() throws Exception {
62      	String new_content = "new_content";
63          if (m_file instanceof File) {
64          	// Write another file
65              URL file2Url = createURL(m_subDirUrl, "File2.txt");
66              NSEntry file = m_subDir.open(file2Url, FLAGS_FILE);
67              Buffer buffer = BufferFactory.createBuffer(new_content.getBytes());
68              ((File)file).write(buffer);
69              file.close();
70              checkWrited(file2Url, new_content);
71              // check size of root directory: should be size of both files in subDir
72              // use SAGA compliant getSize(URL) instead of JSAGA getSize()
73              assertEquals(
74                      DEFAULT_CONTENT.length() + new_content.length(),
75                      ((Directory)m_dir).getSize(m_dirUrl));
76              // delete created file
77              file.remove();
78          } else {
79              fail("Not an instance of class: File");
80          }
81          
82      }
83  }