Index: src/test/java/org/apache/kitty/client/ClientTest.groovy =================================================================== --- src/test/java/org/apache/kitty/client/ClientTest.groovy (revision 0) +++ src/test/java/org/apache/kitty/client/ClientTest.groovy (revision 0) @@ -0,0 +1,68 @@ +/* + * 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.client; + +import static org.junit.Assert.*; +import org.apache.kitty.client.Client +import javax.management.MBeanServerConnection +import org.junit.Test; + +class ClientTest { + + @Test + public void should_correctly_set_a_new_domain_value() { + def mbean_server_connection = { + ['a', 'b', 'c']as String[] + } as MBeanServerConnection + Client client = new Client() + client.remote = mbean_server_connection + + assert client.domain == null + assert client.mBeansPath == null + + client.setDomain 'a' + + assert client.domain == 'a' + assert client.mBeansPath == [] + } + + @Test + public void should_keep_actual_domain_when_trying_to_set_it_with_invalid_value() throws Exception { + def mbean_server_connection = { + ['a', 'b', 'c']as String[] + } as MBeanServerConnection + Client client = new Client() + client.remote = mbean_server_connection + client.domain = 'a' + client.mBeansPath = [] + + client.setDomain 'd' + + assert client.domain == 'a' + } + + @Test + public void should_create_an_object_name_with_just_a_domain() throws Exception { + Client client = new Client() + client.remote = 'remote' + String domain = 'a_domain' + String objectName = client.composeObjectName domain + + assert objectName == "a_domain:*" + } +} Index: src/main/java/org/apache/kitty/CmdShell.groovy =================================================================== --- src/main/java/org/apache/kitty/CmdShell.groovy (revision 1124440) +++ src/main/java/org/apache/kitty/CmdShell.groovy (working copy) @@ -369,7 +369,6 @@ println "Setting the domain to $domain..." if (remote) { getClient().setDomain(domain) - println "The domain is set to $domain" } else { println Constants.ERROR_NOT_CONNECTED Index: src/main/java/org/apache/kitty/client/Client.groovy =================================================================== --- src/main/java/org/apache/kitty/client/Client.groovy (revision 1124440) +++ src/main/java/org/apache/kitty/client/Client.groovy (working copy) @@ -133,6 +133,7 @@ if (it.equals(_domain)) { this.domain = _domain this.mBeansPath = [] + println "The domain is set to $domain" return } } @@ -142,6 +143,10 @@ } } + def composeObjectName(String domain) { + "$domain:*" + } + /** * * @return @@ -149,16 +154,8 @@ public ls() { if (this.remote) { 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 - objectName2 = objectName + "," - } - else { - objectName2 = objectName - } - def pool = new ObjectName(objectName2 + "*") + def objectName = composeObjectName(this.domain) + def pool = new ObjectName(objectName) def paths = {} println objectName println "-----"