Skip to content

Commit 90700db

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 a7ec492 commit 90700db

10 files changed

Lines changed: 114 additions & 108 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
@@ -41,7 +41,6 @@
4141
TestDSAKey.class,
4242
TestDSASignature.class,
4343
TestDSASignatureInteropBC.class,
44-
TestDSASignatureInteropSUN.class,
4544
TestECDH.class,
4645
TestECDHInteropBC.class,
4746
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.
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+

src/test/java/ibm/jceplus/junit/base/BaseTestDSASignatureInterop.java renamed to src/test/java/ibm/jceplus/junit/tests/TestDSASignatureInteropSUN.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*
2-
* Copyright IBM Corp. 2023, 2024
2+
* Copyright IBM Corp. 2023, 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
66
* this code, including the "Classpath" Exception described therein.
77
*/
88

9-
package ibm.jceplus.junit.base;
9+
package ibm.jceplus.junit.tests;
1010

1111
import java.security.InvalidKeyException;
1212
import java.security.InvalidParameterException;
@@ -21,16 +21,37 @@
2121
import java.security.spec.PKCS8EncodedKeySpec;
2222
import java.security.spec.X509EncodedKeySpec;
2323
import java.util.Arrays;
24+
import org.junit.jupiter.api.BeforeEach;
25+
import org.junit.jupiter.api.Tag;
2426
import org.junit.jupiter.api.Test;
27+
import org.junit.jupiter.api.TestInstance;
28+
import org.junit.jupiter.params.Parameter;
29+
import org.junit.jupiter.params.ParameterizedClass;
30+
import org.junit.jupiter.params.provider.MethodSource;
2531
import static org.junit.jupiter.api.Assertions.assertEquals;
2632
import static org.junit.jupiter.api.Assertions.assertTrue;
2733
import static org.junit.jupiter.api.Assertions.fail;
2834

29-
public class BaseTestDSASignatureInterop extends BaseTestSignatureInterop {
35+
@Tag(Tags.OPENJCEPLUS_NAME)
36+
@Tag(Tags.OPENJCEPLUS_FIPS_NAME)
37+
@Tag(Tags.OPENJCEPLUS_MULTITHREAD_NAME)
38+
@Tag(Tags.OPENJCEPLUS_FIPS_MULTITHREAD_NAME)
39+
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
40+
@ParameterizedClass
41+
@MethodSource("ibm.jceplus.junit.tests.TestArguments#getEnabledProviders")
42+
public class TestDSASignatureInteropSUN extends BaseTestSignatureInterop {
3043

44+
@Parameter(0)
45+
TestProvider provider;
3146

3247
static final byte[] origMsg = "this is the original message to be signed".getBytes();
3348

49+
@BeforeEach
50+
public void setUp() throws Exception {
51+
setAndInsertProvider(provider);
52+
setInteropProviderName(TestProvider.SUN.getProviderName());
53+
}
54+
3455
@Test
3556
public void testSHA1withDSA_1024() throws Exception {
3657
KeyPair keyPair = null;

0 commit comments

Comments
 (0)