View Javadoc

1   /*
2    * $Id: SmtpAttachmentsFunctionalInboundAttachmentsOnlyTestCase.java 22518 2011-07-22 07:00:22Z claude.mamo $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.transport.email.transformers;
12  
13  import static org.junit.Assert.assertEquals;
14  import static org.junit.Assert.assertTrue;
15  
16  import org.mule.transport.email.functional.AbstractEmailFunctionalTestCase;
17  
18  import java.util.Arrays;
19  import java.util.Collection;
20  import java.util.List;
21  
22  import javax.activation.MimeType;
23  import javax.mail.BodyPart;
24  import javax.mail.internet.MimeMultipart;
25  
26  import org.junit.Test;
27  import org.junit.runners.Parameterized.Parameters;
28  
29  public class SmtpAttachmentsFunctionalInboundAttachmentsOnlyTestCase extends AbstractEmailFunctionalTestCase
30  {
31  
32      public SmtpAttachmentsFunctionalInboundAttachmentsOnlyTestCase(ConfigVariant variant, String configResources)
33      {
34          super(variant, STRING_MESSAGE, "smtp", configResources);
35          setAddAttachments(true);
36      }
37  
38      @Parameters
39      public static Collection<Object[]> parameters()
40      {
41          return Arrays.asList(new Object[][]{
42              {ConfigVariant.SERVICE, "smtp-functional-test-inbound-attachments-only-service.xml"},
43              {ConfigVariant.FLOW, "smtp-functional-test-inbound-attachments-only-flow.xml"}
44          });
45      }      
46      
47      @Test
48      public void testSend() throws Exception
49      {
50          doSend();
51      }
52  
53      @Override
54      protected void verifyMessage(MimeMultipart content) throws Exception
55      {
56          assertEquals(3, content.getCount());
57          verifyMessage((String) content.getBodyPart(0).getContent());
58          List<String> expectedTypes = Arrays.asList("text/plain", "text/xml");
59          for (int i = 1; i < 2; i++)
60          {
61              BodyPart part = content.getBodyPart(i);
62              String type = part.getContentType();
63              MimeType mt = new MimeType(type);
64              assertTrue(expectedTypes.contains(mt.getPrimaryType() + "/" + mt.getSubType()));
65          }
66      }
67  }