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

Upgrade to Junit 5 #275

Merged
merged 1 commit into from
Oct 28, 2023
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 28 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@
</developer>
</developers>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.10.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>

<!-- NOTE check regularly : it is an upgraded version of dependency of xades4j->guice remove it when xades4j is upgraded -->
Expand All @@ -52,19 +64,7 @@
<artifactId>guava</artifactId>
<version>32.1.2-jre</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.9</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
Expand Down Expand Up @@ -96,6 +96,21 @@
<version>4.0.4</version>
<scope>runtime</scope>
</dependency>

<!-- Test -->

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.9</version>
<scope>test</scope>
</dependency>

</dependencies>

<distributionManagement>
Expand Down
19 changes: 11 additions & 8 deletions src/test/java/xades4j/algorithms/XPath2FilterTransformTest.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
/*
* XAdES4j - A Java library for generation and verification of XAdES signatures.
* Copyright (C) 2012 Luis Goncalves.
*
*
* XAdES4j is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 3 of the License, or any later version.
*
*
* XAdES4j is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
*
* You should have received a copy of the GNU Lesser General Public License along
* with XAdES4j. If not, see <http://www.gnu.org/licenses/>.
*/
package xades4j.algorithms;

import java.util.List;

import org.junit.jupiter.api.Test;
import xades4j.algorithms.XPath2FilterTransform.XPath2Filter;
import org.junit.Test;
import static org.junit.Assert.*;

import static org.junit.jupiter.api.Assertions.*;

/**
*
* @author Luís
*/
public class XPath2FilterTransformTest
Expand Down Expand Up @@ -53,10 +54,12 @@ public void testCreation()
assertEquals("subtract", f.getFilterType());
}

@Test(expected = UnsupportedOperationException.class)
@Test
public void testChangeFiltersListFails()
{
XPath2FilterTransform t = XPath2Filter.intersect("1").union("2");
t.getFilters().clear();
assertThrows(UnsupportedOperationException.class, () -> {
t.getFilters().clear();
});
}
}
66 changes: 28 additions & 38 deletions src/test/java/xades4j/production/KeyInfoBuilderTest.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/*
* XAdES4j - A Java library for generation and verification of XAdES signatures.
* Copyright (C) 2011 Luis Goncalves.
*
*
* XAdES4j is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 3 of the License, or any later version.
*
*
* XAdES4j is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
*
* You should have received a copy of the GNU Lesser General Public License along
* with XAdES4j. If not, see <http://www.gnu.org/licenses/>.
*/
Expand All @@ -26,16 +26,16 @@
import org.apache.xml.security.keys.content.x509.XMLX509Certificate;
import org.apache.xml.security.signature.SignedInfo;
import org.apache.xml.security.signature.XMLSignature;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import xades4j.providers.impl.DefaultX500NameStyleProvider;
import xades4j.utils.SignatureServicesTestBase;

import static org.junit.jupiter.api.Assertions.*;

/**
*
* @author Luís
*/
public class KeyInfoBuilderTest extends SignatureServicesTestBase
Expand All @@ -44,7 +44,7 @@ public class KeyInfoBuilderTest extends SignatureServicesTestBase
private static X509Certificate intermCertificate;
private static List<X509Certificate> certificates;

@BeforeClass
@BeforeAll
public static void setUpClass() throws Exception
{
org.apache.xml.security.Init.init();
Expand All @@ -58,8 +58,6 @@ public static void setUpClass() throws Exception
@Test
public void testIncludeCertAndKey() throws Exception
{
System.out.println("includeCertAndKey");

KeyInfoBuilder keyInfoBuilder = new KeyInfoBuilder(
new BasicSignatureOptions().includeSigningCertificate(SigningCertificateMode.SIGNING_CERTIFICATE).includePublicKey(true),
new SignatureAlgorithms(),
Expand All @@ -69,20 +67,18 @@ public void testIncludeCertAndKey() throws Exception

keyInfoBuilder.buildKeyInfo(certificates, xmlSignature);

Assert.assertEquals(0, xmlSignature.getSignedInfo().getLength());
assertEquals(0, xmlSignature.getSignedInfo().getLength());

KeyValue kv = xmlSignature.getKeyInfo().itemKeyValue(0);
Assert.assertTrue(kv.getPublicKey().getAlgorithm().startsWith("RSA"));
assertTrue(kv.getPublicKey().getAlgorithm().startsWith("RSA"));

XMLX509Certificate x509Certificate = xmlSignature.getKeyInfo().itemX509Data(0).itemCertificate(0);
Assert.assertEquals(testCertificate, x509Certificate.getX509Certificate());
assertEquals(testCertificate, x509Certificate.getX509Certificate());
}
@Test

@Test
public void testIncludeCertChain() throws Exception
{
System.out.println("includeCertChain");

KeyInfoBuilder keyInfoBuilder = new KeyInfoBuilder(
new BasicSignatureOptions().includeSigningCertificate(SigningCertificateMode.FULL_CHAIN),
new SignatureAlgorithms(),
Expand All @@ -92,23 +88,21 @@ public void testIncludeCertChain() throws Exception

keyInfoBuilder.buildKeyInfo(certificates, xmlSignature);

Assert.assertEquals(0, xmlSignature.getSignedInfo().getLength());
Assert.assertEquals(1, xmlSignature.getKeyInfo().lengthX509Data());
Assert.assertEquals(2, xmlSignature.getKeyInfo().itemX509Data(0).lengthCertificate());
assertEquals(0, xmlSignature.getSignedInfo().getLength());

assertEquals(1, xmlSignature.getKeyInfo().lengthX509Data());
assertEquals(2, xmlSignature.getKeyInfo().itemX509Data(0).lengthCertificate());

XMLX509Certificate x509Certificate = xmlSignature.getKeyInfo().itemX509Data(0).itemCertificate(0);
Assert.assertEquals(testCertificate, x509Certificate.getX509Certificate());
assertEquals(testCertificate, x509Certificate.getX509Certificate());

x509Certificate = xmlSignature.getKeyInfo().itemX509Data(0).itemCertificate(1);
Assert.assertEquals(intermCertificate, x509Certificate.getX509Certificate());
assertEquals(intermCertificate, x509Certificate.getX509Certificate());
}

@Test
public void testIncludeIssuerSerial() throws Exception
{
System.out.println("includeIssuerSerial");

KeyInfoBuilder keyInfoBuilder = new KeyInfoBuilder(
new BasicSignatureOptions().includeIssuerSerial(true),
new SignatureAlgorithms(),
Expand All @@ -118,15 +112,13 @@ public void testIncludeIssuerSerial() throws Exception

keyInfoBuilder.buildKeyInfo(certificates, xmlSignature);

Assert.assertEquals(1, xmlSignature.getKeyInfo().lengthX509Data());
Assert.assertEquals(1, xmlSignature.getKeyInfo().itemX509Data(0).lengthIssuerSerial());
assertEquals(1, xmlSignature.getKeyInfo().lengthX509Data());
assertEquals(1, xmlSignature.getKeyInfo().itemX509Data(0).lengthIssuerSerial());
}

@Test
public void testIncludeSubjectName() throws Exception
{
System.out.println("includeSubjectName");

KeyInfoBuilder keyInfoBuilder = new KeyInfoBuilder(
new BasicSignatureOptions().includeSubjectName(true),
new SignatureAlgorithms(),
Expand All @@ -136,15 +128,13 @@ public void testIncludeSubjectName() throws Exception

keyInfoBuilder.buildKeyInfo(certificates, xmlSignature);

Assert.assertEquals(1, xmlSignature.getKeyInfo().lengthX509Data());
Assert.assertEquals(1, xmlSignature.getKeyInfo().itemX509Data(0).lengthSubjectName());
assertEquals(1, xmlSignature.getKeyInfo().lengthX509Data());
assertEquals(1, xmlSignature.getKeyInfo().itemX509Data(0).lengthSubjectName());
}

@Test
public void testSignKeyInfo() throws Exception
{
System.out.println("signKeyInfo");

KeyInfoBuilder keyInfoBuilder = new KeyInfoBuilder(
new BasicSignatureOptions().signKeyInfo(true),
new SignatureAlgorithms(),
Expand All @@ -155,10 +145,10 @@ public void testSignKeyInfo() throws Exception
keyInfoBuilder.buildKeyInfo(certificates, xmlSignature);

SignedInfo signedInfo = xmlSignature.getSignedInfo();
Assert.assertEquals(1, signedInfo.getLength());
assertEquals(1, signedInfo.getLength());

Node refNode = signedInfo.item(0).getContentsBeforeTransformation().getSubNode();
Assert.assertSame(xmlSignature.getKeyInfo().getElement(), refNode);
assertSame(xmlSignature.getKeyInfo().getElement(), refNode);
}

private XMLSignature getTestSignature() throws Exception
Expand Down
8 changes: 2 additions & 6 deletions src/test/java/xades4j/production/OtherSignerTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import xades4j.algorithms.EnvelopedSignatureTransform;
import xades4j.algorithms.ExclusiveCanonicalXMLWithoutComments;
import xades4j.properties.DataObjectDesc;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import xades4j.properties.QualifyingProperty;
Expand All @@ -49,7 +49,7 @@
import static org.apache.xml.security.c14n.Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS;
import static org.apache.xml.security.signature.XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA512;
import static org.apache.xml.security.utils.Constants.*;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;

/**
* @author Luís
Expand All @@ -59,8 +59,6 @@ public class OtherSignerTests extends SignerTestBase
@Test
public void testSignAndAppendAsFirstChild() throws Exception
{
System.out.println("signAndAppendAsFirstChild");

Document doc = getTestDocument();
Element root = doc.getDocumentElement();
XadesSigner signer = new XadesBesSigningProfile(keyingProviderMy).newSigner();
Expand Down Expand Up @@ -94,8 +92,6 @@ public void testSignWithManifest() throws Exception
@Test
public void testSignUsingCustomResolver() throws Exception
{
System.out.println("signUsingCustomResolver");

Document doc = getNewDocument();
XadesSigner signer = new XadesBesSigningProfile(keyingProviderMy).newSigner();
MyResolverSpi resolverSpi = new MyResolverSpi();
Expand Down
4 changes: 1 addition & 3 deletions src/test/java/xades4j/production/PtCcSignerTests.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package xades4j.production;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import xades4j.providers.impl.DirectPasswordProvider;
Expand All @@ -17,7 +17,6 @@ public class PtCcSignerTests extends SignerTestBase
@Test
public void testSignTPtCC() throws Exception
{
System.out.println("signTPtCitizenCard");
assumePtCcPkcs11();

Document doc = getTestDocument();
Expand All @@ -36,7 +35,6 @@ public void testSignTPtCC() throws Exception
@Test
public void testSignBesPtCCWindowsMy() throws Exception
{
System.out.println("signBESPtCitizenCardWindowsMy");
assumeWindows();
assumePtCcPkcs11();

Expand Down
Loading