Я изучаю RestAssured и впервые протестировал Java-программу следующим образом:
Код: Выделить всё
import io.restassured.RestAssured;
import static io.restassured.RestAssured.*;
public class Basics {
public static void main(String[] args) {
// TODO Auto-generated method stub
//we'll provide base URL
RestAssured.baseURI = "https://rahulshettyacademy.com";
//whatever input we provide in postman, we'll chain it here with given()
//to use given() import import static io.restassured.RestAssured.*;
given().log().all().queryParam("key", "qaclick123").header("Content-Type", "application/json")
.body("{\n"
+ " \"location\": {\n"
+ " \"latitude\": \"-38.383494\",\n"
+ " \"longitude\": \"33.427362\"\n"
+ " },\n"
+ " \"accuracy\": \"50\",\n"
+ " \"name\": \"Frontline house\",\n"
+ " \"phone_number\": \"(+91) 983 893 3937\",\n"
+ " \"address\": \"29, side layout, cohen 09\",\n"
+ " \"types\": \"shoe park,shop\",\n"
+ " \"website\": \"http://google.com\",\n"
+ " \"language\": \"French-IN\"\n"
+ "}")
//in when() we'll provide HTTP method and resource
.when().post("maps/api/place/add/json")
//then() is used to validate response
.then().log().all().statusCode(200);
//log().all() - we'll use this with given() and then() to see output
}
}
Когда я выполняю программу, я получаю данные JSON в качестве вывода, а затем несколько исключений:
Код: Выделить всё
Request method: POST
Request URI: https://rahulshettyacademy.com/maps/api/place/add/json?key=qaclick123
Proxy:
Request params:
Query params: key=qaclick123
Form params:
Path params:
Headers: Accept=*/*
Content-Type=application/json
Cookies:
Multiparts:
Body:
{
"location": {
"latitude": "-38.383494",
"longitude": "33.427362"
},
"accuracy": "50",
"name": "Frontline house",
"phone_number": "(+91) 983 893 3937",
"address": "29, side layout, cohen 09",
"types": "shoe park,shop",
"website": "http://google.com",
"language": "French-IN"
}
Exception in thread "main" javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:130)
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at java.base/sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:388)
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at java.base/sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:141)
Вот pom.xml:
Код: Выделить всё
4.0.0
com.rahulshetty
RestAssured
0.0.1-SNAPSHOT
org.apache.maven.plugins
maven-compiler-plugin
3.8.1
io.rest-assured
rest-assured
5.4.0
org.testng
testng
7.9.0
org.hamcrest
hamcrest
2.2
Источник: https://stackoverflow.com/questions/781 ... tassured-t
Мобильная версия