public class ApplicationContextForTest {
protected ApplicationContext applicationContext;
private void initJndi() throws NamingException{
SimpleNamingContextBuilder builder = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
DriverManagerDataSource ds = new DriverManagerDataSource();
ds.setUrl("jdbc:oracle:thin:@localhost:1521:xdtest");
ds.setDriverClassName("oracle.jdbc.OracleDriver");
ds.setUsername("");//数据库用户名
ds.setPassword("");//数据库密码
builder.bind("java:comp/env/LOANAUDITDS", ds);
applicationContext = new ClassPathXmlApplicationContext("classpath:spring.xml","classpath:spring-mybatis.xml","classpath:spring-mvc.xml");
}
public ApplicationContextForTest() throws NamingException{
initJndi();
Assert.notNull(applicationContext);
}
}
@WebAppConfiguration
public class PushControllerTest extends ApplicationContextForTest{
public PushControllerTest() throws NamingException {
super();
}
PushController pushController;
MockMvc mockMvc;
@Before
public void setUp() throws NamingException{
pushController = applicationContext.getBean(PushController.class);
Assert.notNull(pushController);
mockMvc = MockMvcBuilders.standaloneSetup(pushController).build();
Assert.notNull(mockMvc);
}
@Test
public void test_push_client() throws Exception{
mockMvc.perform(post("/push/client.do"))
.andExpect(status().isOk())
.andExpect(content().contentType("application/json;charset=UTF-8"))
.andReturn();
}
}