View Javadoc

1   package org.ogf.saga.logicalfile;
2   
3   import org.junit.After;
4   import org.junit.Before;
5   import org.junit.Test;
6   import org.ogf.saga.namespace.Flags;
7   import org.ogf.saga.namespace.abstracts.AbstractDirectory;
8   import org.ogf.saga.namespace.base.DirectoryBaseTest;
9   import org.ogf.saga.url.URL;
10  
11  import java.util.List;
12  
13  /* ***************************************************
14  * *** Centre de Calcul de l'IN2P3 - Lyon (France) ***
15  * ***             http://cc.in2p3.fr/             ***
16  * ***************************************************
17  * File:   LogicalDirectoryMetaDataTest
18  * Author: Sylvain Reynaud (sreynaud@in2p3.fr)
19  * Author: lionel.schwarz@in2p3.fr
20  * Date:   5 NOV 2013
21  * ***************************************************
22  * Description:                                      */
23  /**
24   *
25   */
26  public abstract class LogicalDirMetaDataTest extends DirectoryBaseTest {
27      private static final String METADATA_KEY = "myKey";
28      private static final String METADATA_VALUE = "myValue";
29      private static final String[] METADATA_FILTER = new String[]{METADATA_KEY+"="+METADATA_VALUE};
30      private static final String[] METADATA_FILTER2 = new String[]{METADATA_KEY+"2"+"="+METADATA_VALUE+"2"};
31      private LogicalDirectory m_dir;
32      private LogicalDirectory m_subDir;
33      private LogicalFile m_file;
34  
35      protected LogicalDirMetaDataTest(String protocol) throws Exception {
36          super(protocol);
37      }
38  
39      @Before
40      public void setUp() throws Exception {
41          super.setUp();
42          if (super.m_dir instanceof LogicalDirectory) {
43              m_dir = (LogicalDirectory) super.m_dir;
44          }
45          if (super.m_subDir instanceof LogicalDirectory) {
46              m_subDir = (LogicalDirectory) super.m_subDir;
47          }
48          if (super.m_file instanceof LogicalFile) {
49              m_file = (LogicalFile) super.m_file;
50          }
51          if (m_dir==null || m_subDir==null || m_file==null) {
52              fail("Not a protocol for logical files");
53          }
54          m_subDir.setAttribute(METADATA_KEY, METADATA_VALUE);
55          m_file.setAttribute(METADATA_KEY, METADATA_VALUE);
56          m_file.setAttribute(METADATA_KEY+"2", METADATA_VALUE+"2");
57      }
58  
59      @After
60      public void tearDown() throws Exception {
61          m_file = null;
62          m_subDir = null;
63          m_dir = null;
64          super.tearDown();
65      }
66  
67      @Test
68      public void test_listAttributes() throws Exception {
69          assertEquals(1, m_subDir.listAttributes().length);
70          assertEquals(2, m_file.listAttributes().length);
71      }
72  
73      @Test
74      public void test_getAttribute() throws Exception {
75          assertEquals(METADATA_VALUE, m_subDir.getAttribute(METADATA_KEY));
76          assertEquals(METADATA_VALUE, m_file.getAttribute(METADATA_KEY));
77          assertEquals(METADATA_VALUE+"2", m_file.getAttribute(METADATA_KEY+"2"));
78      }
79  
80      @Test
81      public void test_find() throws Exception {
82          List<URL> list = m_subDir.find(null, METADATA_FILTER);
83          assertEquals(1, list.size());
84          assertEquals(DEFAULT_FILENAME, list.get(0).toString());
85      }
86  
87      @Test
88      public void test_find_norecurse() throws Exception {
89          List<URL> list = m_dir.find(null, METADATA_FILTER, Flags.NONE.getValue());
90          assertEquals(1, list.size());
91          assertEquals(DEFAULT_SUBDIRNAME, list.get(0).toString());
92  
93          list = m_dir.find(null, METADATA_FILTER2, Flags.NONE.getValue());
94          assertEquals(0, list.size());
95  
96          list = m_dir.find(DEFAULT_FILENAME, METADATA_FILTER, Flags.NONE.getValue());
97          assertEquals(0, list.size());
98      }
99  
100     @Test
101     public void test_find_recurse() throws Exception {
102         List<URL> list = m_dir.find(null, METADATA_FILTER2, Flags.RECURSIVE.getValue());
103         assertEquals(1, list.size());
104         assertEquals(DEFAULT_SUBDIRNAME+DEFAULT_FILENAME, list.get(0).toString());
105 
106         list = m_dir.find(null, METADATA_FILTER, Flags.RECURSIVE.getValue());
107         assertEquals(2, list.size());
108 
109         list = m_dir.find(DEFAULT_FILENAME, METADATA_FILTER, Flags.RECURSIVE.getValue());
110         assertEquals(1, list.size());
111 
112         String[] filter = new String[]{METADATA_KEY+"="+METADATA_VALUE, METADATA_KEY+"2"+"="+METADATA_VALUE+"2"};
113         list = m_dir.find(null, filter, Flags.RECURSIVE.getValue());
114         assertEquals(1, list.size());
115         assertEquals(DEFAULT_SUBDIRNAME+DEFAULT_FILENAME, list.get(0).toString());
116     }
117 }