View Javadoc
1   /*
2    * Copyright 2023 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.jgiven.rabbitmq;
18  
19  import org.testng.annotations.*;
20  
21  import com.rabbitmq.client.*;
22  
23  import dev.aherscu.qa.jgiven.commons.utils.*;
24  import dev.aherscu.qa.jgiven.rabbitmq.model.*;
25  import dev.aherscu.qa.jgiven.rabbitmq.steps.*;
26  import dev.aherscu.qa.jgiven.rabbitmq.utils.*;
27  import lombok.*;
28  
29  public abstract class AbstractRabbitMqTest<K, V> extends
30      ConfigurableScenarioTest<TestConfiguration, RabbitMqScenarioType, RabbitMqFixtures<K, V, ?>, RabbitMqActions<K, V, ?>, RabbitMqVerifications<K, V, ?>> {
31      protected QueueHandler<K, V> queueHandler;
32      protected Connection         connection;
33  
34      public AbstractRabbitMqTest(Class<TestConfiguration> configurationType) {
35          super(configurationType);
36      }
37  
38      @BeforeClass
39      @SneakyThrows
40      protected final void beforeClassOpenConnection() {
41          connection = configuration().connectionFactory().newConnection();
42      }
43  
44      @BeforeMethod
45      protected abstract void beforeMethodInitiateQueueHandler();
46  
47      @AfterMethod(alwaysRun = true)
48      @SneakyThrows
49      protected final void afterMethodCloseQueueHandler() {
50          queueHandler.close();
51      }
52  
53      @AfterClass(alwaysRun = true)
54      @SneakyThrows
55      protected final void afterClassCloseConnection() {
56          connection.close();
57      }
58  }