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 ...
随机推荐
- 绑定线程到特定CPU处理器
参考这篇文章 http://blog.chinaunix.net/uid-27761170-id-5050258.html 代码如下: #define _GNU_SOURCE #include < ...
- C#学习笔记(十一):动态类型
C#是一门静态类型的语言,但是在C#4.0时微软引入了动态类型的概念. dynamic 关键字dynamic用来定义动态对象,我们来看一下动态类型的一些特性. 调用不同类的相同方法 我们有两个或多个不 ...
- 如何将std::string转int,double? (C/C++) (C) (template)
http://www.cnblogs.com/oomusou/archive/2008/08/01/525647.html http://blog.sina.com.cn/s/blog_a843a88 ...
- MongoDB 快速入门--初级
数据库的操作一般来说都是CRUD,这其中最难的就是查询,所有所我们先来了解MongoDB中的 插入(insert) 说到插入,我们就必须得说说如何创建数据库,如何创建集合,然后才是如何创建文档. 在这 ...
- asp.net中使用swfupload上传大文件
转载:http://www.cnblogs.com/niunan/archive/2012/01/12/2320705.html 花了一天多时间研究出来的,其实也就是网上下别人的代码然后再自己修修改改 ...
- Linux单词表
su:Swith user 切换用户,切换到root用户cat: Concatenate 串联uname: Unix name 系统名称df: Disk free 空余硬盘du: Disk ...
- cc2530 makefile简略分析 <contiki学习之三>
前面将contiki的makefile框架都理了下,这篇就以cc2530为收篇吧,也即makefile分析就该到此为止了. contiki/examples/cc2530dk 打开Makefile如下 ...
- .net抓取网页信息 - Jumony框架使用1
往往在实际开发中,经常会用到一些如抓取网站信息之类的的操作,往往大家采用的是用一些正则的方式获取,但是有时候正则是很死板的,我们常常试想能不能使用jquery的选择器,获取符合自己要求的元素,然后进行 ...
- 记录一下在WinXP上搭建Apache的httpd+PHP+MySQL+Wordpress的过程
实验室有台旧电脑,想用它一台服务器. 不知为何,U盘启动盘死活不能启动,所以放弃了安装Linux的念头,直接在原来的XP上弄一个服务器,毕竟用的人也不多,也就局域网的这几个人, 本来主要是搭建一个FT ...
- [AngularJS] ngAnimate angular way !!
Idea is set up javascript as an api, then just change html to control the behavor. var app = angula ...