1   /*
2    * Copyright 2004-2005 Alvaro Gonzalez de Paz (kortsoft)
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License")
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package kortsoft.kmx.deployer;
17  
18  import java.io.File;
19  import java.util.Hashtable;
20  
21  import javax.management.MBeanServer;
22  import javax.management.ObjectName;
23  
24  import kortsoft.kmx.jmx.JmxConfig;
25  
26  import org.jmock.Mock;
27  import org.jmock.MockObjectTestCase;
28  
29  /***
30   * <a href="JarDeployerTest.java.html"><b><i>View Source</i></b></a>
31   *
32   * @author  Alvaro
33   * @version $Revision: 1.1 $
34   *
35   */
36  public class JarDeployerTest extends MockObjectTestCase {
37      
38      public void testDeployElement() throws Exception{
39          File file=new File("test.jar");
40          file.createNewFile();
41          Hashtable<String,String> table=new Hashtable<String,String>(2);
42          table.put(JarDeployer.FILENAME_JMX_PROPERTY,"test.jar");
43          table.put(JarDeployer.TYPE_JMX_PROPERTY,"jar");
44          ObjectName name = 
45              new ObjectName(JmxConfig.getClassLoaderDomainName(),table);
46          JarDeployer jarD=new JarDeployer();
47          Mock mockMBeanServer=mock(MBeanServer.class);
48          jarD.setMBeanServer((MBeanServer)mockMBeanServer.proxy());
49          mockMBeanServer.expects(once()).method("registerMBean")
50              .with(isA(ClassLoader.class),eq(name));
51          jarD.deployElement(file);
52      }
53  }