import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.servlet.ModelAndView;
@Test
@Transactional(readOnly = true)
public void doRightTest()
{
try
{
// read file
InputStream input =
this.getClass().getResourceAsStream("/ctrlPay.json");
assertNotNull(input);
ByteArrayOutputStream output = new ByteArrayOutputStream(BYTES);
byte[] buffer = new byte[BYTES];
int length = 0;
while ((length = input.read(buffer)) != -1)
{
output.write(buffer, 0, length);
}
MockHttpServletRequest request =
new MockHttpServletRequest("POST", "/ctrlpay");
request.setContent(output.toByteArray());
CtrlPayAction controller =
this.getApplicationContext().getBean(CtrlPayAction.class);
ModelAndView m2v =
SystemUtil.getApplicationContext().getBean(BaseAdapter.class)
.handle(request, new MockHttpServletResponse(),
controller);
m2v.getView().render(m2v.getModel(), request,
new MockHttpServletResponse());
assertEquals("success", "success");
}
catch (Exception e)
{
assertEquals("1010203101", e.getMessage());
}
}