2 * Copyright 2005-2010 the original author or authors.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.wamblee.ioc;
18 import junit.framework.TestCase;
21 * Tests the bean kernel. The lookup of the bean factory itself can be tested
22 * only partially. Using a global property file for all test cases would tie all
23 * test cases together therefore no global property file is used.
25 * @author Erik Brakkee
27 public class BeanKernelTest extends TestCase {
29 * Loads the bean factory based on a property file configuration. Verifies
30 * the correct bean factory is loaded.
33 public void testLoadBeanFactoryFromProperties() {
34 BeanFactory factory = BeanKernel
35 .lookupBeanFactory("org/wamblee/general/beankernel.properties");
36 assertTrue(factory instanceof TestBeanFactory);
40 * Loads the bean factory based on a non-existing property file. Verifies
41 * that BeanFactoryException is thrown.
44 public void testNonExistentPropertyFile() {
47 .lookupBeanFactory("org/wamblee/general/beankernel-nonexistent.properties");
48 } catch (BeanFactoryException e) {
56 * Loads the bean factory based on a property file with a non-existing bean
57 * factory defined in it. Verifies that BeanFactoryException is thrown.
60 public void testNonExistentBeanFactory() {
63 .lookupBeanFactory("org/wamblee/general/beankernel-wrong.properties");
64 } catch (BeanFactoryException e) {
72 * Retrieves a bean factory throug the bean kernel. Verifies that beans can
76 public void testRetrieveFactory() {
77 BeanKernel.overrideBeanFactory(new TestBeanFactory()); // bypass
82 BeanFactory factory = BeanKernel.getBeanFactory();
83 assertNotNull(factory);
84 assertEquals("hello", factory.find(String.class));