View Javadoc

1   /*
2    * Copyright 2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.student.common.spring;
17  
18  import org.junit.Assert;
19  import org.junit.Before;
20  import org.junit.Test;
21  import org.junit.runner.RunWith;
22  import org.slf4j.Logger;
23  import org.slf4j.LoggerFactory;
24  import org.springframework.beans.factory.annotation.Autowired;
25  import org.springframework.beans.factory.support.AbstractBeanFactory;
26  import org.springframework.test.context.ContextConfiguration;
27  import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
28  
29  /**
30   * 
31   * Test using only the {@link WebServiceAwareSpringBeanPostProcessor} class.  
32   * 
33   * @author Kuali Student Team
34   * 
35   */
36  @RunWith(SpringJUnit4ClassRunner.class)
37  @ContextConfiguration (locations="classpath:test-spring-post-processor.xml")
38  public class TestWebServiceAwareBeanPostProcessorMultiProcessors {
39  
40  	private static final Logger log = LoggerFactory.getLogger(TestWebServiceAwareBeanPostProcessorMultiProcessors.class);
41  	
42  	@Autowired
43  	private AbstractBeanFactory context;
44  	
45  	/**
46  	 * 
47  	 */
48  	public TestWebServiceAwareBeanPostProcessorMultiProcessors() {
49  	}
50  	
51  	@Before
52  	public void before() {
53  		
54  		/*
55  		 * In this case the WebServiceAwareSpringBeanPostProcessor is the only spring bean post processor being used.
56  		 * 
57  		 * Normally when running from the SpringJUnit4ClassRunner a whole bunch of other bean post processors are configured.
58  		 * 
59  		 * This causes only our post processor to be used.
60  		 * 
61  		 */
62  		
63  		context.getBeanPostProcessors().clear();
64  		context.addBeanPostProcessor(new WebServiceAwareSpringBeanPostProcessor());
65  		
66  		
67  	}
68  	
69  	@Test
70  	public void testDirectDictionaryServiceWithMessageServiceProxy() {
71  	
72  		TestBean bean = context.getBean(TestBean.class);
73  		
74  		String dataDictionaryClassName = bean.getDictionaryService().getClass().getName();
75  		
76  		// this is not a proxy because @Autowired can find the service impl in the applicationContext.
77  		Assert.assertTrue(dataDictionaryClassName.equals("org.kuali.student.common.spring.FakeDictionaryServiceDecoratorImpl"));
78  		
79  		String messageServiceClassName = bean.getMessageService().getClass().getName();
80  		
81  		Assert.assertTrue("class name must contain $Proxy", messageServiceClassName.contains("$Proxy"));
82  		
83  	}
84  }