本文整理汇总了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!!!"));
}
示例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));
}
示例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");
}
示例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!"));
}
示例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));
}
示例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));
}
示例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();
}
}
示例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));
}
示例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()));
}
示例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());
}
示例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()));
}
示例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"));
}
示例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"));
}
示例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"));
}
示例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"));
}