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