Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2010 JBoss Inc Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 
 package org.jbpm.process.workitem.email;
 
 import java.util.List;
 
 
 
 
 public class EmailWorkItemHandlerTest extends TestCase {
     Wiser wiser;    
     
     String emailHost;
     String emailPort;
     
     @Override
     protected void setUp() throws Exception {
         ChainedProperties props = new ChainedProperties"email.conf", ClassLoaderUtil.getClassLoadernullgetClass(), false ));
          = props.getProperty"host""localhost" );
          = props.getProperty"port""2345" );
         
          = new Wiser();
         .setHostname );
         .setPort( Integer.parseInt ) );
         .start();
     }
     
     @Override
     protected void tearDown() throws Exception {
         .stop();
     }
     
     public void test1() {
         
     }
     
     public void FIXME_testSingleTo() throws Exception {
         EmailWorkItemHandler handler = new EmailWorkItemHandler();
         handler.setConnectionnullnull );   
         
         WorkItemImpl workItem = new WorkItemImpl();
         workItem.setParameter"To""person1@domain.com" );
         workItem.setParameter"From""person2@domain.com" );
         workItem.setParameter"Reply-To""person3@domain.com" );
         workItem.setParameter"Subject""Subject 1" );
         workItem.setParameter"Body""Body 1" );
         
         WorkItemManager manager = new DefaultWorkItemManager(null);
         handler.executeWorkItemworkItemmanager );
         
         assertEquals( 1, .getMessages().size() );
         
         MimeMessage msg = (( WiserMessage  ) .getMessages().get( 0 )).getMimeMessage();
         assertEqualsworkItem.getParameter"Body" ), msg.getContent() );
         assertEqualsworkItem.getParameter"Subject" ), msg.getSubject() );
         assertEqualsworkItem.getParameter"From" ), ((InternetAddress)msg.getFrom()[0]).getAddress() );
         assertEqualsworkItem.getParameter"Reply-To" ), ((InternetAddress)msg.getReplyTo()[0]).getAddress() );
         assertEqualsworkItem.getParameter"To" ), ((InternetAddress)msg.getRecipients. )[0]).getAddress() );
         assertNullmsg.getRecipients. ) );
         assertNullmsg.getRecipients. ) );
     }
     
     public void FIXME_testSingleToWithSingleCCAndBCC() throws Exception {
         EmailWorkItemHandler handler = new EmailWorkItemHandler();
         handler.setConnectionnullnull ); 
         
         WorkItemImpl workItem = new WorkItemImpl();
         workItem.setParameter"To""person1@domain.com" );
         workItem.setParameter"Cc""person2@domain.com" );
         workItem.setParameter"Bcc""person3@domain.com" );
         workItem.setParameter"From""person4@domain.com" );
         workItem.setParameter"Reply-To""person5@domain.com" );
        workItem.setParameter"Subject""Subject 1" );
        workItem.setParameter"Body""Body 1" );
        
        WorkItemManager manager = new DefaultWorkItemManager(null);
        handler.executeWorkItemworkItemmanager );
        
        assertEquals( 3, .getMessages().size() );
        
        List<Stringlist = new ArrayList<String>(3);
        list.add.getMessages().get( 0 ).getEnvelopeReceiver() );
        list.add.getMessages().get( 1 ).getEnvelopeReceiver() );
        list.add.getMessages().get( 2 ).getEnvelopeReceiver() );
        
        assertTruelist.contains("person1@domain.com"));
        assertTruelist.contains("person2@domain.com"));
        assertTruelist.contains("person3@domain.com"));
        
        
        MimeMessage msg = (( WiserMessage  ) .getMessages().get( 0 )).getMimeMessage();
        assertEqualsworkItem.getParameter"From" ), .getMessages().get( 0 ).getEnvelopeSender() );
        assertEqualsworkItem.getParameter"Body" ), msg.getContent() );
        assertEqualsworkItem.getParameter"Subject" ), msg.getSubject() );
        assertEqualsworkItem.getParameter"From" ), ((InternetAddress)msg.getFrom()[0]).getAddress() );
        assertEqualsworkItem.getParameter"Reply-To" ), ((InternetAddress)msg.getReplyTo()[0]).getAddress() );
        assertEqualsworkItem.getParameter"To" ), ((InternetAddress)msg.getRecipients. )[0]).getAddress() );
        assertEqualsworkItem.getParameter"Cc" ),((InternetAddress)msg.getRecipients. )[0]).getAddress()  );
        
        msg = (( WiserMessage  ) .getMessages().get( 1 )).getMimeMessage();
        assertEqualsworkItem.getParameter"From" ), .getMessages().get( 1 ).getEnvelopeSender() );
        assertEqualsworkItem.getParameter"Body" ), msg.getContent() );
        assertEqualsworkItem.getParameter"Subject" ), msg.getSubject() );
        assertEqualsworkItem.getParameter"From" ), ((InternetAddress)msg.getFrom()[0]).getAddress() );
        assertEqualsworkItem.getParameter"Reply-To" ), ((InternetAddress)msg.getReplyTo()[0]).getAddress() );
        assertEqualsworkItem.getParameter"To" ), ((InternetAddress)msg.getRecipients. )[0]).getAddress() );
        assertEqualsworkItem.getParameter"Cc" ),((InternetAddress)msg.getRecipients. )[0]).getAddress()  );
        
        msg = (( WiserMessage  ) .getMessages().get( 2 )).getMimeMessage();
        assertEqualsworkItem.getParameter"From" ), .getMessages().get( 2 ).getEnvelopeSender() );
        assertEqualsworkItem.getParameter"Body" ), msg.getContent() );
        assertEqualsworkItem.getParameter"Subject" ), msg.getSubject() );
        assertEqualsworkItem.getParameter"From" ), ((InternetAddress)msg.getFrom()[0]).getAddress() );
        assertEqualsworkItem.getParameter"Reply-To" ), ((InternetAddress)msg.getReplyTo()[0]).getAddress() );
        assertEqualsworkItem.getParameter"To" ), ((InternetAddress)msg.getRecipients. )[0]).getAddress() );
        assertEqualsworkItem.getParameter"Cc" ),((InternetAddress)msg.getRecipients. )[0]).getAddress()  );        
    }    
    
    public void FIXME_testMultipleToWithSingleCCAndBCC() throws Exception {
        EmailWorkItemHandler handler = new EmailWorkItemHandler();
        handler.setConnectionnullnull );    
        
        WorkItemImpl workItem = new WorkItemImpl();
        workItem.setParameter"To""person1@domain.com; person2@domain.com" );
        workItem.setParameter"Cc""person3@domain.com; person4@domain.com"  );
        workItem.setParameter"Bcc","person5@domain.com; person6@domain.com"  );
        workItem.setParameter"From""person4@domain.com" );
        workItem.setParameter"Reply-To""person5@domain.com" );
        workItem.setParameter"Subject""Subject 1" );
        workItem.setParameter"Body""Body 1" );
        
        WorkItemManager manager = new DefaultWorkItemManager(null);
        handler.executeWorkItemworkItemmanager );
        
        assertEquals( 6, .getMessages().size() );
        
        List<Stringlist = new ArrayList<String>(6);
        list.add.getMessages().get( 0 ).getEnvelopeReceiver() );
        list.add.getMessages().get( 1 ).getEnvelopeReceiver() );
        list.add.getMessages().get( 2 ).getEnvelopeReceiver() );
        list.add.getMessages().get( 3 ).getEnvelopeReceiver() );
        list.add.getMessages().get( 4 ).getEnvelopeReceiver() );
        list.add.getMessages().get( 5 ).getEnvelopeReceiver() );
        
        assertTruelist.contains("person1@domain.com"));
        assertTruelist.contains("person2@domain.com"));
        assertTruelist.contains("person3@domain.com"));
        assertTruelist.contains("person4@domain.com"));
        assertTruelist.contains("person5@domain.com"));
        assertTruelist.contains("person6@domain.com"));
                
        // We know from previous test that all MimeMessages will be identical
        MimeMessage msg = (( WiserMessage  ) .getMessages().get( 0 )).getMimeMessage();
        assertEqualsworkItem.getParameter"From" ), .getMessages().get( 0 ).getEnvelopeSender() );
        assertEqualsworkItem.getParameter"Body" ), msg.getContent() );
        assertEqualsworkItem.getParameter"Subject" ), msg.getSubject() );
        assertEqualsworkItem.getParameter"From" ), ((InternetAddress)msg.getFrom()[0]).getAddress() );
        assertEqualsworkItem.getParameter"Reply-To" ), ((InternetAddress)msg.getReplyTo()[0]).getAddress() );
        assertEqualsworkItem.getParameter"To" ), ((InternetAddress)msg.getRecipients. )[0]).getAddress() + "; " + ((InternetAddress)msg.getRecipients. )[1]).getAddress() );
        assertEqualsworkItem.getParameter"Cc" ),((InternetAddress)msg.getRecipients. )[0]).getAddress()  + "; " +  ((InternetAddress)msg.getRecipients. )[1]).getAddress() );       
    }    
New to GrepCode? Check out our FAQ X