This is an automated email from the ASF dual-hosted git repository. gnodet pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit 203f94600d650f81158481f51a8472b1c08eaea1 Author: Guillaume Nodet <[email protected]> AuthorDate: Mon Jul 27 10:53:14 2020 +0200 [CAMEL-11807] Upgrade camel-xmlsecurity to junit5 --- components/camel-xmlsecurity/pom.xml | 11 +- .../component/xmlsecurity/ECDSASignatureTest.java | 17 ++- .../xmlsecurity/SignatureAlgorithmTest.java | 10 +- .../xmlsecurity/SignatureDigestMethodTest.java | 10 +- .../xmlsecurity/SpringXmlSignatureTest.java | 2 +- .../xmlsecurity/XAdESSignaturePropertiesTest.java | 121 +++++++++++++-------- .../component/xmlsecurity/XmlSignatureTest.java | 68 ++++++------ .../xmlsecurity/EncryptionAlgorithmTest.java | 8 +- .../SpringXmlSecurityDataFormatTest.java | 7 +- ...ngXmlSecurityDataFormatWithKeyPasswordTest.java | 7 +- .../camel/dataformat/xmlsecurity/TestHelper.java | 12 +- .../xmlsecurity/XMLEncryption11Test.java | 8 +- .../xmlsecurity/XMLSecurityConcurrencyTest.java | 10 +- .../xmlsecurity/XMLSecurityDataFormatTest.java | 15 +-- 14 files changed, 176 insertions(+), 130 deletions(-) diff --git a/components/camel-xmlsecurity/pom.xml b/components/camel-xmlsecurity/pom.xml index 0683204..eacd7aa 100644 --- a/components/camel-xmlsecurity/pom.xml +++ b/components/camel-xmlsecurity/pom.xml @@ -70,7 +70,12 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> - <artifactId>camel-test</artifactId> + <artifactId>camel-test-spring-junit5</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-test-junit5</artifactId> <scope>test</scope> </dependency> <dependency> @@ -79,8 +84,8 @@ <scope>test</scope> </dependency> <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter</artifactId> <scope>test</scope> </dependency> <dependency> diff --git a/components/camel-xmlsecurity/src/test/java/org/apache/camel/component/xmlsecurity/ECDSASignatureTest.java b/components/camel-xmlsecurity/src/test/java/org/apache/camel/component/xmlsecurity/ECDSASignatureTest.java index 7f66ca1..b973d0a 100644 --- a/components/camel-xmlsecurity/src/test/java/org/apache/camel/component/xmlsecurity/ECDSASignatureTest.java +++ b/components/camel-xmlsecurity/src/test/java/org/apache/camel/component/xmlsecurity/ECDSASignatureTest.java @@ -38,17 +38,22 @@ import org.apache.camel.component.xmlsecurity.api.KeyAccessor; import org.apache.camel.component.xmlsecurity.util.SameDocumentUriDereferencer; import org.apache.camel.spi.Registry; import org.apache.camel.support.SimpleRegistry; -import org.apache.camel.test.junit4.CamelTestSupport; -import org.apache.camel.test.junit4.TestSupport; -import org.junit.Before; -import org.junit.Test; +import org.apache.camel.test.junit5.CamelTestSupport; +import org.apache.camel.test.junit5.TestSupport; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static org.apache.camel.test.junit5.TestSupport.isJavaVendor; /** * Test for the ECDSA algorithms */ public class ECDSASignatureTest extends CamelTestSupport { - + private static String payload; + private Logger log = LoggerFactory.getLogger(getClass()); private boolean canTest = true; static { @@ -241,7 +246,7 @@ public class ECDSASignatureTest extends CamelTestSupport { } @Override - @Before + @BeforeEach public void setUp() throws Exception { disableJMX(); try { diff --git a/components/camel-xmlsecurity/src/test/java/org/apache/camel/component/xmlsecurity/SignatureAlgorithmTest.java b/components/camel-xmlsecurity/src/test/java/org/apache/camel/component/xmlsecurity/SignatureAlgorithmTest.java index 9e8f71e..59851e5 100644 --- a/components/camel-xmlsecurity/src/test/java/org/apache/camel/component/xmlsecurity/SignatureAlgorithmTest.java +++ b/components/camel-xmlsecurity/src/test/java/org/apache/camel/component/xmlsecurity/SignatureAlgorithmTest.java @@ -73,10 +73,10 @@ import org.apache.camel.component.xmlsecurity.util.XmlSignature2Message2MessageW import org.apache.camel.impl.DefaultCamelContext; import org.apache.camel.spi.Registry; import org.apache.camel.support.SimpleRegistry; -import org.apache.camel.test.junit4.CamelTestSupport; -import org.apache.camel.test.junit4.TestSupport; -import org.junit.Before; -import org.junit.Test; +import org.apache.camel.test.junit5.CamelTestSupport; +import org.apache.camel.test.junit5.TestSupport; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Test signing using all available signature methods, apart from EC-algorithms which are @@ -462,7 +462,7 @@ public class SignatureAlgorithmTest extends CamelTestSupport { } @Override - @Before + @BeforeEach public void setUp() throws Exception { setUpKeys("RSA", 2048); disableJMX(); diff --git a/components/camel-xmlsecurity/src/test/java/org/apache/camel/component/xmlsecurity/SignatureDigestMethodTest.java b/components/camel-xmlsecurity/src/test/java/org/apache/camel/component/xmlsecurity/SignatureDigestMethodTest.java index c8189f7..504ee26 100644 --- a/components/camel-xmlsecurity/src/test/java/org/apache/camel/component/xmlsecurity/SignatureDigestMethodTest.java +++ b/components/camel-xmlsecurity/src/test/java/org/apache/camel/component/xmlsecurity/SignatureDigestMethodTest.java @@ -72,10 +72,10 @@ import org.apache.camel.component.xmlsecurity.util.XmlSignature2Message2MessageW import org.apache.camel.impl.DefaultCamelContext; import org.apache.camel.spi.Registry; import org.apache.camel.support.SimpleRegistry; -import org.apache.camel.test.junit4.CamelTestSupport; -import org.apache.camel.test.junit4.TestSupport; -import org.junit.Before; -import org.junit.Test; +import org.apache.camel.test.junit5.CamelTestSupport; +import org.apache.camel.test.junit5.TestSupport; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Test signing using all available digest methods @@ -353,7 +353,7 @@ public class SignatureDigestMethodTest extends CamelTestSupport { } @Override - @Before + @BeforeEach public void setUp() throws Exception { setUpKeys("RSA", 1024); disableJMX(); diff --git a/components/camel-xmlsecurity/src/test/java/org/apache/camel/component/xmlsecurity/SpringXmlSignatureTest.java b/components/camel-xmlsecurity/src/test/java/org/apache/camel/component/xmlsecurity/SpringXmlSignatureTest.java index e0352ce..220ca5d 100644 --- a/components/camel-xmlsecurity/src/test/java/org/apache/camel/component/xmlsecurity/SpringXmlSignatureTest.java +++ b/components/camel-xmlsecurity/src/test/java/org/apache/camel/component/xmlsecurity/SpringXmlSignatureTest.java @@ -33,7 +33,7 @@ import org.apache.camel.component.xmlsecurity.api.XmlSignatureHelper; import org.apache.camel.spi.Registry; import org.apache.camel.spring.SpringCamelContext; import org.apache.camel.support.SimpleRegistry; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.context.support.ClassPathXmlApplicationContext; public class SpringXmlSignatureTest extends XmlSignatureTest { diff --git a/components/camel-xmlsecurity/src/test/java/org/apache/camel/component/xmlsecurity/XAdESSignaturePropertiesTest.java b/components/camel-xmlsecurity/src/test/java/org/apache/camel/component/xmlsecurity/XAdESSignaturePropertiesTest.java index b1896dc..afa985f 100644 --- a/components/camel-xmlsecurity/src/test/java/org/apache/camel/component/xmlsecurity/XAdESSignaturePropertiesTest.java +++ b/components/camel-xmlsecurity/src/test/java/org/apache/camel/component/xmlsecurity/XAdESSignaturePropertiesTest.java @@ -67,12 +67,17 @@ import org.apache.camel.component.xmlsecurity.api.XmlSignatureProperties; import org.apache.camel.component.xmlsecurity.util.TestKeystore; import org.apache.camel.spi.Registry; import org.apache.camel.support.SimpleRegistry; -import org.apache.camel.test.junit4.CamelTestSupport; -import org.apache.camel.test.junit4.TestSupport; -import org.junit.Before; -import org.junit.Test; +import org.apache.camel.test.junit5.CamelTestSupport; +import org.apache.camel.test.junit5.TestSupport; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static org.apache.camel.component.xmlsecurity.XmlSignatureTest.checkThrownException; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; public class XAdESSignaturePropertiesTest extends CamelTestSupport { @@ -90,7 +95,7 @@ public class XAdESSignaturePropertiesTest extends CamelTestSupport { } @Override - @Before + @BeforeEach public void setUp() throws Exception { disableJMX(); super.setUp(); @@ -623,104 +628,124 @@ public class XAdESSignaturePropertiesTest extends CamelTestSupport { + " The correct namespace is 'http://uri.etsi.org/01903/v1.3.2#'.", null); } - @Test(expected = IllegalArgumentException.class) + @Test public void namespaceNull() throws Exception { - new XAdESSignatureProperties().setNamespace(null); + assertThrows(IllegalArgumentException.class, + () -> new XAdESSignatureProperties().setNamespace(null)); } - @Test(expected = IllegalArgumentException.class) + @Test public void signingCertificateURIsNull() throws Exception { - new XAdESSignatureProperties().setSigningCertificateURIs(null); + assertThrows(IllegalArgumentException.class, + () -> new XAdESSignatureProperties().setSigningCertificateURIs(null)); } - @Test(expected = IllegalArgumentException.class) + @Test public void sigPolicyInvalid() throws Exception { - new XAdESSignatureProperties().setSignaturePolicy("invalid"); + assertThrows(IllegalArgumentException.class, + () -> new XAdESSignatureProperties().setSignaturePolicy("invalid")); } - @Test(expected = IllegalArgumentException.class) + @Test public void sigPolicyIdDocumentationReferencesNull() throws Exception { - new XAdESSignatureProperties().setSigPolicyIdDocumentationReferences(null); + assertThrows(IllegalArgumentException.class, + () -> new XAdESSignatureProperties().setSigPolicyIdDocumentationReferences(null)); } - @Test(expected = IllegalArgumentException.class) + @Test public void sigPolicyIdDocumentationReferencesNullEntry() throws Exception { - new XAdESSignatureProperties().setSigPolicyIdDocumentationReferences(Collections.<String> singletonList(null)); + assertThrows(IllegalArgumentException.class, + () -> new XAdESSignatureProperties().setSigPolicyIdDocumentationReferences(Collections.<String> singletonList(null))); } - @Test(expected = IllegalArgumentException.class) + @Test public void sigPolicyIdDocumentationReferencesEmptyEntry() throws Exception { - new XAdESSignatureProperties().setSigPolicyIdDocumentationReferences(Collections.<String> singletonList("")); + assertThrows(IllegalArgumentException.class, + () -> new XAdESSignatureProperties().setSigPolicyIdDocumentationReferences(Collections.<String> singletonList(""))); } - @Test(expected = IllegalArgumentException.class) + @Test public void dataObjectFormatIdentifierDocumentationReferencesNull() throws Exception { - new XAdESSignatureProperties().setDataObjectFormatIdentifierDocumentationReferences(null); + assertThrows(IllegalArgumentException.class, + () -> new XAdESSignatureProperties().setDataObjectFormatIdentifierDocumentationReferences(null)); } - @Test(expected = IllegalArgumentException.class) + @Test public void dataObjectFormatIdentifierDocumentationReferencesNullEntry() throws Exception { - new XAdESSignatureProperties().setDataObjectFormatIdentifierDocumentationReferences(Collections.<String> singletonList(null)); + assertThrows(IllegalArgumentException.class, + () -> new XAdESSignatureProperties().setDataObjectFormatIdentifierDocumentationReferences(Collections.<String> singletonList(null))); } - @Test(expected = IllegalArgumentException.class) + @Test public void dataObjectFormatIdentifierDocumentationReferencesEmptyEntry() throws Exception { - new XAdESSignatureProperties().setDataObjectFormatIdentifierDocumentationReferences(Collections.<String> singletonList("")); + assertThrows(IllegalArgumentException.class, + () -> new XAdESSignatureProperties().setDataObjectFormatIdentifierDocumentationReferences(Collections.<String> singletonList(""))); } - @Test(expected = IllegalArgumentException.class) + @Test public void signerClaimedRolesNull() throws Exception { - new XAdESSignatureProperties().setSignerClaimedRoles(null); + assertThrows(IllegalArgumentException.class, + () -> new XAdESSignatureProperties().setSignerClaimedRoles(null)); } - @Test(expected = IllegalArgumentException.class) + @Test public void signerClaimedRolesNullEntry() throws Exception { - new XAdESSignatureProperties().setSignerClaimedRoles(Collections.<String> singletonList(null)); + assertThrows(IllegalArgumentException.class, + () -> new XAdESSignatureProperties().setSignerClaimedRoles(Collections.<String> singletonList(null))); } - @Test(expected = IllegalArgumentException.class) + @Test public void signerClaimedRolesEmptyEntry() throws Exception { - new XAdESSignatureProperties().setSignerClaimedRoles(Collections.<String> singletonList("")); + assertThrows(IllegalArgumentException.class, + () -> new XAdESSignatureProperties().setSignerClaimedRoles(Collections.<String> singletonList(""))); } - @Test(expected = IllegalArgumentException.class) + @Test public void signerCertifiedRolesNull() throws Exception { - new XAdESSignatureProperties().setSignerCertifiedRoles(null); + assertThrows(IllegalArgumentException.class, + () -> new XAdESSignatureProperties().setSignerCertifiedRoles(null)); } - @Test(expected = IllegalArgumentException.class) + @Test public void signerCertifiedRolesNullEntry() throws Exception { - new XAdESSignatureProperties().setSignerCertifiedRoles(Collections.<XAdESEncapsulatedPKIData> singletonList(null)); + assertThrows(IllegalArgumentException.class, + () -> new XAdESSignatureProperties().setSignerCertifiedRoles(Collections.<XAdESEncapsulatedPKIData> singletonList(null))); } - @Test(expected = IllegalArgumentException.class) + @Test public void commitmentTypeIdDocumentationReferencesNull() throws Exception { - new XAdESSignatureProperties().setCommitmentTypeIdDocumentationReferences(null); + assertThrows(IllegalArgumentException.class, + () -> new XAdESSignatureProperties().setCommitmentTypeIdDocumentationReferences(null)); } - @Test(expected = IllegalArgumentException.class) + @Test public void commitmentTypeIdDocumentationReferencesNullEntry() throws Exception { - new XAdESSignatureProperties().setCommitmentTypeIdDocumentationReferences(Collections.<String> singletonList(null)); + assertThrows(IllegalArgumentException.class, + () -> new XAdESSignatureProperties().setCommitmentTypeIdDocumentationReferences(Collections.<String> singletonList(null))); } - @Test(expected = IllegalArgumentException.class) + @Test public void commitmentTypeIdDocumentationReferencesEmptyEntry() throws Exception { - new XAdESSignatureProperties().setCommitmentTypeIdDocumentationReferences(Collections.<String> singletonList("")); + assertThrows(IllegalArgumentException.class, + () -> new XAdESSignatureProperties().setCommitmentTypeIdDocumentationReferences(Collections.<String> singletonList(""))); } - @Test(expected = IllegalArgumentException.class) + @Test public void commitmentTypeQualifiersNull() throws Exception { - new XAdESSignatureProperties().setCommitmentTypeQualifiers(null); + assertThrows(IllegalArgumentException.class, + () -> new XAdESSignatureProperties().setCommitmentTypeQualifiers(null)); } - @Test(expected = IllegalArgumentException.class) + @Test public void commitmentTypeQualifiersNullEntry() throws Exception { - new XAdESSignatureProperties().setCommitmentTypeQualifiers(Collections.<String> singletonList(null)); + assertThrows(IllegalArgumentException.class, + () -> new XAdESSignatureProperties().setCommitmentTypeQualifiers(Collections.<String> singletonList(null))); } - @Test(expected = IllegalArgumentException.class) + @Test public void commitmentTypeQualifiersEmptyEntry() throws Exception { - new XAdESSignatureProperties().setCommitmentTypeQualifiers(Collections.<String> singletonList("")); + assertThrows(IllegalArgumentException.class, + () -> new XAdESSignatureProperties().setCommitmentTypeQualifiers(Collections.<String> singletonList(""))); } // @@ -850,7 +875,7 @@ public class XAdESSignaturePropertiesTest extends CamelTestSupport { if (startsWith) { assertTrue(result.startsWith(expectedResult)); } else if (NOT_EMPTY.equals(expectedResult)) { - assertTrue("Not empty result for xpath " + xpathString + " expected", !result.isEmpty()); + assertTrue(!result.isEmpty(), "Not empty result for xpath " + xpathString + " expected"); } else { assertEquals(expectedResult, result); } @@ -862,9 +887,9 @@ public class XAdESSignaturePropertiesTest extends CamelTestSupport { XPathExpression expr = getXpath(xpathString, prefix2Namespace); Object result = expr.evaluate(doc, XPathConstants.NODE); if (exists) { - assertNotNull("The xpath " + xpathString + " returned null, expected was a node", result); + assertNotNull(result, "The xpath " + xpathString + " returned null, expected was a node"); } else { - assertNull("The xpath " + xpathString + " returned a node, expected was none: ", result); + assertNull(result, "The xpath " + xpathString + " returned a node, expected was none: "); } } diff --git a/components/camel-xmlsecurity/src/test/java/org/apache/camel/component/xmlsecurity/XmlSignatureTest.java b/components/camel-xmlsecurity/src/test/java/org/apache/camel/component/xmlsecurity/XmlSignatureTest.java index b4949ca..c018394 100644 --- a/components/camel-xmlsecurity/src/test/java/org/apache/camel/component/xmlsecurity/XmlSignatureTest.java +++ b/components/camel-xmlsecurity/src/test/java/org/apache/camel/component/xmlsecurity/XmlSignatureTest.java @@ -100,11 +100,17 @@ import org.apache.camel.impl.DefaultCamelContext; import org.apache.camel.spi.Registry; import org.apache.camel.support.SimpleRegistry; import org.apache.camel.support.processor.validation.SchemaValidationException; -import org.apache.camel.test.junit4.CamelTestSupport; -import org.apache.camel.test.junit4.TestSupport; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.apache.camel.test.junit5.CamelTestSupport; +import org.apache.camel.test.junit5.TestSupport; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class XmlSignatureTest extends CamelTestSupport { @@ -474,7 +480,7 @@ public class XmlSignatureTest extends CamelTestSupport { headers.put(XmlSignatureConstants.HEADER_OMIT_XML_DECLARATION, Boolean.TRUE); InputStream payload = XmlSignatureTest.class .getResourceAsStream("/org/apache/camel/component/xmlsecurity/ExampleEnvelopedXmlSig.xml"); - assertNotNull("Cannot load payload", payload); + assertNotNull(payload, "Cannot load payload"); sendBody("direct:outputnodesearchelementname", payload, headers); assertMockEndpointsSatisfied(); } @@ -561,7 +567,7 @@ public class XmlSignatureTest extends CamelTestSupport { setupMock(); InputStream payload = XmlSignatureTest.class .getResourceAsStream("/org/apache/camel/component/xmlsecurity/ExampleEnvelopedXmlSig.xml"); - assertNotNull("Cannot load payload", payload); + assertNotNull(payload, "Cannot load payload"); sendBody("direct:outputnodesearchelementname", payload); assertMockEndpointsSatisfied(); } @@ -575,7 +581,7 @@ public class XmlSignatureTest extends CamelTestSupport { MockEndpoint mock = setupExceptionMock(); InputStream payload = XmlSignatureTest.class .getResourceAsStream("/org/apache/camel/component/xmlsecurity/ExampleEnvelopedXmlSig.xml"); - assertNotNull("Cannot load payload", payload); + assertNotNull(payload, "Cannot load payload"); sendBody("direct:outputnodesearchelementname", payload); assertMockEndpointsSatisfied(); checkThrownException(mock, XmlSignatureException.class, null); @@ -591,7 +597,7 @@ public class XmlSignatureTest extends CamelTestSupport { MockEndpoint mock = setupExceptionMock(); InputStream payload = XmlSignatureTest.class .getResourceAsStream("/org/apache/camel/component/xmlsecurity/ExampleEnvelopedXmlSig.xml"); - assertNotNull("Cannot load payload", payload); + assertNotNull(payload, "Cannot load payload"); sendBody("direct:outputnodesearchelementname", payload); assertMockEndpointsSatisfied(); checkThrownException(mock, XmlSignatureException.class, null); @@ -602,7 +608,7 @@ public class XmlSignatureTest extends CamelTestSupport { MockEndpoint mock = setupExceptionMock(); InputStream payload = XmlSignatureTest.class .getResourceAsStream("/org/apache/camel/component/xmlsecurity/ExampleEnvelopingDigSig.xml"); - assertNotNull("Cannot load payload", payload); + assertNotNull(payload, "Cannot load payload"); sendBody("direct:outputnodesearchelementname", payload); assertMockEndpointsSatisfied(); checkThrownException(mock, XmlSignatureException.class, null); @@ -613,7 +619,7 @@ public class XmlSignatureTest extends CamelTestSupport { MockEndpoint mock = setupExceptionMock(); InputStream payload = XmlSignatureTest.class .getResourceAsStream("/org/apache/camel/component/xmlsecurity/ExampleEnvelopingDigSigWithSeveralElementsWithNameRoot.xml"); - assertNotNull("Cannot load payload", payload); + assertNotNull(payload, "Cannot load payload"); sendBody("direct:outputnodesearchelementname", payload); assertMockEndpointsSatisfied(); checkThrownException(mock, XmlSignatureException.class, null); @@ -624,7 +630,7 @@ public class XmlSignatureTest extends CamelTestSupport { setupMock(); InputStream payload = XmlSignatureTest.class .getResourceAsStream("/org/apache/camel/component/xmlsecurity/ExampleEnvelopedXmlSig.xml"); - assertNotNull("Cannot load payload", payload); + assertNotNull(payload, "Cannot load payload"); sendBody("direct:outputnodesearchxpath", payload); assertMockEndpointsSatisfied(); } @@ -634,7 +640,7 @@ public class XmlSignatureTest extends CamelTestSupport { MockEndpoint mock = setupExceptionMock(); InputStream payload = XmlSignatureTest.class .getResourceAsStream("/org/apache/camel/component/xmlsecurity/ExampleEnvelopingDigSig.xml"); - assertNotNull("Cannot load payload", payload); + assertNotNull(payload, "Cannot load payload"); sendBody("direct:outputnodesearchxpath", payload); assertMockEndpointsSatisfied(); checkThrownException(mock, XmlSignatureException.class, null); @@ -645,7 +651,7 @@ public class XmlSignatureTest extends CamelTestSupport { MockEndpoint mock = setupExceptionMock(); InputStream payload = XmlSignatureTest.class .getResourceAsStream("/org/apache/camel/component/xmlsecurity/ExampleEnvelopingDigSigWithSeveralElementsWithNameRoot.xml"); - assertNotNull("Cannot load payload", payload); + assertNotNull(payload, "Cannot load payload"); sendBody("direct:outputnodesearchxpath", payload); assertMockEndpointsSatisfied(); checkThrownException(mock, XmlSignatureException.class, null); @@ -697,11 +703,11 @@ public class XmlSignatureTest extends CamelTestSupport { } @Test - @Ignore("Cannot resolve <Reference URI=\"testFile.txt\">") + @Disabled("Cannot resolve <Reference URI=\"testFile.txt\">") public void testVerifyInvalidContentHashException() throws Exception { MockEndpoint mock = setupExceptionMock(); InputStream payload = XmlSignatureTest.class.getResourceAsStream("/org/apache/camel/component/xmlsecurity/ExampleDetached.xml"); - assertNotNull("Cannot load payload", payload); + assertNotNull(payload, "Cannot load payload"); sendBody("direct:invalidhash", payload); assertMockEndpointsSatisfied(); checkThrownException(mock, XmlSignatureInvalidContentHashException.class, null); @@ -712,7 +718,7 @@ public class XmlSignatureTest extends CamelTestSupport { MockEndpoint mock = setupExceptionMock(); InputStream payload = XmlSignatureTest.class .getResourceAsStream("/org/apache/camel/component/xmlsecurity/ManifestTest_TamperedContent.xml"); - assertNotNull("Cannot load payload", payload); + assertNotNull(payload, "Cannot load payload"); sendBody("direct:invalidhash", payload); assertMockEndpointsSatisfied(); checkThrownException(mock, XmlSignatureInvalidContentHashException.class, null); @@ -727,13 +733,13 @@ public class XmlSignatureTest extends CamelTestSupport { setupMock("some text tampered"); InputStream payload = XmlSignatureTest.class .getResourceAsStream("/org/apache/camel/component/xmlsecurity/ManifestTest_TamperedContent.xml"); - assertNotNull("Cannot load payload", payload); + assertNotNull(payload, "Cannot load payload"); sendBody("direct:cryptocontextprops", payload); assertMockEndpointsSatisfied(); } @Test - @Ignore("Not all JDKs have provider to verify this key") + @Disabled("Not all JDKs have provider to verify this key") public void testVerifySignatureInvalidValueException() throws Exception { MockEndpoint mock = setupExceptionMock(); setUpKeys("DSA", 512); @@ -742,7 +748,7 @@ public class XmlSignatureTest extends CamelTestSupport { // payload needs DSA key InputStream payload = XmlSignatureTest.class .getResourceAsStream("/org/apache/camel/component/xmlsecurity/ExampleEnvelopingDigSig.xml"); - assertNotNull("Cannot load payload", payload); + assertNotNull(payload, "Cannot load payload"); sendBody("direct:verifyexceptions", payload); assertMockEndpointsSatisfied(); checkThrownException(mock, XmlSignatureInvalidValueException.class, null); @@ -753,7 +759,7 @@ public class XmlSignatureTest extends CamelTestSupport { MockEndpoint mock = setupExceptionMock(); InputStream payload = XmlSignatureTest.class .getResourceAsStream("/org/apache/camel/component/xmlsecurity/ExampleEnvelopingDigSig.xml"); - assertNotNull("Cannot load payload", payload); + assertNotNull(payload, "Cannot load payload"); sendBody("direct:verifyInvalidKeyException", payload); assertMockEndpointsSatisfied(); checkThrownException(mock, XmlSignatureInvalidKeyException.class, null); @@ -771,7 +777,7 @@ public class XmlSignatureTest extends CamelTestSupport { MockEndpoint mock = setupExceptionMock(); InputStream payload = XmlSignatureTest.class .getResourceAsStream("/org/apache/camel/component/xmlsecurity/ExampleEnvelopedXmlSig.xml"); - assertNotNull("Cannot load payload", payload); + assertNotNull(payload, "Cannot load payload"); sendBody("direct:xmlSignatureChecker", payload); assertMockEndpointsSatisfied(); checkThrownException(mock, XmlSignatureInvalidException.class, null); @@ -782,7 +788,7 @@ public class XmlSignatureTest extends CamelTestSupport { setupMock("some text tampered"); InputStream payload = XmlSignatureTest.class .getResourceAsStream("/org/apache/camel/component/xmlsecurity/ManifestTest_TamperedContent.xml"); - assertNotNull("Cannot load payload", payload); + assertNotNull(payload, "Cannot load payload"); sendBody("direct:validationFailedHandler", payload); assertMockEndpointsSatisfied(); } @@ -835,7 +841,7 @@ public class XmlSignatureTest extends CamelTestSupport { // already Element sigEle = testDetachedSignatureInternal(); Attr attr = sigEle.getAttributeNode("Id"); - assertNull("Signature element contains Id attribute", attr); + assertNull(attr, "Signature element contains Id attribute"); } @Test @@ -857,7 +863,7 @@ public class XmlSignatureTest extends CamelTestSupport { Element sigEle = testDetachedSignatureInternal(); String value = sigEle.getAttribute("Id"); assertNotNull("Signature Id is null", value); - assertTrue("Signature Id value does not start with '_'", value.startsWith("_")); + assertTrue(value.startsWith("_"), "Signature Id value does not start with '_'"); } private Element testDetachedSignatureInternal() throws InterruptedException, XPathExpressionException, SAXException, IOException, @@ -1266,8 +1272,8 @@ public class XmlSignatureTest extends CamelTestSupport { Message message = getMessage(mock); String body = message.getBody(String.class); assertNotNull(body); - assertTrue("The message body " + body + " does not contain the expected string " + expectedPartContent, - body.contains(expectedPartContent)); + assertTrue(body.contains(expectedPartContent), + "The message body " + body + " does not contain the expected string " + expectedPartContent); } private Object checkXpath(MockEndpoint mock, String xpathString, final Map<String, String> prefix2Namespace) @@ -1298,7 +1304,7 @@ public class XmlSignatureTest extends CamelTestSupport { xpath.setNamespaceContext(nc); XPathExpression expr = xpath.compile(xpathString); Object result = expr.evaluate(XmlSignatureHelper.newDocumentBuilder(true).parse(body), XPathConstants.NODE); - assertNotNull("The xpath " + xpathString + " returned a null value", result); + assertNotNull(result, "The xpath " + xpathString + " returned a null value"); return result; } @@ -1320,7 +1326,7 @@ public class XmlSignatureTest extends CamelTestSupport { static void checkThrownException(MockEndpoint mock, Class<? extends Exception> cl, String expectedMessage, Class<? extends Exception> expectedCauseClass) throws Exception { Exception e = (Exception) mock.getExchanges().get(0).getProperty(Exchange.EXCEPTION_CAUGHT); - assertNotNull("Expected excpetion " + cl.getName() + " missing", e); + assertNotNull(e, "Expected excpetion " + cl.getName() + " missing"); if (e.getClass() != cl) { String stackTrace = getStrackTrace(e); fail("Exception " + cl.getName() + " excpected, but was " + e.getClass().getName() + ": " + stackTrace); @@ -1330,7 +1336,7 @@ public class XmlSignatureTest extends CamelTestSupport { } if (expectedCauseClass != null) { Throwable cause = e.getCause(); - assertNotNull("Expected cause exception" + expectedCauseClass.getName() + " missing", cause); + assertNotNull(cause, "Expected cause exception" + expectedCauseClass.getName() + " missing"); if (expectedCauseClass != cause.getClass()) { fail("Cause exception " + expectedCauseClass.getName() + " expected, but was " + cause.getClass().getName() + ": " + getStrackTrace(e)); @@ -1392,7 +1398,7 @@ public class XmlSignatureTest extends CamelTestSupport { } @Override - @Before + @BeforeEach public void setUp() throws Exception { setUpKeys("RSA", 1024); disableJMX(); diff --git a/components/camel-xmlsecurity/src/test/java/org/apache/camel/dataformat/xmlsecurity/EncryptionAlgorithmTest.java b/components/camel-xmlsecurity/src/test/java/org/apache/camel/dataformat/xmlsecurity/EncryptionAlgorithmTest.java index 3261b0c..d7575fd 100644 --- a/components/camel-xmlsecurity/src/test/java/org/apache/camel/dataformat/xmlsecurity/EncryptionAlgorithmTest.java +++ b/components/camel-xmlsecurity/src/test/java/org/apache/camel/dataformat/xmlsecurity/EncryptionAlgorithmTest.java @@ -27,10 +27,10 @@ import javax.xml.transform.OutputKeys; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.converter.jaxp.XmlConverter; import org.apache.camel.support.jsse.KeyStoreParameters; -import org.apache.camel.test.junit4.CamelTestSupport; +import org.apache.camel.test.junit5.CamelTestSupport; import org.apache.xml.security.encryption.XMLCipher; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Test all available encryption algorithms @@ -57,7 +57,7 @@ public class EncryptionAlgorithmTest extends CamelTestSupport { } @Override - @Before + @BeforeEach public void setUp() throws Exception { super.setUp(); context.getGlobalOptions().put(XmlConverter.OUTPUT_PROPERTIES_PREFIX + OutputKeys.ENCODING, "UTF-8"); diff --git a/components/camel-xmlsecurity/src/test/java/org/apache/camel/dataformat/xmlsecurity/SpringXmlSecurityDataFormatTest.java b/components/camel-xmlsecurity/src/test/java/org/apache/camel/dataformat/xmlsecurity/SpringXmlSecurityDataFormatTest.java index e5c27bb..53124ae 100644 --- a/components/camel-xmlsecurity/src/test/java/org/apache/camel/dataformat/xmlsecurity/SpringXmlSecurityDataFormatTest.java +++ b/components/camel-xmlsecurity/src/test/java/org/apache/camel/dataformat/xmlsecurity/SpringXmlSecurityDataFormatTest.java @@ -18,12 +18,11 @@ package org.apache.camel.dataformat.xmlsecurity; import org.apache.camel.CamelContext; import org.apache.camel.CamelContextAware; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.apache.camel.test.spring.junit5.CamelSpringTest; +import org.junit.jupiter.api.Test; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -@RunWith(SpringJUnit4ClassRunner.class) +@CamelSpringTest @ContextConfiguration public class SpringXmlSecurityDataFormatTest implements CamelContextAware { diff --git a/components/camel-xmlsecurity/src/test/java/org/apache/camel/dataformat/xmlsecurity/SpringXmlSecurityDataFormatWithKeyPasswordTest.java b/components/camel-xmlsecurity/src/test/java/org/apache/camel/dataformat/xmlsecurity/SpringXmlSecurityDataFormatWithKeyPasswordTest.java index 501818da..6633ee5 100644 --- a/components/camel-xmlsecurity/src/test/java/org/apache/camel/dataformat/xmlsecurity/SpringXmlSecurityDataFormatWithKeyPasswordTest.java +++ b/components/camel-xmlsecurity/src/test/java/org/apache/camel/dataformat/xmlsecurity/SpringXmlSecurityDataFormatWithKeyPasswordTest.java @@ -18,12 +18,11 @@ package org.apache.camel.dataformat.xmlsecurity; import org.apache.camel.CamelContext; import org.apache.camel.CamelContextAware; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.apache.camel.test.spring.junit5.CamelSpringTest; +import org.junit.jupiter.api.Test; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -@RunWith(SpringJUnit4ClassRunner.class) +@CamelSpringTest @ContextConfiguration public class SpringXmlSecurityDataFormatWithKeyPasswordTest implements CamelContextAware { diff --git a/components/camel-xmlsecurity/src/test/java/org/apache/camel/dataformat/xmlsecurity/TestHelper.java b/components/camel-xmlsecurity/src/test/java/org/apache/camel/dataformat/xmlsecurity/TestHelper.java index eea2440..f48fd92 100644 --- a/components/camel-xmlsecurity/src/test/java/org/apache/camel/dataformat/xmlsecurity/TestHelper.java +++ b/components/camel-xmlsecurity/src/test/java/org/apache/camel/dataformat/xmlsecurity/TestHelper.java @@ -35,12 +35,14 @@ import org.apache.camel.component.mock.MockEndpoint; import org.apache.camel.converter.jaxp.XmlConverter; import org.apache.xml.security.encryption.XMLCipher; import org.apache.xml.security.encryption.XMLEncryptionException; -import org.junit.Assert; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.xmlunit.builder.DiffBuilder; import org.xmlunit.diff.Diff; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + public class TestHelper { protected static final String NS_XML_FRAGMENT = "<ns1:cheesesites xmlns:ns1=\"http://cheese.xmlsecurity.camel.apache.org/\">" @@ -134,7 +136,7 @@ public class TestHelper { if (log.isDebugEnabled()) { logMessage(exchange, inDoc); } - Assert.assertTrue("The XML message has no encrypted data.", hasEncryptedData(inDoc)); + assertTrue(hasEncryptedData(inDoc), "The XML message has no encrypted data."); return inDoc; } @@ -155,12 +157,12 @@ public class TestHelper { if (log.isDebugEnabled()) { logMessage(exchange, inDoc); } - Assert.assertFalse("The XML message has encrypted data.", hasEncryptedData(inDoc)); + assertFalse(hasEncryptedData(inDoc), "The XML message has encrypted data."); // verify that the decrypted message matches what was sent Diff xmlDiff = DiffBuilder.compare(fragment).withTest(inDoc).checkForIdentical().build(); - Assert.assertFalse("The decrypted document does not match the control document:\n" + xmlDiff.toString(), xmlDiff.hasDifferences()); + assertFalse(xmlDiff.hasDifferences(), "The decrypted document does not match the control document:\n" + xmlDiff.toString()); } protected void testDecryption(CamelContext context) throws Exception { @@ -177,7 +179,7 @@ public class TestHelper { XmlConverter converter = new XmlConverter(); String xmlStr = converter.toString(inDoc, exchange); log.info(xmlStr); - Assert.assertFalse("The XML message has encrypted data.", hasEncryptedData(inDoc)); + assertFalse(hasEncryptedData(inDoc), "The XML message has encrypted data."); } private boolean hasEncryptedData(Document doc) throws Exception { diff --git a/components/camel-xmlsecurity/src/test/java/org/apache/camel/dataformat/xmlsecurity/XMLEncryption11Test.java b/components/camel-xmlsecurity/src/test/java/org/apache/camel/dataformat/xmlsecurity/XMLEncryption11Test.java index 3beeb57..3a302be 100644 --- a/components/camel-xmlsecurity/src/test/java/org/apache/camel/dataformat/xmlsecurity/XMLEncryption11Test.java +++ b/components/camel-xmlsecurity/src/test/java/org/apache/camel/dataformat/xmlsecurity/XMLEncryption11Test.java @@ -26,11 +26,11 @@ import javax.xml.transform.OutputKeys; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.converter.jaxp.XmlConverter; import org.apache.camel.support.jsse.KeyStoreParameters; -import org.apache.camel.test.junit4.CamelTestSupport; +import org.apache.camel.test.junit5.CamelTestSupport; import org.apache.xml.security.encryption.XMLCipher; import org.apache.xml.security.utils.EncryptionConstants; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Some unit tests for XML Encryption 1.1 functionality @@ -59,7 +59,7 @@ public class XMLEncryption11Test extends CamelTestSupport { } @Override - @Before + @BeforeEach public void setUp() throws Exception { super.setUp(); context.getGlobalOptions().put(XmlConverter.OUTPUT_PROPERTIES_PREFIX + OutputKeys.ENCODING, "UTF-8"); diff --git a/components/camel-xmlsecurity/src/test/java/org/apache/camel/dataformat/xmlsecurity/XMLSecurityConcurrencyTest.java b/components/camel-xmlsecurity/src/test/java/org/apache/camel/dataformat/xmlsecurity/XMLSecurityConcurrencyTest.java index 53ab358..a6f794b 100644 --- a/components/camel-xmlsecurity/src/test/java/org/apache/camel/dataformat/xmlsecurity/XMLSecurityConcurrencyTest.java +++ b/components/camel-xmlsecurity/src/test/java/org/apache/camel/dataformat/xmlsecurity/XMLSecurityConcurrencyTest.java @@ -25,8 +25,12 @@ import java.util.concurrent.Executors; import javax.crypto.KeyGenerator; import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.test.junit4.CamelTestSupport; -import org.junit.Test; +import org.apache.camel.test.junit5.CamelTestSupport; +import org.junit.jupiter.api.Test; + +import static org.apache.camel.test.junit5.TestSupport.body; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public class XMLSecurityConcurrencyTest extends CamelTestSupport { @@ -61,7 +65,7 @@ public class XMLSecurityConcurrencyTest extends CamelTestSupport { String secure = getMockEndpoint("mock:secure").getReceivedExchanges().get(0).getIn().getBody(String.class); assertNotNull(secure); - assertTrue("Should not be readable", secure.indexOf("read") == -1); + assertTrue(secure.indexOf("read") == -1, "Should not be readable"); executor.shutdownNow(); } diff --git a/components/camel-xmlsecurity/src/test/java/org/apache/camel/dataformat/xmlsecurity/XMLSecurityDataFormatTest.java b/components/camel-xmlsecurity/src/test/java/org/apache/camel/dataformat/xmlsecurity/XMLSecurityDataFormatTest.java index 548599a..07f50ba 100644 --- a/components/camel-xmlsecurity/src/test/java/org/apache/camel/dataformat/xmlsecurity/XMLSecurityDataFormatTest.java +++ b/components/camel-xmlsecurity/src/test/java/org/apache/camel/dataformat/xmlsecurity/XMLSecurityDataFormatTest.java @@ -32,12 +32,13 @@ import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.mock.MockEndpoint; import org.apache.camel.converter.jaxp.XmlConverter; import org.apache.camel.support.jsse.KeyStoreParameters; -import org.apache.camel.test.junit4.CamelTestSupport; +import org.apache.camel.test.junit5.CamelTestSupport; import org.apache.commons.codec.Charsets; import org.apache.xml.security.encryption.XMLCipher; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Unit test of the encryptXML data format. @@ -56,7 +57,7 @@ public class XMLSecurityDataFormatTest extends CamelTestSupport { } @Override - @Before + @BeforeEach public void setUp() throws Exception { super.setUp(); context.getGlobalOptions().put(XmlConverter.OUTPUT_PROPERTIES_PREFIX + OutputKeys.ENCODING, "UTF-8"); @@ -208,7 +209,7 @@ public class XMLSecurityDataFormatTest extends CamelTestSupport { Document doc = xmlsecTestHelper.testEncryption(TestHelper.XML_FRAGMENT, context); NodeList nodeList = doc.getElementsByTagNameNS("http://www.w3.org/2000/09/xmldsig#", "RSAKeyValue"); - Assert.assertTrue(nodeList.getLength() > 0); + assertTrue(nodeList.getLength() > 0); } @Test @@ -232,7 +233,7 @@ public class XMLSecurityDataFormatTest extends CamelTestSupport { Document doc = xmlsecTestHelper.testEncryption(TestHelper.XML_FRAGMENT, context); NodeList nodeList = doc.getElementsByTagNameNS("http://www.w3.org/2000/09/xmldsig#", "RSAKeyValue"); - Assert.assertTrue(nodeList.getLength() == 0); + assertTrue(nodeList.getLength() == 0); } /*
