Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate examples to junit5 #7417

Merged
merged 19 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
3e94bab
Migrate Hazelcast examples from junit4 to junit5
samed-bicer Aug 15, 2023
5308421
Migrate ImmuDb examples from junit4 to junit5
samed-bicer Aug 15, 2023
862fa0d
Migrate kafka-cluster examples from junit4 to junit5
samed-bicer Aug 15, 2023
13fcd56
Migrate nats examples from junit4 to junit5
samed-bicer Aug 15, 2023
912ac43
Migrate sftp examples from junit4 to junit5
samed-bicer Aug 15, 2023
348a101
Migrate singleton-container examples from junit4 to junit5
samed-bicer Aug 15, 2023
25e649a
Migrate solr-container examples from junit4 to junit5
samed-bicer Aug 15, 2023
1113f45
Migrate zookeeper examples from junit4 to junit5
samed-bicer Aug 15, 2023
e067005
Migrate spring-boot examples from junit4 to junit5
samed-bicer Aug 15, 2023
fb3a845
Migrate spring-boot-kotlin examples from junit4 to junit5
samed-bicer Aug 15, 2023
1842d4f
Migrate redis-backed-cache examples from junit4 to junit5
samed-bicer Aug 15, 2023
ceb3e68
Migrate selenium-container examples from junit4 to junit5
samed-bicer Aug 15, 2023
bad1441
Remove unnecessary public access modifiers from junit5 tests
samed-bicer Aug 24, 2023
fd4e115
Merge branch 'main' into migrate-examples-junit5
eddumelendez Aug 30, 2023
ee81dec
Update examples/spring-boot-kotlin-redis/src/test/kotlin/com/example/…
eddumelendez Aug 30, 2023
f32e5d5
Update examples/spring-boot/src/test/java/com/example/AbstractIntegra…
eddumelendez Aug 30, 2023
8e6477e
Update examples/spring-boot-kotlin-redis/src/test/kotlin/com/example/…
eddumelendez Aug 30, 2023
90f0651
Update examples/spring-boot-kotlin-redis/src/test/kotlin/com/example/…
eddumelendez Aug 30, 2023
b8c7312
Fix format
eddumelendez Aug 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions examples/hazelcast/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ dependencies {
testImplementation 'com.hazelcast:hazelcast:5.2.3'
testImplementation 'ch.qos.logback:logback-classic:1.3.8'
testImplementation 'org.assertj:assertj-core:3.24.2'
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.0'
}

test {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import com.hazelcast.client.HazelcastClient;
import com.hazelcast.client.config.ClientConfig;
import com.hazelcast.core.HazelcastInstance;
import org.junit.After;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.Network;
import org.testcontainers.containers.wait.strategy.Wait;
Expand All @@ -18,7 +18,7 @@
/**
* Examples with Hazelcast using both a single container and a cluster with two containers.
*/
public class HazelcastTest {
class HazelcastTest {

// Hazelcast values
private static final String HZ_IMAGE_NAME = "hazelcast/hazelcast:5.2.0";
Expand Down Expand Up @@ -46,13 +46,13 @@ public class HazelcastTest {

private static final String TRUE_VALUE = "true";

@After
public void cleanUp() {
@AfterEach
void cleanUp() {
HazelcastClient.shutdownAll();
}

@Test
public void singleHazelcastContainer() {
void singleHazelcastContainer() {
try (
GenericContainer<?> container = new GenericContainer<>(DockerImageName.parse(HZ_IMAGE_NAME))
.withExposedPorts(DEFAULT_EXPOSED_PORT)
Expand All @@ -76,7 +76,7 @@ public void singleHazelcastContainer() {
}

@Test
public void hazelcastCluster() {
void hazelcastCluster() {
Network network = Network.newNetwork();
try (
GenericContainer<?> container1 = new GenericContainer<>(DockerImageName.parse(HZ_IMAGE_NAME))
Expand Down
6 changes: 6 additions & 0 deletions examples/immudb/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ repositories {
dependencies {
implementation 'io.codenotary:immudb4j:1.0.0'
testImplementation 'org.testcontainers:testcontainers'
testImplementation 'org.testcontainers:junit-jupiter'
testImplementation 'org.assertj:assertj-core:3.24.2'
testImplementation 'com.google.guava:guava:23.0'
testImplementation 'ch.qos.logback:logback-classic:1.3.8'
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.0'
}

test {
useJUnitPlatform()
}
30 changes: 16 additions & 14 deletions examples/immudb/src/test/java/ImmuDbTest.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import io.codenotary.immudb4j.Entry;
import io.codenotary.immudb4j.ImmuClient;
import io.codenotary.immudb4j.exceptions.VerificationException;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;

import static org.assertj.core.api.Assertions.assertThat;

/**
* Test class for the ImmuDbClient.
*/
public class ImmuDbTest {
@Testcontainers
class ImmuDbTest {

// Default port for the ImmuDb server
private static final int IMMUDB_PORT = 3322;
Expand All @@ -29,16 +31,16 @@ public class ImmuDbTest {
private final String IMMUDB_DATABASE = "defaultdb";

// Test container for the ImmuDb database, with the latest version of the image and exposed port
@ClassRule
@Container
public static final GenericContainer<?> immuDbContainer = new GenericContainer<>("codenotary/immudb:1.3")
.withExposedPorts(IMMUDB_PORT)
.waitingFor(Wait.forLogMessage(".*Web API server enabled.*", 1));

// ImmuClient used to interact with the DB
private ImmuClient immuClient;

@Before
public void setUp() {
@BeforeEach
void setUp() {
this.immuClient =
ImmuClient
.newBuilder()
Expand All @@ -48,13 +50,13 @@ public void setUp() {
this.immuClient.openSession(IMMUDB_DATABASE, IMMUDB_USER, IMMUDB_PASSWORD);
}

@After
public void tearDown() {
@AfterEach
void tearDown() {
this.immuClient.closeSession();
}

@Test
public void testGetValue() {
void testGetValue() {
try {
immuClient.set("test1", "test2".getBytes());

Expand All @@ -64,10 +66,10 @@ public void testGetValue() {
byte[] value = entry.getValue();
assertThat(new String(value)).isEqualTo("test2");
} else {
Assert.fail();
Assertions.fail();
}
} catch (VerificationException e) {
Assert.fail();
Assertions.fail();
}
}
}
5 changes: 5 additions & 0 deletions examples/kafka-cluster/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ dependencies {
testImplementation 'org.assertj:assertj-core:3.24.2'
testImplementation 'com.google.guava:guava:23.0'
testImplementation 'ch.qos.logback:logback-classic:1.3.8'
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.0'
}

test {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.common.serialization.StringDeserializer;
import org.apache.kafka.common.serialization.StringSerializer;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.rnorth.ducttape.unreliables.Unreliables;

import java.time.Duration;
Expand All @@ -25,10 +25,10 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.tuple;

public class KafkaContainerClusterTest {
class KafkaContainerClusterTest {

@Test
public void testKafkaContainerCluster() throws Exception {
void testKafkaContainerCluster() throws Exception {
try (KafkaContainerCluster cluster = new KafkaContainerCluster("6.2.1", 3, 2)) {
cluster.start();
String bootstrapServers = cluster.getBootstrapServers();
Expand All @@ -40,7 +40,7 @@ public void testKafkaContainerCluster() throws Exception {
}

@Test
public void testKafkaContainerKraftCluster() throws Exception {
void testKafkaContainerKraftCluster() throws Exception {
try (KafkaContainerKraftCluster cluster = new KafkaContainerKraftCluster("7.0.0", 3, 2)) {
cluster.start();
String bootstrapServers = cluster.getBootstrapServers();
Expand All @@ -52,7 +52,7 @@ public void testKafkaContainerKraftCluster() throws Exception {
}

@Test
public void testKafkaContainerKraftClusterAfterConfluentPlatform740() throws Exception {
void testKafkaContainerKraftClusterAfterConfluentPlatform740() throws Exception {
try (KafkaContainerKraftCluster cluster = new KafkaContainerKraftCluster("7.4.0", 3, 2)) {
cluster.start();
String bootstrapServers = cluster.getBootstrapServers();
Expand Down
5 changes: 5 additions & 0 deletions examples/nats/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@ dependencies {
testImplementation 'io.nats:jnats:2.16.13'
testImplementation 'ch.qos.logback:logback-classic:1.3.8'
testImplementation 'org.apache.httpcomponents:httpclient:4.5.14'
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.0'
}

test {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.HttpClientBuilder;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.GenericContainer;

import java.io.IOException;

import static org.assertj.core.api.Assertions.assertThat;

public class NatsContainerTest {
class NatsContainerTest {

public static final Integer NATS_PORT = 4222;

public static final Integer NATS_MGMT_PORT = 8222;

@Test
public void test() throws IOException, InterruptedException {
void test() throws IOException, InterruptedException {
try (
GenericContainer<?> nats = new GenericContainer<>("nats:2.9.8-alpine3.16")
.withExposedPorts(NATS_PORT, NATS_MGMT_PORT)
Expand All @@ -38,7 +38,7 @@ public void test() throws IOException, InterruptedException {
}

@Test
public void testServerStatus() throws IOException {
void testServerStatus() throws IOException {
try (
GenericContainer<?> nats = new GenericContainer<>("nats:2.9.8-alpine3.16")
.withExposedPorts(NATS_PORT, NATS_MGMT_PORT)
Expand Down
7 changes: 6 additions & 1 deletion examples/redis-backed-cache/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ dependencies {
implementation 'com.google.code.gson:gson:2.10.1'
implementation 'com.google.guava:guava:23.0'
testImplementation 'org.testcontainers:testcontainers'
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.testcontainers:junit-jupiter'
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.0'
testImplementation 'ch.qos.logback:logback-classic:1.3.8'
testImplementation 'org.assertj:assertj-core:3.24.2'
}

test {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import com.mycompany.cache.Cache;
import com.mycompany.cache.RedisBackedCache;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.utility.DockerImageName;
import redis.clients.jedis.Jedis;

Expand All @@ -14,23 +15,24 @@
/**
* Integration test for Redis-backed cache implementation.
*/
public class RedisBackedCacheTest {
@Testcontainers
class RedisBackedCacheTest {

@Rule
@Container
public GenericContainer<?> redis = new GenericContainer<>(DockerImageName.parse("redis:3.0.6"))
.withExposedPorts(6379);

private Cache cache;

@Before
public void setUp() throws Exception {
@BeforeEach
void setUp() throws Exception {
Jedis jedis = new Jedis(redis.getHost(), redis.getMappedPort(6379));

cache = new RedisBackedCache(jedis, "test");
}

@Test
public void testFindingAnInsertedValue() {
void testFindingAnInsertedValue() {
cache.put("foo", "FOO");
Optional<String> foundObject = cache.get("foo", String.class);

Expand All @@ -41,7 +43,7 @@ public void testFindingAnInsertedValue() {
}

@Test
public void testNotFindingAValueThatWasNotInserted() {
void testNotFindingAValueThatWasNotInserted() {
Optional<String> foundObject = cache.get("bar", String.class);

assertThat(foundObject.isPresent())
Expand Down
6 changes: 6 additions & 0 deletions examples/selenium-container/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,11 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.testcontainers:selenium'
testImplementation 'org.testcontainers:junit-jupiter'
testImplementation 'org.assertj:assertj-core:3.24.2'
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.0'
}

test {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import com.example.DemoApplication;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeOptions;
Expand All @@ -13,10 +12,11 @@
import org.springframework.context.ApplicationListener;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.testcontainers.Testcontainers;
import org.testcontainers.containers.BrowserWebDriverContainer;
import org.testcontainers.containers.BrowserWebDriverContainer.VncRecordingMode;
import org.testcontainers.junit.jupiter.Container;

import java.io.File;
import java.time.Duration;
Expand All @@ -27,21 +27,22 @@
/**
* Simple example of plain Selenium usage.
*/
@RunWith(SpringJUnit4ClassRunner.class)
@org.testcontainers.junit.jupiter.Testcontainers
@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = DemoApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ContextConfiguration(initializers = SeleniumContainerTest.Initializer.class)
public class SeleniumContainerTest {
class SeleniumContainerTest {

@LocalServerPort
private int port;

@Rule
@Container
public BrowserWebDriverContainer chrome = new BrowserWebDriverContainer()
.withCapabilities(new ChromeOptions())
.withRecordingMode(VncRecordingMode.RECORD_ALL, new File("build"));

@Test
public void simplePlainSeleniumTest() {
void simplePlainSeleniumTest() {
RemoteWebDriver driver = new RemoteWebDriver(chrome.getSeleniumAddress(), new ChromeOptions());
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30));

Expand All @@ -51,7 +52,7 @@ public void simplePlainSeleniumTest() {
assertThat(hElement).as("The h element is found").isNotEmpty();
}

public static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {

@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
Expand Down
5 changes: 5 additions & 0 deletions examples/sftp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ dependencies {
testImplementation 'org.testcontainers:testcontainers'
testImplementation 'org.assertj:assertj-core:3.24.2'
testImplementation 'ch.qos.logback:logback-classic:1.3.8'
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.0'
}

test {
useJUnitPlatform()
}
Loading
Loading