Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlyn Normington2010-04-20 14:38:13 +0000
committerGlyn Normington2010-04-20 14:38:13 +0000
commit1fe315346425dcdea73feebd431aba7ae2a75f61 (patch)
tree617c48f3ec41fb2cde58e215bc42bc2b3a5d8678 /org.eclipse.virgo.medic.test
downloadorg.eclipse.virgo.medic-1fe315346425dcdea73feebd431aba7ae2a75f61.tar.gz
org.eclipse.virgo.medic-1fe315346425dcdea73feebd431aba7ae2a75f61.tar.xz
org.eclipse.virgo.medic-1fe315346425dcdea73feebd431aba7ae2a75f61.zip
[bug 307650] initial check-in from dm Server Virgo medic 0a647883a0176f60d8572f51c7eff591b7e408b6
Diffstat (limited to 'org.eclipse.virgo.medic.test')
-rw-r--r--org.eclipse.virgo.medic.test/.classpath27
-rw-r--r--org.eclipse.virgo.medic.test/.project35
-rw-r--r--org.eclipse.virgo.medic.test/.settings/com.springsource.server.ide.bundlor.core.prefs5
-rw-r--r--org.eclipse.virgo.medic.test/.settings/org.eclipse.wst.common.project.facet.core.xml4
-rw-r--r--org.eclipse.virgo.medic.test/.springBeans13
-rw-r--r--org.eclipse.virgo.medic.test/build.xml8
-rw-r--r--org.eclipse.virgo.medic.test/ivy.xml24
-rw-r--r--org.eclipse.virgo.medic.test/src/main/java/org/eclipse/virgo/medic/test/eventlog/LoggedEvent.java105
-rw-r--r--org.eclipse.virgo.medic.test/src/main/java/org/eclipse/virgo/medic/test/eventlog/MockEventLogger.java164
-rw-r--r--org.eclipse.virgo.medic.test/src/main/resources/.gitignore0
-rw-r--r--org.eclipse.virgo.medic.test/src/test/java/org/eclipse/virgo/medic/test/eventlog/LoggedEventTests.java77
-rw-r--r--org.eclipse.virgo.medic.test/src/test/java/org/eclipse/virgo/medic/test/eventlog/MockEventLoggerTests.java168
-rw-r--r--org.eclipse.virgo.medic.test/src/test/resources/.gitignore0
-rw-r--r--org.eclipse.virgo.medic.test/template.mf10
14 files changed, 640 insertions, 0 deletions
diff --git a/org.eclipse.virgo.medic.test/.classpath b/org.eclipse.virgo.medic.test/.classpath
new file mode 100644
index 0000000..ed078d7
--- /dev/null
+++ b/org.eclipse.virgo.medic.test/.classpath
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src/main/java">
+ <attributes>
+ <attribute name="com.springsource.server.ide.jdt.core.test.classpathentry" value="false"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="src" path="src/main/resources">
+ <attributes>
+ <attribute name="com.springsource.server.ide.jdt.core.test.classpathentry" value="false"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="src" output="target/test-classes" path="src/test/java">
+ <attributes>
+ <attribute name="com.springsource.server.ide.jdt.core.test.classpathentry" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="src" output="target/test-classes" path="src/test/resources">
+ <attributes>
+ <attribute name="com.springsource.server.ide.jdt.core.test.classpathentry" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="var" path="MEDIC_IVY_CACHE/org.junit/com.springsource.org.junit/4.7.0/com.springsource.org.junit-4.7.0.jar" sourcepath="/MEDIC_IVY_CACHE/org.junit/com.springsource.org.junit/4.7.0/com.springsource.org.junit-sources-4.7.0.jar"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.virgo.medic"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
diff --git a/org.eclipse.virgo.medic.test/.project b/org.eclipse.virgo.medic.test/.project
new file mode 100644
index 0000000..723469b
--- /dev/null
+++ b/org.eclipse.virgo.medic.test/.project
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.virgo.medic.test</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.wst.common.project.facet.core.builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.springframework.ide.eclipse.core.springbuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.springsource.server.ide.bundlor.core.builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>com.springsource.server.ide.facet.core.bundlenature</nature>
+ <nature>org.springframework.ide.eclipse.core.springnature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
+ </natures>
+</projectDescription>
diff --git a/org.eclipse.virgo.medic.test/.settings/com.springsource.server.ide.bundlor.core.prefs b/org.eclipse.virgo.medic.test/.settings/com.springsource.server.ide.bundlor.core.prefs
new file mode 100644
index 0000000..03d978a
--- /dev/null
+++ b/org.eclipse.virgo.medic.test/.settings/com.springsource.server.ide.bundlor.core.prefs
@@ -0,0 +1,5 @@
+#Thu Nov 12 08:44:28 GMT 2009
+com.springsource.server.ide.bundlor.core.bundlor.generated.manifest.autoformatting=true
+com.springsource.server.ide.bundlor.core.byte.code.scanning=true
+com.springsource.server.ide.bundlor.core.template.properties.files=../build.versions
+eclipse.preferences.version=1
diff --git a/org.eclipse.virgo.medic.test/.settings/org.eclipse.wst.common.project.facet.core.xml b/org.eclipse.virgo.medic.test/.settings/org.eclipse.wst.common.project.facet.core.xml
new file mode 100644
index 0000000..801f856
--- /dev/null
+++ b/org.eclipse.virgo.medic.test/.settings/org.eclipse.wst.common.project.facet.core.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<faceted-project>
+ <installed facet="com.springsource.server.bundle" version="1.0"/>
+</faceted-project>
diff --git a/org.eclipse.virgo.medic.test/.springBeans b/org.eclipse.virgo.medic.test/.springBeans
new file mode 100644
index 0000000..5152991
--- /dev/null
+++ b/org.eclipse.virgo.medic.test/.springBeans
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beansProjectDescription>
+ <version>1</version>
+ <pluginVersion><![CDATA[2.2.5.M1]]></pluginVersion>
+ <configSuffixes>
+ <configSuffix><![CDATA[xml]]></configSuffix>
+ </configSuffixes>
+ <enableImports><![CDATA[false]]></enableImports>
+ <configs>
+ </configs>
+ <configSets>
+ </configSets>
+</beansProjectDescription>
diff --git a/org.eclipse.virgo.medic.test/build.xml b/org.eclipse.virgo.medic.test/build.xml
new file mode 100644
index 0000000..6cd0295
--- /dev/null
+++ b/org.eclipse.virgo.medic.test/build.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="org.eclipse.virgo.medic.test">
+
+ <property file="${basedir}/../build.properties"/>
+ <property file="${basedir}/../build.versions"/>
+ <import file="${basedir}/../virgo-build/standard/default.xml"/>
+
+</project>
diff --git a/org.eclipse.virgo.medic.test/ivy.xml b/org.eclipse.virgo.medic.test/ivy.xml
new file mode 100644
index 0000000..43762ad
--- /dev/null
+++ b/org.eclipse.virgo.medic.test/ivy.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?xml-stylesheet type="text/xsl" href="http://ivyrep.jayasoft.org/ivy-doc.xsl"?>
+<ivy-module
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="http://incubator.apache.org/ivy/schemas/ivy.xsd"
+ version="1.3">
+
+ <info organisation="org.eclipse.virgo.medic" module="${ant.project.name}"/>
+
+ <configurations>
+ <include file="${virgo.build.dir}/common/default-ivy-configurations.xml"/>
+ </configurations>
+
+ <publications>
+ <artifact name="${ant.project.name}"/>
+ <artifact name="${ant.project.name}-sources" type="src" ext="jar"/>
+ </publications>
+
+ <dependencies>
+ <dependency org="org.eclipse.virgo.medic" name="org.eclipse.virgo.medic" rev="latest.integration" conf="compile->compile"/>
+ <dependency org="org.junit" name="com.springsource.org.junit" rev="${org.junit}" conf="test->runtime"/>
+ </dependencies>
+
+</ivy-module>
diff --git a/org.eclipse.virgo.medic.test/src/main/java/org/eclipse/virgo/medic/test/eventlog/LoggedEvent.java b/org.eclipse.virgo.medic.test/src/main/java/org/eclipse/virgo/medic/test/eventlog/LoggedEvent.java
new file mode 100644
index 0000000..72db818
--- /dev/null
+++ b/org.eclipse.virgo.medic.test/src/main/java/org/eclipse/virgo/medic/test/eventlog/LoggedEvent.java
@@ -0,0 +1,105 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.medic.test.eventlog;
+
+import java.io.PrintStream;
+
+import org.eclipse.virgo.medic.eventlog.Level;
+
+
+public class LoggedEvent {
+
+ private final String code;
+
+ private final Level level;
+
+ private final Throwable throwable;
+
+ private final Object[] inserts;
+
+ LoggedEvent(String code, Level level, Object... inserts) {
+ this(code, level, null, inserts);
+ }
+
+ LoggedEvent(String code, Level level, Throwable throwable, Object... inserts) {
+ this.code = code;
+ this.level = level;
+ this.throwable = throwable;
+ this.inserts = inserts.clone();
+ }
+
+ /**
+ * Returns the code of the event that was logged.
+ *
+ * @return the logged event's code.
+ */
+ public String getCode() {
+ return this.code;
+ }
+
+ /**
+ * Returns the level of the event that was logged.
+ *
+ * @return the logged event's level
+ */
+ public Level getLevel() {
+ return this.level;
+ }
+
+ /**
+ * Returns the <code>Throwable</code> that was logged as part of the event, or <code>null</code> if no
+ * <code>Throwable</code> was logged
+ *
+ * @return The logged <code>Throwable</code>
+ */
+ public Throwable getThrowable() {
+ return throwable;
+ }
+
+ /**
+ * Returns the inserts that were logged, or an empty array if no inserts were logged.
+ *
+ * @return The logged inserts, never <code>null</code>.
+ */
+ public Object[] getInserts() {
+ return inserts.clone();
+ }
+
+ /**
+ * Print (to outStr) a human-readable form of the LoggedEvent, without fancy formatting.
+ *
+ * @param printStream where to print it
+ */
+ public void print(PrintStream printStream) {
+ printStream.print(String.format("Code: '%s' Level: '%s'", this.code, String.valueOf(this.level)));
+ printInserts(printStream);
+ if (this.throwable!=null) {
+ printStream.print(" Exception: ");
+ this.throwable.printStackTrace(printStream);
+ }
+ }
+
+ /**
+ * Print inserts.
+ *
+ * @param outStr where to print them
+ */
+ private void printInserts(PrintStream outStr) {
+ if (inserts.length != 0) {
+ outStr.print(String.format(" Inserts: {'%s'", String.valueOf(this.inserts[0])));
+ for (int ins = 1; ins < this.inserts.length; ++ins) {
+ outStr.print(String.format(", '%s'", String.valueOf(this.inserts[ins])));
+ }
+ outStr.print("}");
+ }
+ }
+}
diff --git a/org.eclipse.virgo.medic.test/src/main/java/org/eclipse/virgo/medic/test/eventlog/MockEventLogger.java b/org.eclipse.virgo.medic.test/src/main/java/org/eclipse/virgo/medic/test/eventlog/MockEventLogger.java
new file mode 100644
index 0000000..6f7903c
--- /dev/null
+++ b/org.eclipse.virgo.medic.test/src/main/java/org/eclipse/virgo/medic/test/eventlog/MockEventLogger.java
@@ -0,0 +1,164 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.medic.test.eventlog;
+
+import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.eclipse.virgo.medic.eventlog.EventLogger;
+import org.eclipse.virgo.medic.eventlog.Level;
+import org.eclipse.virgo.medic.eventlog.LogEvent;
+
+
+/**
+ * A mock implementation of {@link EventLogger} for testing purposes. The events that have been logged can be accessed
+ * by calling {@link #getLoggedEvents()}.<br/>
+ * This implementation saves all events for subsequent analysis, and has an option to clear the log for re-use.<br/>
+ * This version also has an operation for asserting that the sequence of events matches a supplied array. This is for
+ * convenient unit tests.
+ * <p/>
+ *
+ * <strong>Concurrent Semantics:</strong><br/>
+ * Thread-safe during logging, but not for retrieval and re-initialisation.
+ */
+public class MockEventLogger implements EventLogger {
+
+ private final List<LoggedEvent> loggedEvents = new CopyOnWriteArrayList<LoggedEvent>();
+
+ private final boolean noisy;
+
+ private volatile boolean called = false;
+
+ private final PrintStream printStream;
+
+ public MockEventLogger() {
+ this(false, null);
+ }
+
+ public MockEventLogger(boolean noisy, PrintStream printStream) {
+ this.noisy = noisy;
+ this.printStream = printStream;
+ }
+
+ public void log(LogEvent logEvent, Object... inserts) {
+ this.log(logEvent.getEventCode(), logEvent.getLevel(), inserts);
+ }
+
+ public void log(LogEvent logEvent, Throwable throwable, Object... inserts) {
+ this.log(logEvent.getEventCode(), logEvent.getLevel(), throwable, inserts);
+ }
+
+ public void log(String code, Level level, Object... inserts) {
+ LoggedEvent loggedEvent = new LoggedEvent(code, level, inserts);
+ this.loggedEvents.add(loggedEvent);
+ this.called = true;
+ if (noisy) {
+ loggedEvent.print(this.printStream);
+ }
+ }
+
+ public void log(String code, Level level, Throwable throwable, Object... inserts) {
+ LoggedEvent loggedEvent = new LoggedEvent(code, level, throwable, inserts);
+ this.loggedEvents.add(loggedEvent);
+ this.called = true;
+ if (noisy) {
+ loggedEvent.print(this.printStream);
+ }
+ }
+
+ /**
+ * Returns a <code>List</code> of the events that have been logged. The order of the items in the list corresponds
+ * to the order in which the events were logged. If no events have been logged an empty list is returned.
+ *
+ * @return the logged events
+ */
+ public List<LoggedEvent> getLoggedEvents() {
+ return this.loggedEvents;
+ }
+
+ /**
+ * @return true if this EventLogger has been called since (re)initialisation.
+ */
+ public boolean getCalled() {
+ return this.called;
+ }
+
+ /**
+ * Reinitialise this EventLogger.
+ */
+ public void reinitialise() {
+ this.called = false;
+ this.loggedEvents.clear();
+ }
+
+ /**
+ * Helper method for unit tests to check sequence of logged events after a test.
+ *
+ * @param codes sequence of message codes expected
+ * @return true iff sequence of codes matches logged events exactly
+ */
+ public boolean isLogged(String... codes) {
+ if (this.loggedEvents.size() != codes.length) {
+ return false;
+ }
+ int index = 0;
+ for (String code : codes) {
+ if (!code.equals(this.loggedEvents.get(index++).getCode())) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Helper method for unit tests to check superset of logged events after a test.
+ *
+ * @param codes sequence of message codes expected to be contained in logged events (in any order)
+ * @return true iff the codes are all in the saved {@link LoggedEvent}s.
+ */
+ public boolean containsLogged(String... codes) {
+ List<String> codeList = new ArrayList<String>();
+ for (LoggedEvent event : this.loggedEvents) {
+ codeList.add(event.getCode());
+ }
+ for (String code : codes) {
+ if (!codeList.contains(code)){
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Helper method for unit tests to retrieve specific logged events from saved events.
+ *
+ * @param codes sequence of message codes to have events extracted, in order.
+ * @return LoggedEvents with supplied codes in same sequence from log.
+ */
+ public List<LoggedEvent> getEventsWithCodes(String... codes) {
+ List<LoggedEvent> eventList = new ArrayList<LoggedEvent>();
+ int eventIndex = 0;
+ int loggedEventsSize = this.loggedEvents.size();
+ for (String code : codes) {
+ while (eventIndex < loggedEventsSize) {
+ LoggedEvent loggedEvent = this.loggedEvents.get(eventIndex++);
+ if (code.equals(loggedEvent.getCode())) {
+ eventList.add(loggedEvent);
+ break;
+ }
+ }
+ }
+ return eventList;
+ }
+}
diff --git a/org.eclipse.virgo.medic.test/src/main/resources/.gitignore b/org.eclipse.virgo.medic.test/src/main/resources/.gitignore
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/org.eclipse.virgo.medic.test/src/main/resources/.gitignore
diff --git a/org.eclipse.virgo.medic.test/src/test/java/org/eclipse/virgo/medic/test/eventlog/LoggedEventTests.java b/org.eclipse.virgo.medic.test/src/test/java/org/eclipse/virgo/medic/test/eventlog/LoggedEventTests.java
new file mode 100644
index 0000000..7ad8333
--- /dev/null
+++ b/org.eclipse.virgo.medic.test/src/test/java/org/eclipse/virgo/medic/test/eventlog/LoggedEventTests.java
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.medic.test.eventlog;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.io.StringWriter;
+import java.io.Writer;
+
+import org.eclipse.virgo.medic.eventlog.Level;
+import org.eclipse.virgo.medic.test.eventlog.LoggedEvent;
+import org.junit.Test;
+
+
+public class LoggedEventTests {
+
+ @Test
+ public void print() {
+ StringWriter printedWriter = new StringWriter();
+ PrintStream printStream = new PrintStream(new WriterOutputStream(printedWriter));
+
+ new LoggedEvent("code", Level.WARNING, "a", 5, true).print(printStream);
+
+ String printed = printedWriter.toString();
+ assertEquals("Code: 'code' Level: 'WARNING' Inserts: {'a', '5', 'true'}", printed);
+ }
+
+ @Test
+ public void printWithOneInsert() {
+ StringWriter printedWriter = new StringWriter();
+ PrintStream printStream = new PrintStream(new WriterOutputStream(printedWriter));
+
+ new LoggedEvent("code", Level.WARNING, 5).print(printStream);
+
+ String printed = printedWriter.toString();
+ System.out.println(printed);
+ assertEquals("Code: 'code' Level: 'WARNING' Inserts: {'5'}", printed);
+ }
+
+ @Test
+ public void printWithNoInserts() {
+ StringWriter printedWriter = new StringWriter();
+ PrintStream printStream = new PrintStream(new WriterOutputStream(printedWriter));
+
+ new LoggedEvent("code", Level.WARNING).print(printStream);
+
+ String printed = printedWriter.toString();
+ System.out.println(printed);
+ assertEquals("Code: 'code' Level: 'WARNING'", printed);
+ }
+
+ private static final class WriterOutputStream extends OutputStream {
+
+ private final Writer writer;
+
+ private WriterOutputStream(Writer writer) {
+ this.writer = writer;
+ }
+
+ @Override
+ public void write(int b) throws IOException {
+ writer.write(b);
+ }
+ }
+}
diff --git a/org.eclipse.virgo.medic.test/src/test/java/org/eclipse/virgo/medic/test/eventlog/MockEventLoggerTests.java b/org.eclipse.virgo.medic.test/src/test/java/org/eclipse/virgo/medic/test/eventlog/MockEventLoggerTests.java
new file mode 100644
index 0000000..933e5c0
--- /dev/null
+++ b/org.eclipse.virgo.medic.test/src/test/java/org/eclipse/virgo/medic/test/eventlog/MockEventLoggerTests.java
@@ -0,0 +1,168 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.medic.test.eventlog;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
+import org.eclipse.virgo.medic.eventlog.Level;
+import org.eclipse.virgo.medic.test.eventlog.LoggedEvent;
+import org.eclipse.virgo.medic.test.eventlog.MockEventLogger;
+import org.junit.Test;
+
+
+public class MockEventLoggerTests {
+
+ private final MockEventLogger eventLogger = new MockEventLogger();
+
+ @Test
+ public void emptyList() {
+ List<LoggedEvent> loggedEvents = this.eventLogger.getLoggedEvents();
+ assertNotNull(loggedEvents);
+ assertEquals(0, loggedEvents.size());
+ }
+
+ @Test
+ public void eventWithoutThrowableWithInserts() {
+ this.eventLogger.log("123", Level.INFO, "a", "b", true);
+
+ List<LoggedEvent> loggedEvents = this.eventLogger.getLoggedEvents();
+ assertNotNull(loggedEvents);
+ assertEquals(1, loggedEvents.size());
+
+ LoggedEvent loggedEvent = loggedEvents.get(0);
+ assertEquals("123", loggedEvent.getCode());
+ assertEquals(Level.INFO, loggedEvent.getLevel());
+ assertNull(loggedEvent.getThrowable());
+ assertArrayEquals(new Object[] { "a", "b", true }, loggedEvent.getInserts());
+ }
+
+ @Test
+ public void eventWithoutThrowableWithoutInserts() {
+ this.eventLogger.log("234", Level.ERROR);
+
+ List<LoggedEvent> loggedEvents = this.eventLogger.getLoggedEvents();
+ assertNotNull(loggedEvents);
+ assertEquals(1, loggedEvents.size());
+
+ LoggedEvent loggedEvent = loggedEvents.get(0);
+ assertEquals("234", loggedEvent.getCode());
+ assertEquals(Level.ERROR, loggedEvent.getLevel());
+ assertNull(loggedEvent.getThrowable());
+ assertNotNull(loggedEvent.getInserts());
+ assertEquals(0, loggedEvent.getInserts().length);
+ }
+
+ @Test
+ public void eventWithThrowableWithInserts() {
+ Throwable throwable = new Throwable();
+ this.eventLogger.log("345", Level.WARNING, throwable, "a", "b", true);
+
+ List<LoggedEvent> loggedEvents = this.eventLogger.getLoggedEvents();
+ assertNotNull(loggedEvents);
+ assertEquals(1, loggedEvents.size());
+
+ LoggedEvent loggedEvent = loggedEvents.get(0);
+ assertEquals("345", loggedEvent.getCode());
+ assertEquals(Level.WARNING, loggedEvent.getLevel());
+ assertEquals(throwable, loggedEvent.getThrowable());
+ assertArrayEquals(new Object[] { "a", "b", true }, loggedEvent.getInserts());
+ }
+
+ @Test
+ public void eventWithThrowableWithoutInserts() {
+ Throwable throwable = new Throwable();
+ this.eventLogger.log("456", Level.ERROR, throwable);
+
+ List<LoggedEvent> loggedEvents = this.eventLogger.getLoggedEvents();
+ assertNotNull(loggedEvents);
+ assertEquals(1, loggedEvents.size());
+
+ LoggedEvent loggedEvent = loggedEvents.get(0);
+ assertEquals("456", loggedEvent.getCode());
+ assertEquals(Level.ERROR, loggedEvent.getLevel());
+ assertEquals(throwable, loggedEvent.getThrowable());
+ assertNotNull(loggedEvent.getInserts());
+ assertEquals(0, loggedEvent.getInserts().length);
+ }
+
+ @Test
+ public void multipleEventsIncludingDuplicates() {
+ this.eventLogger.log("123", Level.INFO);
+ this.eventLogger.log("234", Level.INFO);
+ this.eventLogger.log("345", Level.INFO);
+ this.eventLogger.log("345", Level.INFO);
+ this.eventLogger.log("123", Level.INFO);
+
+ List<LoggedEvent> loggedEvents = this.eventLogger.getLoggedEvents();
+ assertNotNull(loggedEvents);
+ assertEquals(5, loggedEvents.size());
+ assertLoggedEventMatch(loggedEvents.get(0), "123", null, null);
+ assertLoggedEventMatch(loggedEvents.get(1), "234", null, null);
+ assertLoggedEventMatch(loggedEvents.get(2), "345", null, null);
+ assertLoggedEventMatch(loggedEvents.get(3), "345", null, null);
+ assertLoggedEventMatch(loggedEvents.get(4), "123", null, null);
+ assertTrue("Correct event code sequence not detected", this.eventLogger.isLogged("123", "234", "345", "345", "123"));
+ assertFalse("Incorrect event code sequence not detected", this.eventLogger.isLogged("123", "234", "345", "123"));
+ assertFalse("Incorrect event code sequence not detected", this.eventLogger.isLogged("123", "234", "345", "123", "123"));
+ }
+
+ @Test
+ public void retrieveEventSequenceWithCodes() {
+ this.eventLogger.log("123", Level.INFO, new Integer(1));
+ this.eventLogger.log("234", Level.INFO, new Integer(2));
+ this.eventLogger.log("345", Level.INFO, new Integer(3));
+ this.eventLogger.log("345", Level.INFO, new Integer(4));
+ this.eventLogger.log("123", Level.INFO, new Integer(5));
+
+ List<LoggedEvent> loggedEvents = this.eventLogger.getEventsWithCodes("345", "123", "345", "xyz");
+ assertNotNull(loggedEvents);
+ assertEquals(2, loggedEvents.size());
+ assertLoggedEventMatch(loggedEvents.get(0), "345", Level.INFO, null, 3);
+ assertLoggedEventMatch(loggedEvents.get(1), "123", Level.INFO, null, 5);
+ }
+
+ @Test
+ public void containsEventCodeSequence() {
+ this.eventLogger.log("123", Level.INFO);
+ this.eventLogger.log("234", Level.INFO);
+ this.eventLogger.log("345", Level.INFO);
+ this.eventLogger.log("345", Level.INFO);
+ this.eventLogger.log("123", Level.INFO);
+
+ assertTrue("Failed to detect codes 234, 123, 345", this.eventLogger.containsLogged("234","123","345"));
+ assertFalse("Erroneously detected all codes 123, xyz, 234", this.eventLogger.containsLogged("123", "xyz", "234"));
+ this.eventLogger.reinitialise();
+ assertFalse("Detected code 123 after reinitialisation", this.eventLogger.containsLogged("123"));
+ assertTrue("eventLogger not empty after reinitialisation", this.eventLogger.getLoggedEvents().isEmpty());
+ }
+
+ private static void assertLoggedEventMatch(LoggedEvent loggedEvent, String code, Level level, Throwable throwable, Object... inserts) {
+ assertNotNull(loggedEvent);
+ assertEquals("LoggedEvent code", code, loggedEvent.getCode());
+ if (level != null) {
+ assertEquals("LoggedEvent level in " + code, level, loggedEvent.getLevel());
+ }
+ assertEquals("LoggedEvent throwable in " + code, throwable, loggedEvent.getThrowable());
+ assertEquals("Number of inserts in " + code, inserts.length, loggedEvent.getInserts().length);
+ int index = 0;
+ for (Object insert : inserts) {
+ assertEquals("LoggedEvent insert in " + code, insert, loggedEvent.getInserts()[index++]);
+ }
+ }
+}
diff --git a/org.eclipse.virgo.medic.test/src/test/resources/.gitignore b/org.eclipse.virgo.medic.test/src/test/resources/.gitignore
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/org.eclipse.virgo.medic.test/src/test/resources/.gitignore
diff --git a/org.eclipse.virgo.medic.test/template.mf b/org.eclipse.virgo.medic.test/template.mf
new file mode 100644
index 0000000..fb6042a
--- /dev/null
+++ b/org.eclipse.virgo.medic.test/template.mf
@@ -0,0 +1,10 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-SymbolicName: org.eclipse.virgo.medic.eventlog.test
+Bundle-Name: Medic Event Log Test Bundle
+Bundle-Vendor: SpringSource Inc.
+Bundle-Version: 1.0.0
+Import-Template:
+ org.eclipse.virgo.medic.*;version="0"
+Excluded-Imports:
+ org.junit.*

Back to the top