001: package org.uispec4j.xml;
002:
003: import junit.framework.AssertionFailedError;
004: import org.uispec4j.utils.AssertionFailureNotDetectedError;
005: import org.uispec4j.utils.UnitTestCase;
006:
007: public class EventLoggerTest extends UnitTestCase {
008: private EventLogger eventLogger = new EventLogger();
009:
010: public void testEventWithoutArgs() throws Exception {
011: eventLogger.log("evt");
012: eventLogger.assertEquals("<log>" + "<evt/>" + "</log>");
013: }
014:
015: public void testStandardCase() throws Exception {
016: eventLogger.log("evt1").add("key1", "value1").add("key2",
017: "value2");
018: eventLogger.log("evt2").add("key3", "value3").add("key4",
019: "value4");
020: eventLogger.assertEquals("<log>"
021: + "<evt1 key1='value1' key2='value2'/>"
022: + "<evt2 key3='value3' key4='value4'/>" + "</log>");
023: }
024:
025: public void testErrorCaseWithWrongValue() throws Exception {
026: eventLogger.log("evt1").add("key1", "value1").add("key2",
027: "value2");
028: eventLogger.log("evt2").add("key3", "value3").add("key4",
029: "value4");
030: checkError("<log>"
031: + "<evt1 key1='value1' key2='AnotherValueWhichIsNotReallyTheExpectedOne'/>"
032: + "<evt2 key3='value3' key4='value4'/>" + "</log>");
033: }
034:
035: public void testErrorCaseWithAdditionalKey() throws Exception {
036: eventLogger.log("evt1").add("key1", "value1").add("key2",
037: "value2");
038: eventLogger.log("evt2").add("key3", "value3").add("key4",
039: "value4");
040: checkError("<log>"
041: + "<evt1 key1='value1' key2='value2' ThisIsAnUnexpectedKey='unexpectedValue'/>"
042: + "<evt2 key3='value3' key4='value4'/>" + "</log>");
043: }
044:
045: public void testErrorCaseWithMissingKey() throws Exception {
046: eventLogger.log("evt1").add("key1", "value1").add(
047: "ThisOneWillbeMissing", "value");
048: eventLogger.log("evt2").add("key3", "value3").add("key4",
049: "value4");
050: checkError("<log>" + "<evt1 key1='value1'/>"
051: + "<evt2 key3='value3' key4='value4'/>" + "</log>");
052: }
053:
054: public void testErrorCaseWithAdditionalEvent() throws Exception {
055: eventLogger.log("evt1").add("key1", "value1").add("key2",
056: "value2");
057: eventLogger.log("evt2").add("key3", "value3").add("key4",
058: "value4");
059: checkError("<log>" + "<evt1 key1='value1' key2='value2'/>"
060: + "<evt2 key3='value3' key4='value4'/>"
061: + "<AdditionalEvent key='value'/>" + "</log>");
062: }
063:
064: public void testErrorCaseWithMissingEvent() throws Exception {
065: eventLogger.log("evt1").add("key1", "value1").add("key2",
066: "value2");
067: eventLogger.log("ThisOneWillBeMissing").add("key3", "value3")
068: .add("key4", "value4");
069: checkError("<log>" + "<evt1 key1='value1' key2='value2'/>"
070: + "</log>");
071: }
072:
073: public void testOrderIsSignificant() throws Exception {
074: eventLogger.log("evt1");
075: eventLogger.log("evt2");
076: checkError("<log>" + " <evt2/>" + " <evt1/>" + "</log>");
077: }
078:
079: public void testListenerIsResetAfterEveryCheck() throws Exception {
080: eventLogger.log("evt1");
081: eventLogger.assertEquals("<log>" + "<evt1/>" + "</log>");
082: eventLogger.log("evt2");
083: eventLogger.assertEquals("<log>" + "<evt2/>" + "</log>");
084: }
085:
086: public void testEmptyExpectedString() throws Exception {
087: try {
088: eventLogger.assertEquals("");
089: throw new AssertionFailureNotDetectedError();
090: } catch (AssertionFailedError e) {
091: }
092: }
093:
094: public void testAssertEmpty() throws Exception {
095: eventLogger.assertEmpty();
096: }
097:
098: public void testAssertEmptyError() throws Exception {
099: eventLogger.log("UnexpectedEvent");
100: try {
101: eventLogger.assertEmpty();
102: throw new AssertionFailureNotDetectedError();
103: } catch (AssertionFailedError e) {
104: }
105: }
106:
107: public void testAssertWithXmlTestLogger() throws Exception {
108: eventLogger.log("evt1").add("key", "value");
109: EventLogger expected = new EventLogger();
110: expected.log("evt1").add("key", "value");
111: eventLogger.assertEquals(expected);
112: }
113:
114: public void testAssertXmlTestLoggerFailsWithXmlTestLoggerEmpty()
115: throws Exception {
116: eventLogger.log("evt1");
117:
118: EventLogger expected = new EventLogger();
119: try {
120: eventLogger.assertEquals(expected);
121: throw new AssertionFailureNotDetectedError();
122: } catch (AssertionFailedError e) {
123: }
124: }
125:
126: public void testAssertXmlTestLoggerFailsXmlTestLoggerNotEmpty()
127: throws Exception {
128: eventLogger.log("evt1");
129:
130: EventLogger expected = new EventLogger();
131: expected.log("evt1");
132: expected.log("evt2");
133: try {
134: eventLogger.assertEquals(expected);
135: throw new AssertionFailureNotDetectedError();
136: } catch (AssertionFailedError e) {
137: }
138: }
139:
140: public void testAssertEquivalent() throws Exception {
141: eventLogger.log("evt1");
142: eventLogger.log("evt2");
143: eventLogger.log("evt3");
144: eventLogger.assertEquivalent("<log>" + " <evt3/>"
145: + " <evt1/>" + " <evt2/>" + "</log>");
146:
147: try {
148: eventLogger.assertEquivalent("<log>" + " <evt1/>"
149: + "</log>");
150: throw new AssertionFailureNotDetectedError();
151: } catch (AssertionFailedError e) {
152: }
153: }
154:
155: private void checkError(String s) throws Exception {
156: try {
157: eventLogger.assertEquals(s);
158: throw new AssertionFailureNotDetectedError();
159: } catch (AssertionFailedError e) {
160: }
161: }
162: }
|