You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ge...@apache.org on 2009/07/21 17:30:31 UTC
svn commit: r796348 - in /felix/trunk/karaf/gshell: gshell-commands/
gshell-config/
gshell-config/src/main/java/org/apache/felix/karaf/gshell/config/
gshell-config/src/test/ gshell-config/src/test/java/
gshell-config/src/test/java/org/ gshell-config/sr...
Author: gertv
Date: Tue Jul 21 15:30:30 2009
New Revision: 796348
URL: http://svn.apache.org/viewvc?rev=796348&view=rev
Log:
FELIX-1391: Unable to create a new ConfigAdmin PID through the Karaf console
Added:
felix/trunk/karaf/gshell/gshell-config/src/test/
felix/trunk/karaf/gshell/gshell-config/src/test/java/
felix/trunk/karaf/gshell/gshell-config/src/test/java/org/
felix/trunk/karaf/gshell/gshell-config/src/test/java/org/apache/
felix/trunk/karaf/gshell/gshell-config/src/test/java/org/apache/felix/
felix/trunk/karaf/gshell/gshell-config/src/test/java/org/apache/felix/karaf/
felix/trunk/karaf/gshell/gshell-config/src/test/java/org/apache/felix/karaf/gshell/
felix/trunk/karaf/gshell/gshell-config/src/test/java/org/apache/felix/karaf/gshell/config/
felix/trunk/karaf/gshell/gshell-config/src/test/java/org/apache/felix/karaf/gshell/config/EditCommandTest.java (with props)
Modified:
felix/trunk/karaf/gshell/gshell-commands/ (props changed)
felix/trunk/karaf/gshell/gshell-config/pom.xml
felix/trunk/karaf/gshell/gshell-config/src/main/java/org/apache/felix/karaf/gshell/config/EditCommand.java
felix/trunk/karaf/gshell/gshell-console/ (props changed)
felix/trunk/karaf/gshell/gshell-ssh/ (props changed)
Propchange: felix/trunk/karaf/gshell/gshell-commands/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Jul 21 15:30:30 2009
@@ -0,0 +1,5 @@
+target
+eclipse-classes
+.classpath
+.project
+.settings
Modified: felix/trunk/karaf/gshell/gshell-config/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/karaf/gshell/gshell-config/pom.xml?rev=796348&r1=796347&r2=796348&view=diff
==============================================================================
--- felix/trunk/karaf/gshell/gshell-config/pom.xml (original)
+++ felix/trunk/karaf/gshell/gshell-config/pom.xml Tue Jul 21 15:30:30 2009
@@ -54,6 +54,12 @@
<artifactId>org.osgi.compendium</artifactId>
<scope>provided</scope>
</dependency>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-jdk14</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
Modified: felix/trunk/karaf/gshell/gshell-config/src/main/java/org/apache/felix/karaf/gshell/config/EditCommand.java
URL: http://svn.apache.org/viewvc/felix/trunk/karaf/gshell/gshell-config/src/main/java/org/apache/felix/karaf/gshell/config/EditCommand.java?rev=796348&r1=796347&r2=796348&view=diff
==============================================================================
--- felix/trunk/karaf/gshell/gshell-config/src/main/java/org/apache/felix/karaf/gshell/config/EditCommand.java (original)
+++ felix/trunk/karaf/gshell/gshell-config/src/main/java/org/apache/felix/karaf/gshell/config/EditCommand.java Tue Jul 21 15:30:30 2009
@@ -17,6 +17,7 @@
package org.apache.felix.karaf.gshell.config;
import java.util.Dictionary;
+import java.util.Properties;
import org.apache.felix.gogo.commands.Argument;
import org.apache.felix.gogo.commands.Option;
@@ -37,6 +38,9 @@
return;
}
Dictionary props = admin.getConfiguration(pid).getProperties();
+ if (props == null) {
+ props = new Properties();
+ }
this.session.put(PROPERTY_CONFIG_PID, pid);
this.session.put(PROPERTY_CONFIG_PROPS, props);
}
Added: felix/trunk/karaf/gshell/gshell-config/src/test/java/org/apache/felix/karaf/gshell/config/EditCommandTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/karaf/gshell/gshell-config/src/test/java/org/apache/felix/karaf/gshell/config/EditCommandTest.java?rev=796348&view=auto
==============================================================================
--- felix/trunk/karaf/gshell/gshell-config/src/test/java/org/apache/felix/karaf/gshell/config/EditCommandTest.java (added)
+++ felix/trunk/karaf/gshell/gshell-config/src/test/java/org/apache/felix/karaf/gshell/config/EditCommandTest.java Tue Jul 21 15:30:30 2009
@@ -0,0 +1,155 @@
+/*
+ * 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.
+ */
+package org.apache.felix.karaf.gshell.config;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+
+import java.io.InputStream;
+import java.io.PrintStream;
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+import org.easymock.EasyMock;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.service.command.CommandSession;
+
+/**
+ * Test cases for {@link EditCommand}
+ */
+public class EditCommandTest extends TestCase {
+
+ private static final String PID = "my.test.persistent.id";
+
+ private EditCommand command;
+ private BundleContext context;
+ private ConfigurationAdmin admin;
+ private CommandSession session;
+
+ @Override
+ protected void setUp() throws Exception {
+ command = new EditCommand();
+
+ context = EasyMock.createMock(BundleContext.class);
+ command.setBundleContext(context);
+
+ ServiceReference reference = createMock(ServiceReference.class);
+ expect(context.getServiceReference(ConfigurationAdmin.class.getName())).andReturn(reference);
+
+ admin = createMock(ConfigurationAdmin.class);
+ expect(context.getService(reference)).andReturn(admin);
+ expect(context.ungetService(reference)).andReturn(Boolean.TRUE);
+
+ replay(context);
+
+ session = new MockCommandSession();
+ }
+
+ public void testExecuteOnExistingPid() throws Exception {
+ Configuration config = createMock(Configuration.class);
+ expect(admin.getConfiguration(PID)).andReturn(config);
+ replay(admin);
+
+ // the ConfigAdmin service returns a Dictionary for an existing PID
+ Properties props = new Properties();
+ expect(config.getProperties()).andReturn(props);
+ replay(config);
+
+ command.pid = PID;
+ command.execute(session);
+
+ // the PID and Dictionary should have been set on the session
+ assertEquals("The PID should be set on the session",
+ PID, session.get(ConfigCommandSupport.PROPERTY_CONFIG_PID));
+ assertSame("The Dictionary returned by the ConfigAdmin service should be set on the session",
+ props, session.get(ConfigCommandSupport.PROPERTY_CONFIG_PROPS));
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testExecuteOnNewPid() throws Exception {
+ Configuration config = createMock(Configuration.class);
+ expect(admin.getConfiguration(PID)).andReturn(config);
+ replay(admin);
+
+ // the ConfigAdmin service does not return a Dictionary for a new PID
+ expect(config.getProperties()).andReturn(null);
+ replay(config);
+
+ command.pid = PID;
+ command.execute(session);
+
+ // the PID and an empty Dictionary should have been set on the session
+ assertEquals("The PID should be set on the session",
+ PID, session.get(ConfigCommandSupport.PROPERTY_CONFIG_PID));
+ Dictionary props = (Dictionary) session.get(ConfigCommandSupport.PROPERTY_CONFIG_PROPS);
+ assertNotNull("Should have a Dictionary on the session", props);
+ assertTrue("Should have an empty Dictionary on the session", props.isEmpty());
+ }
+
+ /*
+ * A mock CommandSession implementation that only cares about the properties set on the session
+ */
+ private class MockCommandSession implements CommandSession {
+
+ private Map<String, Object> properties = new HashMap<String, Object>();
+
+ public void close() {
+ // not implemented
+ }
+
+ public Object convert(Class<?> type, Object instance) {
+ // not implemented
+ return null;
+ }
+
+ public Object execute(CharSequence commandline) throws Exception {
+ // not implemented
+ return null;
+ }
+
+ public CharSequence format(Object target, int level) {
+ // not implemented
+ return null;
+ }
+
+ public Object get(String name) {
+ return properties.get(name);
+ }
+
+ public PrintStream getConsole() {
+ // not implemented
+ return null;
+ }
+
+ public InputStream getKeyboard() {
+ // not implemented
+ return null;
+ }
+
+ public void put(String name, Object value) {
+ properties.put(name, value);
+ }
+ }
+}
Propchange: felix/trunk/karaf/gshell/gshell-config/src/test/java/org/apache/felix/karaf/gshell/config/EditCommandTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: felix/trunk/karaf/gshell/gshell-console/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Jul 21 15:30:30 2009
@@ -0,0 +1,5 @@
+target
+eclipse-classes
+.classpath
+.project
+.settings
Propchange: felix/trunk/karaf/gshell/gshell-ssh/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Jul 21 15:30:30 2009
@@ -0,0 +1,5 @@
+target
+eclipse-classes
+.classpath
+.project
+.settings