1   /*
2    * Copyright 2004-2009 the Seasar Foundation and the Others.
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,
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.seasar.cubby.plugins.spring;
17  
18  import static org.junit.Assert.assertEquals;
19  import static org.junit.Assert.assertNull;
20  
21  import org.junit.Before;
22  import org.junit.Test;
23  import org.seasar.cubby.plugin.Plugin;
24  import org.seasar.cubby.plugins.spring.spi.SpringContainerProvider;
25  import org.seasar.cubby.spi.ContainerProvider;
26  import org.seasar.cubby.spi.Provider;
27  import org.springframework.mock.web.MockServletContext;
28  import org.springframework.web.context.ContextLoader;
29  
30  /**
31   * {@link SpringPlugin} のテストです
32   * 
33   * @author someda
34   */
35  public class SpringPluginTest {
36  
37  	private Plugin plugin;
38  
39  	@Before
40  	public void before() throws Exception {
41  		plugin = new SpringPlugin();
42  		MockServletContext context = new MockServletContext();
43  		context.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
44  				"/applicationContext.xml");
45  		ContextLoader contextLoader = new ContextLoader();
46  		contextLoader.initWebApplicationContext(context);
47  		plugin.initialize(context);
48  	}
49  
50  	/**
51  	 * サポートしているプロバイダの場合
52  	 * 
53  	 * @throws Exception
54  	 */
55  	@Test
56  	public void getProvider1() throws Exception {
57  		ContainerProvider actual = plugin.getProvider(ContainerProvider.class);
58  		assertEquals(SpringContainerProvider.class, actual.getClass());
59  	}
60  
61  	/**
62  	 * サポートしていないプロバイダの場合
63  	 * 
64  	 * @throws Exception
65  	 */
66  	@Test
67  	public void getProvider2() throws Exception {
68  		MockProvider actual = plugin.getProvider(MockProvider.class);
69  		assertNull(actual);
70  	}
71  
72  	private static interface MockProvider extends Provider {
73  	}
74  
75  }