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 ...
随机推荐
- 201. Segment Tree Build
最后更新 二刷 08-Jan-2017 一刷忘了什么时候做的,只是觉得这几个题挺好的,一步一步手动构建线段树,最终理解了这个数据结构,并且后面有利用的地方. 其实重要的3个东西题目已经提供了: 1) ...
- 被mysql中的wait_timeout坑了
今天被mysql里的wait_timeout坑了 网上能搜到很多关于mysql中的wait_timeout相关的文章,但是大多数只是说明了他的作用,而且都说这个参数要配合那个inter ...
- 在 CentOS 上安装和配置 OpenNebula
转自:http://www.aikaiyuan.com/4889.html 我们提到的云计算一般有三种类型:软件即服务(Software as a Service, SaaS),平台即服务(Platf ...
- Java模拟网站登录02【转载】
如何用Java代码模拟一些如百度.QQ之类的网站登录?有两个方式,一是发送模拟请求,二是模拟浏览器操作,而这两种方式恰好在Java有开源实现,在这里介绍一个工具包,它是家喻户晓的HttpClient. ...
- Windbg命令
(1)!runaway命令显示每个线程消费的时间 参考:http://blog.csdn.net/hgy413/article/details/7564252 (2)!wow64exts.sw 关闭6 ...
- ZJU-PAT 1065. A+B and C (64bit) (20)
Given three integers A, B and C in [-263, 263], you are supposed to tell whether A+B > C. Input S ...
- HDU 2037 今年暑假不AC (贪心)
今年暑假不AC Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- Python dictionary implementation
Python dictionary implementation http://www.laurentluce.com/posts/python-dictionary-implementation/ ...
- 【ZZ】MySql语句大全:创建、授权、查询、修改等
http://blog.csdn.net/evankaka/article/details/45580845
- 目录操作函数opendir、readdir和closedir
首先,明确一个类型DIR的含义: #include <dirent.h> DIR A type representing a directory stream. DIR是在目录项格式 ...