You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by at...@apache.org on 2010/01/08 21:16:30 UTC

svn commit: r897317 - in /incubator/aries/trunk/jmx/jmx-core/src: main/java/org/apache/aries/jmx/cm/ test/java/org/apache/aries/jmx/cm/

Author: atk
Date: Fri Jan  8 20:16:28 2010
New Revision: 897317

URL: http://svn.apache.org/viewvc?rev=897317&view=rev
Log:
ARIES-36 Implement ConfigurationAdmin MBean

Added:
    incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/cm/
    incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/cm/ConfigurationAdmin.java   (with props)
    incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/cm/ConfigurationAdminMBeanHandler.java   (with props)
    incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/cm/
    incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/cm/ConfigurationAdminMBeanHandlerTest.java   (with props)
    incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/cm/ConfigurationAdminTest.java   (with props)

Added: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/cm/ConfigurationAdmin.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/cm/ConfigurationAdmin.java?rev=897317&view=auto
==============================================================================
--- incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/cm/ConfigurationAdmin.java (added)
+++ incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/cm/ConfigurationAdmin.java Fri Jan  8 20:16:28 2010
@@ -0,0 +1,236 @@
+/**
+ *  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.aries.jmx.cm;
+
+import static org.osgi.jmx.JmxConstants.*;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.List;
+
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.TabularData;
+import javax.management.openmbean.TabularDataSupport;
+
+import org.apache.aries.jmx.codec.PropertyData;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.jmx.service.cm.ConfigurationAdminMBean;
+import org.osgi.service.cm.Configuration;
+
+/**
+ * Implementation of <code>ConfigurationAdminMBean</code> 
+ *
+ * @version $Rev$ $Date$
+ */
+public class ConfigurationAdmin implements ConfigurationAdminMBean {
+
+    private org.osgi.service.cm.ConfigurationAdmin configurationAdmin;
+    
+    /**
+     * Constructs a ConfigurationAdmin implementation
+     * @param configurationAdmin instance of org.osgi.service.cm.ConfigurationAdmin service
+     */
+    public ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin configurationAdmin) {
+        this.configurationAdmin = configurationAdmin;
+    }
+    
+    
+    /**
+     * @see org.osgi.jmx.service.cm.ConfigurationAdminMBean#createFactoryConfiguration(java.lang.String)
+     */
+    public String createFactoryConfiguration(String factoryPid) throws IOException {
+        return createFactoryConfiguration(factoryPid, null); 
+    }
+
+    /**
+     * @see org.osgi.jmx.service.cm.ConfigurationAdminMBean#createFactoryConfiguration(java.lang.String, java.lang.String)
+     */
+    public String createFactoryConfiguration(String factoryPid, String location) throws IOException {
+        if (factoryPid == null || factoryPid.length() < 1) {
+            throw new IllegalArgumentException("Argument factoryPid cannot be null or empty");
+        }
+        Configuration config = configurationAdmin.createFactoryConfiguration(factoryPid, location);
+        return config.getPid();
+    }
+
+    /**
+     * @see org.osgi.jmx.service.cm.ConfigurationAdminMBean#delete(java.lang.String)
+     */
+    public void delete(String pid) throws IOException {
+       delete(pid, null);
+    }
+
+    /**
+     * @see org.osgi.jmx.service.cm.ConfigurationAdminMBean#delete(java.lang.String, java.lang.String)
+     */
+    public void delete(String pid, String location) throws IOException {
+        if (pid == null || pid.length() < 1) {
+            throw new IllegalArgumentException("Argument pid cannot be null or empty");
+        }
+        Configuration config = configurationAdmin.getConfiguration(pid, location);
+        config.delete();
+    }
+
+    /**
+     * @see org.osgi.jmx.service.cm.ConfigurationAdminMBean#deleteConfigurations(java.lang.String)
+     */
+    public void deleteConfigurations(String filter) throws IOException {
+        if (filter == null || filter.length() < 1) {
+            throw new IllegalArgumentException("Argument filter cannot be null or empty");
+        }
+        Configuration[] configuations = null;
+        try {
+            configuations = configurationAdmin.listConfigurations(filter);
+        }
+        catch (InvalidSyntaxException e) {
+            throw new IllegalArgumentException("Invalid filter [" + filter + "] : " + e);
+        }
+        if (configuations != null) {
+            for (Configuration config : configuations) {
+                config.delete();
+            }
+        }
+    }
+
+    /**
+     * @see org.osgi.jmx.service.cm.ConfigurationAdminMBean#getBundleLocation(java.lang.String)
+     */
+    public String getBundleLocation(String pid) throws IOException {
+        if (pid == null || pid.length() < 1) {
+            throw new IllegalArgumentException("Argument pid cannot be null or empty");
+        }
+        Configuration config = configurationAdmin.getConfiguration(pid, null);
+        String bundleLocation = (config.getBundleLocation() == null) ? "Configuration is not yet bound to a bundle location" : config.getBundleLocation();
+        return bundleLocation;
+    }
+
+    /**
+     * @see org.osgi.jmx.service.cm.ConfigurationAdminMBean#getConfigurations(java.lang.String)
+     */
+    public String[][] getConfigurations(String filter) throws IOException {
+        if (filter == null || filter.length() < 1) {
+            throw new IllegalArgumentException("Argument filter cannot be null or empty");
+        }
+        List<String[]> result = new ArrayList<String[]>();
+        Configuration[] configurations = null;
+        try {
+            configurations = configurationAdmin.listConfigurations(filter);
+        }
+        catch (InvalidSyntaxException e) {
+            throw new IllegalArgumentException("Invalid filter [" + filter + "] : " + e);
+        }
+        if (configurations != null) {
+            for (Configuration config : configurations) {
+                result.add(new String[] { config.getPid(), config.getBundleLocation() });
+            }
+        }
+        return result.toArray(new String[result.size()][]);
+    }
+
+    /**
+     * @see org.osgi.jmx.service.cm.ConfigurationAdminMBean#getFactoryPid(java.lang.String)
+     */
+    public String getFactoryPid(String pid) throws IOException {
+       return getFactoryPid(pid, null);
+    }
+
+    /**
+     * @see org.osgi.jmx.service.cm.ConfigurationAdminMBean#getFactoryPid(java.lang.String, java.lang.String)
+     */
+    public String getFactoryPid(String pid, String location) throws IOException {
+        if (pid == null || pid.length() < 1) {
+            throw new IllegalArgumentException("Argument pid cannot be null or empty");
+        }
+        Configuration config = configurationAdmin.getConfiguration(pid, location);
+        return config.getFactoryPid();
+    }
+
+    /**
+     * @see org.osgi.jmx.service.cm.ConfigurationAdminMBean#getProperties(java.lang.String)
+     */
+    public TabularData getProperties(String pid) throws IOException {
+       return getProperties(pid, null);
+    }
+
+    /**
+     * @see org.osgi.jmx.service.cm.ConfigurationAdminMBean#getProperties(java.lang.String, java.lang.String)
+     */
+    @SuppressWarnings("unchecked")
+    public TabularData getProperties(String pid, String location) throws IOException {
+        if (pid == null || pid.length() < 1) {
+            throw new IllegalArgumentException("Argument pid cannot be null or empty");
+        }
+        TabularData propertiesTable = new TabularDataSupport(PROPERTIES_TYPE);
+        Configuration config = configurationAdmin.getConfiguration(pid, location);
+        Dictionary<String, Object> properties = config.getProperties();
+        if (properties != null) {
+            Enumeration<String> keys = properties.keys();
+            while (keys.hasMoreElements()) {
+                String key = keys.nextElement();
+                propertiesTable.put(PropertyData.newInstance(key, properties.get(key)).toCompositeData());
+            }
+        }
+        return propertiesTable;
+    }
+
+    /**
+     * @see org.osgi.jmx.service.cm.ConfigurationAdminMBean#setBundleLocation(java.lang.String, java.lang.String)
+     */
+    public void setBundleLocation(String pid, String location) throws IOException {
+        if (pid == null || pid.length() < 1) {
+            throw new IllegalArgumentException("Argument factoryPid cannot be null or empty");
+        }
+        Configuration config = configurationAdmin.getConfiguration(pid, null);
+        config.setBundleLocation(location);
+    }
+
+    /**
+     * @see org.osgi.jmx.service.cm.ConfigurationAdminMBean#update(java.lang.String, javax.management.openmbean.TabularData)
+     */
+    public void update(String pid, TabularData configurationTable) throws IOException {
+        update(pid, null, configurationTable);
+    }
+
+    /**
+     * @see org.osgi.jmx.service.cm.ConfigurationAdminMBean#update(java.lang.String, java.lang.String, javax.management.openmbean.TabularData)
+     */
+    @SuppressWarnings("unchecked")
+    public void update(String pid, String location, TabularData configurationTable) throws IOException {
+        if (pid == null || pid.length() < 1) {
+            throw new IllegalArgumentException("Argument pid cannot be null or empty");
+        }
+        if (configurationTable == null) {
+            throw new IllegalArgumentException("Argument properties cannot be null");
+        }
+        if (!PROPERTIES_TYPE.equals(configurationTable.getTabularType())) {
+            throw new IllegalArgumentException("Invalid TabularType ["  + configurationTable.getTabularType() + "]");
+        }
+        Dictionary<String, Object> configurationProperties = new Hashtable<String, Object>();
+        Collection<CompositeData> compositeData = (Collection<CompositeData>) configurationTable.values();
+        for (CompositeData row: compositeData) {
+            PropertyData<? extends Class> propertyData = PropertyData.from(row);
+            configurationProperties.put(propertyData.getKey(), propertyData.getValue());
+        }
+        Configuration config = configurationAdmin.getConfiguration(pid, location);
+        config.update(configurationProperties);
+    }
+
+}

Propchange: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/cm/ConfigurationAdmin.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/cm/ConfigurationAdmin.java
------------------------------------------------------------------------------
    svn:keywords = Revision Date

Added: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/cm/ConfigurationAdminMBeanHandler.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/cm/ConfigurationAdminMBeanHandler.java?rev=897317&view=auto
==============================================================================
--- incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/cm/ConfigurationAdminMBeanHandler.java (added)
+++ incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/cm/ConfigurationAdminMBeanHandler.java Fri Jan  8 20:16:28 2010
@@ -0,0 +1,74 @@
+/**
+ *  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.aries.jmx.cm;
+
+import javax.management.NotCompliantMBeanException;
+import javax.management.StandardMBean;
+
+import org.apache.aries.jmx.AbstractCompendiumHandler;
+import org.apache.aries.jmx.Logger;
+import org.apache.aries.jmx.MBeanHandler;
+import org.apache.aries.jmx.agent.JMXAgentContext;
+import org.osgi.jmx.service.cm.ConfigurationAdminMBean;
+import org.osgi.service.log.LogService;
+
+/**
+ * <p>
+ * Implementation of <code>MBeanHandler</code> which manages the <code>ConfigurationAdminMBean</code> implementation
+ * 
+ * @see MBeanHandler </p>
+ * 
+ * @version $Rev$ $Date$
+ */
+public class ConfigurationAdminMBeanHandler extends AbstractCompendiumHandler {
+
+    /**
+     * Constructs new ConfigurationAdminMBeanHandler instance
+     * 
+     * @param agentContext
+     *            JMXAgentContext instance
+     */
+    public ConfigurationAdminMBeanHandler(JMXAgentContext agentContext) {
+        super(agentContext, "org.osgi.service.cm.ConfigurationAdmin");
+    }
+
+    /**
+     * @see org.apache.aries.jmx.AbstractCompendiumHandler#constructInjectMBean(java.lang.Object)
+     */
+    @Override
+    protected StandardMBean constructInjectMBean(Object targetService) {
+        ConfigurationAdminMBean caMBean = new org.apache.aries.jmx.cm.ConfigurationAdmin(
+                (org.osgi.service.cm.ConfigurationAdmin) targetService);
+        StandardMBean mbean = null;
+        try {
+            mbean = new StandardMBean(caMBean, ConfigurationAdminMBean.class);
+        } catch (NotCompliantMBeanException e) {
+            Logger logger = agentContext.getLogger();
+            logger.log(LogService.LOG_ERROR, "Failed to instantiate MBean for "
+                    + ConfigurationAdminMBean.class.getName(), e);
+        }
+        return mbean;
+    }
+
+    /**
+     * @see org.apache.aries.jmx.MBeanHandler#getName()
+     */
+    public String getName() {
+        return ConfigurationAdminMBean.OBJECTNAME;
+    }
+
+}

Propchange: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/cm/ConfigurationAdminMBeanHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/cm/ConfigurationAdminMBeanHandler.java
------------------------------------------------------------------------------
    svn:keywords = Revision Date

Added: incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/cm/ConfigurationAdminMBeanHandlerTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/cm/ConfigurationAdminMBeanHandlerTest.java?rev=897317&view=auto
==============================================================================
--- incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/cm/ConfigurationAdminMBeanHandlerTest.java (added)
+++ incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/cm/ConfigurationAdminMBeanHandlerTest.java Fri Jan  8 20:16:28 2010
@@ -0,0 +1,52 @@
+/**
+ *  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.aries.jmx.cm;
+
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.mock;
+
+import javax.management.StandardMBean;
+
+import org.apache.aries.jmx.Logger;
+import org.apache.aries.jmx.agent.JMXAgentContext;
+import org.junit.Test;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+/**
+ * 
+ *
+ * @version $Rev$ $Date$
+ */
+public class ConfigurationAdminMBeanHandlerTest {
+
+    
+    @Test
+    public void testConstructInjectMBean() {
+        
+        BundleContext bundleContext = mock(BundleContext.class);
+        Logger agentLogger = mock(Logger.class);   
+        JMXAgentContext agentContext = new JMXAgentContext(bundleContext, null, agentLogger);
+        ConfigurationAdmin cAdmin = mock(ConfigurationAdmin.class);
+        
+        ConfigurationAdminMBeanHandler handler = new ConfigurationAdminMBeanHandler(agentContext);
+        StandardMBean mbean = handler.constructInjectMBean(cAdmin);
+        assertNotNull(mbean);
+        
+    }
+
+}

Propchange: incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/cm/ConfigurationAdminMBeanHandlerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/cm/ConfigurationAdminMBeanHandlerTest.java
------------------------------------------------------------------------------
    svn:keywords = Revision Date

Added: incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/cm/ConfigurationAdminTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/cm/ConfigurationAdminTest.java?rev=897317&view=auto
==============================================================================
--- incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/cm/ConfigurationAdminTest.java (added)
+++ incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/cm/ConfigurationAdminTest.java Fri Jan  8 20:16:28 2010
@@ -0,0 +1,247 @@
+/**
+ *  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.aries.jmx.cm;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.osgi.jmx.JmxConstants.PROPERTIES_TYPE;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import javax.management.openmbean.TabularData;
+import javax.management.openmbean.TabularDataSupport;
+
+import org.apache.aries.jmx.codec.PropertyData;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.osgi.framework.Constants;
+import org.osgi.service.cm.Configuration;
+
+/**
+ * 
+ *
+ * @version $Rev$ $Date$
+ */
+public class ConfigurationAdminTest {
+
+   
+    @Test
+    public void testCreateFactoryConfiguration() throws Exception {
+        
+        org.osgi.service.cm.ConfigurationAdmin admin = mock(org.osgi.service.cm.ConfigurationAdmin.class);
+        String fpid = "org.apache.aries.jmx.mock.factory";
+        Configuration config = mock(Configuration.class);
+        
+        when(admin.createFactoryConfiguration(eq(fpid), anyString())).thenReturn(config);
+        when(config.getPid()).thenReturn(fpid + "-1260133982371-0");
+        
+        ConfigurationAdmin mbean = new ConfigurationAdmin(admin);
+        assertEquals(fpid + "-1260133982371-0", mbean.createFactoryConfiguration(fpid));
+        assertEquals(fpid + "-1260133982371-0", mbean.createFactoryConfiguration(fpid, "/bundlex"));
+        
+    }
+
+   
+    @Test
+    public void testDelete() throws Exception {
+        
+        org.osgi.service.cm.ConfigurationAdmin admin = mock(org.osgi.service.cm.ConfigurationAdmin.class);
+        String pid = "org.apache.aries.jmx.mock";
+        Configuration config = mock(Configuration.class);
+        
+        when(admin.getConfiguration(pid, null)).thenReturn(config);
+        
+        ConfigurationAdmin mbean = new ConfigurationAdmin(admin);
+        mbean.delete(pid);
+        verify(config).delete();
+        
+        reset(config);
+        
+        when(admin.getConfiguration(pid, "location")).thenReturn(config);
+        mbean.delete(pid, "location");
+        verify(config).delete();
+        
+    }
+
+  
+    @Test
+    public void testDeleteConfigurations() throws Exception {
+
+        org.osgi.service.cm.ConfigurationAdmin admin = mock(org.osgi.service.cm.ConfigurationAdmin.class);
+        String filter = "(" + Constants.SERVICE_PID + "=org.apache.aries.jmx.mock)";
+        
+        Configuration a = mock(Configuration.class);
+        Configuration b = mock(Configuration.class);
+        
+        when(admin.listConfigurations(filter)).thenReturn(new Configuration[] { a, b });
+        
+        ConfigurationAdmin mbean = new ConfigurationAdmin(admin);
+        mbean.deleteConfigurations(filter);
+
+        verify(a).delete();
+        verify(b).delete();
+        
+    }
+
+   
+    @Test
+    public void testGetBundleLocation() throws Exception {
+
+        org.osgi.service.cm.ConfigurationAdmin admin = mock(org.osgi.service.cm.ConfigurationAdmin.class);
+        String pid = "org.apache.aries.jmx.mock";
+        Configuration config = mock(Configuration.class);
+        
+        when(admin.getConfiguration(pid, null)).thenReturn(config);
+        when(config.getBundleLocation()).thenReturn("/location");
+        ConfigurationAdmin mbean = new ConfigurationAdmin(admin);
+        
+        assertEquals("/location", mbean.getBundleLocation(pid));
+        
+    }
+
+ 
+    @Test
+    public void testGetConfigurations() throws Exception {
+     
+        org.osgi.service.cm.ConfigurationAdmin admin = mock(org.osgi.service.cm.ConfigurationAdmin.class);
+        String factoryPid = "org.apache.aries.jmx.factory.mock";
+        String filter = "(" + org.osgi.service.cm.ConfigurationAdmin.SERVICE_FACTORYPID + "=org.apache.aries.jmx.factory.mock)";
+        String location = "../location";
+        
+        Configuration a = mock(Configuration.class);
+        when(a.getPid()).thenReturn(factoryPid + "-2160133952674-0");
+        when(a.getBundleLocation()).thenReturn(location);
+        Configuration b = mock(Configuration.class);
+        when(b.getPid()).thenReturn(factoryPid + "-1260133982371-1");
+        when(b.getBundleLocation()).thenReturn(location);
+        
+        when(admin.listConfigurations(filter)).thenReturn(new Configuration[] { a, b});
+        
+        ConfigurationAdmin mbean = new ConfigurationAdmin(admin);
+        String[][] result = mbean.getConfigurations(filter);
+        assertEquals(2, result.length);
+        assertArrayEquals(new String[]{ factoryPid + "-2160133952674-0", location }, result[0] );
+        assertArrayEquals(new String[]{ factoryPid + "-1260133982371-1", location }, result[1] );
+        
+    }
+
+   
+    @Test
+    public void testGetFactoryPid() throws Exception {
+
+        org.osgi.service.cm.ConfigurationAdmin admin = mock(org.osgi.service.cm.ConfigurationAdmin.class);
+        String factoryPid = "org.apache.aries.jmx.factory.mock";
+        
+        Configuration config = mock(Configuration.class);
+        when(admin.getConfiguration(eq(factoryPid  + "-1260133982371-0"), anyString())).thenReturn(config);
+        when(config.getFactoryPid()).thenReturn(factoryPid);
+        
+        ConfigurationAdmin mbean = new ConfigurationAdmin(admin);
+        assertEquals(factoryPid, mbean.getFactoryPid(factoryPid  + "-1260133982371-0"));
+        assertEquals(factoryPid, mbean.getFactoryPid(factoryPid  + "-1260133982371-0", "location"));
+        
+    }
+
+    
+    @Test
+    public void testGetProperties() throws Exception {
+
+        org.osgi.service.cm.ConfigurationAdmin admin = mock(org.osgi.service.cm.ConfigurationAdmin.class);
+        String pid = "org.apache.aries.jmx.mock";
+        Configuration config = mock(Configuration.class);
+        
+        Dictionary<String, Object> props = new Hashtable<String, Object>();
+        props.put("one", "value");
+        props.put("two", 2);
+        when(admin.getConfiguration(eq(pid), anyString())).thenReturn(config);
+        when(config.getProperties()).thenReturn(props);
+        
+        ConfigurationAdmin mbean = new ConfigurationAdmin(admin);
+        
+        TabularData properties = mbean.getProperties(pid, null);
+        assertNotNull(properties);
+        assertEquals(PROPERTIES_TYPE, properties.getTabularType());
+        assertEquals(2, properties.values().size());
+        PropertyData<? extends Object> oneData = PropertyData.from(properties.get(new Object[]{ "one"}));
+        assertEquals("value", oneData.getValue());
+        PropertyData<? extends Object> twoData = PropertyData.from(properties.get(new Object[]{ "two"}));
+        assertEquals(2, twoData.getValue());
+        assertEquals("2", twoData.getEncodedValue());
+        
+    }
+
+   
+
+    @Test
+    public void testSetBundleLocation() throws Exception {
+
+        org.osgi.service.cm.ConfigurationAdmin admin = mock(org.osgi.service.cm.ConfigurationAdmin.class);
+        String pid = "org.apache.aries.jmx.mock";
+        
+        Configuration config = mock(Configuration.class);
+        when(admin.getConfiguration(pid, null)).thenReturn(config);
+        
+        ConfigurationAdmin mbean = new ConfigurationAdmin(admin);
+        mbean.setBundleLocation(pid, "file:/newlocation");
+        
+        ArgumentCaptor<String> locationArgument = ArgumentCaptor.forClass(String.class);
+        verify(config).setBundleLocation(locationArgument.capture());
+        
+        assertEquals("file:/newlocation", locationArgument.getValue());
+        
+    }
+
+   
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testUpdateTabularData() throws Exception {
+       
+        TabularData data = new TabularDataSupport(PROPERTIES_TYPE);
+        PropertyData<String> p1 = PropertyData.newInstance("one", "first");
+        data.put(p1.toCompositeData());
+        PropertyData<Integer> p2 = PropertyData.newInstance("two", 3);
+        data.put(p2.toCompositeData());
+        
+        org.osgi.service.cm.ConfigurationAdmin admin = mock(org.osgi.service.cm.ConfigurationAdmin.class);
+        String pid = "org.apache.aries.jmx.mock";
+        
+        Configuration config = mock(Configuration.class);
+        when(admin.getConfiguration(pid, null)).thenReturn(config);
+        
+        ConfigurationAdmin mbean = new ConfigurationAdmin(admin);
+        mbean.update(pid, null, data);
+        
+        ArgumentCaptor<Dictionary> props = ArgumentCaptor.forClass(Dictionary.class);
+        verify(config).update(props.capture());
+        
+        Dictionary configProperties = props.getValue();
+        assertEquals("first", configProperties.get("one"));
+        assertEquals(3, configProperties.get("two"));
+        
+    }
+
+  
+
+}

Propchange: incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/cm/ConfigurationAdminTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/cm/ConfigurationAdminTest.java
------------------------------------------------------------------------------
    svn:keywords = Revision Date