BaseTest.java 1.74 KB
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
package test.hospital;

import org.junit.Before;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.mock.web.MockHttpSession;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

import com.alibaba.fastjson.JSONObject;

@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(locations = { "classpath:app-context.xml"

// ,
// "classpath:app-datasource.xml",
// "classpath:app-tx.xml",
// "classpath:app-mail.xml"
})
public class BaseTest extends AbstractTransactionalJUnit4SpringContextTests {

protected MockHttpServletRequest request;
protected MockHttpSession session;
protected MockHttpServletResponse response;
protected MockMvc mockMvc;
@Autowired
private WebApplicationContext webApplicationContext;

@Before
public void setup() throws Exception {
request = new MockHttpServletRequest();
response = new MockHttpServletResponse();
session = new MockHttpSession();
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
}

protected void outPrint(Object obj) {
System.err.println(obj);
}

protected void outJson(Object obj) {
System.err.println(JSONObject.toJSONString(obj));
}

}