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

Update tests to use Junit 5 #252

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -550,12 +550,6 @@
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.11.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite</artifactId>
Expand Down
6 changes: 4 additions & 2 deletions src/test/java/ibm/jceplus/junit/TestAll.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
import org.junit.platform.suite.api.SelectClasses;
import org.junit.platform.suite.api.Suite;

@SelectClasses({ibm.jceplus.junit.openjceplus.TestAll.class,
ibm.jceplus.junit.openjceplusfips.TestAll.class,})
@SelectClasses({
ibm.jceplus.junit.openjceplus.TestAll.class,
ibm.jceplus.junit.openjceplusfips.TestAll.class
})

@Suite
public class TestAll {
Expand Down
7 changes: 5 additions & 2 deletions src/test/java/ibm/jceplus/junit/TestIntegration.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
import org.junit.platform.suite.api.SelectClasses;
import org.junit.platform.suite.api.Suite;

@SelectClasses({ibm.jceplus.junit.openjceplus.integration.TestAll.class,
ibm.jceplus.junit.openjceplusfips.integration.TestAll.class})
@SelectClasses({
ibm.jceplus.junit.openjceplus.integration.TestAll.class,
ibm.jceplus.junit.openjceplusfips.integration.TestAll.class
})

@Suite
public class TestIntegration {
}
5 changes: 4 additions & 1 deletion src/test/java/ibm/jceplus/junit/TestMemStressAll.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
import org.junit.platform.suite.api.SelectClasses;
import org.junit.platform.suite.api.Suite;

@SelectClasses({ibm.jceplus.junit.openjceplus.memstress.TestMemStressAll.class})
@SelectClasses({
ibm.jceplus.junit.openjceplus.memstress.TestMemStressAll.class
})

@Suite
public class TestMemStressAll {
}
18 changes: 11 additions & 7 deletions src/test/java/ibm/jceplus/junit/TestMultithread.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,20 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import junit.framework.TestCase;
import org.junit.jupiter.api.Test;
import org.junit.platform.launcher.Launcher;
import org.junit.platform.launcher.LauncherDiscoveryRequest;
import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder;
import org.junit.platform.launcher.core.LauncherFactory;
import org.junit.platform.launcher.listeners.SummaryGeneratingListener;
import org.junit.platform.launcher.listeners.TestExecutionSummary;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass;

public class TestMultithread extends TestCase {
public class TestMultithread {
private final int numThreads = 10;
private final int timeoutSec = 3000;
private final int timeoutSec = 4500;
private final String[] testList = {
"ibm.jceplus.junit.openjceplus.multithread.TestAES_128",
"ibm.jceplus.junit.openjceplus.multithread.TestAES_192",
Expand Down Expand Up @@ -113,12 +115,13 @@ public void run() {
}
// wait until all threads are ready
assertTrue(
"Timeout initializing threads! Perform long lasting initializations before passing runnables to assertConcurrent",
allExecutorThreadsReady.await(numThreads * 50, TimeUnit.MILLISECONDS));
allExecutorThreadsReady.await(numThreads * 100, TimeUnit.MILLISECONDS),
"Timeout initializing threads! Perform long lasting initializations before passing runnables to assertConcurrent");
// start all test runners
afterInitBlocker.countDown();
assertTrue(message + " timeout! More than " + maxTimeoutSeconds + " seconds",
allDone.await(maxTimeoutSeconds, TimeUnit.SECONDS));
assertTrue(
allDone.await(maxTimeoutSeconds, TimeUnit.SECONDS),
message + " timeout! More than " + maxTimeoutSeconds + " seconds");
} finally {
threadPool.shutdownNow();
}
Expand Down Expand Up @@ -154,6 +157,7 @@ public List<TestExecutionSummary.Failure> call() {
};
}

@Test
public void testMultithread() {
System.out.println("#threads=" + numThreads + " timeout=" + timeoutSec);

Expand Down
18 changes: 11 additions & 7 deletions src/test/java/ibm/jceplus/junit/TestMultithreadFIPS.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,20 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import junit.framework.TestCase;
import org.junit.jupiter.api.Test;
import org.junit.platform.launcher.Launcher;
import org.junit.platform.launcher.LauncherDiscoveryRequest;
import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder;
import org.junit.platform.launcher.core.LauncherFactory;
import org.junit.platform.launcher.listeners.SummaryGeneratingListener;
import org.junit.platform.launcher.listeners.TestExecutionSummary;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass;

public class TestMultithreadFIPS extends TestCase {
public class TestMultithreadFIPS {
private final int numThreads = 10;
private final int timeoutSec = 3000;
private final int timeoutSec = 4500;
private final String[] testList = {
"ibm.jceplus.junit.openjceplusfips.multithread.TestAES_128",
"ibm.jceplus.junit.openjceplusfips.multithread.TestAES_192",
Expand Down Expand Up @@ -108,12 +110,13 @@ public void run() {
}
// wait until all threads are ready
assertTrue(
"Timeout initializing threads! Perform long lasting initializations before passing runnables to assertConcurrent",
allExecutorThreadsReady.await(numThreads * 50, TimeUnit.MILLISECONDS));
allExecutorThreadsReady.await(numThreads * 100, TimeUnit.MILLISECONDS),
"Timeout initializing threads! Perform long lasting initializations before passing runnables to assertConcurrent");
// start all test runners
afterInitBlocker.countDown();
assertTrue(message + " timeout! More than " + maxTimeoutSeconds + " seconds",
allDone.await(maxTimeoutSeconds, TimeUnit.SECONDS));
assertTrue(
allDone.await(maxTimeoutSeconds, TimeUnit.SECONDS),
message + " timeout! More than " + maxTimeoutSeconds + " seconds");
} finally {
threadPool.shutdownNow();
}
Expand Down Expand Up @@ -149,6 +152,7 @@ public List<TestExecutionSummary.Failure> call() {
};
}

@Test
public void testMultithreadFIPS() {
System.out.println("#threads=" + numThreads + " timeout=" + timeoutSec);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@
import java.security.SecureRandom;
import java.util.Arrays;
import java.util.Random;
import org.junit.jupiter.api.Test;

/**
* Test class for ByteArrayOutputDelay
*
*/
public class BaseByteArrayOutputDelayTest extends BaseTestPublicMethodsToMakeNonPublic {

public BaseByteArrayOutputDelayTest(String providerName) {
super(providerName);
}

private static byte[] TEST_DATA = new byte[1024];

static {
Expand All @@ -36,42 +33,35 @@ public BaseByteArrayOutputDelayTest(String providerName) {

private static int TEST_COUNT = 0;

public static void main(String[] args) throws IOException {

testSingleByte();
testIllegalByteDelay();
testDifferentDelayWritingByteAtATime();
testDelayLargerThanInput();
testDelaySameSizeAsInput();
testRandom();

System.out.println("Number of succesful tests = " + TEST_COUNT);
}

public static void testInputSizeNotMultipleOfDelay() throws IOException {
@Test
public void testInputSizeNotMultipleOfDelay() throws IOException {
testByteArrayOutputDelay(16, 11, TEST_DATA); // test left overs
}

public static void testDelaySameSizeAsInput() throws IOException {
@Test
public void testDelaySameSizeAsInput() throws IOException {
testByteArrayOutputDelay(1024, 1024, TEST_DATA); // test one shot
}

public static void testDelayLargerThanInput() throws IOException {
@Test
public void testDelayLargerThanInput() throws IOException {
testByteArrayOutputDelay(4096, 1, TEST_DATA); // test buffer larger than data
}

public static void testRandom() throws IOException {
@Test
public void testRandom() throws IOException {
testRandom(20);
}

public static void testDifferentDelayWritingByteAtATime() throws IOException {
@Test
public void testDifferentDelayWritingByteAtATime() throws IOException {
for (int bufferSize = 0; bufferSize < 17; ++bufferSize) {
testByteArrayOutputDelay(bufferSize, 1, TEST_DATA);
}

}

private static void testRandom(int iterations) throws IOException {
private void testRandom(int iterations) throws IOException {
System.out.println("Running " + iterations + " random iterations");
Random random = new SecureRandom();

Expand All @@ -96,7 +86,8 @@ private static void testRandom(int iterations) throws IOException {
*
* @throws IOException
*/
public static void testSingleByte() throws IOException {
@Test
public void testSingleByte() throws IOException {
byte[] oneByte = {(byte) 255};
testByteArrayOutputDelay(0, 1, oneByte); // no buffer
testByteArrayOutputDelay(1, 1, oneByte);
Expand All @@ -109,7 +100,8 @@ public static void testSingleByte() throws IOException {
*
* @throws IOException
*/
public static void testIllegalByteDelay() throws IOException {
@Test
public void testIllegalByteDelay() throws IOException {
byte[] oneByte = {(byte) 255};
try {
testByteArrayOutputDelay(-1, 1, oneByte);
Expand All @@ -129,7 +121,7 @@ public static void testIllegalByteDelay() throws IOException {
* @param testData - data test with
* @throws IOException
*/
public static void testByteArrayOutputDelay(int delayByte, int chopSize, byte[] testData)
private void testByteArrayOutputDelay(int delayByte, int chopSize, byte[] testData)
throws IOException {
System.out.println("Test bufferSize: " + delayByte + " chopSize: " + chopSize
+ " Total length of input data: " + testData.length);
Expand Down
27 changes: 0 additions & 27 deletions src/test/java/ibm/jceplus/junit/base/BaseTest.java

This file was deleted.

Loading