Skip to content

Commit

Permalink
Remove duplicate testing code
Browse files Browse the repository at this point in the history
  • Loading branch information
tsegismont committed Mar 21, 2023
1 parent 3980b35 commit adebae9
Show file tree
Hide file tree
Showing 17 changed files with 152 additions and 194 deletions.
7 changes: 7 additions & 0 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1864,6 +1864,13 @@
<artifactId>quarkus-reactive-datasource-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-reactive-datasource-deployment</artifactId>
<version>${project.version}</version>
<scope>test</scope>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-reactive-db2-client</artifactId>
Expand Down
16 changes: 16 additions & 0 deletions extensions/reactive-datasource/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
<artifactId>quarkus-junit5-internal</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand All @@ -46,6 +51,17 @@
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.quarkus.reactive.datasource;

import java.util.HashMap;
import java.util.Map;

import org.jboss.logging.Logger;

import io.quarkus.credentials.CredentialsProvider;

public abstract class ChangingCredentialsProviderBase implements CredentialsProvider {

private static final Logger log = Logger.getLogger(ChangingCredentialsProviderBase.class.getName());

private final String user2;
private final String password2;

private volatile Map<String, String> properties;

protected ChangingCredentialsProviderBase(String user1, String password1, String user2, String password2) {
properties = new HashMap<>();
properties.put(USER_PROPERTY_NAME, user1);
properties.put(PASSWORD_PROPERTY_NAME, password1);
this.user2 = user2;
this.password2 = password2;
}

public void changeProperties() {
properties = new HashMap<>();
properties.put(USER_PROPERTY_NAME, user2);
properties.put(PASSWORD_PROPERTY_NAME, password2);
}

@Override
public Map<String, String> getCredentials(String credentialsProviderName) {
log.info("credentials provider returning " + properties);
return properties;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package io.quarkus.reactive.datasource;

import static io.restassured.RestAssured.given;
import static java.util.concurrent.TimeUnit.SECONDS;

import org.hamcrest.CoreMatchers;
import org.junit.jupiter.api.Test;

public abstract class ChangingCredentialsTestBase {

private String user1;
private String user2;

protected ChangingCredentialsTestBase(String user1, String user2) {
this.user1 = user1;
this.user2 = user2;
}

@Test
public void testConnect() throws Exception {
given()
.when().get("/test")
.then()
.statusCode(200)
.body(CoreMatchers.equalTo(user1));

SECONDS.sleep(2); // sleep longer than pool idle connection timeout

given()
.when().get("/test")
.then()
.statusCode(200)
.body(CoreMatchers.equalTo(user2));
}

}
6 changes: 6 additions & 0 deletions extensions/reactive-mssql-client/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-reactive-datasource-deployment</artifactId>
<scope>test</scope>
<type>test-jar</type>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,13 @@
package io.quarkus.reactive.mssql.client;

import java.util.HashMap;
import java.util.Map;

import jakarta.enterprise.context.ApplicationScoped;

import org.jboss.logging.Logger;

import io.quarkus.credentials.CredentialsProvider;
import io.quarkus.reactive.datasource.ChangingCredentialsProviderBase;

@ApplicationScoped
public class ChangingCredentialsProvider implements CredentialsProvider {

private static final Logger log = Logger.getLogger(ChangingCredentialsProvider.class.getName());

private volatile Map<String, String> properties;
public class ChangingCredentialsProvider extends ChangingCredentialsProviderBase {

public ChangingCredentialsProvider() {
properties = new HashMap<>();
properties.put(USER_PROPERTY_NAME, "sa");
properties.put(PASSWORD_PROPERTY_NAME, "A_Str0ng_Required_Password");
}

public void changeProperties() {
properties = new HashMap<>();
properties.put(USER_PROPERTY_NAME, "user2");
properties.put(PASSWORD_PROPERTY_NAME, "user2_Has_A_Str0ng_Required_Password");
}

@Override
public Map<String, String> getCredentials(String credentialsProviderName) {
log.info("credentials provider returning " + properties);
return properties;
super("sa", "A_Str0ng_Required_Password", "user2", "user2_Has_A_Str0ng_Required_Password");
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package io.quarkus.reactive.mssql.client;

import static io.restassured.RestAssured.given;
import static java.util.concurrent.TimeUnit.SECONDS;

import org.hamcrest.CoreMatchers;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.reactive.datasource.ChangingCredentialsTestBase;
import io.quarkus.test.QuarkusUnitTest;

public class ChangingCredentialsTest {
public class ChangingCredentialsTest extends ChangingCredentialsTestBase {

@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
Expand All @@ -18,21 +14,7 @@ public class ChangingCredentialsTest {
.addClass(ChangingCredentialsTestResource.class)
.addAsResource("application-changing-credentials.properties", "application.properties"));

@Test
public void testConnect() throws Exception {
given()
.when().get("/test")
.then()
.statusCode(200)
.body(CoreMatchers.equalTo("dbo"));

SECONDS.sleep(2); // sleep longer than pool idle connection timeout

given()
.when().get("/test")
.then()
.statusCode(200)
.body(CoreMatchers.equalTo("user2"));
public ChangingCredentialsTest() {
super("dbo", "user2");
}

}
6 changes: 6 additions & 0 deletions extensions/reactive-mysql-client/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-reactive-datasource-deployment</artifactId>
<scope>test</scope>
<type>test-jar</type>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,13 @@
package io.quarkus.reactive.mysql.client;

import java.util.HashMap;
import java.util.Map;

import jakarta.enterprise.context.ApplicationScoped;

import org.jboss.logging.Logger;

import io.quarkus.credentials.CredentialsProvider;
import io.quarkus.reactive.datasource.ChangingCredentialsProviderBase;

@ApplicationScoped
public class ChangingCredentialsProvider implements CredentialsProvider {

private static final Logger log = Logger.getLogger(ChangingCredentialsProvider.class.getName());

private volatile Map<String, String> properties;
public class ChangingCredentialsProvider extends ChangingCredentialsProviderBase {

public ChangingCredentialsProvider() {
properties = new HashMap<>();
properties.put(USER_PROPERTY_NAME, "hibernate_orm_test");
properties.put(PASSWORD_PROPERTY_NAME, "hibernate_orm_test");
}

public void changeProperties() {
properties = new HashMap<>();
properties.put(USER_PROPERTY_NAME, "user2");
properties.put(PASSWORD_PROPERTY_NAME, "user2");
}

@Override
public Map<String, String> getCredentials(String credentialsProviderName) {
log.info("credentials provider returning " + properties);
return properties;
super("hibernate_orm_test", "hibernate_orm_test", "user2", "user2");
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package io.quarkus.reactive.mysql.client;

import static io.restassured.RestAssured.given;
import static java.util.concurrent.TimeUnit.SECONDS;

import org.hamcrest.CoreMatchers;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.reactive.datasource.ChangingCredentialsTestBase;
import io.quarkus.test.QuarkusUnitTest;

public class ChangingCredentialsTest {
public class ChangingCredentialsTest extends ChangingCredentialsTestBase {

@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
Expand All @@ -18,21 +14,7 @@ public class ChangingCredentialsTest {
.addClass(ChangingCredentialsTestResource.class)
.addAsResource("application-changing-credentials.properties", "application.properties"));

@Test
public void testConnect() throws Exception {
given()
.when().get("/test")
.then()
.statusCode(200)
.body(CoreMatchers.equalTo("hibernate_orm_test@%"));

SECONDS.sleep(2); // sleep longer than pool idle connection timeout

given()
.when().get("/test")
.then()
.statusCode(200)
.body(CoreMatchers.equalTo("user2@%"));
public ChangingCredentialsTest() {
super("hibernate_orm_test@%", "user2@%");
}

}
6 changes: 6 additions & 0 deletions extensions/reactive-oracle-client/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-reactive-datasource-deployment</artifactId>
<scope>test</scope>
<type>test-jar</type>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,13 @@
package io.quarkus.reactive.oracle.client;

import java.util.HashMap;
import java.util.Map;

import jakarta.enterprise.context.ApplicationScoped;

import org.jboss.logging.Logger;

import io.quarkus.credentials.CredentialsProvider;
import io.quarkus.reactive.datasource.ChangingCredentialsProviderBase;

@ApplicationScoped
public class ChangingCredentialsProvider implements CredentialsProvider {

private static final Logger log = Logger.getLogger(ChangingCredentialsProvider.class.getName());

private volatile Map<String, String> properties;
public class ChangingCredentialsProvider extends ChangingCredentialsProviderBase {

public ChangingCredentialsProvider() {
properties = new HashMap<>();
properties.put(USER_PROPERTY_NAME, "SYSTEM");
properties.put(PASSWORD_PROPERTY_NAME, "hibernate_orm_test");
}

public void changeProperties() {
properties = new HashMap<>();
properties.put(USER_PROPERTY_NAME, "user2");
properties.put(PASSWORD_PROPERTY_NAME, "user2");
}

@Override
public Map<String, String> getCredentials(String credentialsProviderName) {
log.info("credentials provider returning " + properties);
return properties;
super("SYSTEM", "hibernate_orm_test", "user2", "user2");
}
}
Loading

0 comments on commit adebae9

Please sign in to comment.