Skip to content

Commit 4966270

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 4966270

12 files changed

Lines changed: 161 additions & 117 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: 15 additions & 8 deletions
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
@@ -30,6 +30,19 @@ public void setProviderName(String providerName) {
3030
public void setAndInsertProvider(TestProvider provider) throws Exception {
3131
this.providerName = provider.getProviderName();
3232
switch (provider) {
33+
case OpenJCEPlus:
34+
loadProvider(TestProvider.OpenJCEPlus);
35+
break;
36+
case OpenJCEPlusFIPS:
37+
loadProvider(TestProvider.OpenJCEPlusFIPS);
38+
break;
39+
default:
40+
throw new Exception("Provider not supported: " + provider.getProviderName());
41+
}
42+
}
43+
44+
public void setAndInsertInteropProvider(TestProvider interopProvider) throws Exception {
45+
switch (interopProvider) {
3346
case BC:
3447
loadProvider(TestProvider.BC);
3548
break;
@@ -45,14 +58,8 @@ public void setAndInsertProvider(TestProvider provider) throws Exception {
4558
case SunEC:
4659
loadProvider(TestProvider.SunEC);
4760
break;
48-
case OpenJCEPlus:
49-
loadProvider(TestProvider.OpenJCEPlus);
50-
break;
51-
case OpenJCEPlusFIPS:
52-
loadProvider(TestProvider.OpenJCEPlusFIPS);
53-
break;
5461
default:
55-
throw new Exception("Provider not supported: " + provider.getProviderName());
62+
throw new Exception("Provider not supported: " + interopProvider.getProviderName());
5663
}
5764
}
5865

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)