Skip to content

Commit

Permalink
Update tests to use Junit 5
Browse files Browse the repository at this point in the history
Tests have been updated to use Junit5. Changes made include:
- Removing the `junit-vintage-engine` dependency. This is no longer
in use given all tests now make use of Junit 5.
- Tests are sorted by alphabetical in test suites.
- Tests no longer need to extend `junit.framework.TestCase`.
- Tests are explicitly declared with the `@Test` annotation.
- Test constructors have been removed. Arguments to the base tests are
now sent using getters and setters. This is typically only used for
setting providers, algorithms, or key sizes in tests.
- Various `main()` methods of tests were removed as they are no longer
in use. Tests can be run using various Junit 5 test execution tools
such as IDEs, command line tools, and `mvn` surefire which is already
in place in this project.
- `BaseTest` was removed as it is no longer in use and represents a
Junit 3 test. A new `BaseTestJunit5` test has been created to represent
the new base for the test hierarchy.
- The concept of warming up a test has been removed from a few
locations. Tests are not expected to act as performance tests.
- Copyrights were updated.
- Various empty comment blocks were removed.
- Some tests were not executing using the expected provider since the
incorrect `Utils` class was in use. This was corrected to use the
correct class.
- Tests `TestAESGCM_192`, `TestAESGCM_256`, and `TestRSA_4096` were
added to the `OpenJCEPlus` and `OpenJCEPlusFIPS` provider test suites.
- Tests `TestECDHInteropBC`, `TestRSATypeCheckEnabled`, `TestAES_192`,
and `TestAES_256` were added to the `OpenJCEPlus` provider test suite
- Tests `TestAES_192` and `TestAES_256` were removed from the
`TestMultithreadFIPS` since these tests take a long period of time to
complete. Coverage functionally is still maintained since they are
executed as part of the `OpenJCEPlusFIPS` provider tests.
- Increased timeouts associated with tests `TestMultithreadFIPS` and
`TestMultithread`.

Signed-off-by: Jason Katonica <katonica@us.ibm.com>
  • Loading branch information
jasonkatonica committed Oct 21, 2024
1 parent 14d7077 commit 9700266
Show file tree
Hide file tree
Showing 481 changed files with 7,072 additions and 17,865 deletions.
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -523,12 +523,6 @@
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.11.0</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

0 comments on commit 9700266

Please sign in to comment.