Created
December 26, 2024 17:34
-
-
Save borodicht/9b5f53cf2bacabf9e725a709ddf799af to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.gson.Gson; | |
import com.google.gson.GsonBuilder; | |
import org.testng.annotations.Test; | |
import static io.restassured.RestAssured.when; | |
public class HHTest { | |
@Test | |
public void checkHH() { | |
String response = when() | |
.get("https://api.hh.ru/vacancies?text=QA") | |
.then() | |
.log().all() | |
.statusCode(200) | |
.extract().asString(); | |
Gson gson = new GsonBuilder() | |
.excludeFieldsWithoutExposeAnnotation() | |
.create(); | |
VacancyResponse vac = gson.fromJson(response, VacancyResponse.class); | |
System.out.println(vac); | |
for(Vacancy vacs: vac.getItems()) { | |
if (vacs.getSalary() != null) { | |
System.out.println(vacs); | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io.restassured.http.ContentType; | |
import org.testng.annotations.Test; | |
import static io.restassured.RestAssured.given; | |
import static io.restassured.RestAssured.when; | |
import static org.hamcrest.Matchers.equalTo; | |
import static org.hamcrest.Matchers.hasItem; | |
public class PetStoreTest { | |
//Изолированные | |
//CRUD | |
@Test | |
public void checkCreatePetWithoutBody() { | |
given() | |
.log().all() | |
.contentType(ContentType.JSON) | |
.body("") | |
.when() | |
.post("https://petstore.swagger.io/v2/pet") | |
.then() | |
.log().all() | |
.statusCode(405) | |
.body("code", equalTo(405)) | |
.body("type", equalTo("unknown")) | |
.body("message", equalTo("no data")); | |
} | |
@Test | |
public void checkCreatePet() { | |
long id = given() | |
.log().all() | |
.contentType(ContentType.JSON) | |
.body("{\n" + | |
" \"category\": {\n" + | |
" \"id\": 10,\n" + | |
" \"name\": \"Cat\"\n" + | |
" },\n" + | |
" \"name\": \"Tomas\",\n" + | |
" \"photoUrls\": [\n" + | |
" \"onliner.by\"\n" + | |
" ],\n" + | |
" \"tags\": [\n" + | |
" {\n" + | |
" \"id\": 15,\n" + | |
" \"name\": \"Street\"\n" + | |
" }\n" + | |
" ],\n" + | |
" \"status\": \"available\"\n" + | |
"}") | |
.when() | |
.post("https://petstore.swagger.io/v2/pet") | |
.then() | |
.log().all() | |
.statusCode(200) | |
.body("name", equalTo("Tomas")) | |
.body("category.name", equalTo("Cat")) | |
.body("photoUrls", hasItem("onliner.by")) | |
.extract().path("id"); | |
when() | |
.get("https://petstore.swagger.io/v2/pet/" + id) | |
.then() | |
.log().all() | |
.statusCode(200); | |
given() | |
.contentType(ContentType.JSON) | |
.body("{\n" + | |
" \"id\": " + id + ",\n" + | |
" \"category\": {\n" + | |
" \"id\": 20,\n" + | |
" \"name\": \"Dog\"\n" + | |
" },\n" + | |
" \"name\": \"Bush\",\n" + | |
" \"photoUrls\": [\n" + | |
" \"zzz.by\"\n" + | |
" ],\n" + | |
" \"tags\": [\n" + | |
" {\n" + | |
" \"id\": 0,\n" + | |
" \"name\": \"Home\"\n" + | |
" }\n" + | |
" ],\n" + | |
" \"status\": \"available\"\n" + | |
"}") | |
.when() | |
.put("https://petstore.swagger.io/v2/pet") | |
.then() | |
.log().all() | |
.statusCode(200); | |
when() | |
.delete("https://petstore.swagger.io/v2/pet/" + id) | |
.then() | |
.log().all() | |
.statusCode(200); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.gson.annotations.Expose; | |
import lombok.Data; | |
@Data | |
public class Salary { | |
@Expose | |
int from; | |
@Expose | |
int to; | |
@Expose | |
String currency; | |
double average; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import lombok.Data; | |
@Data | |
public class Vacancy { | |
Salary salary; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.gson.annotations.Expose; | |
import com.google.gson.annotations.SerializedName; | |
import lombok.Data; | |
import java.util.List; | |
@Data | |
public class VacancyResponse { | |
@SerializedName("found") | |
@Expose | |
int found; | |
@SerializedName("pages") | |
@Expose | |
int pages; | |
List<Vacancy> items; | |
@SerializedName("per_pag") | |
@Expose | |
int perPage; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment