Index: src/test/java/org/apache/kitty/test/ClientTest1.groovy =================================================================== --- src/test/java/org/apache/kitty/test/ClientTest1.groovy (revision ) +++ src/test/java/org/apache/kitty/test/ClientTest1.groovy (revision ) @@ -0,0 +1,64 @@ +/* + * 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.kitty.test + +import org.apache.kitty.client.Client +import org.junit.Test +import groovy.mock.interceptor.MockFor +import javax.management.ObjectName +import org.apache.kitty.exceptions.DomainIsNoneException +import javax.management.MBeanServerConnection; +import static org.junit.Assert.* + +class ClientTest1 { + @Test + public void shouldListNamesForDomain() throws Exception { + Client client = new Client() + + // Mock the remote connection + def mockForRemote = new MockFor(MBeanServerConnection) + mockForRemote.ignore.asBoolean { + true + } + mockForRemote.ignore.getDomains { + ['a_domain'] + } + + // Prepare the names list + mockForRemote.ignore.queryNames { a,b -> + def set = new HashSet() + set.add(new ObjectName("a_domain", "test1", "1")) + set.add(new ObjectName("a_domain", "test2", "2")) + set.add(new ObjectName("a_domain", "test3", "3")) + return set + } + + def theProxyInstance = mockForRemote.proxyInstance() + + // Verify "ls" is working + mockForRemote.use { + client.remote = theProxyInstance + client.setDomain('a_domain') + try { + client.ls() + } catch(DomainIsNoneException dine) { + fail("DomainIsNoneException thrown") + } + } + } +} \ No newline at end of file Index: src/main/java/org/apache/kitty/client/Client.groovy =================================================================== --- src/main/java/org/apache/kitty/client/Client.groovy (revision 1103602) +++ src/main/java/org/apache/kitty/client/Client.groovy (revision ) @@ -151,7 +151,7 @@ if (this.domain) { def objectName = this.domain + ":" def objectName2 - if (objectName.length() > 0) { + if (mBeansPath.size() > 0) { objectName += ",".concat(this.mBeansPath.join()) // make sure mBeansPath is a list, otherwise remove the .join() command objectName2 = objectName + "," } @@ -159,14 +159,16 @@ objectName2 = objectName } def pool = new ObjectName(objectName2 + "*") - def paths = {} + def paths = [] println objectName println "-----" + + // List the MBeans names def qNames = this.remote.queryNames(pool, null) try { qNames.each { mbean -> def p = mbean.toString().split(objectName2)[1].split(',')[0] - paths[p] = p + paths << p } paths.each { p -> println "M " + p } } @@ -174,7 +176,7 @@ throw new DomainIsNoneException() } - try { + try { mbean = this.remote.getMBeanInfo( new ObjectName(objectName)) for (attr in mbean.getAttributes()) { def readable @@ -205,7 +207,7 @@ } } catch(Exception e) { - // + // ObjectName not found } try { @@ -219,7 +221,7 @@ } } catch(Exception e) { - throw new DomainIsNoneException() + // ObjectName not found } } }