Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Frost2011-06-14 08:33:48 -0400
committerChristopher Frost2011-06-14 08:33:48 -0400
commit3b7bfa9c8eeccdf56156af34983498316f65b500 (patch)
treefc3714791ac302977ba28c604a9714328250f6e4
parentd8da9d1f6d82488cb6af9be2ebdde909f9749477 (diff)
downloadorg.eclipse.virgo.medic-3b7bfa9c8eeccdf56156af34983498316f65b500.tar.gz
org.eclipse.virgo.medic-3b7bfa9c8eeccdf56156af34983498316f65b500.tar.xz
org.eclipse.virgo.medic-3b7bfa9c8eeccdf56156af34983498316f65b500.zip
Fixing the way the LogService recieves log messages from Equinox
-rw-r--r--org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/impl/MedicActivator.java11
-rw-r--r--org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/log/osgi/OSGiLogServiceListener.java (renamed from org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/log/osgi/OSGiLogServiceImpl.java)58
-rw-r--r--org.eclipse.virgo.medic.core/src/test/java/org/eclipse/virgo/medic/impl/MedicActivatorTests.java9
-rw-r--r--org.eclipse.virgo.medic.core/src/test/java/org/eclipse/virgo/medic/log/osgi/OSGiLogServiceImplTests.java284
-rw-r--r--org.eclipse.virgo.medic.core/src/test/java/org/eclipse/virgo/medic/log/osgi/OSGiLogServiceListenerTests.java308
5 files changed, 349 insertions, 321 deletions
diff --git a/org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/impl/MedicActivator.java b/org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/impl/MedicActivator.java
index acba2fb..75f7023 100644
--- a/org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/impl/MedicActivator.java
+++ b/org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/impl/MedicActivator.java
@@ -21,7 +21,9 @@ import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleListener;
import org.osgi.framework.ServiceFactory;
+import org.osgi.framework.ServiceReference;
import org.osgi.service.cm.ConfigurationListener;
+import org.osgi.service.log.LogReaderService;
import org.osgi.service.log.LogService;
import org.slf4j.LoggerFactory;
@@ -58,7 +60,7 @@ import org.eclipse.virgo.medic.log.impl.logback.DelegatingContextSelector;
import org.eclipse.virgo.medic.log.impl.logback.JoranLoggerContextConfigurer;
import org.eclipse.virgo.medic.log.impl.logback.LoggerContextConfigurer;
import org.eclipse.virgo.medic.log.impl.logback.StandardContextSelectorDelegate;
-import org.eclipse.virgo.medic.log.osgi.OSGiLogServiceImpl;
+import org.eclipse.virgo.medic.log.osgi.OSGiLogServiceListener;
import org.eclipse.virgo.util.osgi.ServiceRegistrationTracker;
public final class MedicActivator implements BundleActivator {
@@ -104,11 +106,14 @@ public final class MedicActivator implements BundleActivator {
logStart(context, configurationProvider);
eventLogStart(context);
dumpStart(context, configurationProvider);
- this.registrationTracker.track(context.registerService(LogService.class.getName(), new OSGiLogServiceImpl(LoggerFactory.getLogger(LogService.class)), null));
+
+ ServiceReference<LogReaderService> logReaderReference = context.getServiceReference(LogReaderService.class);
+ LogReaderService logReader = context.getService(logReaderReference);
+ logReader.addLogListener(new OSGiLogServiceListener(LoggerFactory.getLogger(LogService.class)));
+ context.ungetService(logReaderReference);
}
public void stop(BundleContext context) throws Exception {
-
this.registrationTracker.unregisterAll();
dumpStop();
diff --git a/org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/log/osgi/OSGiLogServiceImpl.java b/org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/log/osgi/OSGiLogServiceListener.java
index abb6d97..f3e43da 100644
--- a/org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/log/osgi/OSGiLogServiceImpl.java
+++ b/org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/log/osgi/OSGiLogServiceListener.java
@@ -13,7 +13,8 @@
package org.eclipse.virgo.medic.log.osgi;
-import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogEntry;
+import org.osgi.service.log.LogListener;
import org.osgi.service.log.LogService;
import org.slf4j.Logger;
@@ -25,19 +26,38 @@ import org.slf4j.Logger;
* <strong>Concurrent Semantics</strong><br />
* TODO Document concurrent semantics of EquinoxLogServiceImpl
*/
-public class OSGiLogServiceImpl implements LogService {
+public class OSGiLogServiceListener implements LogListener {
private final Logger logger;
- public OSGiLogServiceImpl(Logger logger) {
+ public OSGiLogServiceListener(Logger logger) {
this.logger = logger;
}
-
+
/**
* {@inheritDoc}
*/
- @Override
- public void log(int level, String message) {
+ @Override
+ public void logged(LogEntry entry) {
+ if(entry.getException() == null){
+ this.log(entry.getLevel(), formatMessage(entry));
+ } else {
+ this.log(entry.getLevel(), formatMessage(entry), entry.getException());
+ }
+ }
+
+ private String formatMessage(LogEntry entry){
+ String message = entry.getMessage();
+ if(entry.getServiceReference() != null){
+ message = String.format("{Service %s}: %s", entry.getServiceReference().getProperty("service.id").toString(), message);
+ }
+ if(entry.getBundle() != null){
+ message = String.format("{Bundle %s-%s}: %s", entry.getBundle().getSymbolicName(), entry.getBundle().getVersion().toString(), message);
+ }
+ return message;
+ }
+
+ private void log(int level, String message) {
switch (level) {
case LogService.LOG_DEBUG :
this.logger.debug(message);
@@ -57,11 +77,7 @@ public class OSGiLogServiceImpl implements LogService {
}
}
- /**
- * {@inheritDoc}
- */
- @Override
- public void log(int level, String message, Throwable exception) {
+ private void log(int level, String message, Throwable exception) {
switch (level) {
case LogService.LOG_DEBUG :
this.logger.debug(message, exception);
@@ -80,25 +96,5 @@ public class OSGiLogServiceImpl implements LogService {
break;
}
}
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void log(ServiceReference sr, int level, String message) {
- this.log(level, String.format("{Service %s}: %s", getServiceDescription(sr), message));
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void log(ServiceReference sr, int level, String message, Throwable exception) {
- this.log(level, String.format("{Service %s}: %s", getServiceDescription(sr), message), exception);
- }
-
- private String getServiceDescription(ServiceReference<?> sr){
- return sr.getProperty("service.id").toString();
- }
}
diff --git a/org.eclipse.virgo.medic.core/src/test/java/org/eclipse/virgo/medic/impl/MedicActivatorTests.java b/org.eclipse.virgo.medic.core/src/test/java/org/eclipse/virgo/medic/impl/MedicActivatorTests.java
index 66b644e..89357b9 100644
--- a/org.eclipse.virgo.medic.core/src/test/java/org/eclipse/virgo/medic/impl/MedicActivatorTests.java
+++ b/org.eclipse.virgo.medic.core/src/test/java/org/eclipse/virgo/medic/impl/MedicActivatorTests.java
@@ -24,6 +24,7 @@ import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleListener;
import org.osgi.service.cm.ConfigurationListener;
+import org.osgi.service.log.LogReaderService;
import org.osgi.service.packageadmin.PackageAdmin;
@@ -48,9 +49,11 @@ public class MedicActivatorTests {
bundleContext.addProperty("org.eclipse.virgo.suppress.heap.dumps", "false");
PackageAdmin packageAdmin = createNiceMock(PackageAdmin.class);
- replay(packageAdmin);
+ LogReaderService logReaderService = createNiceMock(LogReaderService.class);
+ replay(packageAdmin, logReaderService);
- bundleContext.registerService(PackageAdmin.class.getName(), packageAdmin, null);
+ bundleContext.registerService(PackageAdmin.class, packageAdmin, null);
+ bundleContext.registerService(LogReaderService.class, logReaderService, null);
bundleActivator.start(bundleContext);
assertServiceListenerCount(bundleContext, 1);
@@ -66,7 +69,7 @@ public class MedicActivatorTests {
bundleActivator.stop(bundleContext);
- assertEquals(1, bundleContext.getServiceRegistrations().size());
+ assertEquals(2, bundleContext.getServiceRegistrations().size());
}
@Test
diff --git a/org.eclipse.virgo.medic.core/src/test/java/org/eclipse/virgo/medic/log/osgi/OSGiLogServiceImplTests.java b/org.eclipse.virgo.medic.core/src/test/java/org/eclipse/virgo/medic/log/osgi/OSGiLogServiceImplTests.java
deleted file mode 100644
index a80cc8f..0000000
--- a/org.eclipse.virgo.medic.core/src/test/java/org/eclipse/virgo/medic/log/osgi/OSGiLogServiceImplTests.java
+++ /dev/null
@@ -1,284 +0,0 @@
-/*
- * This file is part of the Eclipse Virgo project.
- *
- * Copyright (c) 2011 copyright_holder
- * 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:
- * cgfrost - initial contribution
- */
-
-package org.eclipse.virgo.medic.log.osgi;
-
-import static org.junit.Assert.*;
-
-import org.eclipse.virgo.teststubs.osgi.framework.StubBundleContext;
-import org.eclipse.virgo.teststubs.osgi.framework.StubServiceReference;
-import org.eclipse.virgo.teststubs.osgi.framework.StubServiceRegistration;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.log.LogService;
-import org.slf4j.Logger;
-
-import static org.easymock.EasyMock.*;
-
-/**
- *
- * OSGiLogServiceImplTests
- */
-public class OSGiLogServiceImplTests {
-
- private static final String TEST_MESSAGE = "Danger Will Robinson, Danger!!!";
-
- private static final ServiceReference<Object> SERVICE_REF = new StubServiceReference<Object>(3l, 3, new StubServiceRegistration<Object>(new StubBundleContext(), "org.eclipse.virgo.not.here"));
-
- private static final String SERVICE_PREFIX = "{Service 3}: ";
-
- private static final String INVALID_PREFIX = "Log Message of unknown severity 99: ";
-
- private static final Throwable FAIL = new Throwable("Got lost in space");
-
- private OSGiLogServiceImpl osgiLogService;
-
- private Logger logService;
-
- /**
- * @throws java.lang.Exception
- */
- @Before
- public void setUp() throws Exception {
- this.logService = createMock(Logger.class);
- this.osgiLogService = new OSGiLogServiceImpl(this.logService);
- }
-
- @After
- public void setDown() {
- verify(this.logService);
- }
-
- /**
- * Test method for {@link org.eclipse.virgo.medic.log.osgi.OSGiLogServiceImpl#log(int, java.lang.String)}.
- */
- @Test
- public void testDebugLog() {
- this.logService.debug(TEST_MESSAGE);
- expectLastCall().once();
- replay(this.logService);
- this.osgiLogService.log(LogService.LOG_DEBUG, TEST_MESSAGE);
- }
-
- /**
- * Test method for {@link org.eclipse.virgo.medic.log.osgi.OSGiLogServiceImpl#log(int, java.lang.String, java.lang.Throwable)}.
- */
- @Test
- public void testDebugLogThrowable() {
- this.logService.debug(TEST_MESSAGE, FAIL);
- expectLastCall().once();
- replay(this.logService);
- this.osgiLogService.log(LogService.LOG_DEBUG, TEST_MESSAGE, FAIL);
- }
-
- /**
- * Test method for {@link org.eclipse.virgo.medic.log.osgi.OSGiLogServiceImpl#log(org.osgi.framework.ServiceReference, int, java.lang.String)}.
- */
- @Test
- public void testDebugLogServiceReference() {
- this.logService.debug(SERVICE_PREFIX +TEST_MESSAGE);
- expectLastCall().once();
- replay(this.logService);
- this.osgiLogService.log(SERVICE_REF, LogService.LOG_DEBUG, TEST_MESSAGE);
- }
-
- /**
- * Test method for {@link org.eclipse.virgo.medic.log.osgi.OSGiLogServiceImpl#log(org.osgi.framework.ServiceReference, int, java.lang.String, java.lang.Throwable)}.
- */
- @Test
- public void testDebugLogServiceReferenceThrowable() {
- this.logService.debug(SERVICE_PREFIX + TEST_MESSAGE, FAIL);
- expectLastCall().once();
- replay(this.logService);
- this.osgiLogService.log(SERVICE_REF, LogService.LOG_DEBUG, TEST_MESSAGE, FAIL);
- }
-
- /**
- * Test method for {@link org.eclipse.virgo.medic.log.osgi.OSGiLogServiceImpl#log(int, java.lang.String)}.
- */
- @Test
- public void testInfoLog() {
- this.logService.info(TEST_MESSAGE);
- expectLastCall().once();
- replay(this.logService);
- this.osgiLogService.log(LogService.LOG_INFO, TEST_MESSAGE);
- }
-
- /**
- * Test method for {@link org.eclipse.virgo.medic.log.osgi.OSGiLogServiceImpl#log(int, java.lang.String, java.lang.Throwable)}.
- */
- @Test
- public void testInfoLogThrowable() {
- this.logService.info(TEST_MESSAGE, FAIL);
- expectLastCall().once();
- replay(this.logService);
- this.osgiLogService.log(LogService.LOG_INFO, TEST_MESSAGE, FAIL);
- }
-
- /**
- * Test method for {@link org.eclipse.virgo.medic.log.osgi.OSGiLogServiceImpl#log(org.osgi.framework.ServiceReference, int, java.lang.String)}.
- */
- @Test
- public void testInfoLogServiceReference() {
- this.logService.info(SERVICE_PREFIX +TEST_MESSAGE);
- expectLastCall().once();
- replay(this.logService);
- this.osgiLogService.log(SERVICE_REF, LogService.LOG_INFO, TEST_MESSAGE);
- }
-
- /**
- * Test method for {@link org.eclipse.virgo.medic.log.osgi.OSGiLogServiceImpl#log(org.osgi.framework.ServiceReference, int, java.lang.String, java.lang.Throwable)}.
- */
- @Test
- public void testInfoLogServiceReferenceThrowable() {
- this.logService.info(SERVICE_PREFIX + TEST_MESSAGE, FAIL);
- expectLastCall().once();
- replay(this.logService);
- this.osgiLogService.log(SERVICE_REF, LogService.LOG_INFO, TEST_MESSAGE, FAIL);
- }
-
- /**
- * Test method for {@link org.eclipse.virgo.medic.log.osgi.OSGiLogServiceImpl#log(int, java.lang.String)}.
- */
- @Test
- public void testWarningLog() {
- this.logService.warn(TEST_MESSAGE);
- expectLastCall().once();
- replay(this.logService);
- this.osgiLogService.log(LogService.LOG_WARNING, TEST_MESSAGE);
- }
-
- /**
- * Test method for {@link org.eclipse.virgo.medic.log.osgi.OSGiLogServiceImpl#log(int, java.lang.String, java.lang.Throwable)}.
- */
- @Test
- public void testWarningLogThrowable() {
- this.logService.warn(TEST_MESSAGE, FAIL);
- expectLastCall().once();
- replay(this.logService);
- this.osgiLogService.log(LogService.LOG_WARNING, TEST_MESSAGE, FAIL);
- }
-
- /**
- * Test method for {@link org.eclipse.virgo.medic.log.osgi.OSGiLogServiceImpl#log(org.osgi.framework.ServiceReference, int, java.lang.String)}.
- */
- @Test
- public void testWarningLogServiceReference() {
- this.logService.warn(SERVICE_PREFIX +TEST_MESSAGE);
- expectLastCall().once();
- replay(this.logService);
- this.osgiLogService.log(SERVICE_REF, LogService.LOG_WARNING, TEST_MESSAGE);
- }
-
- /**
- * Test method for {@link org.eclipse.virgo.medic.log.osgi.OSGiLogServiceImpl#log(org.osgi.framework.ServiceReference, int, java.lang.String, java.lang.Throwable)}.
- */
- @Test
- public void testWarningLogServiceReferenceThrowable() {
- this.logService.warn(SERVICE_PREFIX + TEST_MESSAGE, FAIL);
- expectLastCall().once();
- replay(this.logService);
- this.osgiLogService.log(SERVICE_REF, LogService.LOG_WARNING, TEST_MESSAGE, FAIL);
- }
-
- /**
- * Test method for {@link org.eclipse.virgo.medic.log.osgi.OSGiLogServiceImpl#log(int, java.lang.String)}.
- */
- @Test
- public void testErrorLog() {
- this.logService.error(TEST_MESSAGE);
- expectLastCall().once();
- replay(this.logService);
- this.osgiLogService.log(LogService.LOG_ERROR, TEST_MESSAGE);
- }
-
- /**
- * Test method for {@link org.eclipse.virgo.medic.log.osgi.OSGiLogServiceImpl#log(int, java.lang.String, java.lang.Throwable)}.
- */
- @Test
- public void testErrorLogThrowable() {
- this.logService.error(TEST_MESSAGE, FAIL);
- expectLastCall().once();
- replay(this.logService);
- this.osgiLogService.log(LogService.LOG_ERROR, TEST_MESSAGE, FAIL);
- }
-
- /**
- * Test method for {@link org.eclipse.virgo.medic.log.osgi.OSGiLogServiceImpl#log(org.osgi.framework.ServiceReference, int, java.lang.String)}.
- */
- @Test
- public void testErrorLogServiceReference() {
- this.logService.error(SERVICE_PREFIX +TEST_MESSAGE);
- expectLastCall().once();
- replay(this.logService);
- this.osgiLogService.log(SERVICE_REF, LogService.LOG_ERROR, TEST_MESSAGE);
- }
-
- /**
- * Test method for {@link org.eclipse.virgo.medic.log.osgi.OSGiLogServiceImpl#log(org.osgi.framework.ServiceReference, int, java.lang.String, java.lang.Throwable)}.
- */
- @Test
- public void testErrorLogServiceReferenceThrowable() {
- this.logService.error(SERVICE_PREFIX + TEST_MESSAGE, FAIL);
- expectLastCall().once();
- replay(this.logService);
- this.osgiLogService.log(SERVICE_REF, LogService.LOG_ERROR, TEST_MESSAGE, FAIL);
- }
-
- /**
- * Test method for {@link org.eclipse.virgo.medic.log.osgi.OSGiLogServiceImpl#log(int, java.lang.String)}.
- */
- @Test
- public void testInvalidLog() {
- this.logService.error(INVALID_PREFIX + TEST_MESSAGE);
- expectLastCall().once();
- replay(this.logService);
- this.osgiLogService.log(99, TEST_MESSAGE);
- }
-
- /**
- * Test method for {@link org.eclipse.virgo.medic.log.osgi.OSGiLogServiceImpl#log(int, java.lang.String, java.lang.Throwable)}.
- */
- @Test
- public void testInvalidLogThrowable() {
- this.logService.error(INVALID_PREFIX + TEST_MESSAGE, FAIL);
- expectLastCall().once();
- replay(this.logService);
- this.osgiLogService.log(99, TEST_MESSAGE, FAIL);
- }
-
- /**
- * Test method for {@link org.eclipse.virgo.medic.log.osgi.OSGiLogServiceImpl#log(org.osgi.framework.ServiceReference, int, java.lang.String)}.
- */
- @Test
- public void testInvalidLogServiceReference() {
- this.logService.error(INVALID_PREFIX + SERVICE_PREFIX +TEST_MESSAGE);
- expectLastCall().once();
- replay(this.logService);
- this.osgiLogService.log(SERVICE_REF, 99, TEST_MESSAGE);
- }
-
- /**
- * Test method for {@link org.eclipse.virgo.medic.log.osgi.OSGiLogServiceImpl#log(org.osgi.framework.ServiceReference, int, java.lang.String, java.lang.Throwable)}.
- */
- @Test
- public void testInvalidLogServiceReferenceThrowable() {
- this.logService.error(INVALID_PREFIX + SERVICE_PREFIX + TEST_MESSAGE, FAIL);
- expectLastCall().once();
- replay(this.logService);
- this.osgiLogService.log(SERVICE_REF, 99, TEST_MESSAGE, FAIL);
- }
-
-}
diff --git a/org.eclipse.virgo.medic.core/src/test/java/org/eclipse/virgo/medic/log/osgi/OSGiLogServiceListenerTests.java b/org.eclipse.virgo.medic.core/src/test/java/org/eclipse/virgo/medic/log/osgi/OSGiLogServiceListenerTests.java
new file mode 100644
index 0000000..1e40f3a
--- /dev/null
+++ b/org.eclipse.virgo.medic.core/src/test/java/org/eclipse/virgo/medic/log/osgi/OSGiLogServiceListenerTests.java
@@ -0,0 +1,308 @@
+/*
+ * This file is part of the Eclipse Virgo project.
+ *
+ * Copyright (c) 2011 copyright_holder
+ * 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:
+ * cgfrost - initial contribution
+ */
+
+package org.eclipse.virgo.medic.log.osgi;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
+import org.eclipse.virgo.teststubs.osgi.framework.StubBundle;
+import org.eclipse.virgo.teststubs.osgi.framework.StubBundleContext;
+import org.eclipse.virgo.teststubs.osgi.framework.StubServiceReference;
+import org.eclipse.virgo.teststubs.osgi.framework.StubServiceRegistration;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.Version;
+import org.osgi.service.log.LogEntry;
+import org.osgi.service.log.LogService;
+import org.slf4j.Logger;
+
+/**
+ *
+ * OSGiLogServiceImplTests
+ */
+public class OSGiLogServiceListenerTests {
+
+ private static final String TEST_MESSAGE = "Danger Will Robinson, Danger!!!";
+
+ private static final StubBundle BUNDLE = new StubBundle("org.eclipse.virgo.not.here", Version.emptyVersion);
+
+ private static final ServiceReference<Object> SERVICE_REF = new StubServiceReference<Object>(3l, 3, new StubServiceRegistration<Object>(new StubBundleContext(BUNDLE), "org.eclipse.virgo.not.here"));
+
+ private static final String SERVICE_PREFIX = "{Service 3}: ";
+
+ private static final String BUNDLE_PREFIX = "{Bundle org.eclipse.virgo.not.here-0.0.0}: ";
+
+ private static final String INVALID_PREFIX = "Log Message of unknown severity 99: ";
+
+ private static final Throwable FAIL = new Throwable("Got lost in space");
+
+ private OSGiLogServiceListener osgiLogListener;
+
+ private Logger logService;
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ this.logService = createMock(Logger.class);
+ this.osgiLogListener = new OSGiLogServiceListener(this.logService);
+ }
+
+ @After
+ public void setDown() {
+ verify(this.logService);
+ }
+
+ @Test
+ public void testDebugLog() {
+ this.logService.debug(TEST_MESSAGE);
+ expectLastCall().once();
+ replay(this.logService);
+ this.osgiLogListener.logged(buildLogEntry(null, null, LogService.LOG_DEBUG, TEST_MESSAGE, null));
+ }
+
+ @Test
+ public void testDebugLogThrowable() {
+ this.logService.debug(TEST_MESSAGE, FAIL);
+ expectLastCall().once();
+ replay(this.logService);
+ this.osgiLogListener.logged(buildLogEntry(null, null, LogService.LOG_DEBUG, TEST_MESSAGE, FAIL));
+ }
+
+ @Test
+ public void testDebugLogServiceReference() {
+ this.logService.debug(SERVICE_PREFIX +TEST_MESSAGE);
+ expectLastCall().once();
+ replay(this.logService);
+ this.osgiLogListener.logged(buildLogEntry(SERVICE_REF, null, LogService.LOG_DEBUG, TEST_MESSAGE, null));
+ }
+
+ @Test
+ public void testDebugLogBundle() {
+ this.logService.debug(BUNDLE_PREFIX + TEST_MESSAGE);
+ expectLastCall().once();
+ replay(this.logService);
+ this.osgiLogListener.logged(buildLogEntry(null, BUNDLE, LogService.LOG_DEBUG, TEST_MESSAGE, null));
+ }
+
+ @Test
+ public void testDebugLogServiceReferenceThrowableBundle() {
+ this.logService.debug(BUNDLE_PREFIX + SERVICE_PREFIX + TEST_MESSAGE, FAIL);
+ expectLastCall().once();
+ replay(this.logService);
+ this.osgiLogListener.logged(buildLogEntry(SERVICE_REF, BUNDLE, LogService.LOG_DEBUG, TEST_MESSAGE, FAIL));
+ }
+
+ @Test
+ public void testInfoLog() {
+ this.logService.info(TEST_MESSAGE);
+ expectLastCall().once();
+ replay(this.logService);
+ this.osgiLogListener.logged(buildLogEntry(null, null, LogService.LOG_INFO, TEST_MESSAGE, null));
+ }
+
+ @Test
+ public void testInfoLogThrowable() {
+ this.logService.info(TEST_MESSAGE, FAIL);
+ expectLastCall().once();
+ replay(this.logService);
+ this.osgiLogListener.logged(buildLogEntry(null, null, LogService.LOG_INFO, TEST_MESSAGE, FAIL));
+ }
+
+ @Test
+ public void testInfoLogServiceReference() {
+ this.logService.info(SERVICE_PREFIX +TEST_MESSAGE);
+ expectLastCall().once();
+ replay(this.logService);
+ this.osgiLogListener.logged(buildLogEntry(SERVICE_REF, null, LogService.LOG_INFO, TEST_MESSAGE, null));
+ }
+
+ @Test
+ public void testInfoLogBundle() {
+ this.logService.info(BUNDLE_PREFIX + TEST_MESSAGE);
+ expectLastCall().once();
+ replay(this.logService);
+ this.osgiLogListener.logged(buildLogEntry(null, BUNDLE, LogService.LOG_INFO, TEST_MESSAGE, null));
+ }
+
+ @Test
+ public void testInfoLogServiceReferenceThrowableBundle() {
+ this.logService.info(BUNDLE_PREFIX + SERVICE_PREFIX + TEST_MESSAGE, FAIL);
+ expectLastCall().once();
+ replay(this.logService);
+ this.osgiLogListener.logged(buildLogEntry(SERVICE_REF, BUNDLE, LogService.LOG_INFO, TEST_MESSAGE, FAIL));
+ }
+
+ @Test
+ public void testWarningLog() {
+ this.logService.warn(TEST_MESSAGE);
+ expectLastCall().once();
+ replay(this.logService);
+ this.osgiLogListener.logged(buildLogEntry(null, null, LogService.LOG_WARNING, TEST_MESSAGE, null));
+ }
+
+ @Test
+ public void testWarningLogThrowable() {
+ this.logService.warn(TEST_MESSAGE, FAIL);
+ expectLastCall().once();
+ replay(this.logService);
+ this.osgiLogListener.logged(buildLogEntry(null, null, LogService.LOG_WARNING, TEST_MESSAGE, FAIL));
+ }
+
+ @Test
+ public void testWarningLogServiceReference() {
+ this.logService.warn(SERVICE_PREFIX +TEST_MESSAGE);
+ expectLastCall().once();
+ replay(this.logService);
+ this.osgiLogListener.logged(buildLogEntry(SERVICE_REF, null, LogService.LOG_WARNING, TEST_MESSAGE, null));
+ }
+
+ @Test
+ public void testWarningLogBundle() {
+ this.logService.warn(BUNDLE_PREFIX + TEST_MESSAGE);
+ expectLastCall().once();
+ replay(this.logService);
+ this.osgiLogListener.logged(buildLogEntry(null, BUNDLE, LogService.LOG_WARNING, TEST_MESSAGE, null));
+ }
+
+ @Test
+ public void testWarningLogServiceReferenceThrowableBundle() {
+ this.logService.warn(BUNDLE_PREFIX + SERVICE_PREFIX + TEST_MESSAGE, FAIL);
+ expectLastCall().once();
+ replay(this.logService);
+ this.osgiLogListener.logged(buildLogEntry(SERVICE_REF, BUNDLE, LogService.LOG_WARNING, TEST_MESSAGE, FAIL));
+ }
+
+ @Test
+ public void testErrorLog() {
+ this.logService.error(TEST_MESSAGE);
+ expectLastCall().once();
+ replay(this.logService);
+ this.osgiLogListener.logged(buildLogEntry(null, null, LogService.LOG_ERROR, TEST_MESSAGE, null));
+ }
+
+ @Test
+ public void testErrorLogThrowable() {
+ this.logService.error(TEST_MESSAGE, FAIL);
+ expectLastCall().once();
+ replay(this.logService);
+ this.osgiLogListener.logged(buildLogEntry(null, null, LogService.LOG_ERROR, TEST_MESSAGE, FAIL));
+ }
+
+ @Test
+ public void testErrorLogServiceReference() {
+ this.logService.error(SERVICE_PREFIX +TEST_MESSAGE);
+ expectLastCall().once();
+ replay(this.logService);
+ this.osgiLogListener.logged(buildLogEntry(SERVICE_REF, null, LogService.LOG_ERROR, TEST_MESSAGE, null));
+ }
+
+ @Test
+ public void testErrorLogBundle() {
+ this.logService.error(BUNDLE_PREFIX + TEST_MESSAGE);
+ expectLastCall().once();
+ replay(this.logService);
+ this.osgiLogListener.logged(buildLogEntry(null, BUNDLE, LogService.LOG_ERROR, TEST_MESSAGE, null));
+ }
+
+ @Test
+ public void testErrorLogServiceReferenceThrowableBundle() {
+ this.logService.error(BUNDLE_PREFIX + SERVICE_PREFIX + TEST_MESSAGE, FAIL);
+ expectLastCall().once();
+ replay(this.logService);
+ this.osgiLogListener.logged(buildLogEntry(SERVICE_REF, BUNDLE, LogService.LOG_ERROR, TEST_MESSAGE, FAIL));
+ }
+
+ @Test
+ public void testInvalidLog() {
+ this.logService.error(INVALID_PREFIX + TEST_MESSAGE);
+ expectLastCall().once();
+ replay(this.logService);
+ this.osgiLogListener.logged(buildLogEntry(null, null, 99, TEST_MESSAGE, null));
+ }
+
+ @Test
+ public void testInvalidLogThrowable() {
+ this.logService.error(INVALID_PREFIX + TEST_MESSAGE, FAIL);
+ expectLastCall().once();
+ replay(this.logService);
+ this.osgiLogListener.logged(buildLogEntry(null, null, 99, TEST_MESSAGE, FAIL));
+ }
+
+ @Test
+ public void testInvalidLogServiceReference() {
+ this.logService.error(INVALID_PREFIX + SERVICE_PREFIX +TEST_MESSAGE);
+ expectLastCall().once();
+ replay(this.logService);
+ this.osgiLogListener.logged(buildLogEntry(SERVICE_REF, null, 99, TEST_MESSAGE, null));
+ }
+
+ @Test
+ public void testInvalidLogBundle() {
+ this.logService.error(INVALID_PREFIX + BUNDLE_PREFIX + TEST_MESSAGE);
+ expectLastCall().once();
+ replay(this.logService);
+ this.osgiLogListener.logged(buildLogEntry(null, BUNDLE, 99, TEST_MESSAGE, null));
+ }
+
+ @Test
+ public void testInvalidLogServiceReferenceThrowableBundle() {
+ this.logService.error(INVALID_PREFIX + BUNDLE_PREFIX + SERVICE_PREFIX + TEST_MESSAGE, FAIL);
+ expectLastCall().once();
+ replay(this.logService);
+ this.osgiLogListener.logged(buildLogEntry(SERVICE_REF, BUNDLE, 99, TEST_MESSAGE, FAIL));
+ }
+
+ private LogEntry buildLogEntry(final ServiceReference<Object> ref, final Bundle bundle, final int level, final String message, final Throwable fail){
+ return new LogEntry() {
+
+ @Override
+ public long getTime() {
+ return 0;
+ }
+
+ @Override
+ public ServiceReference<?> getServiceReference() {
+ return ref;
+ }
+
+ @Override
+ public String getMessage() {
+ return message;
+ }
+
+ @Override
+ public int getLevel() {
+ return level;
+ }
+
+ @Override
+ public Throwable getException() {
+ return fail;
+ }
+
+ @Override
+ public Bundle getBundle() {
+ return bundle;
+ }
+ };
+ }
+
+}

Back to the top