LinearProcessorTestpublic class LinearProcessorTest extends TestCase Currently here as a proof of JAMES-421.
Fixing code will follow |
Fields Summary |
---|
Collection | c | LinearProcessor | t | MimeMessage | mw | String | content | String | sep | String | body | org.apache.mailet.MailetContext | mockContext | public static int | counter | private org.apache.mailet.MailetConfig | mockMailetConfig | private CheckerMailet | checkerMailet |
Constructors Summary |
---|
public LinearProcessorTest(String arg0)
super(arg0);
MimeMessageInputStreamSource mmis = null;
try {
mmis = new MimeMessageInputStreamSource("test", new SharedByteArrayInputStream((content+sep+body).getBytes()));
} catch (MessagingException e) {
}
mw = new MimeMessageCopyOnWriteProxy(mmis);
setUp();
|
Methods Summary |
---|
public void | setUp()
super.setUp();
t = new LinearProcessor();
Logger l = new ConsoleLogger();
t.enableLogging(l);
t.initialize();
| public void | tearDown()
t.dispose();
super.tearDown();
| public void | testCopyOnWrite()
t.setSpool(new MockSpoolRepository());
Matcher recipientIs = new RecipientIs();
recipientIs.init(new DummyMatcherConfig("rec1@domain.com"));
Matcher all = new All();
all.init(new DummyMatcherConfig(""));
Mailet changeBody = new MyMailet();
Mailet changeBody2 = new MyMailet();
changeBody.init(mockMailetConfig);
changeBody2.init(mockMailetConfig);
Mailet dumpSystemErr = new DumpSystemErr();
changeBody.init(mockMailetConfig);
checkerMailet = new CheckerMailet();
t.add(recipientIs,changeBody);
t.add(all,changeBody);
t.add(all,dumpSystemErr);
t.add(all,checkerMailet);
t.closeProcessorLists();
Collection recipients = new ArrayList();
recipients.add(new MailAddress("rec1","domain.com"));
recipients.add(new MailAddress("rec2","domain.com"));
try {
MailImpl m = new MailImpl("mail1",new MailAddress("sender","domain.com"),recipients,mw);
t.service(m);
ArrayList a = checkerMailet.receivedMails;
assertEquals(2,a.size());
MimeMessage m1 = ((Mail) a.get(0)).getMessage();
MimeMessage m2 = ((Mail) a.get(1)).getMessage();
assertNotSame(m1,m2);
assertEquals(m1.getSubject(),"new text 1");
assertEquals(m2.getSubject(),"new text 2");
m.dispose();
} catch (MessagingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
| public void | testStateChange()
t.setSpool(new MockSpoolRepository() {
public void store(Mail mc) throws MessagingException {
assertEquals("MYSTATE",mc.getState());
super.store(mc);
}
});
Matcher recipientIs = new RecipientIs();
recipientIs.init(new DummyMatcherConfig("rec1@domain.com"));
Matcher all = new All();
all.init(new DummyMatcherConfig(""));
Mailet dumpSystemErr = new DumpSystemErr();
checkerMailet = new CheckerMailet();
t.add(recipientIs,dumpSystemErr);
t.add(all,dumpSystemErr);
t.add(all,checkerMailet);
t.closeProcessorLists();
Collection recipients = new ArrayList();
recipients.add(new MailAddress("rec1","domain.com"));
recipients.add(new MailAddress("rec2","domain.com"));
try {
MailImpl m = new MailImpl("mail1",new MailAddress("sender","domain.com"),recipients,mw);
m.setState("MYSTATE");
t.service(m);
ArrayList a = checkerMailet.receivedMails;
assertEquals(2,a.size());
MimeMessage m1 = ((Mail) a.get(0)).getMessage();
MimeMessage m2 = ((Mail) a.get(1)).getMessage();
assertNotSame(m1,m2);
assertEquals("MYSTATE",((Mail) a.get(0)).getState());
assertEquals("MYSTATE",((Mail) a.get(1)).getState());
m.dispose();
} catch (MessagingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
|
|