Skip to content

Commit

Permalink
Update integration tests to use JUnit 5
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanemerson committed Oct 11, 2023
1 parent ed622ca commit 516f371
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 45 deletions.
22 changes: 18 additions & 4 deletions integration-tests/server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-server-testdriver-junit4</artifactId>
</dependency>
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-server-testdriver-junit5</artifactId>
Expand All @@ -80,6 +76,24 @@
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${version.junit5}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${version.junit5}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite</artifactId>
<version>${version.junit.platform}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.infinispan.quarkus.server;

import static org.infinispan.server.test.core.Common.sync;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.BufferedReader;
import java.io.IOException;
Expand All @@ -13,12 +13,10 @@
import org.infinispan.client.rest.RestCacheManagerClient;
import org.infinispan.client.rest.RestClient;
import org.infinispan.client.rest.RestResponse;
import org.infinispan.server.test.junit4.InfinispanServerRule;
import org.infinispan.server.test.junit4.InfinispanServerRuleBuilder;
import org.infinispan.server.test.junit4.InfinispanServerTestMethodRule;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.infinispan.server.test.junit5.InfinispanServerExtension;
import org.infinispan.server.test.junit5.InfinispanServerExtensionBuilder;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

/**
* Test to ensure that the native quarkus CLI is able to execute.
Expand All @@ -27,18 +25,15 @@
* @since 12.1
*/
public class NativeCliIT {
@ClassRule
public static final InfinispanServerRule SERVERS =
InfinispanServerRuleBuilder.config("configuration/ClusteredServerTest.xml")
@RegisterExtension
public static final InfinispanServerExtension SERVERS =
InfinispanServerExtensionBuilder.config("configuration/ClusteredServerTest.xml")
.numServers(1)
.build();

@Rule
public InfinispanServerTestMethodRule SERVER_TEST = new InfinispanServerTestMethodRule(SERVERS);

@Test
public void testCliBatch() throws Exception {
RestClient client = SERVER_TEST.rest().create();
RestClient client = SERVERS.rest().create();
RestCacheManagerClient cm = client.cacheManager("default");
RestResponse restResponse = sync(cm.healthStatus());
assertEquals(200, restResponse.getStatus());
Expand All @@ -65,12 +60,12 @@ public void testCliBatch() throws Exception {
}).start();

p.waitFor(5, TimeUnit.SECONDS);
assertEquals(0, p.exitValue());
String stderr = sb.toString();
if (!stderr.isEmpty()) {
System.err.println(stderr);
fail("Unexpected CLI output in stderr");
}
assertEquals(0, p.exitValue());
restResponse = sync(client.cache("mybatch").exists());
assertEquals(204, restResponse.getStatus());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
import org.infinispan.server.functional.rest.RestOperations;
import org.infinispan.server.functional.rest.RestRouter;
import org.infinispan.server.functional.rest.RestServerResource;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.platform.suite.api.SelectClasses;
import org.junit.platform.suite.api.Suite;

/**
* We must extend {@link ClusteredIT} so that we can specify the test classes required in the suite. All of these
* tests rely on {@code InfinispanServerRule SERVERS = ClusteredIT.SERVERS;}, so it's not possible to simply execute
* them outside of a suite as the containers are shutdown after the first test class has completed.
* We must extend {@link ClusteredIT} so that we can specify the test classes required in the suite. All of these tests
* rely on {@code InfinispanServerRule SERVERS = ClusteredIT.SERVERS;}, so it's not possible to simply execute them
* outside of a suite as the containers are shutdown after the first test class has completed.
*
* @author Ryan Emerson
* @since 11.0
*/
@RunWith(Suite.class)
@Suite.SuiteClasses({
@Suite
@SelectClasses({
HotRodCacheOperations.class,
HotRodCounterOperations.class,
HotRodMultiMapOperations.class,
Expand All @@ -29,5 +29,5 @@
RestRouter.class,
RestServerResource.class
})
public class NativeClusteredIT extends ClusteredIT {
public class NativeClusteredIT extends ClusteredIT {
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package org.infinispan.quarkus.server;

import static org.infinispan.server.test.core.AbstractInfinispanServerDriver.abbreviate;
import static org.infinispan.server.test.core.Common.sync;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import org.infinispan.client.rest.RestCacheManagerClient;
import org.infinispan.client.rest.RestClient;
import org.infinispan.client.rest.RestResponse;
import org.infinispan.server.test.junit4.InfinispanServerRule;
import org.infinispan.server.test.junit4.InfinispanServerRuleBuilder;
import org.infinispan.server.test.junit4.InfinispanServerTestMethodRule;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.infinispan.server.test.junit5.InfinispanServerExtension;
import org.infinispan.server.test.junit5.InfinispanServerExtensionBuilder;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand All @@ -25,14 +24,12 @@
*/
public class RestCacheManagerResource {

@ClassRule
public static final InfinispanServerRule SERVERS =
InfinispanServerRuleBuilder.config("configuration/ClusteredServerTest.xml")
@RegisterExtension
public static final InfinispanServerExtension SERVERS =
InfinispanServerExtensionBuilder.config("configuration/ClusteredServerTest.xml")
.numServers(2)
.property("infinispan.bind.address", "0.0.0.0")
.build();
@Rule
public InfinispanServerTestMethodRule SERVER_TEST = new InfinispanServerTestMethodRule(SERVERS);

private final ObjectMapper mapper = new ObjectMapper();

Expand All @@ -51,7 +48,7 @@ public void testHealthInfo() throws Exception {
JsonNode root = mapper.readTree(restResponse.getBody());

JsonNode clusterHealth = root.get("cluster_health");
assertEquals(RestCacheManagerResource.class.getName(), clusterHealth.get("cluster_name").asText());
assertEquals(abbreviate(RestCacheManagerResource.class.getName()), clusterHealth.get("cluster_name").asText());
assertEquals("HEALTHY", clusterHealth.get("health_status").asText());
assertEquals(2, clusterHealth.get("number_of_nodes").asInt());
assertEquals(2, clusterHealth.withArray("node_names").size());
Expand All @@ -76,7 +73,7 @@ public void testNamedCacheConfiguration() throws Exception {

@Test
public void testCacheInfo() throws Exception {
RestClient client = SERVER_TEST.rest().create();
RestClient client = SERVERS.rest().create();
String cacheName = "test";
RestResponse restResponse = sync(client.cache(cacheName).createWithTemplate("org.infinispan.LOCAL"));
assertEquals(200, restResponse.getStatus());
Expand All @@ -103,6 +100,6 @@ public void testCacheInfo() throws Exception {
}

private RestCacheManagerClient client() {
return SERVER_TEST.rest().create().cacheManager("default");
return SERVERS.rest().create().cacheManager("default");
}
}

0 comments on commit 516f371

Please sign in to comment.