1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package dev.aherscu.qa.testing.example.scenarios.tutorial6;
18
19 import static dev.aherscu.qa.jgiven.commons.utils.AbstractCsvDataProvider.*;
20 import static dev.aherscu.qa.testing.utils.StreamMatchersExtensions.*;
21 import static jakarta.ws.rs.core.Response.Status.Family.*;
22 import static org.hamcrest.Matchers.*;
23 import static org.hamcrest.Matchers.equalTo;
24
25 import org.testng.annotations.*;
26
27 import dev.aherscu.qa.jgiven.commons.model.*;
28 import dev.aherscu.qa.jgiven.commons.tags.*;
29 import dev.aherscu.qa.jgiven.commons.utils.*;
30 import dev.aherscu.qa.jgiven.rest.model.*;
31 import dev.aherscu.qa.jgiven.rest.tags.*;
32 import dev.aherscu.qa.testing.example.*;
33 import dev.aherscu.qa.testing.example.model.tutorial.*;
34 import dev.aherscu.qa.testing.example.steps.tutorial.*;
35 import dev.aherscu.qa.testing.utils.rest.*;
36 import jakarta.ws.rs.client.*;
37
38 @RestTest
39 public class SwaggerPetstore extends
40 ConfigurableScenarioTest<TestConfiguration, RestScenarioType, SwaggerPetstoreFixtures<?>, SwaggerPetstoreActions<?>, SwaggerPetstoreVerifications<?>> {
41
42 public static final class CredentialsCsvDataProvider
43 extends AbstractCsvDataProvider {
44 @Override
45 protected Class<?> type() {
46 return Credentials.class;
47 }
48 }
49
50 protected Client client;
51
52 protected SwaggerPetstore() {
53 super(TestConfiguration.class);
54 }
55
56 @Test
57 @Reference("235")
58 public void shouldAddPet() {
59 given()
60 .a_swagger_petstore(client)
61 .with(configuration());
62
63 when()
64 .adding(Pet.builder()
65 .name(randomId())
66 .build());
67
68 then()
69 .the_available_pets(adaptedStream(pet -> pet.name,
70 hasItemsMatching(equalTo(randomId()))));
71 }
72
73 @Test(dataProviderClass = CredentialsCsvDataProvider.class,
74 dataProvider = DATA)
75 @Reference("235")
76 public void shouldLogin(final Credentials credentials) {
77 given()
78 .a_swagger_petstore(client)
79 .with(configuration());
80
81 when()
82 .logging_in_with(credentials);
83
84 then()
85 .the_login_response(hasProperty("code", equalTo(200)))
86 .and().the_response_status(is(SUCCESSFUL));
87 }
88
89 @AfterClass
90 protected void afterClassCloseRestClient() {
91 client.close();
92 }
93
94 @BeforeClass
95 protected void beforeClassOpenRestClient() {
96 client = LoggingClientBuilder.newClient();
97 }
98 }