如何在 Spring Controller 中测试“资源”:
@RequestMapping(value = "/{query}", method = RequestMethod.GET)
public @ResponseBody String getResource(
HttpServletRequest req,
HttpServletResponse res,
@PathVariable String query,
@RequestParam(value="param1", required = false) String param1,
@RequestParam(value="param2", required = false) String param2) throws SomeException{
return service.read(query);
}
由于我正在使用 App Engine 进行开发,因此我有一个这样的 JUnit 脚手架:
@ContextConfiguration(locations = { "classpath:service/client-config.xml" })
@RunWith(SpringJUnit4ClassRunner.class)
public class LocalDatastoreTest {
private final LocalServiceTestHelper helper =
new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig());
@Before
public void setUp() {
helper.setUp();
}
@After
public void tearDown() {
helper.tearDown();
}
@Test
public void test() {
}
}