Jersey(1.19.1) - Client API, Testing services
The Jersey client API was originally developed to aid the testing of the Jersey server-side, primarily to make it easier to write functional tests in conjunction with the JUnit framework for execution and reporting. It is used extensively and there are currently over 1000 tests.
Embedded servers, Grizzly and a special in-memory server, are utilized to deploy the test-based services. Many of the Jersey samples contain tests that utilize the client API to server both for testing and examples of how to use the API. The samples utilize Grizzly or embedded Glassfish to deploy the services.
The following code snippets are presented from the single unit test HelloWorldWebAppTest
of the helloworld-webapp sample. The setUp
method, called before a test is executed, creates an instance of the Glassfish server, deploys the application, and a WebResource
instance that references the base resource:
@Override
protected void setUp() throws Exception {
super.setUp(); // Start Glassfish
glassfish = new GlassFish(BASE_URI.getPort()); // Deploy Glassfish referencing the web.xml
ScatteredWar war = new ScatteredWar(
BASE_URI.getRawPath(),
new File("src/main/webapp"),
new File("src/main/webapp/WEB-INF/web.xml"),
Collections.singleton(new File("target/classes").toURI().toURL()));
glassfish.deploy(war); Client c = Client.create();
r = c.resource(BASE_URI);
}
The tearDown
method, called after a test is executed, stops the Glassfish server.
@Override
protected void tearDown() throws Exception {
super.tearDown();
glassfish.stop();
}
The testHelloWorld
method tests that the response to a GET
request to the Web resource returns “Hello World”:
public void testHelloWorld() throws Exception {
String responseMsg = r.path("helloworld").get(String.class);
assertEquals("Hello World", responseMsg);
}
Note the use of the path
method on the WebResource
to build from the base WebResource
.
Jersey(1.19.1) - Client API, Testing services的更多相关文章
- Jersey(1.19.1) - Client API, Uniform Interface Constraint
The Jersey client API is a high-level Java based API for interoperating with RESTful Web services. I ...
- Jersey(1.19.1) - Client API, Ease of use and reusing JAX-RS artifacts
Since a resource is represented as a Java type it makes it easy to configure, pass around and inject ...
- Jersey(1.19.1) - Client API, Overview of the API
To utilize the client API it is first necessary to create an instance of a Client, for example: Clie ...
- Jersey(1.19.1) - Client API, Using filters
Filtering requests and responses can provide useful functionality that is hidden from the applicatio ...
- Jersey(1.19.1) - Client API, Security with Http(s)URLConnection
With Http(s)URLConnection The support for security, specifically HTTP authentication and/or cookie m ...
- Jersey(1.19.1) - Client API, Proxy Configuration
为 Jersey Client 设置代理,可以使用带有 ClientHandler 参数的构造方法创建 Client 实例. public static void main(String[] args ...
- docker报Error response from daemon: client is newer than server (client API version: 1.24, server API version: 1.19)
docker version Client: Version: 17.05.0-ce API version: 1.24 (downgraded from 1.29) Go version: go1. ...
- Jersey(1.19.1) - XML Support
As you probably already know, Jersey uses MessageBodyWriters and MessageBodyReaders to parse incomin ...
- Jersey(1.19.1) - JSON Support
Jersey JSON support comes as a set of JAX-RS MessageBodyReader<T> and MessageBodyWriter<T&g ...
随机推荐
- 转载github上最全的资源教程--前端涉及的所有知识体系
以下地址为园子里一个哥们总结的前端所涉及的所有知识体系 http://www.cnblogs.com/bymax/p/5878113.html 很值得学习参考
- http协议详细介绍
HTTP协议/IIS 原理及ASP.NET运行机制浅析[图解] 转自:http://www.cnblogs.com/wenthink/archive/2013/05/06/HTTP_IIS_ASPNE ...
- java线程中的wait和notify以及notifyall
一.区别与联系 1.1.wait(),notify()和notifyAll()都是java.lang.Object的方法,而确实sleep方法是Thread类中的方法,这是为什么呢? 因为wait和 ...
- HTML5 - HTML5 postMessage API 注意事项
一:发送 window.postMessage("Hello, world", "http://127.0.0.1:8080"); 注意,必须要加上http:/ ...
- Eclipse10大快捷键组合
一个Eclipse骨灰级开发者总结了他认为最有用但又不太为人所知的快捷键组合.通过这些组合可以更加容易的浏览源代码,使得整体的开发效率和质量得到提升. Ctrl+Shift+C 快速单行注释 也适用于 ...
- ERROR 1227 (42000): Access denied; you need (at least one of) the PROCESS privilege(s) for this oper
1 用以往的mysql登陆模式登陆 [mysql@eanintmydbc002db1 mysqllog]$ mysql Enter password: Welcome to the MySQL m ...
- Android进阶2之APK方式换肤
public class MainActivity extends Activity { private Button defaultbutton = null; @Override public v ...
- Error creating bean with name 'menuController': Injection of autowired dependency……
出现了一大串错误 Error creating bean with name 'userController': Injection of autowired dependencies failed. ...
- yii泛域名
return CMap::mergeArray( require (dirname(__FILE__) . '/main.php'), array( 'components' => array( ...
- python源码解析
http://blog.csdn.net/balabalamerobert/article/category/168910