当前位置: 首页>>代码示例>>Java>>正文


Java RestAssured类代码示例

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


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


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