1   package org.weda.workflow;
2   
3   import java.util.ArrayList;
4   import java.util.List;
5   import tim.test.LogableTestCase;
6   
7   /**
8    *
9    * @author tim
10   */
11  public class AbstractEntryTest extends LogableTestCase {
12      
13      public AbstractEntryTest(String name) {
14          super(name);
15      }
16      
17      public void test_defaultEntry_config() throws Exception {
18          Entry entry = new TestAbstractEntry();
19          entry.setDefaultEntry(true);
20          entry.init();
21          assertTrue(entry.isDefaultEntry());
22          assertTrue(entry.isExactMatch());
23          assertTrue(entry.matches("testExpr"));
24          List<String> groupValues=entry.getGroupValues();
25          assertNotNull(groupValues);
26          assertEquals(1, groupValues.size());
27          assertEquals("testExpr", groupValues.get(0));
28      }
29      
30      public void test_exactMatch() throws Exception {
31          Entry entry = new TestAbstractEntry();
32          entry.setName("testName");
33          entry.init();
34          assertFalse(entry.isDefaultEntry());
35          assertTrue(entry.isExactMatch());
36          assertTrue(entry.matches("testName"));
37          List<String> groupValues=entry.getGroupValues();
38          assertNotNull(groupValues);
39          assertEquals(1, groupValues.size());
40          assertEquals("testName", groupValues.get(0));
41          assertFalse(entry.matches("testName1"));
42          groupValues=entry.getGroupValues();
43          assertNotNull(groupValues);
44          assertEquals(0, groupValues.size());
45      }
46      
47      public void test_regexpMatch() throws Exception {
48          final Entry entry = new TestAbstractEntry();
49          entry.setName("/(.*)Edit\\.html/");
50          entry.init();
51          assertFalse(entry.isDefaultEntry());
52          assertFalse(entry.isExactMatch());
53          assertTrue(entry.matches("CompanyEdit.html"));
54          //
55          final List<String> groupValues2 = new ArrayList<String>();
56          Thread thread = new Thread(){
57              public void run(){
58                  try{
59                      entry.matches("PersonEdit.html");
60                      log.debug("Size: "+entry.getGroupValues().size());
61                      groupValues2.addAll(entry.getGroupValues());
62                  }catch(Exception e){}
63              }
64          };
65          thread.start();
66          //while (thread.isAlive()) Thread.currentThread().sleep(100);
67          thread.join();
68          List<String> groupValues=entry.getGroupValues();
69          assertNotNull(groupValues);
70          assertEquals(2, groupValues.size());        
71          assertEquals("CompanyEdit.html", groupValues.get(0));
72          assertEquals("Company", groupValues.get(1));
73          assertNotNull(groupValues2);
74          assertEquals(2, groupValues2.size());
75          assertEquals("PersonEdit.html", groupValues2.get(0));
76          assertEquals("Person", groupValues2.get(1));
77          assertFalse(entry.matches("CompanyList.html"));        
78      }
79  }