You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2018/05/15 06:47:01 UTC

[camel] branch master updated: [CAMEL-11257] Enhance unit tests and fixed Javadoc

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new 399ac64  [CAMEL-11257] Enhance unit tests and fixed Javadoc
399ac64 is described below

commit 399ac647ab05b7d608427d3ccb3e0bbf94e06310
Author: William Collins <pu...@gmail.com>
AuthorDate: Mon May 14 15:15:21 2018 -0400

    [CAMEL-11257] Enhance unit tests and fixed Javadoc
---
 .../camel/component/as2/api/AS2ClientManager.java  | 18 ++++++++--
 .../camel/component/as2/api/entity/MimeEntity.java | 12 +++----
 .../as2/AS2ClientManagerIntegrationTest.java       | 38 +++++++++++++++++++---
 3 files changed, 55 insertions(+), 13 deletions(-)

diff --git a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2ClientManager.java b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2ClientManager.java
index 72f5807..f13f282 100644
--- a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2ClientManager.java
+++ b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2ClientManager.java
@@ -159,9 +159,21 @@ public class AS2ClientManager {
      *
      * @param ediMessage
      *            - EDI message to transport
-     * @param httpContext
-     *            - the subject sent in the interchange request.
-     * @throws HttpException
+     * @param requestUri
+     *            - resource location to deliver message
+     * @param subject - message subject
+     * @param from - RFC2822 address of sender
+     * @param as2From - AS2 name of sender
+     * @param as2To - AS2 name of recipient
+     * @param as2MessageStructure - the structure of AS2 to send; see {@link AS2MessageStructure}
+     * @param ediMessageContentType - the content typw of EDI message
+     * @param ediMessageTransferEncoding - the transfer encoding used to transport EDI message
+     * @param signingCertificateChain - the chain of certificates used to sign the message or <code>null</code> if sending EDI message unsigned
+     * @param signingPrivateKey - the private key used to sign EDI message
+     * @param dispositionNotificationTo - an RFC2822 address to request a receipt or <code>null</code> if no receipt requested
+     * @param signedReceiptMicAlgorithms - the senders list of signing algorithms for signing receipt, in preferred order,  or <code>null</code> if requesting an unsigned receipt.
+     * @return {@link HttpCoreContext} containing request and response used to send EDI message
+     * @throws HttpException when things go wrong.
      */
     public HttpCoreContext send(String ediMessage,
                                 String requestUri,
diff --git a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/entity/MimeEntity.java b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/entity/MimeEntity.java
index 56b8a4a..5eab3d1 100644
--- a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/entity/MimeEntity.java
+++ b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/entity/MimeEntity.java
@@ -129,7 +129,7 @@ public abstract class MimeEntity extends AbstractHttpEntity {
     /**
      * Obtains the Content-Transfer-Encoding header.
      * The default implementation returns the value of the
-     * {@link #contentEncoding contentTransferEncoding} attribute.
+     * {@link #contentEncoding contentEncoding} attribute.
      *
      * @return  the Content-Transfer-Encoding header, or {@code null}
      */
@@ -140,12 +140,12 @@ public abstract class MimeEntity extends AbstractHttpEntity {
     /**
      * Specifies the Content-Transfer-Encoding header.
      * The default implementation sets the value of the
-     * {@link #contentTranferEncoding contentTransferEncoding} attribute.
+     * {@link #contentTransferEncoding contentTransferEncoding} attribute.
      *
      * @param contentTransferEncoding   the new Content-Transfer-Encoding header, or
      *                          {@code null} to unset
      */
-    public void setContentTranserEncoding(final Header contentTransferEncoding) {
+    public void setContentTransferEncoding(final Header contentTransferEncoding) {
         this.contentTransferEncoding = contentTransferEncoding;
         if (contentTransferEncoding != null) {
             addHeader(contentTransferEncoding);
@@ -157,9 +157,9 @@ public abstract class MimeEntity extends AbstractHttpEntity {
     /**
      * Specifies the Content-Transfer-Encoding header, as a string.
      * The default implementation calls
-     * {@link #setContentTransferEncoding(Header) setContentEncoding(Header)}.
+     * {@link #setContentTransferEncoding(Header) setContentTransferEncoding(Header)}.
      *
-     * @param ceString     the new Content-Transfer-Encoding header, or
+     * @param contentTranserEncoding - the new Content-Transfer-Encoding header, or
      *                     {@code null} to unset
      */
     public void setContentTransferEncoding(final String contentTranserEncoding) {
@@ -167,7 +167,7 @@ public abstract class MimeEntity extends AbstractHttpEntity {
         if (contentTranserEncoding != null) {
             h = new BasicHeader(AS2Header.CONTENT_TRANSFER_ENCODING, contentTranserEncoding);
         }
-        setContentTranserEncoding(h);
+        setContentTransferEncoding(h);
     }
 
 
diff --git a/components/camel-as2/camel-as2-component/src/test/java/org/apache/camel/component/as2/AS2ClientManagerIntegrationTest.java b/components/camel-as2/camel-as2-component/src/test/java/org/apache/camel/component/as2/AS2ClientManagerIntegrationTest.java
index f862ada..3c1459b 100644
--- a/components/camel-as2/camel-as2-component/src/test/java/org/apache/camel/component/as2/AS2ClientManagerIntegrationTest.java
+++ b/components/camel-as2/camel-as2-component/src/test/java/org/apache/camel/component/as2/AS2ClientManagerIntegrationTest.java
@@ -38,12 +38,17 @@ import org.apache.camel.component.as2.api.AS2MimeType;
 import org.apache.camel.component.as2.api.AS2ServerConnection;
 import org.apache.camel.component.as2.api.AS2ServerManager;
 import org.apache.camel.component.as2.api.AS2SignedDataGenerator;
+import org.apache.camel.component.as2.api.entity.AS2DispositionType;
+import org.apache.camel.component.as2.api.entity.AS2MessageDispositionNotificationEntity;
 import org.apache.camel.component.as2.api.entity.ApplicationEDIEntity;
 import org.apache.camel.component.as2.api.entity.ApplicationPkcs7SignatureEntity;
+import org.apache.camel.component.as2.api.entity.DispositionMode;
 import org.apache.camel.component.as2.api.entity.DispositionNotificationMultipartReportEntity;
 import org.apache.camel.component.as2.api.entity.MimeEntity;
 import org.apache.camel.component.as2.api.entity.MultipartSignedEntity;
 import org.apache.camel.component.as2.api.util.HttpMessageUtils;
+import org.apache.camel.component.as2.api.util.MicUtils;
+import org.apache.camel.component.as2.api.util.MicUtils.ReceivedContentMic;
 import org.apache.camel.component.as2.internal.AS2ApiCollection;
 import org.apache.camel.component.as2.internal.AS2ClientManagerApiMethod;
 import org.apache.http.HttpEntity;
@@ -80,6 +85,8 @@ public class AS2ClientManagerIntegrationTest extends AbstractAS2TestSupport {
     private static final Logger LOG = LoggerFactory.getLogger(AS2ClientManagerIntegrationTest.class);
     private static final String PATH_PREFIX = AS2ApiCollection.getCollection().getApiName(AS2ClientManagerApiMethod.class).getName();
 
+    private static final String ORIGIN_SERVER_NAME = "AS2ClientManagerIntegrationTest Server";
+    private static final String AS2_VERSION = "1.1";
     private static final String REQUEST_URI = "/";
     private static final String SUBJECT = "Test Case";
     private static final String AS2_NAME = "878051556";
@@ -116,7 +123,8 @@ public class AS2ClientManagerIntegrationTest extends AbstractAS2TestSupport {
             + "UNT+23+00000000000117'\n"
             + "UNZ+1+00000000000778'\n";
 
-    private static final String EXPECTED_AS2_VERSION = "1.1";
+    private static final String EDI_MESSAGE_CONTENT_TRANSFER_ENCODING = "7bit";
+    private static final String EXPECTED_AS2_VERSION = AS2_VERSION;
     private static final String EXPECTED_MDN_SUBJECT = MDN_SUBJECT_PREFIX + SUBJECT;
     private static final String[] SIGNED_RECEIPT_MIC_ALGORITHMS = new String[] {"sha1", "md5"};
 
@@ -191,7 +199,7 @@ public class AS2ClientManagerIntegrationTest extends AbstractAS2TestSupport {
         // parameter type is org.apache.http.entity.ContentType
         headers.put("CamelAS2.ediMessageContentType", ContentType.create(AS2MediaType.APPLICATION_EDIFACT, AS2Charset.US_ASCII));
         // parameter type is String
-        headers.put("CamelAS2.ediMessageTransferEncoding", null);
+        headers.put("CamelAS2.ediMessageTransferEncoding", EDI_MESSAGE_CONTENT_TRANSFER_ENCODING);
         // parameter type is java.security.cert.Certificate[]
         headers.put("CamelAS2.signingCertificateChain", null);
         // parameter type is java.security.PrivateKey
@@ -236,6 +244,15 @@ public class AS2ClientManagerIntegrationTest extends AbstractAS2TestSupport {
         assertEquals("Unexpected content type in second body part of report",
                 ContentType.create(AS2MimeType.MESSAGE_DISPOSITION_NOTIFICATION, AS2Charset.US_ASCII).toString(),
                 secondPart.getContentTypeValue());
+        
+        assertTrue("", secondPart instanceof AS2MessageDispositionNotificationEntity);
+        AS2MessageDispositionNotificationEntity messageDispositionNotificationEntity = (AS2MessageDispositionNotificationEntity) secondPart;
+        assertEquals("Unexpected value for reporting UA", ORIGIN_SERVER_NAME, messageDispositionNotificationEntity.getReportingUA());
+        assertEquals("Unexpected value for final recipient", AS2_NAME, messageDispositionNotificationEntity.getFinalRecipient());
+        assertEquals("Unexpected value for original message ID", HttpMessageUtils.getHeaderValue(request, AS2Header.MESSAGE_ID), messageDispositionNotificationEntity.getOriginalMessageId());
+        assertEquals("Unexpected value for disposition mode", DispositionMode.AUTOMATIC_ACTION_MDN_SENT_AUTOMATICALLY, messageDispositionNotificationEntity.getDispositionMode());
+        assertEquals("Unexpected value for disposition type", AS2DispositionType.PROCESSED, messageDispositionNotificationEntity.getDispositionType());
+        
     }
 
     @Test
@@ -256,7 +273,7 @@ public class AS2ClientManagerIntegrationTest extends AbstractAS2TestSupport {
         // parameter type is org.apache.http.entity.ContentType
         headers.put("CamelAS2.ediMessageContentType", ContentType.create(AS2MediaType.APPLICATION_EDIFACT, AS2Charset.US_ASCII));
         // parameter type is String
-        headers.put("CamelAS2.ediMessageTransferEncoding", null);
+        headers.put("CamelAS2.ediMessageTransferEncoding", EDI_MESSAGE_CONTENT_TRANSFER_ENCODING);
         // parameter type is java.security.cert.Certificate[]
         headers.put("CamelAS2.signingCertificateChain", certList.toArray(new Certificate[0]));
         // parameter type is java.security.PrivateKey
@@ -300,6 +317,7 @@ public class AS2ClientManagerIntegrationTest extends AbstractAS2TestSupport {
         assertNotNull("Response entity", responseEntity);
         assertTrue("Unexpected response entity type", responseEntity instanceof MultipartSignedEntity);
         MultipartSignedEntity responseSignedEntity = (MultipartSignedEntity) responseEntity;
+        assertTrue("Signature for response entity is invalid", responseSignedEntity.isValid());
         MimeEntity responseSignedDataEntity = responseSignedEntity.getSignedDataEntity();
         assertTrue("Signed entity wrong type", responseSignedDataEntity instanceof DispositionNotificationMultipartReportEntity);
         DispositionNotificationMultipartReportEntity reportEntity = (DispositionNotificationMultipartReportEntity)responseSignedDataEntity;
@@ -312,6 +330,18 @@ public class AS2ClientManagerIntegrationTest extends AbstractAS2TestSupport {
                 secondPart.getContentTypeValue());
         ApplicationPkcs7SignatureEntity signatureEntity = responseSignedEntity.getSignatureEntity();
         assertNotNull("Signature Entity", signatureEntity);
+        
+        assertTrue("", secondPart instanceof AS2MessageDispositionNotificationEntity);
+        AS2MessageDispositionNotificationEntity messageDispositionNotificationEntity = (AS2MessageDispositionNotificationEntity) secondPart;
+        assertEquals("Unexpected value for reporting UA", ORIGIN_SERVER_NAME, messageDispositionNotificationEntity.getReportingUA());
+        assertEquals("Unexpected value for final recipient", AS2_NAME, messageDispositionNotificationEntity.getFinalRecipient());
+        assertEquals("Unexpected value for original message ID", HttpMessageUtils.getHeaderValue(request, AS2Header.MESSAGE_ID), messageDispositionNotificationEntity.getOriginalMessageId());
+        assertEquals("Unexpected value for disposition mode", DispositionMode.AUTOMATIC_ACTION_MDN_SENT_AUTOMATICALLY, messageDispositionNotificationEntity.getDispositionMode());
+        assertEquals("Unexpected value for disposition type", AS2DispositionType.PROCESSED, messageDispositionNotificationEntity.getDispositionType());
+        
+        ReceivedContentMic receivedContentMic = messageDispositionNotificationEntity.getReceivedContentMic();
+        ReceivedContentMic computedContentMic = MicUtils.createReceivedContentMic((HttpEntityEnclosingRequest)request);
+        assertEquals("Received content MIC does not match computed", computedContentMic.getEncodedMessageDigest(), receivedContentMic.getEncodedMessageDigest());
     }
 
     @BeforeClass
@@ -380,7 +410,7 @@ public class AS2ClientManagerIntegrationTest extends AbstractAS2TestSupport {
     }
 
     private static void receiveTestMessages() throws IOException {
-        serverConnection = new AS2ServerConnection("1.1", "AS2ClientManagerIntegrationTest Server",
+        serverConnection = new AS2ServerConnection(AS2_VERSION, ORIGIN_SERVER_NAME,
                 "server.example.com", 8888, serverCertList.toArray(new Certificate[0]), serverSigningKP.getPrivate());
         serverConnection.listen("/", new RequestHandler());
     }

-- 
To stop receiving notification emails like this one, please contact
davsclaus@apache.org.