Skip to content

Commit

Permalink
Upgrade tests to JUnit 5 (closes clusterbench#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhusar committed Mar 7, 2024
1 parent cd62d32 commit a7bc5ff
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 39 deletions.
9 changes: 7 additions & 2 deletions clusterbench-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,13 @@
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

package org.jboss.test.clusterbench.common.load;

import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;

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

/**
* @author Michal Babacek
Expand All @@ -23,8 +23,8 @@ public void spawnLoadThreadsTest() {
String result = averageSystemLoad.spawnLoadThreads(threads, duration);
long ended = System.currentTimeMillis();
String infoMessage = "DONE, I was stressing CPU with " + threads + " evil threads for ";
assertTrue("This message [" + infoMessage + "] has to be a substring of [" + result + "].", result.contains(infoMessage));
assertTrue(result.contains(infoMessage), "This message [" + infoMessage + "] has to be a substring of [" + result + "].");
long took = ended - started;
assertTrue("CPU stressing took less time than it should have. Was:" + took + ", expected at least:" + duration, took >= duration);
assertTrue(took >= duration, "CPU stressing took less time than it should have. Was:" + took + ", expected at least:" + duration);
}
}
17 changes: 15 additions & 2 deletions clusterbench-ee10-ear/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M9</version>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.9.1</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>failsafe-integration-test</id>
Expand Down Expand Up @@ -128,8 +136,13 @@
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

package org.jboss.test.clusterbench.ear;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Optional;
Expand All @@ -14,8 +17,7 @@
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;

/**
* @author Radoslav Husar
Expand All @@ -32,8 +34,9 @@ public void test() throws Exception {
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
HttpGet httpGet = new HttpGet("http://localhost:8080/clusterbench/debug");


try (CloseableHttpResponse response = httpClient.execute(httpGet)) {
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
assertEquals(200, response.getStatusLine().getStatusCode());
HttpEntity entity = response.getEntity();

Optional<String> optionalNodeName = new BufferedReader(new InputStreamReader(entity.getContent()))
Expand All @@ -45,13 +48,14 @@ public void test() throws Exception {
})
.findFirst();


if (optionalNodeName.isPresent()) {
Assert.assertEquals(JBOSS_NODE_NAME, optionalNodeName.get());
assertEquals(JBOSS_NODE_NAME, optionalNodeName.get());
} else {
Assert.fail();
fail();
}
}
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

package org.jboss.test.clusterbench.ear;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Arrays;
import java.util.Optional;

Expand All @@ -14,8 +17,7 @@
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;

/**
* Test for {@link org.jboss.test.clusterbench.web.debug.HttpResponseServlet}.
Expand All @@ -30,27 +32,27 @@ public void test() throws Exception {
HttpGet httpGet = new HttpGet("http://localhost:8080/clusterbench/http-response?code=200");

try (CloseableHttpResponse response = httpClient.execute(httpGet)) {
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
assertEquals(200, response.getStatusLine().getStatusCode());

String responseBody = EntityUtils.toString(response.getEntity());
Assert.assertTrue(responseBody.contains("HTTP Code was: 200"));
Assert.assertTrue(responseBody.contains("JVM route: " + DebugServletIT.JBOSS_NODE_NAME));
Assert.assertTrue(responseBody.contains("Session isNew: true"));
assertTrue(responseBody.contains("HTTP Code was: 200"));
assertTrue(responseBody.contains("JVM route: " + DebugServletIT.JBOSS_NODE_NAME));
assertTrue(responseBody.contains("Session isNew: true"));

// Also ensure session is created
Optional<Header> header = Arrays.stream(response.getAllHeaders()).filter(h -> Arrays.stream(h.getElements()).anyMatch(e -> e.getName().equals("JSESSIONID"))).findAny();
Assert.assertTrue(header.isPresent());
assertTrue(header.isPresent());
}

httpGet = new HttpGet("http://localhost:8080/clusterbench/http-response?code=503");

try (CloseableHttpResponse response = httpClient.execute(httpGet)) {
Assert.assertEquals(503, response.getStatusLine().getStatusCode());
assertEquals(503, response.getStatusLine().getStatusCode());

String responseBody = EntityUtils.toString(response.getEntity());
Assert.assertTrue(responseBody.contains("HTTP Code was: 503"));
Assert.assertTrue(responseBody.contains("JVM route: " + DebugServletIT.JBOSS_NODE_NAME));
Assert.assertTrue(responseBody.contains("Session isNew: false"));
assertTrue(responseBody.contains("HTTP Code was: 503"));
assertTrue(responseBody.contains("JVM route: " + DebugServletIT.JBOSS_NODE_NAME));
assertTrue(responseBody.contains("Session isNew: false"));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

package org.jboss.test.clusterbench.ear;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Arrays;
import java.util.Optional;

Expand All @@ -14,8 +18,7 @@
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;

/**
* @author Radoslav Husar
Expand All @@ -28,27 +31,27 @@ public void test() throws Exception {
HttpGet httpGet = new HttpGet("http://localhost:8080/clusterbench/jboss-node-name");

try (CloseableHttpResponse response = httpClient.execute(httpGet)) {
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
assertEquals(200, response.getStatusLine().getStatusCode());

String responseBody = EntityUtils.toString(response.getEntity());
Assert.assertEquals(DebugServletIT.JBOSS_NODE_NAME, responseBody);
assertEquals(DebugServletIT.JBOSS_NODE_NAME, responseBody);

// Also ensure session is created with ?create=true
Optional<Header> header = Arrays.stream(response.getAllHeaders()).filter(h -> Arrays.stream(h.getElements()).anyMatch(e -> e.getName().equals("JSESSIONID"))).findAny();
Assert.assertFalse(header.isPresent());
assertFalse(header.isPresent());
}

httpGet = new HttpGet("http://localhost:8080/clusterbench/jboss-node-name?create=true");

try (CloseableHttpResponse response = httpClient.execute(httpGet)) {
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
assertEquals(200, response.getStatusLine().getStatusCode());

String responseBody = EntityUtils.toString(response.getEntity());
Assert.assertEquals(DebugServletIT.JBOSS_NODE_NAME, responseBody);
assertEquals(DebugServletIT.JBOSS_NODE_NAME, responseBody);

// Also ensure session is created with ?create=true
Optional<Header> header = Arrays.stream(response.getAllHeaders()).filter(h -> Arrays.stream(h.getElements()).anyMatch(e -> e.getName().equals("JSESSIONID"))).findAny();
Assert.assertTrue(header.isPresent());
assertTrue(header.isPresent());
}
}
}
Expand Down
6 changes: 0 additions & 6 deletions clusterbench-ee10-web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,6 @@
<artifactId>jgroups</artifactId>
<scope>provided</scope>
</dependency>
<!-- Unit tests -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
14 changes: 14 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<version.org.wildfly>31.0.1.Final</version.org.wildfly>
<version.org.wildfly.cloud-feature-pack>6.0.0.Final</version.org.wildfly.cloud-feature-pack>
<version.org.wildfly.maven.plugin>4.2.2.Final</version.org.wildfly.maven.plugin>
<version.org.junit.jupiter>5.10.0</version.org.junit.jupiter>
<wildfly.skip>true</wildfly.skip>
</properties>

Expand All @@ -70,6 +71,19 @@
<version>${version.org.wildfly.cloud-feature-pack}</version>
<type>zip</type>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${version.org.junit.jupiter}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${version.org.junit.jupiter}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down

0 comments on commit a7bc5ff

Please sign in to comment.