TheOldDriver
8/14/2017 - 6:51 AM

测试conroller

测试conroller

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:META-INF/spring/*.xml","file:src/main/webapp/WEB-INF/spring-configuration/*.xml",
"file:src/main/webapp/WEB-INF/*.xml"})
@WebAppConfiguration
public class PaymentCallBackControllerTest {
	private MockMvc mvc;
	@Autowired
	WebApplicationContext webApplicationConnect;


	@Before
	public void setUp() {
		mvc = MockMvcBuilders.webAppContextSetup(webApplicationConnect).build();
	}

	@Test
	public void test() throws Exception {
		String url = "/paymentCallBack/weBankCall";
		MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.post(url)
				.param("merId", "122")
				.param("orderId", "PN2017071900000003")
				.param("bizType", "01")
				.param("reqDate", "20170720")
				.param("reqTime", "152538")
				.param("amount", "10000.00")
				.param("status", "PR03")
				.param("settleDate", "")
				.param("respCode", "")
				.param("respMsg", "")
				.param("signature", "6a64e85028f4b89c1ab129bf21b622a853f85146cacd587225449c7b6545da90886c4c870a2f1df08bf220328bd86693d8a5e24e6e214c595fc992e9bc63594b0c700df03f84ff0f42f84645306740b4b8f9ffed0b7b8d12f77feb1927de134bee71d6be7dbecb3f862b426c08baeddbe21b59a745bdb0004ec8dde44baafb42").accept(MediaType.APPLICATION_JSON)).andReturn();
		
		int status = mvcResult.getResponse().getStatus();
		String content = mvcResult.getResponse().getContentAsString();
		System.out.println("status:" + status);
		System.out.println("content:" + content);

	}
}