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") + } + } + } +} 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,30 +151,32 @@ if (this.domain) { def objectName = this.domain + ":" def objectName2 - if (objectName.length() > 0) { - objectName += ",".concat(this.mBeansPath.join()) // make sure mBeansPath is a list, otherwise remove the .join() command + if (mBeansPath.size() > 0) { + objectName += this.mBeansPath.join(',') // make sure mBeansPath is a list, otherwise remove the .join() command objectName2 = objectName + "," } else { 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.each { p -> println "M " + p } + paths.each { p, dummy -> println "M " + p } } catch(Exception e) { 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 } } } @@ -239,7 +241,7 @@ } else { for (p in path.split(',')) { - this.mBeansPath.append(p) + this.mBeansPath << p } } } @@ -397,7 +399,7 @@ public pwd() { def name if (this.domain) { - name = this.domain + ":" + ",".concat(this.mBeansPath.join()) // may need to change this + name = this.domain + ":" + this.mBeansPath.join(',') } return name