View Javadoc

1   package com.atlassian.johnson.config;
2   
3   import com.atlassian.johnson.event.EventLevel;
4   import com.atlassian.johnson.event.EventType;
5   import junit.framework.TestCase;
6   import mock.MockEventCheck;
7   import mock.MockSetupConfig;
8   import mock.MockApplicationEventCheck;
9   import mock.MockRequestEventCheck;
10  
11  public class TestJohnsonConfig extends TestCase
12  {
13      public void testGetInstance() throws ConfigurationException
14      {
15          JohnsonConfig config = new JohnsonConfig("test-johnson-config.xml");
16  
17          // parameters
18          assertEquals("bar", config.getParams().get("foo"));
19          assertEquals("bat", config.getParams().get("baz"));
20  
21          // setup config
22          assertTrue(config.getSetupConfig() instanceof MockSetupConfig);
23  
24          // event checks
25          assertEquals(3, config.getEventChecks().size());
26          assertTrue(config.getEventChecks().get(0) instanceof MockEventCheck);
27  
28          assertEquals(1, config.getRequestEventChecks().size());
29          assertTrue(config.getEventChecks().get(1) instanceof MockRequestEventCheck);
30  
31          assertEquals(1, config.getApplicationEventChecks().size());
32          assertTrue(config.getEventChecks().get(2) instanceof MockApplicationEventCheck);
33  
34  
35          assertTrue(config.getEventCheck(1) instanceof MockEventCheck);
36          assertTrue(config.getEventCheck(2) instanceof MockRequestEventCheck);
37          assertNull(config.getEventCheck(3));
38  
39          // setup and error paths
40          assertEquals("/the/setup/path.jsp", config.getSetupPath());
41          assertEquals("/the/error/path.jsp", config.getErrorPath());
42  
43          // ignore paths
44          assertEquals(2, config.getIgnorePaths().size());
45          assertTrue(config.getIgnorePaths().contains("/ignore/path/1.jsp"));
46          assertTrue(config.getIgnorePaths().contains("/ignore/path/*.html"));
47  
48          // some ignore mapping tests
49          assertTrue(config.isIgnoredPath("/ignore/path/1.jsp"));
50          assertTrue(config.isIgnoredPath("/ignore/path/2.html"));
51          assertTrue(config.isIgnoredPath("/ignore/path/foo.html"));
52          assertFalse(config.isIgnoredPath("/ignore/path"));
53  
54          // event levels
55          EventLevel expectedError = new EventLevel("error", "Error");
56          assertEquals(expectedError, config.getEventLevel("error"));
57          EventLevel expectedWarning = new EventLevel("warning", "This is a warning buddy");
58          assertEquals(expectedWarning, config.getEventLevel("warning"));
59  
60          // event types
61          EventType expectedDatabase = new EventType("database", "Database");
62          assertEquals(expectedDatabase, config.getEventType("database"));
63          EventType expectedUpgrade = new EventType("upgrade", "Upgrade");
64          assertEquals(expectedUpgrade, config.getEventType("upgrade"));
65      }
66  
67      public void testBadEventCheck()
68      {
69          try
70          {
71              new JohnsonConfig("test-johnson-config-badeventcheck.xml");
72              fail("Should have thrown a ConfigurationException.");
73          }
74          catch (ConfigurationException e)
75          {
76              assertTrue(e.getMessage().indexOf("Eventcheck java.lang.Object does not implement EventCheck interface.") != -1);
77          }
78      }
79  
80      public void testBadEventCheckId()
81      {
82          try
83          {
84              new JohnsonConfig("test-johnson-config-badid.xml");
85              fail("Should have thrown a ConfigurationException.");
86          }
87          catch (ConfigurationException e)
88          {
89              assertTrue(e.getMessage().indexOf("Eventcheck id must be an integer.") != -1);
90          }
91      }
92  
93      public void testDuplicateEventCheckId()
94      {
95          try
96          {
97              new JohnsonConfig("test-johnson-config-duplicateid.xml");
98              fail("Should have thrown a ConfigurationException.");
99          }
100         catch (ConfigurationException e)
101         {
102             assertTrue(e.getMessage().indexOf("Duplicate eventcheck id '" + 1 + "'.") != -1);
103         }
104     }
105 }