View Javadoc
1   package org.melati.admin.test;
2   
3   
4   import org.melati.Melati;
5   import org.melati.MelatiConfig;
6   import org.melati.PoemContext;
7   import org.melati.admin.AdminUtils;
8   import org.melati.poem.test.PoemTestCase;
9   import org.melati.servlet.test.MockHttpServletRequest;
10  import org.melati.servlet.test.MockHttpServletResponse;
11  import org.melati.template.TemplateContext;
12  import org.melati.template.TemplateEngine;
13  
14  
15  /**
16   * @author timp
17   * @since 2006-03-11
18   */
19  public class AdminUtilsTest extends PoemTestCase {
20    protected static MelatiConfig mc = null;
21    protected static TemplateEngine templateEngine = null;
22    protected static Melati m = null;
23    protected AdminUtils au;
24  
25    /**
26     * Constructor for AdminUtilsTest.
27     * @param name
28     */
29    public AdminUtilsTest(String name) {
30      super(name);
31    }
32  
33    protected void setUp()
34        throws Exception {
35      super.setUp();
36      mc = new MelatiConfig();
37      templateEngine = mc.getTemplateEngine();
38      if (templateEngine != null)
39        templateEngine.init(mc);
40      else fail();
41      MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest(); 
42      mockHttpServletRequest.setPathInfo("melatitest/user/Selection");
43      mockHttpServletRequest.setRequestURI("melatitest/user/Selection");
44      System.err.println(mockHttpServletRequest.getRequestURI());
45      MockHttpServletResponse mockServletResponse = new MockHttpServletResponse();
46      m = new Melati(mc, mockHttpServletRequest, mockServletResponse);
47      m.setTemplateEngine(templateEngine);
48      assertNotNull(m.getTemplateEngine());
49      TemplateContext templateContext =
50        templateEngine.getTemplateContext();
51      m.setTemplateContext(templateContext);
52      PoemContext pc = new PoemContext();
53      pc.setLogicalDatabase("melatijunit");
54      pc.setTable("user");
55      pc.setTroid(new Integer(1));
56      pc.setMethod("Selection");
57      m.setPoemContext(pc);
58      au = new AdminUtils(m);
59    }
60  
61    protected void tearDown()
62        throws Exception {
63      super.tearDown();
64    }
65  
66    /**
67     * @see org.melati.admin.AdminUtils#
68     *          specialFacilities(Melati, MarkupLanguage, Persistent)
69     */
70    public void testSpecialFacilities() throws Exception {
71      m.loadTableAndObject();
72      assertEquals("", 
73          au.specialFacilities(m, m.getMarkupLanguage(), m.getObject()));
74    }
75    
76    /**
77     * @see org.melati.admin.AdminUtils#ToggledOrderSelectionURL(Melati, String, String)
78     */
79    public void testToggledOrderSelectionURL() throws Exception { 
80      m.loadTableAndObject();
81      
82      assertEquals("melatitest/user/Selection?field_order-1=23&field_order-1-toggle=true", 
83          au.getToggledOrderSelectionURL(m, "field_order-1", "23"));    
84    }
85  
86    /**
87     * @see org.melati.admin.AdminUtils#getStaticURL()
88     */
89    public void testGetStaticURL() {
90      assertEquals("/melati-static/admin/static", au.getStaticURL());
91    }
92  
93    /**
94     * @see org.melati.admin.AdminUtils#createTree(Treeable)
95     */
96    public void testCreateTree() {
97    }
98  
99    /**
100    * Test simpleName.
101    */
102   public void testSimpleName() { 
103     assertEquals("admin", AdminUtils.simpleName("org.melati.admin"));    
104     assertEquals("admin", AdminUtils.simpleName(".admin"));    
105     assertEquals("", AdminUtils.simpleName("admin."));    
106     assertEquals("admin", AdminUtils.simpleName("admin"));    
107   }
108   
109   public void testCsvEscaped() { 
110     assertEquals("Double quotes (\"\") are used to escape double quotes in CSV format", 
111         AdminUtils.csvEscaped("Double quotes (\") are used to escape double quotes in CSV format"));
112   }
113   
114 }