This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 025a24661aeb CAMEL-19635: camel-as2: cleanup the tests (#31108)
025a24661aeb is described below
commit 025a24661aeb8f94c76399089a6c3a8382bccf34
Author: Guillaume Nodet <[email protected]>
AuthorDate: Mon Nov 30 11:51:40 2026 +0100
CAMEL-19635: camel-as2: cleanup the tests (#31108)
Part of CAMEL-19635: AS2ClientManagerIT and AS2ServerManagerIT move
repeated checks into helper methods,
the async MDN test checks the HTTP status of the receipt delivery, and
verifyEdiMessage uses assertTrue instead
of the assert keyword.
Co-authored-by: Claude Sonnet 4.6 <[email protected]>
---
.../camel/component/as2/AS2ClientManagerIT.java | 372 +++++----------------
.../camel/component/as2/AS2ServerManagerIT.java | 116 +------
2 files changed, 104 insertions(+), 384 deletions(-)
diff --git
a/components/camel-as2/camel-as2-component/src/test/java/org/apache/camel/component/as2/AS2ClientManagerIT.java
b/components/camel-as2/camel-as2-component/src/test/java/org/apache/camel/component/as2/AS2ClientManagerIT.java
index c8b63822e92b..715eb79e63a5 100644
---
a/components/camel-as2/camel-as2-component/src/test/java/org/apache/camel/component/as2/AS2ClientManagerIT.java
+++
b/components/camel-as2/camel-as2-component/src/test/java/org/apache/camel/component/as2/AS2ClientManagerIT.java
@@ -87,7 +87,6 @@ import org.junit.jupiter.api.extension.RegisterExtension;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
@@ -183,25 +182,15 @@ public class AS2ClientManagerIT extends
AbstractAS2ITSupport {
private void plainMessageSend(Object msg, String encoding) throws
Exception {
final Map<String, Object> headers = new HashMap<>();
- // parameter type is String
headers.put("CamelAs2.requestUri", REQUEST_URI);
- // parameter type is String
headers.put("CamelAs2.subject", SUBJECT);
- // parameter type is String
headers.put("CamelAs2.from", FROM);
- // parameter type is String
headers.put("CamelAs2.as2From", AS2_NAME);
- // parameter type is String
headers.put("CamelAs2.as2To", AS2_NAME);
- // parameter type is
org.apache.camel.component.as2.api.AS2MessageStructure
headers.put("CamelAs2.as2MessageStructure", AS2MessageStructure.PLAIN);
- // parameter type is String
headers.put("CamelAs2.ediMessageContentType",
AS2MediaType.APPLICATION_EDIFACT);
- // parameter type is String
headers.put("CamelAs2.ediMessageTransferEncoding", encoding);
- // parameter type is String
headers.put("CamelAs2.dispositionNotificationTo", "[email protected]");
- // parameter type is String
headers.put("CamelAs2.attachedFileName", "");
final Triple<HttpEntity, HttpRequest, HttpResponse> result =
executeRequest(headers, msg);
@@ -218,71 +207,26 @@ public class AS2ClientManagerIT extends
AbstractAS2ITSupport {
assertTrue(entity instanceof ApplicationEntity, "Request body does not
contain EDI entity");
ApplicationEntity appEntity = (ApplicationEntity) entity;
- verifyMessage(appEntity, encoding);
+ verifyEdiMessage(appEntity, encoding);
- assertNotNull(response, "Response");
- assertTrue(HttpMessageUtils.getHeaderValue(response,
AS2Header.CONTENT_TYPE).startsWith(AS2MimeType.MULTIPART_REPORT),
- "Unexpected response type");
- assertEquals(AS2Constants.MIME_VERSION,
HttpMessageUtils.getHeaderValue(response, AS2Header.MIME_VERSION),
- "Unexpected mime version");
- assertEquals(EXPECTED_AS2_VERSION,
HttpMessageUtils.getHeaderValue(response, AS2Header.AS2_VERSION),
- "Unexpected AS2 version");
- assertEquals(EXPECTED_MDN_SUBJECT,
HttpMessageUtils.getHeaderValue(response, AS2Header.SUBJECT),
- "Unexpected MDN subject");
- assertEquals(MDN_FROM, HttpMessageUtils.getHeaderValue(response,
AS2Header.FROM), "Unexpected MDN from");
- assertEquals(AS2_NAME, HttpMessageUtils.getHeaderValue(response,
AS2Header.AS2_FROM), "Unexpected AS2 from");
- assertEquals(AS2_NAME, HttpMessageUtils.getHeaderValue(response,
AS2Header.AS2_TO), "Unexpected AS2 to");
- assertNotNull(HttpMessageUtils.getHeaderValue(response,
AS2Header.MESSAGE_ID), "Missing message id");
+ verifyMdnResponse(response);
assertNotNull(responseEntity, "Response entity");
assertTrue(responseEntity instanceof
DispositionNotificationMultipartReportEntity, "Unexpected response entity
type");
- DispositionNotificationMultipartReportEntity reportEntity
- = (DispositionNotificationMultipartReportEntity)
responseEntity;
- assertEquals(2, reportEntity.getPartCount(), "Unexpected number of
body parts in report");
- MimeEntity firstPart = reportEntity.getPart(0);
- assertEquals(ContentType.create(AS2MimeType.TEXT_PLAIN,
StandardCharsets.US_ASCII).toString(),
- firstPart.getContentType(), "Unexpected content type in first
body part of report");
- MimeEntity secondPart = reportEntity.getPart(1);
-
assertEquals(ContentType.create(AS2MimeType.MESSAGE_DISPOSITION_NOTIFICATION).toString(),
- secondPart.getContentType(),
- "Unexpected content type in second body part of report");
-
- assertTrue(secondPart instanceof
AS2MessageDispositionNotificationEntity, "");
- AS2MessageDispositionNotificationEntity
messageDispositionNotificationEntity
- = (AS2MessageDispositionNotificationEntity) secondPart;
- assertEquals(ORIGIN_SERVER_NAME,
messageDispositionNotificationEntity.getReportingUA(),
- "Unexpected value for reporting UA");
- assertEquals(AS2_NAME,
messageDispositionNotificationEntity.getFinalRecipient(),
- "Unexpected value for final recipient");
- assertEquals(HttpMessageUtils.getHeaderValue(request,
AS2Header.MESSAGE_ID),
- messageDispositionNotificationEntity.getOriginalMessageId(),
"Unexpected value for original message ID");
- assertEquals(DispositionMode.AUTOMATIC_ACTION_MDN_SENT_AUTOMATICALLY,
- messageDispositionNotificationEntity.getDispositionMode(),
"Unexpected value for disposition mode");
- assertEquals(AS2DispositionType.PROCESSED,
messageDispositionNotificationEntity.getDispositionType(),
- "Unexpected value for disposition type");
-
+
verifyDispositionNotificationReport((DispositionNotificationMultipartReportEntity)
responseEntity, request);
}
@Test
public void plainMessageSendTestWhenDispositionNotificationToNotSet()
throws Exception {
final Map<String, Object> headers = new HashMap<>();
- // parameter type is String
headers.put("CamelAs2.requestUri", REQUEST_URI);
- // parameter type is String
headers.put("CamelAs2.subject", SUBJECT);
- // parameter type is String
headers.put("CamelAs2.from", FROM);
- // parameter type is String
headers.put("CamelAs2.as2From", AS2_NAME);
- // parameter type is String
headers.put("CamelAs2.as2To", AS2_NAME);
- // parameter type is
org.apache.camel.component.as2.api.AS2MessageStructure
headers.put("CamelAs2.as2MessageStructure", AS2MessageStructure.PLAIN);
- // parameter type is String
headers.put("CamelAs2.ediMessageContentType",
AS2MediaType.APPLICATION_EDIFACT);
- // parameter type is String
headers.put("CamelAs2.ediMessageTransferEncoding",
EDI_MESSAGE_CONTENT_TRANSFER_ENCODING);
- // parameter type is String
headers.put("CamelAs2.attachedFileName", "");
final Triple<HttpEntity, HttpRequest, HttpResponse> result =
executeRequest(headers, EDI_MESSAGE);
@@ -323,21 +267,13 @@ public class AS2ClientManagerIT extends
AbstractAS2ITSupport {
@Test
public void plainMessageSend2Test() throws Exception {
final Map<String, Object> headers = new HashMap<>();
- // parameter type is String
headers.put("CamelAs2.requestUri", REQUEST_URI);
- // parameter type is String
headers.put("CamelAs2.subject", SUBJECT);
- // parameter type is String
headers.put("CamelAs2.from", FROM);
- // parameter type is
org.apache.camel.component.as2.api.AS2MessageStructure
headers.put("CamelAs2.as2MessageStructure", AS2MessageStructure.PLAIN);
- // parameter type is String
headers.put("CamelAs2.ediMessageContentType",
AS2MediaType.APPLICATION_EDIFACT);
- // parameter type is String
headers.put("CamelAs2.ediMessageTransferEncoding",
EDI_MESSAGE_CONTENT_TRANSFER_ENCODING);
- // parameter type is String
headers.put("CamelAs2.dispositionNotificationTo", "[email protected]");
- // parameter type is String
headers.put("CamelAs2.attachedFileName", "");
final Triple<HttpEntity, HttpRequest, HttpResponse> result =
executeRequest2(headers);
@@ -358,47 +294,11 @@ public class AS2ClientManagerIT extends
AbstractAS2ITSupport {
String ediMessage = (String) appEntity.getEdiMessage();
assertEquals(EDI_MESSAGE.replaceAll("[\n\r]", ""),
ediMessage.replaceAll("[\n\r]", ""), "EDI message is different");
- assertNotNull(response, "Response");
- assertTrue(HttpMessageUtils.getHeaderValue(response,
AS2Header.CONTENT_TYPE).startsWith(AS2MimeType.MULTIPART_REPORT),
- "Unexpected response type");
- assertEquals(AS2Constants.MIME_VERSION,
HttpMessageUtils.getHeaderValue(response, AS2Header.MIME_VERSION),
- "Unexpected mime version");
- assertEquals(EXPECTED_AS2_VERSION,
HttpMessageUtils.getHeaderValue(response, AS2Header.AS2_VERSION),
- "Unexpected AS2 version");
- assertEquals(EXPECTED_MDN_SUBJECT,
HttpMessageUtils.getHeaderValue(response, AS2Header.SUBJECT),
- "Unexpected MDN subject");
- assertEquals(MDN_FROM, HttpMessageUtils.getHeaderValue(response,
AS2Header.FROM), "Unexpected MDN from");
- assertEquals(AS2_NAME, HttpMessageUtils.getHeaderValue(response,
AS2Header.AS2_FROM), "Unexpected AS2 from");
- assertEquals(AS2_NAME, HttpMessageUtils.getHeaderValue(response,
AS2Header.AS2_TO), "Unexpected AS2 to");
- assertNotNull(HttpMessageUtils.getHeaderValue(response,
AS2Header.MESSAGE_ID), "Missing message id");
+ verifyMdnResponse(response);
assertNotNull(responseEntity, "Response entity");
assertTrue(responseEntity instanceof
DispositionNotificationMultipartReportEntity, "Unexpected response entity
type");
- DispositionNotificationMultipartReportEntity reportEntity
- = (DispositionNotificationMultipartReportEntity)
responseEntity;
- assertEquals(2, reportEntity.getPartCount(), "Unexpected number of
body parts in report");
- MimeEntity firstPart = reportEntity.getPart(0);
- assertEquals(ContentType.create(AS2MimeType.TEXT_PLAIN,
StandardCharsets.US_ASCII).toString(),
- firstPart.getContentType(), "Unexpected content type in first
body part of report");
- MimeEntity secondPart = reportEntity.getPart(1);
-
assertEquals(ContentType.create(AS2MimeType.MESSAGE_DISPOSITION_NOTIFICATION).toString(),
- secondPart.getContentType(),
- "Unexpected content type in second body part of report");
-
- assertTrue(secondPart instanceof
AS2MessageDispositionNotificationEntity, "");
- AS2MessageDispositionNotificationEntity
messageDispositionNotificationEntity
- = (AS2MessageDispositionNotificationEntity) secondPart;
- assertEquals(ORIGIN_SERVER_NAME,
messageDispositionNotificationEntity.getReportingUA(),
- "Unexpected value for reporting UA");
- assertEquals(AS2_NAME,
messageDispositionNotificationEntity.getFinalRecipient(),
- "Unexpected value for final recipient");
- assertEquals(HttpMessageUtils.getHeaderValue(request,
AS2Header.MESSAGE_ID),
- messageDispositionNotificationEntity.getOriginalMessageId(),
"Unexpected value for original message ID");
- assertEquals(DispositionMode.AUTOMATIC_ACTION_MDN_SENT_AUTOMATICALLY,
- messageDispositionNotificationEntity.getDispositionMode(),
"Unexpected value for disposition mode");
- assertEquals(AS2DispositionType.PROCESSED,
messageDispositionNotificationEntity.getDispositionType(),
- "Unexpected value for disposition type");
-
+
verifyDispositionNotificationReport((DispositionNotificationMultipartReportEntity)
responseEntity, request);
}
@Test
@@ -413,29 +313,17 @@ public class AS2ClientManagerIT extends
AbstractAS2ITSupport {
private void envelopedMessageSend(Object msg, String encoding) throws
Exception {
final Map<String, Object> headers = new HashMap<>();
- // parameter type is String
headers.put("CamelAs2.requestUri", REQUEST_URI);
- // parameter type is String
headers.put("CamelAs2.subject", SUBJECT);
- // parameter type is String
headers.put("CamelAs2.from", FROM);
- // parameter type is String
headers.put("CamelAs2.as2From", AS2_NAME);
- // parameter type is String
headers.put("CamelAs2.as2To", AS2_NAME);
- // parameter type is
org.apache.camel.component.as2.api.AS2MessageStructure
headers.put("CamelAs2.as2MessageStructure",
AS2MessageStructure.ENCRYPTED);
- // parameter type is String
headers.put("CamelAs2.ediMessageContentType",
AS2MediaType.APPLICATION_EDIFACT);
- // parameter type is String
headers.put("CamelAs2.ediMessageTransferEncoding", encoding);
- // parameter type is String
headers.put("CamelAs2.dispositionNotificationTo", "[email protected]");
- // parameter type is
org.apache.camel.component.as2.api.AS2EncryptionAlgorithm
headers.put("CamelAs2.encryptingAlgorithm",
AS2EncryptionAlgorithm.AES128_CBC);
- // parameter type is java.security.cert.Certificate[]
headers.put("CamelAs2.encryptingCertificateChain", new Certificate[] {
clientCert });
- // parameter type is String
headers.put("CamelAs2.attachedFileName", "");
final Triple<HttpEntity, HttpRequest, HttpResponse> result =
executeRequest(headers, msg);
@@ -457,49 +345,13 @@ public class AS2ClientManagerIT extends
AbstractAS2ITSupport {
assertTrue(envelopeEntity instanceof ApplicationEntity, "Enveloped
entity is not an EDI entity");
ApplicationEntity appEntity = (ApplicationEntity) envelopeEntity;
- verifyMessage(appEntity, encoding);
+ verifyEdiMessage(appEntity, encoding);
- assertNotNull(response, "Response");
- assertTrue(HttpMessageUtils.getHeaderValue(response,
AS2Header.CONTENT_TYPE).startsWith(AS2MimeType.MULTIPART_REPORT),
- "Unexpected response type");
- assertEquals(AS2Constants.MIME_VERSION,
HttpMessageUtils.getHeaderValue(response, AS2Header.MIME_VERSION),
- "Unexpected mime version");
- assertEquals(EXPECTED_AS2_VERSION,
HttpMessageUtils.getHeaderValue(response, AS2Header.AS2_VERSION),
- "Unexpected AS2 version");
- assertEquals(EXPECTED_MDN_SUBJECT,
HttpMessageUtils.getHeaderValue(response, AS2Header.SUBJECT),
- "Unexpected MDN subject");
- assertEquals(MDN_FROM, HttpMessageUtils.getHeaderValue(response,
AS2Header.FROM), "Unexpected MDN from");
- assertEquals(AS2_NAME, HttpMessageUtils.getHeaderValue(response,
AS2Header.AS2_FROM), "Unexpected AS2 from");
- assertEquals(AS2_NAME, HttpMessageUtils.getHeaderValue(response,
AS2Header.AS2_TO), "Unexpected AS2 to");
- assertNotNull(HttpMessageUtils.getHeaderValue(response,
AS2Header.MESSAGE_ID), "Missing message id");
+ verifyMdnResponse(response);
assertNotNull(responseEntity, "Response entity");
assertTrue(responseEntity instanceof
DispositionNotificationMultipartReportEntity, "Unexpected response entity
type");
- DispositionNotificationMultipartReportEntity reportEntity
- = (DispositionNotificationMultipartReportEntity)
responseEntity;
- assertEquals(2, reportEntity.getPartCount(), "Unexpected number of
body parts in report");
- MimeEntity firstPart = reportEntity.getPart(0);
- assertEquals(ContentType.create(AS2MimeType.TEXT_PLAIN,
StandardCharsets.US_ASCII).toString(),
- firstPart.getContentType(), "Unexpected content type in first
body part of report");
- MimeEntity secondPart = reportEntity.getPart(1);
-
assertEquals(ContentType.create(AS2MimeType.MESSAGE_DISPOSITION_NOTIFICATION).toString(),
- secondPart.getContentType(),
- "Unexpected content type in second body part of report");
-
- assertTrue(secondPart instanceof
AS2MessageDispositionNotificationEntity, "");
- AS2MessageDispositionNotificationEntity
messageDispositionNotificationEntity
- = (AS2MessageDispositionNotificationEntity) secondPart;
- assertEquals(ORIGIN_SERVER_NAME,
messageDispositionNotificationEntity.getReportingUA(),
- "Unexpected value for reporting UA");
- assertEquals(AS2_NAME,
messageDispositionNotificationEntity.getFinalRecipient(),
- "Unexpected value for final recipient");
- assertEquals(HttpMessageUtils.getHeaderValue(request,
AS2Header.MESSAGE_ID),
- messageDispositionNotificationEntity.getOriginalMessageId(),
"Unexpected value for original message ID");
- assertEquals(DispositionMode.AUTOMATIC_ACTION_MDN_SENT_AUTOMATICALLY,
- messageDispositionNotificationEntity.getDispositionMode(),
"Unexpected value for disposition mode");
- assertEquals(AS2DispositionType.PROCESSED,
messageDispositionNotificationEntity.getDispositionType(),
- "Unexpected value for disposition type");
-
+
verifyDispositionNotificationReport((DispositionNotificationMultipartReportEntity)
responseEntity, request);
}
@Test
@@ -514,33 +366,19 @@ public class AS2ClientManagerIT extends
AbstractAS2ITSupport {
private void multipartSignedMessage(Object msg, String encoding) throws
Exception {
final Map<String, Object> headers = new HashMap<>();
- // parameter type is String
headers.put("CamelAs2.requestUri", REQUEST_URI);
- // parameter type is String
headers.put("CamelAs2.subject", SUBJECT);
- // parameter type is String
headers.put("CamelAs2.from", FROM);
- // parameter type is String
headers.put("CamelAs2.as2From", AS2_NAME);
- // parameter type is String
headers.put("CamelAs2.as2To", AS2_NAME);
- // parameter type is
org.apache.camel.component.as2.api.AS2MessageStructure
headers.put("CamelAs2.as2MessageStructure",
AS2MessageStructure.SIGNED);
- // parameter type is String
headers.put("CamelAs2.ediMessageContentType",
AS2MediaType.APPLICATION_EDIFACT);
- // parameter type is String
headers.put("CamelAs2.ediMessageTransferEncoding", encoding);
- // parameter type is
org.apache.camel.component.as2.api.AS2SignatureAlgorithm
headers.put("CamelAs2.signingAlgorithm",
AS2SignatureAlgorithm.SHA512WITHRSA);
- // parameter type is java.security.cert.Certificate[]
headers.put("CamelAs2.signingCertificateChain", new Certificate[] {
clientCert });
- // parameter type is java.security.PrivateKey
headers.put("CamelAs2.signingPrivateKey", clientKeyPair.getPrivate());
- // parameter type is String
headers.put("CamelAs2.dispositionNotificationTo", "[email protected]");
- // parameter type is String[]
headers.put("CamelAs2.signedReceiptMicAlgorithms",
SIGNED_RECEIPT_MIC_ALGORITHMS);
- // parameter type is String
headers.put("CamelAs2.attachedFileName", "");
final Triple<HttpEntity, HttpRequest, HttpResponse> result =
executeRequest(headers, msg);
@@ -559,7 +397,7 @@ public class AS2ClientManagerIT extends
AbstractAS2ITSupport {
MimeEntity signedEntity = ((MultipartSignedEntity)
entity).getSignedDataEntity();
assertTrue(signedEntity instanceof ApplicationEntity, "Signed entity
wrong type");
ApplicationEntity ediMessageEntity = (ApplicationEntity) signedEntity;
- verifyMessage(ediMessageEntity, encoding);
+ verifyEdiMessage(ediMessageEntity, encoding);
assertNotNull(response, "Response");
String contentTypeHeaderValue =
HttpMessageUtils.getHeaderValue(response, AS2Header.CONTENT_TYPE);
@@ -584,34 +422,15 @@ public class AS2ClientManagerIT extends
AbstractAS2ITSupport {
MimeEntity responseSignedDataEntity =
responseSignedEntity.getSignedDataEntity();
assertTrue(responseSignedDataEntity instanceof
DispositionNotificationMultipartReportEntity,
"Signed entity wrong type");
- DispositionNotificationMultipartReportEntity reportEntity
- = (DispositionNotificationMultipartReportEntity)
responseSignedDataEntity;
- assertEquals(2, reportEntity.getPartCount(), "Unexpected number of
body parts in report");
- MimeEntity firstPart = reportEntity.getPart(0);
- assertEquals(ContentType.create(AS2MimeType.TEXT_PLAIN,
StandardCharsets.US_ASCII).toString(),
- firstPart.getContentType(), "Unexpected content type in first
body part of report");
- MimeEntity secondPart = reportEntity.getPart(1);
-
assertEquals(ContentType.create(AS2MimeType.MESSAGE_DISPOSITION_NOTIFICATION).toString(),
- secondPart.getContentType(),
- "Unexpected content type in second body part of report");
ApplicationPkcs7SignatureEntity signatureEntity =
responseSignedEntity.getSignatureEntity();
assertNotNull(signatureEntity, "Signature Entity");
- assertTrue(secondPart instanceof
AS2MessageDispositionNotificationEntity, "");
- AS2MessageDispositionNotificationEntity
messageDispositionNotificationEntity
- = (AS2MessageDispositionNotificationEntity) secondPart;
- assertEquals(ORIGIN_SERVER_NAME,
messageDispositionNotificationEntity.getReportingUA(),
- "Unexpected value for reporting UA");
- assertEquals(AS2_NAME,
messageDispositionNotificationEntity.getFinalRecipient(),
- "Unexpected value for final recipient");
- assertEquals(HttpMessageUtils.getHeaderValue(request,
AS2Header.MESSAGE_ID),
- messageDispositionNotificationEntity.getOriginalMessageId(),
"Unexpected value for original message ID");
- assertEquals(DispositionMode.AUTOMATIC_ACTION_MDN_SENT_AUTOMATICALLY,
- messageDispositionNotificationEntity.getDispositionMode(),
"Unexpected value for disposition mode");
- assertEquals(AS2DispositionType.PROCESSED,
messageDispositionNotificationEntity.getDispositionType(),
- "Unexpected value for disposition type");
+ DispositionNotificationMultipartReportEntity reportEntity
+ = (DispositionNotificationMultipartReportEntity)
responseSignedDataEntity;
+ verifyDispositionNotificationReport(reportEntity, request);
- ReceivedContentMic receivedContentMic =
messageDispositionNotificationEntity.getReceivedContentMic();
+ ReceivedContentMic receivedContentMic
+ = ((AS2MessageDispositionNotificationEntity)
reportEntity.getPart(1)).getReceivedContentMic();
ReceivedContentMic computedContentMic
= MicUtils.createReceivedContentMic((ClassicHttpRequest)
request, new Certificate[] { clientCert },
null);
@@ -622,33 +441,19 @@ public class AS2ClientManagerIT extends
AbstractAS2ITSupport {
@Test
public void multipartSignedXMLMessageTest() throws Exception {
final Map<String, Object> headers = new HashMap<>();
- // parameter type is String
headers.put("CamelAs2.requestUri", REQUEST_URI);
- // parameter type is String
headers.put("CamelAs2.subject", SUBJECT);
- // parameter type is String
headers.put("CamelAs2.from", FROM);
- // parameter type is String
headers.put("CamelAs2.as2From", AS2_NAME);
- // parameter type is String
headers.put("CamelAs2.as2To", AS2_NAME);
- // parameter type is
org.apache.camel.component.as2.api.AS2MessageStructure
headers.put("CamelAs2.as2MessageStructure",
AS2MessageStructure.SIGNED);
- // parameter type is String
headers.put("CamelAs2.ediMessageContentType",
AS2MediaType.APPLICATION_XML);
- // parameter type is String
headers.put("CamelAs2.ediMessageTransferEncoding",
EDI_MESSAGE_CONTENT_TRANSFER_ENCODING);
- // parameter type is
org.apache.camel.component.as2.api.AS2SignatureAlgorithm
headers.put("CamelAs2.signingAlgorithm",
AS2SignatureAlgorithm.SHA512WITHRSA);
- // parameter type is java.security.cert.Certificate[]
headers.put("CamelAs2.signingCertificateChain", new Certificate[] {
clientCert });
- // parameter type is java.security.PrivateKey
headers.put("CamelAs2.signingPrivateKey", clientKeyPair.getPrivate());
- // parameter type is String
headers.put("CamelAs2.dispositionNotificationTo", "[email protected]");
- // parameter type is String[]
headers.put("CamelAs2.signedReceiptMicAlgorithms",
SIGNED_RECEIPT_MIC_ALGORITHMS);
- // parameter type is String
headers.put("CamelAs2.attachedFileName", "");
final Triple<HttpEntity, HttpRequest, HttpResponse> result =
executeRequest(headers, EDI_MESSAGE);
@@ -695,34 +500,15 @@ public class AS2ClientManagerIT extends
AbstractAS2ITSupport {
MimeEntity responseSignedDataEntity =
responseSignedEntity.getSignedDataEntity();
assertTrue(responseSignedDataEntity instanceof
DispositionNotificationMultipartReportEntity,
"Signed entity wrong type");
- DispositionNotificationMultipartReportEntity reportEntity
- = (DispositionNotificationMultipartReportEntity)
responseSignedDataEntity;
- assertEquals(2, reportEntity.getPartCount(), "Unexpected number of
body parts in report");
- MimeEntity firstPart = reportEntity.getPart(0);
- assertEquals(ContentType.create(AS2MimeType.TEXT_PLAIN,
StandardCharsets.US_ASCII).toString(),
- firstPart.getContentType(), "Unexpected content type in first
body part of report");
- MimeEntity secondPart = reportEntity.getPart(1);
-
assertEquals(ContentType.create(AS2MimeType.MESSAGE_DISPOSITION_NOTIFICATION).toString(),
- secondPart.getContentType(),
- "Unexpected content type in second body part of report");
ApplicationPkcs7SignatureEntity signatureEntity =
responseSignedEntity.getSignatureEntity();
assertNotNull(signatureEntity, "Signature Entity");
- assertTrue(secondPart instanceof
AS2MessageDispositionNotificationEntity, "");
- AS2MessageDispositionNotificationEntity
messageDispositionNotificationEntity
- = (AS2MessageDispositionNotificationEntity) secondPart;
- assertEquals(ORIGIN_SERVER_NAME,
messageDispositionNotificationEntity.getReportingUA(),
- "Unexpected value for reporting UA");
- assertEquals(AS2_NAME,
messageDispositionNotificationEntity.getFinalRecipient(),
- "Unexpected value for final recipient");
- assertEquals(HttpMessageUtils.getHeaderValue(request,
AS2Header.MESSAGE_ID),
- messageDispositionNotificationEntity.getOriginalMessageId(),
"Unexpected value for original message ID");
- assertEquals(DispositionMode.AUTOMATIC_ACTION_MDN_SENT_AUTOMATICALLY,
- messageDispositionNotificationEntity.getDispositionMode(),
"Unexpected value for disposition mode");
- assertEquals(AS2DispositionType.PROCESSED,
messageDispositionNotificationEntity.getDispositionType(),
- "Unexpected value for disposition type");
+ DispositionNotificationMultipartReportEntity xmlReportEntity
+ = (DispositionNotificationMultipartReportEntity)
responseSignedDataEntity;
+ verifyDispositionNotificationReport(xmlReportEntity, request);
- ReceivedContentMic receivedContentMic =
messageDispositionNotificationEntity.getReceivedContentMic();
+ ReceivedContentMic receivedContentMic
+ = ((AS2MessageDispositionNotificationEntity)
xmlReportEntity.getPart(1)).getReceivedContentMic();
ReceivedContentMic computedContentMic
= MicUtils.createReceivedContentMic((ClassicHttpRequest)
request, new Certificate[] { clientCert }, null);
assertEquals(computedContentMic.getEncodedMessageDigest(),
receivedContentMic.getEncodedMessageDigest(),
@@ -741,29 +527,17 @@ public class AS2ClientManagerIT extends
AbstractAS2ITSupport {
private void compressedMessage(Object msg, String encoding) throws
Exception {
final Map<String, Object> headers = new HashMap<>();
- // parameter type is String
headers.put("CamelAs2.requestUri", REQUEST_URI);
- // parameter type is String
headers.put("CamelAs2.subject", SUBJECT);
- // parameter type is String
headers.put("CamelAs2.from", FROM);
- // parameter type is String
headers.put("CamelAs2.as2From", AS2_NAME);
- // parameter type is String
headers.put("CamelAs2.as2To", AS2_NAME);
- // parameter type is
org.apache.camel.component.as2.api.AS2MessageStructure
headers.put("CamelAs2.as2MessageStructure",
AS2MessageStructure.PLAIN_COMPRESSED);
- // parameter type is String
headers.put("CamelAs2.ediMessageContentType",
AS2MediaType.APPLICATION_EDIFACT);
- // parameter type is String
headers.put("CamelAs2.ediMessageTransferEncoding", encoding);
- // parameter type is
org.apache.camel.component.as2.api.AS2CompressionAlgorithm
headers.put("CamelAs2.compressionAlgorithm",
AS2CompressionAlgorithm.ZLIB);
- // parameter type is String
headers.put("CamelAs2.dispositionNotificationTo", "[email protected]");
- // parameter type is String[]
headers.put("CamelAs2.signedReceiptMicAlgorithms",
SIGNED_RECEIPT_MIC_ALGORITHMS);
- // parameter type is String
headers.put("CamelAs2.attachedFileName", "");
final Triple<HttpEntity, HttpRequest, HttpResponse> result =
executeRequest(headers, msg);
@@ -783,7 +557,7 @@ public class AS2ClientManagerIT extends
AbstractAS2ITSupport {
= ((ApplicationPkcs7MimeCompressedDataEntity)
entity).getCompressedEntity(new ZlibExpanderProvider());
assertTrue(compressedEntity instanceof ApplicationEntity, "Signed
entity wrong type");
ApplicationEntity ediMessageEntity = (ApplicationEntity)
compressedEntity;
- verifyMessage(ediMessageEntity, encoding);
+ verifyEdiMessage(ediMessageEntity, encoding);
assertNotNull(response, "Response");
String contentTypeHeaderValue =
HttpMessageUtils.getHeaderValue(response, AS2Header.CONTENT_TYPE);
@@ -808,34 +582,15 @@ public class AS2ClientManagerIT extends
AbstractAS2ITSupport {
MimeEntity responseSignedDataEntity =
responseSignedEntity.getSignedDataEntity();
assertTrue(responseSignedDataEntity instanceof
DispositionNotificationMultipartReportEntity,
"Signed entity wrong type");
- DispositionNotificationMultipartReportEntity reportEntity
- = (DispositionNotificationMultipartReportEntity)
responseSignedDataEntity;
- assertEquals(2, reportEntity.getPartCount(), "Unexpected number of
body parts in report");
- MimeEntity firstPart = reportEntity.getPart(0);
- assertEquals(ContentType.create(AS2MimeType.TEXT_PLAIN,
StandardCharsets.US_ASCII).toString(),
- firstPart.getContentType(), "Unexpected content type in first
body part of report");
- MimeEntity secondPart = reportEntity.getPart(1);
-
assertEquals(ContentType.create(AS2MimeType.MESSAGE_DISPOSITION_NOTIFICATION).toString(),
- secondPart.getContentType(),
- "Unexpected content type in second body part of report");
ApplicationPkcs7SignatureEntity signatureEntity =
responseSignedEntity.getSignatureEntity();
assertNotNull(signatureEntity, "Signature Entity");
- assertTrue(secondPart instanceof
AS2MessageDispositionNotificationEntity, "");
- AS2MessageDispositionNotificationEntity
messageDispositionNotificationEntity
- = (AS2MessageDispositionNotificationEntity) secondPart;
- assertEquals(ORIGIN_SERVER_NAME,
messageDispositionNotificationEntity.getReportingUA(),
- "Unexpected value for reporting UA");
- assertEquals(AS2_NAME,
messageDispositionNotificationEntity.getFinalRecipient(),
- "Unexpected value for final recipient");
- assertEquals(HttpMessageUtils.getHeaderValue(request,
AS2Header.MESSAGE_ID),
- messageDispositionNotificationEntity.getOriginalMessageId(),
"Unexpected value for original message ID");
- assertEquals(DispositionMode.AUTOMATIC_ACTION_MDN_SENT_AUTOMATICALLY,
- messageDispositionNotificationEntity.getDispositionMode(),
"Unexpected value for disposition mode");
- assertEquals(AS2DispositionType.PROCESSED,
messageDispositionNotificationEntity.getDispositionType(),
- "Unexpected value for disposition type");
+ DispositionNotificationMultipartReportEntity compressedReportEntity
+ = (DispositionNotificationMultipartReportEntity)
responseSignedDataEntity;
+ verifyDispositionNotificationReport(compressedReportEntity, request);
- ReceivedContentMic receivedContentMic =
messageDispositionNotificationEntity.getReceivedContentMic();
+ ReceivedContentMic receivedContentMic
+ = ((AS2MessageDispositionNotificationEntity)
compressedReportEntity.getPart(1)).getReceivedContentMic();
ReceivedContentMic computedContentMic
= MicUtils.createReceivedContentMic((ClassicHttpRequest)
request, null,
null);
@@ -844,9 +599,8 @@ public class AS2ClientManagerIT extends
AbstractAS2ITSupport {
}
@Test
- public void asyncMDNTest() {
- assertDoesNotThrow(() -> runAsyncMDNTest());
-
+ public void asyncMDNTest() throws Exception {
+ runAsyncMDNTest();
}
private void runAsyncMDNTest() throws CamelException, HttpException {
@@ -890,11 +644,12 @@ public class AS2ClientManagerIT extends
AbstractAS2ITSupport {
dispositionModifier, failureFields, errorFields,
warningFields, extensionFields, null, "boundary",
true, null, "Got your message!", null);
- // Send MDN
- @SuppressWarnings("unused")
- HttpCoreContext httpContext
- = mdnManager.send(mdn, mdn.getMainMessageContentType(),
- "http://localhost:" + mdnTargetPort.getPort() +
"/handle-receipts");
+ // Send MDN and verify that the server accepted it with a 2xx response
+ HttpCoreContext mdnContext = mdnManager.send(mdn,
mdn.getMainMessageContentType(),
+ "http://localhost:" + mdnTargetPort.getPort() +
"/handle-receipts");
+ int responseCode = mdnContext.getResponse().getCode();
+ assertTrue(responseCode >= 200 && responseCode < 300,
+ "Expected a 2xx response from the MDN server, got: " +
responseCode);
}
@Override
@@ -955,8 +710,7 @@ public class AS2ClientManagerIT extends
AbstractAS2ITSupport {
Processor proc = new Processor() {
public void process(Exchange exchange) {
HttpMessage message =
exchange.getIn(HttpMessage.class);
- @SuppressWarnings("unused")
- String body = message.getBody(String.class);
+ message.getBody(String.class);
}
};
// test route for send
@@ -1026,13 +780,65 @@ public class AS2ClientManagerIT extends
AbstractAS2ITSupport {
clientCert = Utils.makeCertificate(clientKeyPair, signingDN, issueKP,
issueDN);
}
- private void verifyMessage(ApplicationEntity appEntity, String encoding)
throws IOException {
+ /**
+ * Verifies the MDN response HTTP headers for a standard MULTIPART_REPORT
response.
+ */
+ private void verifyMdnResponse(HttpResponse response) {
+ assertNotNull(response, "Response");
+ assertTrue(HttpMessageUtils.getHeaderValue(response,
AS2Header.CONTENT_TYPE).startsWith(AS2MimeType.MULTIPART_REPORT),
+ "Unexpected response type");
+ assertEquals(AS2Constants.MIME_VERSION,
HttpMessageUtils.getHeaderValue(response, AS2Header.MIME_VERSION),
+ "Unexpected mime version");
+ assertEquals(EXPECTED_AS2_VERSION,
HttpMessageUtils.getHeaderValue(response, AS2Header.AS2_VERSION),
+ "Unexpected AS2 version");
+ assertEquals(EXPECTED_MDN_SUBJECT,
HttpMessageUtils.getHeaderValue(response, AS2Header.SUBJECT),
+ "Unexpected MDN subject");
+ assertEquals(MDN_FROM, HttpMessageUtils.getHeaderValue(response,
AS2Header.FROM), "Unexpected MDN from");
+ assertEquals(AS2_NAME, HttpMessageUtils.getHeaderValue(response,
AS2Header.AS2_FROM), "Unexpected AS2 from");
+ assertEquals(AS2_NAME, HttpMessageUtils.getHeaderValue(response,
AS2Header.AS2_TO), "Unexpected AS2 to");
+ assertNotNull(HttpMessageUtils.getHeaderValue(response,
AS2Header.MESSAGE_ID), "Missing message id");
+ }
+
+ /**
+ * Verifies the structure and content of a
DispositionNotificationMultipartReportEntity.
+ */
+ private void verifyDispositionNotificationReport(
+ DispositionNotificationMultipartReportEntity reportEntity,
HttpRequest request) {
+ assertEquals(2, reportEntity.getPartCount(), "Unexpected number of
body parts in report");
+ MimeEntity firstPart = reportEntity.getPart(0);
+ assertEquals(ContentType.create(AS2MimeType.TEXT_PLAIN,
StandardCharsets.US_ASCII).toString(),
+ firstPart.getContentType(), "Unexpected content type in first
body part of report");
+ MimeEntity secondPart = reportEntity.getPart(1);
+
assertEquals(ContentType.create(AS2MimeType.MESSAGE_DISPOSITION_NOTIFICATION).toString(),
+ secondPart.getContentType(),
+ "Unexpected content type in second body part of report");
+
+ assertTrue(secondPart instanceof
AS2MessageDispositionNotificationEntity,
+ "Unexpected type for second body part of report");
+ AS2MessageDispositionNotificationEntity
messageDispositionNotificationEntity
+ = (AS2MessageDispositionNotificationEntity) secondPart;
+ assertEquals(ORIGIN_SERVER_NAME,
messageDispositionNotificationEntity.getReportingUA(),
+ "Unexpected value for reporting UA");
+ assertEquals(AS2_NAME,
messageDispositionNotificationEntity.getFinalRecipient(),
+ "Unexpected value for final recipient");
+ assertEquals(HttpMessageUtils.getHeaderValue(request,
AS2Header.MESSAGE_ID),
+ messageDispositionNotificationEntity.getOriginalMessageId(),
"Unexpected value for original message ID");
+ assertEquals(DispositionMode.AUTOMATIC_ACTION_MDN_SENT_AUTOMATICALLY,
+ messageDispositionNotificationEntity.getDispositionMode(),
"Unexpected value for disposition mode");
+ assertEquals(AS2DispositionType.PROCESSED,
messageDispositionNotificationEntity.getDispositionType(),
+ "Unexpected value for disposition type");
+ }
+
+ /**
+ * Verifies the EDI message content of an ApplicationEntity against the
expected encoding.
+ */
+ private void verifyEdiMessage(ApplicationEntity appEntity, String
encoding) throws IOException {
if (EDI_MESSAGE_CONTENT_TRANSFER_ENCODING.equals(encoding)) {
- assert (appEntity.getEdiMessage() instanceof String);
+ assertTrue(appEntity.getEdiMessage() instanceof String, "EDI
message is not a String");
String rcvdMessage = ((String)
appEntity.getEdiMessage()).replaceAll("\r", "");
assertEquals(EDI_MESSAGE, rcvdMessage, "EDI message does not
match");
} else if ("base64".equals(encoding)) {
- assert (appEntity.getEdiMessage() instanceof InputStream);
+ assertTrue(appEntity.getEdiMessage() instanceof InputStream, "EDI
message is not an InputStream");
InputStream is = (InputStream) appEntity.getEdiMessage();
String rcvdMessage = new String(is.readAllBytes(),
StandardCharsets.US_ASCII).replaceAll("\r", "");
assertEquals(EDI_MESSAGE, rcvdMessage, "EDI message does not
match");
diff --git
a/components/camel-as2/camel-as2-component/src/test/java/org/apache/camel/component/as2/AS2ServerManagerIT.java
b/components/camel-as2/camel-as2-component/src/test/java/org/apache/camel/component/as2/AS2ServerManagerIT.java
index ef47be008eb6..3a397cd07809 100644
---
a/components/camel-as2/camel-as2-component/src/test/java/org/apache/camel/component/as2/AS2ServerManagerIT.java
+++
b/components/camel-as2/camel-as2-component/src/test/java/org/apache/camel/component/as2/AS2ServerManagerIT.java
@@ -50,7 +50,6 @@ import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.HttpResponse;
import org.apache.hc.core5.http.HttpStatus;
-import org.apache.hc.core5.http.HttpVersion;
import org.apache.hc.core5.http.protocol.HttpCoreContext;
import org.bouncycastle.util.io.Streams;
import org.junit.jupiter.api.Test;
@@ -100,9 +99,7 @@ public class AS2ServerManagerIT extends
AS2ServerManagerITBase {
null, null, null);
MockEndpoint mockEndpoint = getMockEndpoint("mock:as2RcvMsgs");
- mockEndpoint.expectedMinimumMessageCount(1);
- mockEndpoint.setResultWaitTime(TimeUnit.MILLISECONDS.convert(30,
TimeUnit.SECONDS));
- mockEndpoint.assertIsSatisfied();
+ verifyMock(mockEndpoint);
final List<Exchange> exchanges = mockEndpoint.getExchanges();
assertNotNull(exchanges, "listen result");
@@ -116,22 +113,8 @@ public class AS2ServerManagerIT extends
AS2ServerManagerITBase {
HttpCoreContext coreContext =
exchange.getProperty(AS2Constants.AS2_INTERCHANGE, HttpCoreContext.class);
assertNotNull(coreContext, "context");
HttpRequest request = coreContext.getRequest();
- assertNotNull(request, "request");
- assertEquals(METHOD, request.getMethod(), "Unexpected method value");
- assertEquals(REQUEST_URI, request.getUri().getPath(), "Unexpected
request URI value");
- assertEquals(HttpVersion.HTTP_1_1, request.getVersion(), "Unexpected
HTTP version value");
- assertEquals(SUBJECT,
request.getFirstHeader(AS2Header.SUBJECT).getValue(), "Unexpected subject
value");
- assertEquals(FROM, request.getFirstHeader(AS2Header.FROM).getValue(),
"Unexpected from value");
- assertEquals(AS2_VERSION,
request.getFirstHeader(AS2Header.AS2_VERSION).getValue(), "Unexpected AS2
version value");
- assertEquals(AS2_NAME,
request.getFirstHeader(AS2Header.AS2_FROM).getValue(), "Unexpected AS2 from
value");
- assertEquals(AS2_NAME,
request.getFirstHeader(AS2Header.AS2_TO).getValue(), "Unexpected AS2 to value");
-
assertTrue(request.getFirstHeader(AS2Header.MESSAGE_ID).getValue().endsWith(CLIENT_FQDN
+ ">"),
- "Unexpected message id value");
- assertEquals(TARGET_HOST + ":" + targetPort,
request.getFirstHeader(AS2Header.TARGET_HOST).getValue(),
- "Unexpected target host value");
- assertEquals(USER_AGENT,
request.getFirstHeader(AS2Header.USER_AGENT).getValue(), "Unexpected user agent
value");
- assertNotNull(request.getFirstHeader(AS2Header.DATE), "Date value
missing");
- assertNotNull(request.getFirstHeader(AS2Header.CONTENT_LENGTH),
"Content length value missing");
+ verifyRequest(request);
+
assertTrue(request.getFirstHeader(AS2Header.CONTENT_TYPE).getValue().startsWith(AS2MediaType.APPLICATION_EDIFACT),
"Unexpected content type for message");
@@ -177,9 +160,7 @@ public class AS2ServerManagerIT extends
AS2ServerManagerITBase {
null, null, null);
MockEndpoint mockEndpoint = getMockEndpoint("mock:as2RcvMsgs");
- mockEndpoint.expectedMinimumMessageCount(1);
- mockEndpoint.setResultWaitTime(TimeUnit.MILLISECONDS.convert(30,
TimeUnit.SECONDS));
- mockEndpoint.assertIsSatisfied();
+ verifyMock(mockEndpoint);
final List<Exchange> exchanges = mockEndpoint.getExchanges();
assertNotNull(exchanges, "listen result");
@@ -193,22 +174,8 @@ public class AS2ServerManagerIT extends
AS2ServerManagerITBase {
HttpCoreContext coreContext =
exchange.getProperty(AS2Constants.AS2_INTERCHANGE, HttpCoreContext.class);
assertNotNull(coreContext, "context");
HttpRequest request = coreContext.getRequest();
- assertNotNull(request, "request");
- assertEquals(METHOD, request.getMethod(), "Unexpected method value");
- assertEquals(REQUEST_URI, request.getUri().getPath(), "Unexpected
request URI value");
- assertEquals(HttpVersion.HTTP_1_1, request.getVersion(), "Unexpected
HTTP version value");
- assertEquals(SUBJECT,
request.getFirstHeader(AS2Header.SUBJECT).getValue(), "Unexpected subject
value");
- assertEquals(FROM, request.getFirstHeader(AS2Header.FROM).getValue(),
"Unexpected from value");
- assertEquals(AS2_VERSION,
request.getFirstHeader(AS2Header.AS2_VERSION).getValue(), "Unexpected AS2
version value");
- assertEquals(AS2_NAME,
request.getFirstHeader(AS2Header.AS2_FROM).getValue(), "Unexpected AS2 from
value");
- assertEquals(AS2_NAME,
request.getFirstHeader(AS2Header.AS2_TO).getValue(), "Unexpected AS2 to value");
-
assertTrue(request.getFirstHeader(AS2Header.MESSAGE_ID).getValue().endsWith(CLIENT_FQDN
+ ">"),
- "Unexpected message id value");
- assertEquals(TARGET_HOST + ":" + targetPort,
request.getFirstHeader(AS2Header.TARGET_HOST).getValue(),
- "Unexpected target host value");
- assertEquals(USER_AGENT,
request.getFirstHeader(AS2Header.USER_AGENT).getValue(), "Unexpected user agent
value");
- assertNotNull(request.getFirstHeader(AS2Header.DATE), "Date value
missing");
- assertNotNull(request.getFirstHeader(AS2Header.CONTENT_LENGTH),
"Content length value missing");
+ verifyRequest(request);
+
assertTrue(request.getFirstHeader(AS2Header.CONTENT_TYPE).getValue().startsWith(AS2MediaType.APPLICATION_EDIFACT),
"Unexpected content type for message");
assertEquals(MessageFormatter.format(CONTENT_DISPOSITION_PATTERN,
ATTACHED_FILE_NAME).getMessage(),
@@ -276,9 +243,7 @@ public class AS2ServerManagerIT extends
AS2ServerManagerITBase {
null, null, null);
MockEndpoint mockEndpoint = getMockEndpoint("mock:as2RcvMsgs");
- mockEndpoint.expectedMinimumMessageCount(1);
- mockEndpoint.setResultWaitTime(TimeUnit.MILLISECONDS.convert(30,
TimeUnit.SECONDS));
- mockEndpoint.assertIsSatisfied();
+ verifyMock(mockEndpoint);
final List<Exchange> exchanges = mockEndpoint.getExchanges();
assertNotNull(exchanges, "listen result");
@@ -291,23 +256,8 @@ public class AS2ServerManagerIT extends
AS2ServerManagerITBase {
HttpCoreContext coreContext =
exchange.getProperty(AS2Constants.AS2_INTERCHANGE, HttpCoreContext.class);
assertNotNull(coreContext, "context");
HttpRequest request = coreContext.getRequest();
- assertNotNull(request, "request");
- assertEquals(METHOD, request.getMethod(), "Unexpected method value");
- assertEquals(REQUEST_URI, request.getUri().getPath(), "Unexpected
request URI value");
- assertEquals(HttpVersion.HTTP_1_1, request.getVersion(), "Unexpected
HTTP version value");
-
- assertEquals(SUBJECT,
request.getFirstHeader(AS2Header.SUBJECT).getValue(), "Unexpected subject
value");
- assertEquals(FROM, request.getFirstHeader(AS2Header.FROM).getValue(),
"Unexpected from value");
- assertEquals(AS2_VERSION,
request.getFirstHeader(AS2Header.AS2_VERSION).getValue(), "Unexpected AS2
version value");
- assertEquals(AS2_NAME,
request.getFirstHeader(AS2Header.AS2_FROM).getValue(), "Unexpected AS2 from
value");
- assertEquals(AS2_NAME,
request.getFirstHeader(AS2Header.AS2_TO).getValue(), "Unexpected AS2 to value");
-
assertTrue(request.getFirstHeader(AS2Header.MESSAGE_ID).getValue().endsWith(CLIENT_FQDN
+ ">"),
- "Unexpected message id value");
- assertEquals(TARGET_HOST + ":" + targetPort,
request.getFirstHeader(AS2Header.TARGET_HOST).getValue(),
- "Unexpected target host value");
- assertEquals(USER_AGENT,
request.getFirstHeader(AS2Header.USER_AGENT).getValue(), "Unexpected user agent
value");
- assertNotNull(request.getFirstHeader(AS2Header.DATE), "Date value
missing");
- assertNotNull(request.getFirstHeader(AS2Header.CONTENT_LENGTH),
"Content length value missing");
+ verifyRequest(request);
+
assertTrue(request.getFirstHeader(AS2Header.CONTENT_TYPE).getValue().startsWith(AS2MediaType.MULTIPART_SIGNED),
"Unexpected content type for message");
@@ -355,9 +305,7 @@ public class AS2ServerManagerIT extends
AS2ServerManagerITBase {
null, null, null);
MockEndpoint mockEndpoint = getMockEndpoint("mock:as2RcvMsgs");
- mockEndpoint.expectedMinimumMessageCount(1);
- mockEndpoint.setResultWaitTime(TimeUnit.MILLISECONDS.convert(30,
TimeUnit.SECONDS));
- mockEndpoint.assertIsSatisfied();
+ verifyMock(mockEndpoint);
final List<Exchange> exchanges = mockEndpoint.getExchanges();
assertNotNull(exchanges, "listen result");
@@ -370,23 +318,8 @@ public class AS2ServerManagerIT extends
AS2ServerManagerITBase {
HttpCoreContext coreContext =
exchange.getProperty(AS2Constants.AS2_INTERCHANGE, HttpCoreContext.class);
assertNotNull(coreContext, "context");
HttpRequest request = coreContext.getRequest();
- assertNotNull(request, "request");
- assertEquals(METHOD, request.getMethod(), "Unexpected method value");
- assertEquals(REQUEST_URI, request.getUri().getPath(), "Unexpected
request URI value");
- assertEquals(HttpVersion.HTTP_1_1, request.getVersion(), "Unexpected
HTTP version value");
-
- assertEquals(SUBJECT,
request.getFirstHeader(AS2Header.SUBJECT).getValue(), "Unexpected subject
value");
- assertEquals(FROM, request.getFirstHeader(AS2Header.FROM).getValue(),
"Unexpected from value");
- assertEquals(AS2_VERSION,
request.getFirstHeader(AS2Header.AS2_VERSION).getValue(), "Unexpected AS2
version value");
- assertEquals(AS2_NAME,
request.getFirstHeader(AS2Header.AS2_FROM).getValue(), "Unexpected AS2 from
value");
- assertEquals(AS2_NAME,
request.getFirstHeader(AS2Header.AS2_TO).getValue(), "Unexpected AS2 to value");
-
assertTrue(request.getFirstHeader(AS2Header.MESSAGE_ID).getValue().endsWith(CLIENT_FQDN
+ ">"),
- "Unexpected message id value");
- assertEquals(TARGET_HOST + ":" + targetPort,
request.getFirstHeader(AS2Header.TARGET_HOST).getValue(),
- "Unexpected target host value");
- assertEquals(USER_AGENT,
request.getFirstHeader(AS2Header.USER_AGENT).getValue(), "Unexpected user agent
value");
- assertNotNull(request.getFirstHeader(AS2Header.DATE), "Date value
missing");
- assertNotNull(request.getFirstHeader(AS2Header.CONTENT_LENGTH),
"Content length value missing");
+ verifyRequest(request);
+
assertTrue(request.getFirstHeader(AS2Header.CONTENT_TYPE).getValue().startsWith(AS2MediaType.MULTIPART_SIGNED),
"Unexpected content type for message");
@@ -431,8 +364,6 @@ public class AS2ServerManagerIT extends
AS2ServerManagerITBase {
kpg.initialize(2048, new SecureRandom());
String hackerIssueDN = "O=Hackers Unlimited Ltd., C=US";
var hackerIssueKP = kpg.generateKeyPair();
- var hackerissueCert = Utils.makeCertificate(
- hackerIssueKP, hackerIssueDN, hackerIssueKP, hackerIssueDN);
String hackerSigningDN = "CN=John Doe, [email protected], O=Self
Signed, C=US";
var hackerSigningKP = kpg.generateKeyPair();
var hackerSigningCert = Utils.makeCertificate(
@@ -446,9 +377,7 @@ public class AS2ServerManagerIT extends
AS2ServerManagerITBase {
null, null, null);
MockEndpoint mockEndpoint = getMockEndpoint("mock:as2RcvMsgs");
- mockEndpoint.expectedMinimumMessageCount(1);
- mockEndpoint.setResultWaitTime(TimeUnit.MILLISECONDS.convert(30,
TimeUnit.SECONDS));
- mockEndpoint.assertIsSatisfied();
+ verifyMock(mockEndpoint);
final List<Exchange> exchanges = mockEndpoint.getExchanges();
assertNotNull(exchanges, "listen result");
@@ -461,23 +390,8 @@ public class AS2ServerManagerIT extends
AS2ServerManagerITBase {
HttpCoreContext coreContext =
exchange.getProperty(AS2Constants.AS2_INTERCHANGE, HttpCoreContext.class);
assertNotNull(coreContext, "context");
HttpRequest request = coreContext.getRequest();
- assertNotNull(request, "request");
- assertEquals(METHOD, request.getMethod(), "Unexpected method value");
- assertEquals(REQUEST_URI, request.getUri().getPath(), "Unexpected
request URI value");
- assertEquals(HttpVersion.HTTP_1_1, request.getVersion(), "Unexpected
HTTP version value");
-
- assertEquals(SUBJECT,
request.getFirstHeader(AS2Header.SUBJECT).getValue(), "Unexpected subject
value");
- assertEquals(FROM, request.getFirstHeader(AS2Header.FROM).getValue(),
"Unexpected from value");
- assertEquals(AS2_VERSION,
request.getFirstHeader(AS2Header.AS2_VERSION).getValue(), "Unexpected AS2
version value");
- assertEquals(AS2_NAME,
request.getFirstHeader(AS2Header.AS2_FROM).getValue(), "Unexpected AS2 from
value");
- assertEquals(AS2_NAME,
request.getFirstHeader(AS2Header.AS2_TO).getValue(), "Unexpected AS2 to value");
-
assertTrue(request.getFirstHeader(AS2Header.MESSAGE_ID).getValue().endsWith(CLIENT_FQDN
+ ">"),
- "Unexpected message id value");
- assertEquals(TARGET_HOST + ":" + targetPort,
request.getFirstHeader(AS2Header.TARGET_HOST).getValue(),
- "Unexpected target host value");
- assertEquals(USER_AGENT,
request.getFirstHeader(AS2Header.USER_AGENT).getValue(), "Unexpected user agent
value");
- assertNotNull(request.getFirstHeader(AS2Header.DATE), "Date value
missing");
- assertNotNull(request.getFirstHeader(AS2Header.CONTENT_LENGTH),
"Content length value missing");
+ verifyRequest(request);
+
assertTrue(request.getFirstHeader(AS2Header.CONTENT_TYPE).getValue().startsWith(AS2MediaType.MULTIPART_SIGNED),
"Unexpected content type for message");