KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > ha > singleton > test > HASingletonControllerUnitTestCase


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2005, JBoss Inc., and individual contributors as indicated
4  * by the @authors tag. See the copyright.txt in the distribution for a
5  * full listing of individual contributors.
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this software; if not, write to the Free
19  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21  */

22 package org.jboss.test.ha.singleton.test;
23
24 import javax.management.ObjectName JavaDoc;
25
26 import junit.framework.TestCase;
27
28 import org.jboss.test.ha.singleton.HASingletonControllerTester;
29
30 /**
31  * HASingletonController tests
32  *
33  * @author Ivelin Ivanov <ivelin@jboss.org>
34  * @version $Revision: 39596 $
35  */

36 public class HASingletonControllerUnitTestCase extends TestCase
37 {
38    private HASingletonControllerTester singletonControllerTester = null;
39
40    public HASingletonControllerUnitTestCase(String JavaDoc name)
41    {
42       super(name);
43    }
44
45    public void setUp()
46    {
47       singletonControllerTester = new HASingletonControllerTester();
48    }
49
50
51    public void tearDown()
52    {
53       singletonControllerTester = null;
54    }
55
56    public void testSetValidTargetName() throws Exception JavaDoc
57    {
58       ObjectName JavaDoc someSingletonService = new ObjectName JavaDoc("jboss:service=HASingletonMBeanExample");
59       singletonControllerTester.setTargetName(someSingletonService);
60
61       assertEquals("setTargetName() failed", singletonControllerTester.getTargetName(), someSingletonService);
62    }
63
64    public void testSetTargetStartMethod()
65    {
66       String JavaDoc someMethod = "startTheSingleton";
67       singletonControllerTester.setTargetStartMethod(someMethod);
68
69       assertEquals("setTargetStartMethod() failed", singletonControllerTester.getTargetStartMethod(), someMethod);
70    }
71
72    public void testSetTargetStartMethodArgument()
73    {
74        String JavaDoc someArgument = "aStartValue";
75        singletonControllerTester.setTargetStartMethodArgument(someArgument);
76   
77        assertEquals("setTargetStartMethodArgument() failed", singletonControllerTester.getTargetStartMethodArgument(), someArgument);
78    }
79
80    public void testSetTargetStopMethodArgument()
81    {
82       String JavaDoc someArgument = "aSopValue";
83       singletonControllerTester.setTargetStopMethodArgument(someArgument);
84   
85       assertEquals("setTargetStopMethodArgument() failed", singletonControllerTester.getTargetStopMethodArgument(), someArgument);
86    }
87
88    /* HASingletonController can now start without a target/method set.
89     * We can use the produced notifications to start/stop other services
90     * by setting a dependency on a Barrier mbean, see JBAS-2626
91    public void testSetNullOrBlankStartTargetName()
92    {
93       String someMethod = "";
94       singletonControllerTester.setTargetStartMethod(someMethod);
95
96       assertEquals("setTargetStartMethod() failed to set default value", singletonControllerTester.getTargetStartMethod(), "startSingleton");
97
98       someMethod = null;
99       singletonControllerTester.setTargetStartMethod(someMethod);
100
101       assertEquals("setTargetStartMethod() failed to set default value", singletonControllerTester.getTargetStartMethod(), "startSingleton");
102    }
103    */

104
105    public void testSetTargetStopMethod()
106    {
107       String JavaDoc someMethod = "stopTheSingleton";
108       singletonControllerTester.setTargetStopMethod(someMethod);
109
110       assertEquals("setTargetStartMethod() failed", singletonControllerTester.getTargetStopMethod(), someMethod);
111    }
112
113    /* HASingletonController can now start without a target/method set.
114     * We can use the produced notifications to start/stop other services
115     * by setting a dependency on a Barrier mbean, see JBAS-2626
116    public void testSetNullOrBlankStopTargetName()
117    {
118       String someMethod = "";
119       singletonControllerTester.setTargetStopMethod(someMethod);
120
121       assertEquals("setTargetStartMethod() failed to set default value", singletonControllerTester.getTargetStopMethod(), "stopSingleton");
122
123       someMethod = null;
124       singletonControllerTester.setTargetStopMethod(someMethod);
125
126       assertEquals("setTargetStartMethod() failed to set default value", singletonControllerTester.getTargetStopMethod(), "stopSingleton");
127    }
128    */

129
130    public void testStartSingleton() throws Exception JavaDoc
131    {
132       ObjectName JavaDoc serviceName = new ObjectName JavaDoc("jboss:service=HASingletonMBeanExample");
133       singletonControllerTester.setTargetName(serviceName);
134       singletonControllerTester.setTargetStartMethod("startTheSingleton");
135
136       singletonControllerTester.startSingleton();
137
138       assertEquals("method not invoked as expected",
139          singletonControllerTester.__invokationStack__.pop(), "invokeMBeanMethod:jboss:service=HASingletonMBeanExample.startTheSingleton");
140    }
141
142    public void testStopSingleton() throws Exception JavaDoc
143    {
144       ObjectName JavaDoc serviceName = new ObjectName JavaDoc("jboss:service=HASingletonMBeanExample");
145       singletonControllerTester.setTargetName(serviceName);
146       singletonControllerTester.setTargetStopMethod("stopTheSingleton");
147
148       singletonControllerTester.stopSingleton();
149
150       assertEquals("method not invoked as expected",
151          singletonControllerTester.__invokationStack__.pop(), "invokeMBeanMethod:jboss:service=HASingletonMBeanExample.stopTheSingleton");
152    }
153
154 }
155
Popular Tags