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.junit.runners.BlockJUnit4ClassRunner;
23  import org.kuali.student.r2.common.messages.service.MessageService;
24  import org.slf4j.Logger;
25  import org.slf4j.LoggerFactory;
26  import org.springframework.context.ConfigurableApplicationContext;
27  import org.springframework.context.support.ClassPathXmlApplicationContext;
28  
29  import java.io.IOException;
30  
31  /**
32   * 
33   * Test using only the {@link WebServiceAwareSpringBeanPostProcessor} class.
34   * 
35   * This tests with an application context using the <context:annotation-config/>
36   * element.
37   * 
38   * It should result in only the course offering service being KSB proxied.
39   * 
40   * @author Kuali Student Team
41   * 
42   */
43  @RunWith(BlockJUnit4ClassRunner.class)
44  public class TestWebServiceAwareBeanPostProcessorManualWithContextPostProcessor {
45  
46  	private static final Logger log = LoggerFactory
47  	        .getLogger(TestWebServiceAwareBeanPostProcessorManualWithContextPostProcessor.class);
48  	private ConfigurableApplicationContext context;
49  
50  	/**
51  	 * 
52  	 */
53  	public TestWebServiceAwareBeanPostProcessorManualWithContextPostProcessor() {
54  	}
55  
56  	@Before
57  	public void onBefore() {
58  
59  		/*
60  		 * In this case the <context:annotation-config/> is defined which brings in the default spring bean post processors.
61  		 * 
62  		 * The WebServiceAwareSpringBeanPostProcessor should sit in front of them and resolve the beans using the @WebService annotation where not automatically processed 
63  		 * using the normal @Autowired behaviour.
64  		 */
65  		context = new ClassPathXmlApplicationContext(
66  		        "classpath:test-spring-post-processor-with-annotation-config.xml");
67  
68  		context.registerShutdownHook();
69  
70  	}
71  
72  	@Test
73  	public void testDirectDictionaryServiceWithMessageServiceProxy() {
74  
75  		TestBean bean = context.getBean(TestBean.class);
76  
77  		String dataDictionaryClassName = bean.getDictionaryService().getClass().getName();
78  		
79  		
80  		Assert.assertTrue(dataDictionaryClassName.equals(FakeDictionaryServiceDecoratorImpl.class.getName()));
81  
82  		String messageServiceClassName = bean.getMessageService().getClass()
83  		        .getName();
84  
85  		Assert.assertTrue("class name must contain $Proxy", messageServiceClassName.contains("$Proxy"));
86  		
87  		// TODO: requires https://jira.springsource.org/browse/SPR-10019 to be accepted upstream to work
88  //		Assert.assertNotNull(bean.getNotAService());
89  //		Assert.assertEquals(NotAService.class.getName(), bean.getNotAService().getClass().getName());
90  
91  	}
92  	
93  	@Test
94  	public void testSerializeProxy() throws IOException, ClassNotFoundException {
95  		
96  		TestBean bean = context.getBean(TestBean.class);
97  		
98  		/*
99  		 * Right now there is no way to get the proxt from the container itself we have to get it off of an 
100 		 * already @Autowired property.
101 		 */
102 		MessageService messageService = bean.getMessageService();
103 	
104 		// check that the serializable proxy takes only 394 bytes to serialize
105 		SpringProxyTestUtils.testBeanSerialization(messageService, "org.kuali.student.common.spring.SerializableProxyInvokationHandler (serviceName={http://student.kuali.org/wsdl/message}MessageService)", 408);
106 		
107 		// check that the non serializable service impl would take 2,018,492 bytes to save
108 		SpringProxyTestUtils.testBeanSerialization(new FakeMessageServiceImpl(), FakeMessageServiceImpl.class.getName(), 2018492);
109 		
110 	}
111 	
112 	
113 }