();
if (pid != null) {
Index: shell/config/src/main/java/org/apache/karaf/shell/config/ConfigCommandSupport.java
===================================================================
--- shell/config/src/main/java/org/apache/karaf/shell/config/ConfigCommandSupport.java (revision 1296251)
+++ shell/config/src/main/java/org/apache/karaf/shell/config/ConfigCommandSupport.java (working copy)
@@ -16,18 +16,9 @@
*/
package org.apache.karaf.shell.config;
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
import java.util.Dictionary;
-import java.util.Enumeration;
+
import org.apache.karaf.shell.console.OsgiCommandSupport;
-import org.apache.karaf.util.Properties;
-import org.osgi.framework.Constants;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.cm.Configuration;
-import org.osgi.service.cm.ConfigurationAdmin;
/**
* Abstract class from which all commands related to the ConfigurationAdmin
@@ -36,193 +27,17 @@
* calling another method to actually process the command.
*/
public abstract class ConfigCommandSupport extends OsgiCommandSupport {
-
public static final String PROPERTY_CONFIG_PID = "ConfigCommand.PID";
public static final String PROPERTY_CONFIG_PROPS = "ConfigCommand.Props";
- private static final String PID_FILTER = "(service.pid=%s*)";
- private static final String FILE_PREFIX = "file:";
- private static final String CONFIG_SUFFIX = ".cfg";
- private static final String FACTORY_SEPARATOR = "-";
- private static final String FILEINSTALL_FILE_NAME = "felix.fileinstall.filename";
+ protected ConfigRepository configRepository;
- protected File storage;
-
- protected Object doExecute() throws Exception {
- // Get config admin service.
- ServiceReference ref = getBundleContext().getServiceReference(ConfigurationAdmin.class.getName());
- if (ref == null) {
- System.out.println("ConfigurationAdmin service is unavailable.");
- return null;
- }
- ConfigurationAdmin admin = getConfigurationAdmin();
- if (admin == null) {
- System.out.println("ConfigAdmin service is unavailable.");
- return null;
- }
-
- doExecute(admin);
- return null;
- }
-
+ @SuppressWarnings("rawtypes")
protected Dictionary getEditedProps() throws Exception {
return (Dictionary) this.session.get(PROPERTY_CONFIG_PROPS);
}
-
- protected ConfigurationAdmin getConfigurationAdmin() {
- ServiceReference ref = getBundleContext().getServiceReference(ConfigurationAdmin.class.getName());
- if (ref == null) {
- return null;
- }
- try {
- ConfigurationAdmin admin = (ConfigurationAdmin) getBundleContext().getService(ref);
- if (admin == null) {
- return null;
- } else {
- return admin;
- }
- } finally {
- getBundleContext().ungetService(ref);
- }
+
+ public void setConfigRepository(ConfigRepository configRepository) {
+ this.configRepository = configRepository;
}
- protected abstract void doExecute(ConfigurationAdmin admin) throws Exception;
-
- /**
- *
- * Returns the Configuration object of the given (felix fileinstall) file name.
- *
- *
- * @param fileName
- * @return
- */
- public Configuration findConfigurationByFileName(ConfigurationAdmin admin, String fileName) throws IOException, InvalidSyntaxException {
- if (fileName != null && fileName.contains(FACTORY_SEPARATOR)) {
- String factoryPid = fileName.substring(0, fileName.lastIndexOf(FACTORY_SEPARATOR));
- String absoluteFileName = FILE_PREFIX + storage.getAbsolutePath() + File.separator + fileName + CONFIG_SUFFIX;
- Configuration[] configurations = admin.listConfigurations(String.format(PID_FILTER, factoryPid));
- if (configurations != null) {
- for (Configuration configuration : configurations) {
- Dictionary dictionary = configuration.getProperties();
- if (dictionary != null) {
- String fileInstallFileName = (String) dictionary.get(FILEINSTALL_FILE_NAME);
- if (absoluteFileName.equals(fileInstallFileName)) {
- return configuration;
- }
- }
- }
- }
- }
- return null;
- }
-
- /**
- * Saves config to storage or ConfigurationAdmin.
- *
- * @param admin
- * @param pid
- * @param props
- * @param bypassStorage
- * @throws IOException
- */
- protected void update(ConfigurationAdmin admin, String pid, Dictionary props, boolean bypassStorage) throws IOException {
- if (!bypassStorage && storage != null) {
- persistConfiguration(admin, pid, props);
- } else {
- updateConfiguration(admin, pid, props);
- }
- }
-
- /**
- * Persists configuration to storage.
- *
- * @param admin
- * @param pid
- * @param props
- * @throws IOException
- */
- protected void persistConfiguration(ConfigurationAdmin admin, String pid, Dictionary props) throws IOException {
- File storageFile = new File(storage, pid + ".cfg");
- Configuration cfg = admin.getConfiguration(pid, null);
- if (cfg != null && cfg.getProperties() != null) {
- Object val = cfg.getProperties().get(FILEINSTALL_FILE_NAME);
- if (val instanceof String) {
- if (((String) val).startsWith("file:")) {
- val = ((String) val).substring("file:".length());
- }
- storageFile = new File((String) val);
- }
- }
- Properties p = new Properties(storageFile);
- for (Enumeration keys = props.keys(); keys.hasMoreElements(); ) {
- Object key = keys.nextElement();
- if (!Constants.SERVICE_PID.equals(key)
- && !ConfigurationAdmin.SERVICE_FACTORYPID.equals(key)
- && !FILEINSTALL_FILE_NAME.equals(key)) {
- p.put((String) key, (String) props.get(key));
- }
- }
- // remove "removed" properties from the file
- ArrayList propertiesToRemove = new ArrayList();
- for (Object key : p.keySet()) {
- if (props.get(key) == null
- && !Constants.SERVICE_PID.equals(key)
- && !ConfigurationAdmin.SERVICE_FACTORYPID.equals(key)
- && !FILEINSTALL_FILE_NAME.equals(key)) {
- propertiesToRemove.add(key.toString());
- }
- }
- for (String key : propertiesToRemove) {
- p.remove(key);
- }
- // save the cfg file
- storage.mkdirs();
- p.save();
-
- }
-
- /**
- * Updates the configuration to the {@link ConfigurationAdmin} service.
- *
- * @param admin
- * @param pid
- * @param props
- * @throws IOException
- */
- public void updateConfiguration(ConfigurationAdmin admin, String pid, Dictionary props) throws IOException {
- Configuration cfg = admin.getConfiguration(pid, null);
- if (cfg.getProperties() == null) {
- String[] pids = parsePid(pid);
- if (pids[1] != null) {
- cfg = admin.createFactoryConfiguration(pids[0], null);
- }
- }
- if (cfg.getBundleLocation() != null) {
- cfg.setBundleLocation(null);
- }
- cfg.update(props);
- }
-
- protected String[] parsePid(String pid) {
- int n = pid.indexOf('-');
- if (n > 0) {
- String factoryPid = pid.substring(n + 1);
- pid = pid.substring(0, n);
- return new String[]{pid, factoryPid};
- } else {
- return new String[]{pid, null};
- }
- }
-
- protected void deleteStorage(String pid) throws Exception {
- File cfgFile = new File(storage, pid + ".cfg");
- cfgFile.delete();
- }
-
- public File getStorage() {
- return storage;
- }
-
- public void setStorage(File storage) {
- this.storage = storage;
- }
}
Index: shell/config/src/main/java/org/apache/karaf/shell/config/ConfigPropertyCommandSupport.java
===================================================================
--- shell/config/src/main/java/org/apache/karaf/shell/config/ConfigPropertyCommandSupport.java (revision 1296251)
+++ shell/config/src/main/java/org/apache/karaf/shell/config/ConfigPropertyCommandSupport.java (working copy)
@@ -1,11 +1,9 @@
package org.apache.karaf.shell.config;
import java.util.Dictionary;
+import java.util.Properties;
import org.apache.felix.gogo.commands.Option;
-import java.util.Properties;
-import org.osgi.service.cm.Configuration;
-import org.osgi.service.cm.ConfigurationAdmin;
/**
* Abstract class which commands that are related to property processing should extend.
@@ -19,7 +17,8 @@
protected boolean bypassStorage;
- protected void doExecute(ConfigurationAdmin admin) throws Exception {
+ @SuppressWarnings("rawtypes")
+ protected Object doExecute() throws Exception {
Dictionary props = getEditedProps();
if (props == null && pid == null) {
System.err.println("No configuration is being edited--run the edit command first");
@@ -29,15 +28,17 @@
}
propertyAction(props);
if(requiresUpdate(pid)) {
- update(admin, pid, props, bypassStorage);
+ this.configRepository.update(pid, props, bypassStorage);
}
}
+ return null;
}
/**
* Perform an action on the properties.
* @param props
*/
+ @SuppressWarnings("rawtypes")
protected abstract void propertyAction(Dictionary props);
/**
@@ -60,17 +61,10 @@
* @return
* @throws Exception
*/
+ @SuppressWarnings("rawtypes")
@Override
protected Dictionary getEditedProps() throws Exception {
- if(pid != null) {
- ConfigurationAdmin configurationAdmin = getConfigurationAdmin();
- if(configurationAdmin != null) {
- Configuration configuration = configurationAdmin.getConfiguration(pid);
- if(configuration != null) {
- return configuration.getProperties();
- }
- }
- }
- return super.getEditedProps();
+ Dictionary props = this.configRepository.getConfigProperties(pid);
+ return (props != null) ? props : super.getEditedProps();
}
}
Index: shell/config/src/main/java/org/apache/karaf/shell/config/DeleteCommand.java
===================================================================
--- shell/config/src/main/java/org/apache/karaf/shell/config/DeleteCommand.java (revision 1296251)
+++ shell/config/src/main/java/org/apache/karaf/shell/config/DeleteCommand.java (working copy)
@@ -20,7 +20,6 @@
import org.apache.felix.gogo.commands.Command;
import org.apache.felix.gogo.commands.Option;
import org.osgi.service.cm.Configuration;
-import org.osgi.service.cm.ConfigurationAdmin;
@Command(scope = "config", name = "delete", description = "Delete a configuration.")
public class DeleteCommand extends ConfigCommandSupport {
@@ -31,38 +30,39 @@
@Option(name = "--force", aliases = {}, description = "Force the edition of this config, even if another one was under edition", required = false, multiValued = false)
boolean force;
- @Option(name = "--no-delete-cfg-file", aliases = { }, description = "Do not delete the configuration file from the etc folder", required = false, multiValued = false)
+ @Option(name = "--no-delete-cfg-file", aliases = {}, description = "Do not delete the configuration file from the etc folder", required = false, multiValued = false)
boolean noDeleteCfgFile = false;
@Option(name = "-f", aliases = {"--use-file"}, description = "Configuration lookup using the filename instead of the pid", required = false, multiValued = false)
boolean useFile;
- protected void doExecute(ConfigurationAdmin admin) throws Exception {
+ protected Object doExecute() throws Exception {
String oldPid = (String) this.session.get(PROPERTY_CONFIG_PID);
if (oldPid != null && oldPid.equals(pid) && !force) {
System.err.println("This config is being edited. Cancel / update first, or use the --force option");
- return;
+ return null;
}
// User selected to use file instead.
if (useFile) {
- Configuration configuration = this.findConfigurationByFileName(admin, pid);
+ Configuration configuration = this.configRepository.findConfigurationByFileName(pid);
if(configuration == null) {
System.err.println("Could not find configuration with file install property set to: " + pid);
- return;
+ return null;
}
configuration.delete();
} else {
- Configuration configuration = admin.getConfiguration(pid);
+ Configuration configuration = this.configRepository.getConfigAdmin().getConfiguration(pid);
configuration.delete();
}
if (!noDeleteCfgFile) {
- deleteStorage(pid);
+ this.configRepository.deleteStorage(pid);
}
if (oldPid != null && oldPid.equals(pid) && !force) {
this.session.put(PROPERTY_CONFIG_PID, null);
this.session.put(PROPERTY_CONFIG_PROPS, null);
}
+ return null;
}
}
Index: shell/config/src/main/java/org/apache/karaf/shell/config/EditCommand.java
===================================================================
--- shell/config/src/main/java/org/apache/karaf/shell/config/EditCommand.java (revision 1296251)
+++ shell/config/src/main/java/org/apache/karaf/shell/config/EditCommand.java (working copy)
@@ -23,7 +23,6 @@
import org.apache.felix.gogo.commands.Command;
import org.apache.felix.gogo.commands.Option;
import org.osgi.service.cm.Configuration;
-import org.osgi.service.cm.ConfigurationAdmin;
@Command(scope = "config", name = "edit", description = "Creates or edits a configuration.", detailedDescription="classpath:edit.txt")
public class EditCommand extends ConfigCommandSupport {
@@ -37,25 +36,26 @@
@Option(name = "-f", aliases = {"--use-file"}, description = "Configuration lookup using the filename instead of the pid", required = false, multiValued = false)
boolean useFile;
- protected void doExecute(ConfigurationAdmin admin) throws Exception {
+ @SuppressWarnings("rawtypes")
+ protected Object doExecute() throws Exception {
String oldPid = (String) this.session.get(PROPERTY_CONFIG_PID);
if (oldPid != null && !oldPid.equals(pid) && !force) {
System.err.println("Another config is being edited. Cancel / update first, or use the --force option");
- return;
+ return null;
}
Dictionary props;
//User selected to use file instead.
if (useFile) {
- Configuration configuration = this.findConfigurationByFileName(admin, pid);
+ Configuration configuration = this.configRepository.findConfigurationByFileName(pid);
if(configuration == null) {
System.err.println("Could not find configuration with file install property set to: " + pid);
- return;
+ return null;
}
props = configuration.getProperties();
pid = configuration.getPid();
} else {
- Configuration configuration = admin.getConfiguration(pid, null);
+ Configuration configuration = this.configRepository.getConfigAdmin().getConfiguration(pid, null);
props = configuration.getProperties();
if (props == null) {
props = new Properties();
@@ -63,6 +63,7 @@
}
this.session.put(PROPERTY_CONFIG_PID, pid);
this.session.put(PROPERTY_CONFIG_PROPS, props);
+ return null;
}
}
Index: shell/config/src/main/java/org/apache/karaf/shell/config/ListCommand.java
===================================================================
--- shell/config/src/main/java/org/apache/karaf/shell/config/ListCommand.java (revision 1296251)
+++ shell/config/src/main/java/org/apache/karaf/shell/config/ListCommand.java (working copy)
@@ -19,10 +19,9 @@
import java.util.Dictionary;
import java.util.Enumeration;
-import org.osgi.service.cm.Configuration;
-import org.osgi.service.cm.ConfigurationAdmin;
import org.apache.felix.gogo.commands.Argument;
import org.apache.felix.gogo.commands.Command;
+import org.osgi.service.cm.Configuration;
@Command(scope = "config", name = "list", description = "Lists existing configurations.")
public class ListCommand extends ConfigCommandSupport {
@@ -30,8 +29,9 @@
@Argument(index = 0, name = "query", description = "Specify a LDAP query", required = false, multiValued = false)
String query;
- protected void doExecute(ConfigurationAdmin admin) throws Exception {
- Configuration[] configs = admin.listConfigurations(query);
+ @SuppressWarnings("rawtypes")
+ protected Object doExecute() throws Exception {
+ Configuration[] configs = configRepository.getConfigAdmin().listConfigurations(query);
if (configs != null) {
for (Configuration config : configs) {
System.out.println("----------------------------------------------------------------");
@@ -50,5 +50,6 @@
}
}
}
+ return null;
}
}
Index: shell/config/src/main/java/org/apache/karaf/shell/config/PropAppendCommand.java
===================================================================
--- shell/config/src/main/java/org/apache/karaf/shell/config/PropAppendCommand.java (revision 1296251)
+++ shell/config/src/main/java/org/apache/karaf/shell/config/PropAppendCommand.java (working copy)
@@ -17,13 +17,14 @@
package org.apache.karaf.shell.config;
import java.util.Dictionary;
+
import org.apache.felix.gogo.commands.Argument;
import org.apache.felix.gogo.commands.Command;
/**
* Appends a value to the current property value.
*/
-@Command(scope = "config", name = "propappend", description = "Appends the given value to an existing property or creates the property with the specified name and value.")
+@Command(scope = "config", name = "append-property", description = "Appends the given value to an existing property or creates the property with the specified name and value.")
public class PropAppendCommand extends ConfigPropertyCommandSupport {
@Argument(index = 0, name = "name", description = "The name of the property", required = true, multiValued = false)
@@ -32,6 +33,7 @@
@Argument(index = 1, name = "value", description = "The value to append to the property", required = true, multiValued = false)
String value;
+ @SuppressWarnings({"unchecked", "rawtypes"})
@Override
public void propertyAction(Dictionary props) {
final Object currentValue = props.get(prop);
Index: shell/config/src/main/java/org/apache/karaf/shell/config/PropDelCommand.java
===================================================================
--- shell/config/src/main/java/org/apache/karaf/shell/config/PropDelCommand.java (revision 1296251)
+++ shell/config/src/main/java/org/apache/karaf/shell/config/PropDelCommand.java (working copy)
@@ -17,15 +17,17 @@
package org.apache.karaf.shell.config;
import java.util.Dictionary;
+
import org.apache.felix.gogo.commands.Argument;
import org.apache.felix.gogo.commands.Command;
-@Command(scope = "config", name = "propdel", description = "Deletes a property from configuration being edited.")
+@Command(scope = "config", name = "delete-property", description = "Deletes a property from the configuration being edited.")
public class PropDelCommand extends ConfigPropertyCommandSupport {
@Argument(index = 0, name = "property", description = "The name of the property to delete", required = true, multiValued = false)
String prop;
+ @SuppressWarnings("rawtypes")
@Override
public void propertyAction(Dictionary props) {
props.remove(prop);
Index: shell/config/src/main/java/org/apache/karaf/shell/config/PropListCommand.java
===================================================================
--- shell/config/src/main/java/org/apache/karaf/shell/config/PropListCommand.java (revision 1296251)
+++ shell/config/src/main/java/org/apache/karaf/shell/config/PropListCommand.java (working copy)
@@ -18,11 +18,14 @@
import java.util.Dictionary;
import java.util.Enumeration;
+
import org.apache.felix.gogo.commands.Command;
-@Command(scope = "config", name = "proplist", description = "Lists properties from the currently edited configuration.")
+
+@Command(scope = "config", name = "list-property", description = "Lists properties from the currently edited configuration.")
public class PropListCommand extends ConfigPropertyCommandSupport {
+ @SuppressWarnings("rawtypes")
@Override
public void propertyAction(Dictionary props) {
for (Enumeration e = props.keys(); e.hasMoreElements(); ) {
Index: shell/config/src/main/java/org/apache/karaf/shell/config/PropSetCommand.java
===================================================================
--- shell/config/src/main/java/org/apache/karaf/shell/config/PropSetCommand.java (revision 1296251)
+++ shell/config/src/main/java/org/apache/karaf/shell/config/PropSetCommand.java (working copy)
@@ -20,9 +20,8 @@
import org.apache.felix.gogo.commands.Argument;
import org.apache.felix.gogo.commands.Command;
-import org.osgi.service.cm.ConfigurationAdmin;
-@Command(scope = "config", name = "propset", description = "Sets a property in the currently edited configuration.")
+@Command(scope = "config", name = "set-property", description = "Sets a property in the currently edited configuration.")
public class PropSetCommand extends ConfigPropertyCommandSupport {
@Argument(index = 0, name = "property", description = "The name of the property to set", required = true, multiValued = false)
@@ -31,6 +30,7 @@
@Argument(index = 1, name = "value", description = "The value of the property", required = true, multiValued = false)
String value;
+ @SuppressWarnings({"unchecked", "rawtypes"})
@Override
public void propertyAction(Dictionary props) {
props.put(prop, value);
Index: shell/config/src/main/java/org/apache/karaf/shell/config/UpdateCommand.java
===================================================================
--- shell/config/src/main/java/org/apache/karaf/shell/config/UpdateCommand.java (revision 1296251)
+++ shell/config/src/main/java/org/apache/karaf/shell/config/UpdateCommand.java (working copy)
@@ -17,26 +17,28 @@
package org.apache.karaf.shell.config;
import java.util.Dictionary;
+
import org.apache.felix.gogo.commands.Command;
import org.apache.felix.gogo.commands.Option;
-import org.osgi.service.cm.ConfigurationAdmin;
@Command(scope = "config", name = "update", description = "Saves and propagates changes from the configuration being edited.")
public class UpdateCommand extends ConfigCommandSupport {
- @Option(name = "-b", aliases = {"--bypass-storage"}, multiValued = false, required = false, description = "Do not store the configuration in a properties file, but feed it directly to ConfigAdmin")
+ @Option(name = "-b", aliases = { "--bypass-storage" }, multiValued = false, required = false, description = "Do not store the configuration in a properties file, but feed it directly to ConfigAdmin")
protected boolean bypassStorage;
- protected void doExecute(ConfigurationAdmin admin) throws Exception {
+ @SuppressWarnings("rawtypes")
+ protected Object doExecute() throws Exception {
Dictionary props = getEditedProps();
if (props == null) {
System.err.println("No configuration is being edited--run the edit command first");
- return;
+ return null;
}
String pid = (String) this.session.get(PROPERTY_CONFIG_PID);
- update(admin, pid, props, bypassStorage);
+ this.configRepository.update(pid, props, bypassStorage);
this.session.put(PROPERTY_CONFIG_PID, null);
this.session.put(PROPERTY_CONFIG_PROPS, null);
+ return null;
}
}
Index: shell/config/src/main/resources/OSGI-INF/blueprint/shell-config.xml
===================================================================
--- shell/config/src/main/resources/OSGI-INF/blueprint/shell-config.xml (revision 1296251)
+++ shell/config/src/main/resources/OSGI-INF/blueprint/shell-config.xml (working copy)
@@ -24,11 +24,13 @@
-
+
+
+
-
+
@@ -37,7 +39,7 @@
-
+
@@ -45,53 +47,60 @@
-
+
+
+
+
+
+
-
+
-
+
-
-
-
-
+
+
+
+
+
+
-
+
-
+
-
+
-
+
-
+
@@ -105,7 +114,16 @@
+
+
+
+
+
+
+
+
+
Index: shell/config/src/test/java/org/apache/karaf/shell/config/EditCommandTest.java
===================================================================
--- shell/config/src/test/java/org/apache/karaf/shell/config/EditCommandTest.java (revision 1296251)
+++ shell/config/src/test/java/org/apache/karaf/shell/config/EditCommandTest.java (working copy)
@@ -16,21 +16,21 @@
*/
package org.apache.karaf.shell.config;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+
import java.util.Dictionary;
import java.util.Properties;
import junit.framework.TestCase;
+
import org.apache.felix.service.command.CommandSession;
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 static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
-
/**
* Test cases for {@link EditCommand}
*/
@@ -42,21 +42,19 @@
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).anyTimes();
-
admin = createMock(ConfigurationAdmin.class);
- expect(context.getService(reference)).andReturn(admin);
- expect(context.ungetService(reference)).andReturn(Boolean.TRUE);
-
+ command.setConfigRepository(new ConfigRepository(null, admin, null));
+ expect(context.getBundle(0)).andReturn(null).anyTimes();
+
replay(context);
session = new MockCommandSession();
@@ -82,7 +80,7 @@
props, session.get(ConfigCommandSupport.PROPERTY_CONFIG_PROPS));
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings("rawtypes")
public void testExecuteOnNewPid() throws Exception {
Configuration config = createMock(Configuration.class);
expect(admin.getConfiguration(PID, null)).andReturn(config);
Index: shell/config/src/test/java/org/apache/karaf/shell/config/UpdateCommandTest.java
===================================================================
--- shell/config/src/test/java/org/apache/karaf/shell/config/UpdateCommandTest.java (revision 1296251)
+++ shell/config/src/test/java/org/apache/karaf/shell/config/UpdateCommandTest.java (working copy)
@@ -17,20 +17,20 @@
package org.apache.karaf.shell.config;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+
import java.util.Properties;
import junit.framework.TestCase;
+
import org.apache.felix.service.command.CommandSession;
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 static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
-
/**
* Test cases for {@link EditCommand}
*/
@@ -50,12 +50,9 @@
context = EasyMock.createMock(BundleContext.class);
command.setBundleContext(context);
- ServiceReference reference = createMock(ServiceReference.class);
- expect(context.getServiceReference(ConfigurationAdmin.class.getName())).andReturn(reference).anyTimes();
-
admin = createMock(ConfigurationAdmin.class);
- expect(context.getService(reference)).andReturn(admin);
- expect(context.ungetService(reference)).andReturn(Boolean.TRUE);
+ command.setConfigRepository(new ConfigRepository(null, admin, null));
+ expect(context.getBundle(0)).andReturn(null).anyTimes();
replay(context);