1 package com.atlassian.johnson.config;
2
3 import com.atlassian.johnson.event.EventLevel;
4 import com.atlassian.johnson.event.EventType;
5 import com.atlassian.johnson.test.SimpleApplicationEventCheck;
6 import com.atlassian.johnson.test.SimpleEventCheck;
7 import com.atlassian.johnson.test.SimpleRequestEventCheck;
8 import com.atlassian.johnson.test.SimpleSetupConfig;
9 import org.junit.Test;
10
11 import static org.junit.Assert.*;
12
13 public class XmlJohnsonConfigTest
14 {
15 @Test(expected = ConfigurationJohnsonException.class)
16 public void testBadEventCheck()
17 {
18 XmlJohnsonConfig.fromFile("test-johnson-config-badeventcheck.xml");
19 }
20
21 @Test(expected = ConfigurationJohnsonException.class)
22 public void testBadEventCheckId()
23 {
24 XmlJohnsonConfig.fromFile("test-johnson-config-badid.xml");
25 }
26
27 @Test(expected = ConfigurationJohnsonException.class)
28 public void testDuplicateEventCheckId()
29 {
30 XmlJohnsonConfig.fromFile("test-johnson-config-duplicateid.xml");
31 }
32
33 @Test
34 public void testFromFile()
35 {
36 XmlJohnsonConfig config = XmlJohnsonConfig.fromFile("test-johnson-config.xml");
37
38
39 assertEquals("bar", config.getParams().get("foo"));
40 assertEquals("bat", config.getParams().get("baz"));
41
42
43 assertTrue(config.getSetupConfig() instanceof SimpleSetupConfig);
44
45
46 assertEquals(3, config.getEventChecks().size());
47 assertTrue(config.getEventChecks().get(0) instanceof SimpleEventCheck);
48
49 assertEquals(1, config.getRequestEventChecks().size());
50 assertTrue(config.getEventChecks().get(1) instanceof SimpleRequestEventCheck);
51
52 assertEquals(1, config.getApplicationEventChecks().size());
53 assertTrue(config.getEventChecks().get(2) instanceof SimpleApplicationEventCheck);
54
55
56 assertTrue(config.getEventCheck(1) instanceof SimpleEventCheck);
57 assertTrue(config.getEventCheck(2) instanceof SimpleRequestEventCheck);
58 assertNull(config.getEventCheck(3));
59
60
61 assertEquals("/the/setup/path.jsp", config.getSetupPath());
62 assertEquals("/the/error/path.jsp", config.getErrorPath());
63
64
65 assertEquals(2, config.getIgnorePaths().size());
66 assertTrue(config.getIgnorePaths().contains("/ignore/path/1.jsp"));
67 assertTrue(config.getIgnorePaths().contains("/ignore/path/*.html"));
68
69
70 assertTrue(config.isIgnoredPath("/ignore/path/1.jsp"));
71 assertTrue(config.isIgnoredPath("/ignore/path/2.html"));
72 assertTrue(config.isIgnoredPath("/ignore/path/foo.html"));
73 assertFalse(config.isIgnoredPath("/ignore/path"));
74
75
76 EventLevel expectedError = new EventLevel("error", "Error");
77 assertEquals(expectedError, config.getEventLevel("error"));
78 EventLevel expectedWarning = new EventLevel("warning", "This is a warning buddy");
79 assertEquals(expectedWarning, config.getEventLevel("warning"));
80
81
82 EventType expectedDatabase = new EventType("database", "Database");
83 assertEquals(expectedDatabase, config.getEventType("database"));
84 EventType expectedUpgrade = new EventType("upgrade", "Upgrade");
85 assertEquals(expectedUpgrade, config.getEventType("upgrade"));
86 }
87 }