• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java RestAssured类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.jayway.restassured.RestAssured的典型用法代码示例。如果您正苦于以下问题:Java RestAssured类的具体用法?Java RestAssured怎么用?Java RestAssured使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



RestAssured类属于com.jayway.restassured包,在下文中一共展示了RestAssured类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: greetingShouldReturnTestConfigValue

import com.jayway.restassured.RestAssured; //导入依赖的package包/类
@Test
@Use(service=TestConfigVolumeDescriptor.class)
public void greetingShouldReturnTestConfigValue(ServiceContext context) {
	Service s = context.getService(SERVICE_NAME);
	ServiceInstance si = s.getInstances().stream().findAny().get();
	
	RestAssured
		.given()
			.baseUri("http://" + si.getIp() + ":" + si.getPort())
		.when()
			.get("/greeting")
		.then()
			.assertThat()
			.statusCode(200)
			.and()
			.body("greeting", equalTo("Hello Dockerunit!!!"));
}
 
开发者ID:qzagarese,项目名称:dockerunit,代码行数:18,代码来源:SpringBootTest.java


示例2: envShouldReturnValuesFromImage

import com.jayway.restassured.RestAssured; //导入依赖的package包/类
@Test
@Use(service=BaseDescriptor.class)
public void envShouldReturnValuesFromImage(ServiceContext context) {
	Service s = context.getService(SERVICE_NAME);
	ServiceInstance si = s.getInstances().stream().findAny().get();
	
	RestAssured
		.given()
			.baseUri("http://" + si.getIp() + ":" + si.getPort())
		.when()
			.get("/env/foo")
		.then()
			.assertThat()
			.statusCode(200)
			.and()
			.body("value", equalTo(FOO_VALUE_FROM_IMAGE));
}
 
开发者ID:qzagarese,项目名称:dockerunit,代码行数:18,代码来源:SpringBootTest.java


示例3: configureRestAssured

import com.jayway.restassured.RestAssured; //导入依赖的package包/类
@BeforeClass
public static void configureRestAssured() {
	Vertx vertx = Vertx.vertx();

	JsonObject config = new JsonObject().put("server.port", getRandomPort());

	LoginHandler loginHandler = new LoginHandler();
	loginHandler.setInvocationHandler(new VertxInvocationHandler(vertx));

	RestVerticle restVerticle = new RestVerticle();
	restVerticle.setRequestHandlers(Arrays.asList(loginHandler));

	ServiceVerticle serviceVerticle = new ServiceVerticle();
	serviceVerticle.setServiceHandlers(Arrays.asList(loginHandler));

	DeploymentOptions options = new DeploymentOptions().setConfig(config);
	vertx.deployVerticle(restVerticle, options);
	vertx.deployVerticle(serviceVerticle, options);

	RestAssured.baseURI = "http://localhost";
	RestAssured.port = config.getInteger("server.port");
}
 
开发者ID:simonemasoni,项目名称:vertx_spring,代码行数:23,代码来源:IntegrationTest.java


示例4: greetingShouldReturnImageConfigValue

import com.jayway.restassured.RestAssured; //导入依赖的package包/类
@Test
@Use(service=BaseDescriptor.class)
public void greetingShouldReturnImageConfigValue(ServiceContext context) {
	Service s = context.getService(SERVICE_NAME);
	ServiceInstance si = s.getInstances().stream().findAny().get();
	
	RestAssured
		.given()
			.baseUri("http://" + si.getIp() + ":" + si.getPort())
		.when()
			.get("/greeting")
		.then()
			.assertThat()
			.statusCode(200)
			.and()
			.body("greeting", equalTo("Hello world!"));
}
 
开发者ID:qzagarese,项目名称:dockerunit,代码行数:18,代码来源:SpringBootTest.java


示例5: envShouldReturnValuesFromDescriptor

import com.jayway.restassured.RestAssured; //导入依赖的package包/类
@Test
@Use(service=TestEnvDescriptor.class)
public void envShouldReturnValuesFromDescriptor(ServiceContext context) {
	Service s = context.getService(SERVICE_NAME);
	ServiceInstance si = s.getInstances().stream().findAny().get();
	
	RestAssured
		.given()
			.baseUri("http://" + si.getIp() + ":" + si.getPort())
		.when()
			.get("/env/bar")
		.then()
			.assertThat()
			.statusCode(200)
			.and()
			.body("value", equalTo(BAR_VALUE_FROM_DESCRIPTOR));
}
 
开发者ID:qzagarese,项目名称:dockerunit,代码行数:18,代码来源:SpringBootTest.java


示例6: testCreateTask

import com.jayway.restassured.RestAssured; //导入依赖的package包/类
@Test
public void testCreateTask() {
	Map<String, Object> attributeMap = new ImmutableMap.Builder<String, Object>().put("my-name", "Getter Done")
			.put("description", "12345678901234567890").build();

	Map dataMap = ImmutableMap.of("data", ImmutableMap.of("type", "tasks", "attributes", attributeMap));

	ValidatableResponse response = RestAssured.given().contentType("application/vnd.api+json").body(dataMap).when().post
			("/api/tasks")
			.then().statusCode(CREATED.value());
	response.assertThat().body(matchesJsonSchema(jsonApiSchema));
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:13,代码来源:SpringBootSimpleExampleApplicationTests.java


示例7: setup

import com.jayway.restassured.RestAssured; //导入依赖的package包/类
@BeforeClass
static public void setup() throws MalformedURLException {
    // set base URI and port number to use for all requests
    String serverUrl = System.getProperty("test.url");
    String protocol = DEFAULT_PROTOCOL;
    String host = DEFAULT_HOST;
    int port = DEFAULT_PORT;

    if (serverUrl != null) {
        URL url = new URL(serverUrl);
        protocol = url.getProtocol();
        host = url.getHost();
        port = (url.getPort() == -1) ? DEFAULT_PORT : url.getPort();
    }

    RestAssured.baseURI = protocol + "://" + host;
    RestAssured.port = port;

    // set user name and password to use for basic authentication for all requests
    String userName = System.getProperty("test.user");
    String password = System.getProperty("test.pwd");

    if (userName != null && password != null) {
        RestAssured.authentication = RestAssured.basic(userName, password);
        RestAssured.useRelaxedHTTPSValidation();
    }

}
 
开发者ID:eclipse,项目名称:microprofile-metrics,代码行数:29,代码来源:MpMetricTest.java


示例8: setUp

import com.jayway.restassured.RestAssured; //导入依赖的package包/类
/**
 * Initial Setup
 */
@Before
public void setUp() {

	this.activeProfile = RestUtil.getCurrentProfile();

	this.conf = ConfigFactory.load("application-" + this.activeProfile);
	this.baseURI = conf.getString("server.baseURI");
	this.port = conf.getInt("server.port");
	this.timeout = conf.getInt("service.api.timeout");

	final RequestSpecBuilder build = new RequestSpecBuilder().setBaseUri(baseURI).setPort(port);

	rspec = build.build();
	RestAssured.config = new RestAssuredConfig().encoderConfig(encoderConfig().defaultContentCharset("UTF-8")
			.encodeContentTypeAs("application-json", ContentType.JSON));
}
 
开发者ID:ERS-HCL,项目名称:itest-starter,代码行数:20,代码来源:AbstractITest.java


示例9: testIllegalLatitude

import com.jayway.restassured.RestAssured; //导入依赖的package包/类
/**
 * Test illegal latitude.
 */
@Test
public void testIllegalLatitude() {
	
	RestAssured
	.registerParser("text/plain", Parser.TEXT);

	RestAssured
	.given()
		.param("radius", 0)
		.param("longitude", -1)
		.param("latitude", "asdf")
	.when()
		.get(RESTAURANT_API)
	.then()
		.statusCode(200)
		.body(Matchers.containsString(MethodArgumentTypeMismatchException.class.toString()));
}
 
开发者ID:andju,项目名称:findlunch,代码行数:21,代码来源:RestaurantRestControllerIT.java


示例10: testUserWithInvalidPasswordValidLengthCapitalLetterMissing

import com.jayway.restassured.RestAssured; //导入依赖的package包/类
/**
 * Test user with invalid password valid length capital letter missing.
 */
@Test
public void testUserWithInvalidPasswordValidLengthCapitalLetterMissing() {
	
	RestAssured
	.registerParser("text/plain", Parser.TEXT);
	
	User user = getUser();
	// Set invalid password
	user.setPassword("uop1%");
	// To test a real life scenario, the user type is set to null, since the app does not send an user type within the json.
	user.setUserType(null);
	
	Response response = RestAssured
	.given()
	   	.contentType("application/json")
		.body(user)
	.when()
		.post(REGISTER_USER_API)
	.then()
		.statusCode(409)
		.extract().response();
	
	Assert.assertEquals("2", response.asString());
	
}
 
开发者ID:andju,项目名称:findlunch,代码行数:29,代码来源:RegisterUserRestControllerIT.java


示例11: testIllegalLongitude

import com.jayway.restassured.RestAssured; //导入依赖的package包/类
/**
 * Test illegal longitude.
 */
@Test
public void testIllegalLongitude() {
	
	RestAssured
	.registerParser("text/plain", Parser.TEXT);

	RestAssured
	.given()
		.param("radius", 0)
		.param("longitude", "asdf")
		.param("latitude", -1)
	.when()
		.get(RESTAURANT_API)
	.then()
		.statusCode(200)
		.body(Matchers.containsString(MethodArgumentTypeMismatchException.class.toString()));
}
 
开发者ID:andju,项目名称:findlunch,代码行数:21,代码来源:RestaurantRestControllerIT.java


示例12: testIllegalMethodTypes

import com.jayway.restassured.RestAssured; //导入依赖的package包/类
/**
 * Test illegal method types.
 */
@Test
public void testIllegalMethodTypes() {	
	JsonPath response = RestAssured.given().when().delete(RESTAURANT_API).then().statusCode(405).extract().jsonPath();
	Assert.assertEquals("Request method 'DELETE' not supported", response.getString("message"));
	Assert.assertEquals("Method Not Allowed", response.getString("error"));

	response = RestAssured.given().when().put(RESTAURANT_API).then().statusCode(405).extract().jsonPath();
	Assert.assertEquals("Request method 'PUT' not supported", response.getString("message"));
	Assert.assertEquals("Method Not Allowed", response.getString("error"));

	response = RestAssured.given().when().post(RESTAURANT_API).then().statusCode(405).extract().jsonPath();
	Assert.assertEquals("Request method 'POST' not supported", response.getString("message"));
	Assert.assertEquals("Method Not Allowed", response.getString("error"));

	response = RestAssured.given().when().patch(RESTAURANT_API).then().statusCode(405).extract().jsonPath();
	Assert.assertEquals("Request method 'PATCH' not supported", response.getString("message"));
	Assert.assertEquals("Method Not Allowed", response.getString("error"));
}
 
开发者ID:andju,项目名称:findlunch,代码行数:22,代码来源:RestaurantRestControllerIT.java


示例13: testMissingAuthorizationForRegister

import com.jayway.restassured.RestAssured; //导入依赖的package包/类
/**
 * Test missing authorization for register.
 */
@Test
public void testMissingAuthorizationForRegister()
{
	PushNotification p = getPush(1);
	
	JsonPath response = RestAssured
	.given()
		.contentType("application/json")
		.body(p)
	.when()
		.post(REGISTER_PUSH_API)
	.then()
		.statusCode(401).extract().jsonPath();
	
	Assert.assertEquals("Full authentication is required to access this resource", response.getString("message"));
	Assert.assertEquals("Unauthorized", response.getString("error"));
}
 
开发者ID:andju,项目名称:findlunch,代码行数:21,代码来源:PushNotificationRestControllerIT.java


示例14: testUserNotExisting

import com.jayway.restassured.RestAssured; //导入依赖的package包/类
/**
 * Test with user not present within database.
 */
@Test
public void testUserNotExisting()
{
	
	User user = getUserWithUserTypeAnbieter();
	// Since we need the password within the header as cleartext, it is extracted from the passwordconfirm field
	String authString = user.getUsername() + ":" + user.getPasswordconfirm();
	byte[] base64Encoded = Base64.getEncoder().encode(authString.getBytes());
	String encodedString = new String(base64Encoded);
	
	JsonPath response = RestAssured
	.given()
		.header("Authorization", "Basic " + encodedString)
	.when()
		.get(RESTAURANT_API)
	.then()
		.statusCode(401)
		.extract().jsonPath();
	
	Assert.assertEquals("UserDetailsService returned null, which is an interface contract violation", response.getString("message"));
	Assert.assertEquals("Unauthorized", response.getString("error"));
}
 
开发者ID:andju,项目名称:findlunch,代码行数:26,代码来源:RestaurantRestControllerIT.java


示例15: testWrongUserTypeForGet

import com.jayway.restassured.RestAssured; //导入依赖的package包/类
/**
 * Test wrong user type for get.
 */
@Test
public void testWrongUserTypeForGet() {			
	User user = getUserWithUserTypeAnbieter();
	// Since we need the password within the header as cleartext, it is extracted from the passwordconfirm field
	String authString = user.getUsername() + ":" + user.getPasswordconfirm();
	byte[] base64Encoded = Base64.getEncoder().encode(authString.getBytes());
	String encodedString = new String(base64Encoded);
	
	JsonPath response = RestAssured
	.given()
		.header("Authorization", "Basic " + encodedString)
		.when()
		.get(GET_PUSH_API)
	.then()
		.statusCode(401)
		.extract().jsonPath();

	Assert.assertEquals("UserDetailsService returned null, which is an interface contract violation", response.getString("message"));
	Assert.assertEquals("Unauthorized", response.getString("error"));
}
 
开发者ID:andju,项目名称:findlunch,代码行数:24,代码来源:PushNotificationRestControllerIT.java


示例16: testUsernameAlreadyExists

import com.jayway.restassured.RestAssured; //导入依赖的package包/类
/**
 * Test username alrady exists.
 */
@Test
public void testUsernameAlreadyExists() {
	
	RestAssured
	.registerParser("text/plain", Parser.TEXT);
	
	User user = getUser();
	userRepository.save(user);
	// To test a real life scenaria, the user type is set to null, since the app does not send an user type within the json.
	// It was only set to pre-save the user to the database (data integrity)
	user.setUserType(null);
	
	Response response = RestAssured
	.given()
	   	.contentType("application/json")
		.body(user)
	.when()
		.post(REGISTER_USER_API)
	.then()
		.statusCode(409)
		.extract().response();
	
	Assert.assertEquals("3", response.asString());
}
 
开发者ID:andju,项目名称:findlunch,代码行数:28,代码来源:RegisterUserRestControllerIT.java


示例17: testInvalidAuthorizationHeader

import com.jayway.restassured.RestAssured; //导入依赖的package包/类
/**
 * Test invalid authorization header.
 */
@Test
public void testInvalidAuthorizationHeader()
{
	JsonPath response = RestAssured
	.given()
		.header("Authorization", "Basic invalid")
	.when()
		.get(RESTAURANT_API)
	.then()
		.statusCode(401)
		.extract().jsonPath();
	
	Assert.assertEquals("Invalid basic authentication token", response.getString("message"));
	Assert.assertEquals("Unauthorized", response.getString("error"));

}
 
开发者ID:andju,项目名称:findlunch,代码行数:20,代码来源:RestaurantRestControllerIT.java


示例18: testUserWithInvalidPasswordValidLengthSpecialCharacterMissing

import com.jayway.restassured.RestAssured; //导入依赖的package包/类
/**
 * Test user with invalid password valid length special character missing.
 */
@Test
public void testUserWithInvalidPasswordValidLengthSpecialCharacterMissing() {
	
	RestAssured
	.registerParser("text/plain", Parser.TEXT);
	
	User user = getUser();
	// Set invalid password
	user.setPassword("UOP1z");
	// To test a real life scenario, the user type is set to null, since the app does not send an user type within the json.
	user.setUserType(null);
	
	Response response = RestAssured
	.given()
	   	.contentType("application/json")
		.body(user)
	.when()
		.post(REGISTER_USER_API)
	.then()
		.statusCode(409)
		.extract().response();
	
	Assert.assertEquals("2", response.asString());
	
}
 
开发者ID:andju,项目名称:findlunch,代码行数:29,代码来源:RegisterUserRestControllerIT.java


示例19: testKitchenTypeRestController

import com.jayway.restassured.RestAssured; //导入依赖的package包/类
/**
 * Test kitchen type rest controller.
 */
@Test
public void testKitchenTypeRestController() {	
	List<KitchenType> expectedResult = kitchenTypeRepo.findAll();
	
	Response response = RestAssured.given()
		.when()
		.get(TYPE_API)
	.then()
		.statusCode(200)
		.contentType(ContentType.JSON)
		.body("list.size()", Matchers.is(expectedResult.size()))
		.extract().response(); 
	
	DayOfWeek[] actualResult = response.as(DayOfWeek[].class);
	
	// Check if correct results are present (Only fields that are sent via the rest interface are checked)
	 for(int i=0;i< expectedResult.size();i++) {
		 Assert.assertEquals(expectedResult.get(i).getId(), actualResult[i].getId());
		 Assert.assertEquals(expectedResult.get(i).getName(), actualResult[i].getName());
	 }
}
 
开发者ID:andju,项目名称:findlunch,代码行数:25,代码来源:KitchenTypeRestControllerIT.java


示例20: init

import com.jayway.restassured.RestAssured; //导入依赖的package包/类
@Before
public void init() {
    User user = userRepository.findByEmail("[email protected]");
    if (user == null) {
        user = new User();
        user.setFirstName("Test");
        user.setLastName("Test");
        user.setPassword(passwordEncoder.encode("test"));
        user.setEmail("[email protected]");
        user.setEnabled(true);
        userRepository.save(user);
    } else {
        user.setPassword(passwordEncoder.encode("test"));
        userRepository.save(user);
    }

    RestAssured.port = port;

    String URL_PREFIX = "http://localhost:" + String.valueOf(port);
    LOGGED_USERS_URL = URL_PREFIX + "/loggedUsers";
    SESSION_REGISTRY_LOGGED_USERS_URL = URL_PREFIX + "/loggedUsersFromSessionRegistry";
    formConfig = new FormAuthConfig(URL_PREFIX + "/login", "username", "password");
}
 
开发者ID:Baeldung,项目名称:spring-security-registration,代码行数:24,代码来源:GetLoggedUsersIntegrationTest.java



注:本文中的com.jayway.restassured.RestAssured类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java JDOObjectNotFoundException类代码示例发布时间:2022-05-21
下一篇:
Java AsyncWeiboRunner类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap