Skip to content

Commit 42eef51

Browse files
committed
Add integration test for checking JsonServiceExporter configuration in the application context
Adds same Spring Context XML configuration as described in the README and verifies that beans are properly registered. Signed-off-by: cyb3r4nt <[email protected]>
1 parent 0ca4677 commit 42eef51

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xmlns="http://www.springframework.org/schema/beans"
3+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
4+
5+
<bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/>
6+
7+
<bean id="userService" class="com.googlecode.jsonrpc4j.spring.service.ServiceImpl">
8+
</bean>
9+
10+
<bean name="/UserService.json" class="com.googlecode.jsonrpc4j.spring.JsonServiceExporter">
11+
<property name="service" ref="userService"/>
12+
<property name="serviceInterface" value="com.googlecode.jsonrpc4j.spring.service.Service"/>
13+
</bean>
14+
</beans>

0 commit comments

Comments
 (0)