Skip to content

Commit 68fef36

Browse files
Refactor JUnit 5 Tests for BaseTestDSASignatureInterop
Replace multiple test classes extending BaseTestDSASignatureInterop with a single JUnit 5 parameterized test class Signed-off-by: Mohit Rajbhar <mohit.rajbhar@ibm.com>
1 parent 0350129 commit 68fef36

12 files changed

Lines changed: 155 additions & 110 deletions

src/test/java/ibm/jceplus/junit/TestMultithread.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ public class TestMultithread {
3535
"ibm.jceplus.junit.openjceplus.multithread.TestAliases",
3636
"ibm.jceplus.junit.openjceplus.multithread.TestDH",
3737
"ibm.jceplus.junit.openjceplus.multithread.TestDSAKey",
38-
"ibm.jceplus.junit.openjceplus.multithread.TestDSASignatureInteropSUN",
3938
"ibm.jceplus.junit.openjceplus.multithread.TestECDH",
4039
"ibm.jceplus.junit.openjceplus.multithread.TestECDHInteropSunEC",
4140
"ibm.jceplus.junit.openjceplus.multithread.TestEdDSASignature",

src/test/java/ibm/jceplus/junit/TestMultithreadFIPS.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ public class TestMultithreadFIPS {
3535
"ibm.jceplus.junit.openjceplusfips.multithread.TestAliases",
3636
"ibm.jceplus.junit.openjceplusfips.multithread.TestDH",
3737
"ibm.jceplus.junit.openjceplusfips.multithread.TestDSAKey",
38-
"ibm.jceplus.junit.openjceplusfips.multithread.TestDSASignatureInteropSUN",
3938
"ibm.jceplus.junit.openjceplusfips.multithread.TestECDH",
4039
"ibm.jceplus.junit.openjceplusfips.multithread.TestECDHInteropSunEC",
4140
"ibm.jceplus.junit.openjceplusfips.multithread.TestHKDF",

src/test/java/ibm/jceplus/junit/openjceplus/TestAll.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
TestDSAKey.class,
4040
TestDSASignature.class,
4141
TestDSASignatureInteropBC.class,
42-
TestDSASignatureInteropSUN.class,
4342
TestECDH.class,
4443
TestECDHInteropBC.class,
4544
TestECDHInteropSunEC.class,

src/test/java/ibm/jceplus/junit/openjceplus/TestDSASignatureInteropSUN.java

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestDSASignatureInteropSUN.java

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/test/java/ibm/jceplus/junit/openjceplusfips/TestDSASignatureInteropSUN.java

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestDSASignatureInteropSUN.java

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/test/java/ibm/jceplus/junit/tests/BaseTest.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright IBM Corp. 2025
2+
* Copyright IBM Corp. 2025, 2026
33
*
44
* This code is free software; you can redistribute it and/or modify it
55
* under the terms provided by IBM in the LICENSE file that accompanied
@@ -29,6 +29,14 @@ public void setProviderName(String providerName) {
2929

3030
public void setAndInsertProvider(TestProvider provider) throws Exception {
3131
this.providerName = provider.getProviderName();
32+
loadSupportedProvider(provider);
33+
}
34+
35+
public void setAndInsertInteropProvider(TestProvider interopProvider) throws Exception {
36+
loadSupportedProvider(interopProvider);
37+
}
38+
39+
private void loadSupportedProvider(TestProvider provider) throws Exception {
3240
switch (provider) {
3341
case BC:
3442
loadProvider(TestProvider.BC);
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright IBM Corp. 2023, 2026
3+
*
4+
* This code is free software; you can redistribute it and/or modify it
5+
* under the terms provided by IBM in the LICENSE file that accompanied
6+
* this code, including the "Classpath" Exception described therein.
7+
*/
8+
9+
package ibm.jceplus.junit.tests;
10+
11+
public class BaseTestInterop extends BaseTest {
12+
13+
public String interopProviderName;
14+
public String interopProviderName2;
15+
16+
/**
17+
* Sets the provider name to interop with.
18+
*
19+
* @param providerName the provider name associated with this test case for use.
20+
*/
21+
public void setInteropProviderName(String providerName) {
22+
this.interopProviderName = providerName;
23+
}
24+
25+
/**
26+
* Gets the provider name that is to be used for interop.
27+
*
28+
* @return The provider name associated with the interop provider name.
29+
*/
30+
public String getInteropProviderName() {
31+
return this.interopProviderName;
32+
}
33+
34+
/**
35+
* Sets the provider name to interop with.
36+
*
37+
* @param providerName the provider name associated with this test case for use.
38+
*/
39+
public void setInteropProviderName2(String providerName) {
40+
this.interopProviderName2 = providerName;
41+
}
42+
43+
/**
44+
* Gets the provider name that is to be used for interop.
45+
*
46+
* @return The provider name associated with the interop provider name.
47+
*/
48+
public String getInteropProviderName2() {
49+
return this.interopProviderName2;
50+
}
51+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright IBM Corp. 2023, 2026
3+
*
4+
* This code is free software; you can redistribute it and/or modify it
5+
* under the terms provided by IBM in the LICENSE file that accompanied
6+
* this code, including the "Classpath" Exception described therein.
7+
*/
8+
9+
package ibm.jceplus.junit.tests;
10+
11+
import java.security.PrivateKey;
12+
import java.security.PublicKey;
13+
import java.security.Signature;
14+
import static org.junit.jupiter.api.Assertions.assertTrue;
15+
16+
public class BaseTestSignatureInterop extends BaseTestInterop {
17+
18+
protected void doSignVerify(String sigAlgo, byte[] message, PrivateKey privateKey,
19+
PublicKey publicKey) throws Exception {
20+
doSignVerify(sigAlgo, message, privateKey, publicKey, getProviderName(), getInteropProviderName());
21+
doSignVerify(sigAlgo, message, privateKey, publicKey, getInteropProviderName(), getProviderName());
22+
}
23+
24+
25+
protected static void doSignVerify(String sigAlgo, byte[] message, PrivateKey privateKey,
26+
PublicKey publicKey, String signProvider, String verifyProvider) throws Exception {
27+
Signature signing = Signature.getInstance(sigAlgo, signProvider);
28+
signing.initSign(privateKey);
29+
signing.update(message);
30+
byte[] signedBytes = signing.sign();
31+
32+
Signature verifying = Signature.getInstance(sigAlgo, verifyProvider);
33+
verifying.initVerify(publicKey);
34+
verifying.update(message);
35+
36+
assertTrue(verifying.verify(signedBytes), "Signature verification failed");
37+
}
38+
}
39+

0 commit comments

Comments
 (0)