KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > SpringTestSupport


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 package org.apache.activemq;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23 import org.springframework.context.support.AbstractApplicationContext;
24
25 import java.util.Arrays JavaDoc;
26 import java.util.HashSet JavaDoc;
27 import java.util.Set JavaDoc;
28
29 import junit.framework.TestCase;
30
31 /**
32  * A useful base class for spring based unit test cases
33  *
34  * @version $Revision: 1.1 $
35  */

36 public abstract class SpringTestSupport extends TestCase {
37
38     protected final Log log = LogFactory.getLog(getClass());
39
40     protected AbstractApplicationContext context;
41
42     protected void setUp() throws Exception JavaDoc {
43         context = createApplicationContext();
44     }
45
46     protected abstract AbstractApplicationContext createApplicationContext();;
47
48     protected void tearDown() throws Exception JavaDoc {
49         if (context != null) {
50             context.destroy();
51         }
52     }
53
54     protected Object JavaDoc getBean(String JavaDoc name) {
55         Object JavaDoc bean = context.getBean(name);
56         if (bean == null) {
57             fail("Should have found bean named '" + name + "' in the Spring ApplicationContext");
58         }
59         return bean;
60     }
61
62     protected void assertSetEquals(String JavaDoc description, Object JavaDoc[] expected, Set JavaDoc actual) {
63         Set JavaDoc expectedSet = new HashSet JavaDoc();
64         expectedSet.addAll(Arrays.asList(expected));
65         assertEquals(description, expectedSet, actual);
66     }
67
68 }
69
Popular Tags