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