View Javadoc
1   /*
2    * Copyright 2024 Adrian Herscu
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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      @Ignore("no longer returns the added pet")
59      // FIXME must test manually and fix or otherwise replace with other service
60      public void shouldAddPet() {
61          given()
62              .a_swagger_petstore(client)
63              .with(configuration());
64  
65          when()
66              .adding(Pet.builder()
67                  .name(randomId())
68                  .build());
69  
70          then()
71              .the_available_pets(adaptedStream(pet -> pet.name,
72                  hasItemsMatching(equalTo(randomId()))));
73      }
74  
75      @Test(dataProviderClass = CredentialsCsvDataProvider.class,
76          dataProvider = DATA)
77      @Reference("235")
78      public void shouldLogin(final Credentials credentials) {
79          given()
80              .a_swagger_petstore(client)
81              .with(configuration());
82  
83          when()
84              .logging_in_with(credentials);
85  
86          then()
87              .the_login_response(hasProperty("code", equalTo(200)))
88              .and().the_response_status(is(SUCCESSFUL));
89      }
90  
91      @AfterClass
92      protected void afterClassCloseRestClient() {
93          client.close();
94      }
95  
96      @BeforeClass
97      protected void beforeClassOpenRestClient() {
98          client = LoggingClientBuilder.newClient();
99      }
100 }