You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by cs...@apache.org on 2012/04/04 15:06:32 UTC
svn commit: r1309363 [2/2] - in /karaf/trunk: ./
assemblies/features/standard/src/main/feature/ log/ log/command/
log/command/src/main/java/org/apache/karaf/log/
log/command/src/main/java/org/apache/karaf/log/command/
log/command/src/main/java/org/apac...
Copied: karaf/trunk/log/core/src/test/java/org/apache/karaf/log/core/internal/SetLogLevelTest.java (from r1309258, karaf/trunk/shell/log/src/test/java/org/apache/karaf/shell/log/SetLogLevelTest.java)
URL: http://svn.apache.org/viewvc/karaf/trunk/log/core/src/test/java/org/apache/karaf/log/core/internal/SetLogLevelTest.java?p2=karaf/trunk/log/core/src/test/java/org/apache/karaf/log/core/internal/SetLogLevelTest.java&p1=karaf/trunk/shell/log/src/test/java/org/apache/karaf/shell/log/SetLogLevelTest.java&r1=1309258&r2=1309363&rev=1309363&view=diff
==============================================================================
--- karaf/trunk/shell/log/src/test/java/org/apache/karaf/shell/log/SetLogLevelTest.java (original)
+++ karaf/trunk/log/core/src/test/java/org/apache/karaf/log/core/internal/SetLogLevelTest.java Wed Apr 4 13:06:29 2012
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.karaf.shell.log;
+package org.apache.karaf.log.core.internal;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -23,8 +23,13 @@ import java.util.Hashtable;
import junit.framework.TestCase;
+import org.apache.karaf.log.core.Level;
+import org.apache.karaf.log.core.LogMBean;
+import org.apache.karaf.log.core.LogService;
import org.easymock.EasyMock;
+import org.junit.experimental.categories.Categories.ExcludeCategory;
import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
/**
* Test cases for {@link SetLogLevel}
@@ -34,106 +39,90 @@ public class SetLogLevelTest extends Tes
private static final String ROOT_LOGGER = "log4j.rootLogger";
private static final String PACKAGE_LOGGER = "log4j.logger.org.apache.karaf.test";
- private static final PrintStream ORIGINAL_STDERR = System.err;
- private SetLogLevel command;
+ private LogService logService;
+ private LogMBean logMBean;
+ @SuppressWarnings("rawtypes")
private Hashtable properties;
- private ByteArrayOutputStream stderr;
@Override
protected void setUp() throws Exception {
super.setUp();
- properties = new Hashtable();
- stderr = new ByteArrayOutputStream();
- System.setErr(new PrintStream(stderr));
+ properties = new Hashtable<String, String>();
final Configuration configuration = EasyMock.createMock(Configuration.class);
EasyMock.expect(configuration.getProperties()).andReturn(properties);
- configuration.update(properties);
+ configuration.update(properties);
+ ConfigurationAdmin configAdmin = EasyMock.createMock(ConfigurationAdmin.class);
+ EasyMock.expect(configAdmin.getConfiguration(LogServiceImpl.CONFIGURATION_PID, null)).andReturn(configuration);
+ logService = new LogServiceImpl(configAdmin, new LruList(100));
+ logMBean = new Log(logService);
+ EasyMock.replay(configAdmin);
EasyMock.replay(configuration);
-
- command = new SetLogLevel() {
- @Override
- protected Configuration getConfiguration() throws IOException {
- return configuration;
- }
- };
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
- System.setErr(ORIGINAL_STDERR);
}
public void testInvalidLogLevel() throws Exception {
- runCommand("log:set INVALID");
- assertTrue("Expected an error message on System.err",
- stderr.toString().contains("level must be set to"));
+ try {
+ logMBean.setLevel("INVALID");
+ fail("Exception expected");
+ } catch(IllegalArgumentException e) {
+ // Expected
+ }
}
public void testSetLogLevel() throws Exception {
- runCommand("log:set INFO org.apache.karaf.test");
-
+ logMBean.setLevel("org.apache.karaf.test", "INFO");
assertEquals("INFO", properties.get(PACKAGE_LOGGER));
}
public void testSetRootLogLevel() throws Exception {
- runCommand("log:set INFO");
-
+ logMBean.setLevel("INFO");
assertEquals("INFO", properties.get(ROOT_LOGGER));
}
public void testSetLogLevelLowerCase() throws Exception {
- runCommand("log:set info org.apache.karaf.test");
-
+ logMBean.setLevel("org.apache.karaf.test", "info");
assertEquals("INFO", properties.get(PACKAGE_LOGGER));
}
public void testSetRootLogLevelLowerCase() throws Exception {
- runCommand("log:set info");
-
+ logMBean.setLevel("info");
assertEquals("INFO", properties.get(ROOT_LOGGER));
}
public void testChangeLogLevel() throws Exception {
properties.put(PACKAGE_LOGGER, "DEBUG");
-
- runCommand("log:set INFO org.apache.karaf.test");
-
+ logMBean.setLevel("org.apache.karaf.test", "INFO");
assertEquals("INFO", properties.get(PACKAGE_LOGGER));
}
public void testChangeRootLogLevel() throws Exception {
properties.put(ROOT_LOGGER, "DEBUG");
-
- runCommand("log:set INFO");
-
+ logMBean.setLevel("INFO");
assertEquals("INFO", properties.get(ROOT_LOGGER));
}
public void testChangeLogLevelWithAppender() throws Exception {
properties.put(PACKAGE_LOGGER, "DEBUG, APPENDER1");
-
- runCommand("log:set INFO org.apache.karaf.test");
-
+ logMBean.setLevel("org.apache.karaf.test", "INFO");
assertEquals("INFO, APPENDER1", properties.get(PACKAGE_LOGGER));
}
public void testChangeRootLogLevelWithAppender() throws Exception {
properties.put(ROOT_LOGGER, "DEBUG, APPENDER1");
-
- runCommand("log:set INFO");
-
+ logMBean.setLevel("INFO");
assertEquals("INFO, APPENDER1", properties.get(ROOT_LOGGER));
}
public void testUnsetLogLevel() throws Exception {
properties.put(PACKAGE_LOGGER, "DEBUG");
-
- runCommand("log:set DEFAULT org.apache.karaf.test");
-
+ logMBean.setLevel("org.apache.karaf.test", "DEFAULT");
assertFalse("Configuration for logger org.apache.karaf.test has been removed",
properties.containsKey(PACKAGE_LOGGER));
}
@@ -141,26 +130,9 @@ public class SetLogLevelTest extends Tes
public void testUnsetRootLogLevel() throws Exception {
properties.put(ROOT_LOGGER, "INFO");
-
- runCommand("log:set DEFAULT");
-
+ logMBean.setLevel("org.apache.karaf.test", "DEFAULT");
assertEquals("Configuration for root logger should not be removed",
"INFO", properties.get(ROOT_LOGGER));
- assertTrue("Expected an error message on System.err",
- stderr.toString().contains("Can not unset the ROOT logger"));
}
- /*
- * Simulate running the log:set command
- */
- private void runCommand(String commandline) throws Exception {
- String[] parts = commandline.split(" ");
-
- command.level = parts[1];
- if (parts.length == 3) {
- command.logger = "org.apache.karaf.test";
- }
-
- command.doExecute();
- }
}
Added: karaf/trunk/log/pom.xml
URL: http://svn.apache.org/viewvc/karaf/trunk/log/pom.xml?rev=1309363&view=auto
==============================================================================
--- karaf/trunk/log/pom.xml (added)
+++ karaf/trunk/log/pom.xml Wed Apr 4 13:06:29 2012
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.karaf</groupId>
+ <artifactId>karaf</artifactId>
+ <version>3.0.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <groupId>org.apache.karaf.log</groupId>
+ <artifactId>log</artifactId>
+ <packaging>pom</packaging>
+ <name>Apache Karaf :: Log</name>
+
+ <modules>
+ <module>core</module>
+ <module>command</module>
+ </modules>
+
+</project>
\ No newline at end of file
Modified: karaf/trunk/management/mbeans/pom.xml
URL: http://svn.apache.org/viewvc/karaf/trunk/management/mbeans/pom.xml?rev=1309363&r1=1309362&r2=1309363&view=diff
==============================================================================
--- karaf/trunk/management/mbeans/pom.xml (original)
+++ karaf/trunk/management/mbeans/pom.xml Wed Apr 4 13:06:29 2012
@@ -35,7 +35,6 @@
<modules>
<module>dev</module>
- <module>log</module>
<module>obr</module>
</modules>
Modified: karaf/trunk/pom.xml
URL: http://svn.apache.org/viewvc/karaf/trunk/pom.xml?rev=1309363&r1=1309362&r2=1309363&view=diff
==============================================================================
--- karaf/trunk/pom.xml (original)
+++ karaf/trunk/pom.xml Wed Apr 4 13:06:29 2012
@@ -46,6 +46,7 @@
<module>package</module>
<module>http</module>
<module>service</module>
+ <module>log</module>
<module>deployer</module>
<module>shell</module>
<module>jaas</module>
@@ -385,6 +386,17 @@
</dependency>
<dependency>
+ <groupId>org.apache.karaf.log</groupId>
+ <artifactId>org.apache.karaf.log.core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.karaf.log</groupId>
+ <artifactId>org.apache.karaf.log.command</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
<groupId>org.apache.karaf.config</groupId>
<artifactId>org.apache.karaf.config.core</artifactId>
<version>${project.version}</version>
Modified: karaf/trunk/shell/pom.xml
URL: http://svn.apache.org/viewvc/karaf/trunk/shell/pom.xml?rev=1309363&r1=1309362&r2=1309363&view=diff
==============================================================================
--- karaf/trunk/shell/pom.xml (original)
+++ karaf/trunk/shell/pom.xml Wed Apr 4 13:06:29 2012
@@ -37,7 +37,6 @@
<module>commands</module>
<module>console</module>
<module>dev</module>
- <module>log</module>
<module>obr</module>
<module>ssh</module>
</modules>