|
| 1 | +package com.googlecode.jsonrpc4j.spring; |
| 2 | + |
| 3 | +import org.junit.Test; |
| 4 | +import org.junit.runner.RunWith; |
| 5 | +import org.springframework.beans.factory.annotation.Autowired; |
| 6 | +import org.springframework.context.ApplicationContext; |
| 7 | +import org.springframework.test.context.ContextConfiguration; |
| 8 | +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
| 9 | + |
| 10 | +import com.googlecode.jsonrpc4j.spring.service.Service; |
| 11 | +import com.googlecode.jsonrpc4j.spring.service.ServiceImpl; |
| 12 | + |
| 13 | +import static org.junit.Assert.*; |
| 14 | + |
| 15 | +/** |
| 16 | + * This test ensures that {@link com.googlecode.jsonrpc4j.spring.JsonServiceExporter} bean is |
| 17 | + * constructed according to Spring Framework configuration. |
| 18 | + */ |
| 19 | +@RunWith(SpringJUnit4ClassRunner.class) |
| 20 | +@ContextConfiguration("classpath:serverApplicationContextC.xml") |
| 21 | +public class JsonServiceExporterIntegrationTest { |
| 22 | + |
| 23 | + private static final String BEAN_NAME_AND_URL_PATH = "/UserService.json"; |
| 24 | + |
| 25 | + @Autowired |
| 26 | + private ApplicationContext applicationContext; |
| 27 | + |
| 28 | + @Test |
| 29 | + public void testExportedService() { |
| 30 | + assertNotNull(applicationContext); |
| 31 | + |
| 32 | + // check that the bean was only exported on the configured path. |
| 33 | + { |
| 34 | + Object bean = applicationContext.getBean(BEAN_NAME_AND_URL_PATH); |
| 35 | + assertEquals(JsonServiceExporter.class, bean.getClass()); |
| 36 | + |
| 37 | + String[] names = applicationContext.getBeanNamesForType(JsonServiceExporter.class); |
| 38 | + assertNotNull(names); |
| 39 | + assertEquals(1, names.length); |
| 40 | + assertEquals(BEAN_NAME_AND_URL_PATH, names[0]); |
| 41 | + } |
| 42 | + |
| 43 | + // check that service classes were also successfully configured in the context. |
| 44 | + |
| 45 | + { |
| 46 | + Service service = applicationContext.getBean(Service.class); |
| 47 | + assertTrue(service instanceof ServiceImpl); |
| 48 | + |
| 49 | + ServiceImpl serviceImpl = applicationContext.getBean(ServiceImpl.class); |
| 50 | + assertNotNull(serviceImpl); |
| 51 | + } |
| 52 | + } |
| 53 | +} |
0 commit comments