当前位置: 首页>>代码示例>>Java>>正文


Java GreenMailUtil.random方法代码示例

本文整理汇总了Java中com.icegreen.greenmail.util.GreenMailUtil.random方法的典型用法代码示例。如果您正苦于以下问题:Java GreenMailUtil.random方法的具体用法?Java GreenMailUtil.random怎么用?Java GreenMailUtil.random使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.icegreen.greenmail.util.GreenMailUtil的用法示例。


在下文中一共展示了GreenMailUtil.random方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createTestMessages

import com.icegreen.greenmail.util.GreenMailUtil; //导入方法依赖的package包/类
public void createTestMessages() {
    try {
        GreenMailUser user = greenMail.setUser(TEST_RECIP, "password");

        final String subject = GreenMailUtil.random();
        final String body = GreenMailUtil.random();
        user.deliver(createMimeMessage("[email protected]", subject, body, null));
        user.deliver(createMimeMessage("[email protected]", "Great stuff cheap!", "body", null));
        user.deliver(createMimeMessage("[email protected]", "Happening this month", "stuff", null));
        user.deliver(createMimeMessage("[email protected]", "Get certified today!", "Cheap!", null));
        user.deliver(createMimeMessage("[email protected]", "It's been a long time!", "Let's talk", null));
        user.deliver(createMimeMessage("[email protected]", "The Sound of Drums", "boom boom boom", 
                 Date.from(LocalDate.now().minusYears(2).atStartOfDay().atZone(ZoneId.systemDefault()).toInstant())));

        Session imapSession = greenMail.getImap().createSession();
        Store store = imapSession.getStore("imap");
        store.connect(TEST_RECIP, "password");
        
        Folder defaultFolder = store.getDefaultFolder();  
        Folder inbox = store.getFolder("INBOX");
        inbox.open(Folder.READ_WRITE);
        
        Folder ads = defaultFolder.getFolder("Ads");
        ads.create(Folder.HOLDS_MESSAGES);   
        
        Folder spam = defaultFolder.getFolder("Spam");
        spam.create(Folder.HOLDS_MESSAGES); 
    } catch (MessagingException ex) {
        Logger.getLogger(TestMailUtil.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
开发者ID:PacktPublishing,项目名称:Java-9-Programming-Blueprints,代码行数:32,代码来源:TestMailUtil.java

示例2: testReceive

import com.icegreen.greenmail.util.GreenMailUtil; //导入方法依赖的package包/类
@Test
public void testReceive() throws MessagingException, IOException {
    //Start all email servers using non-default ports.
    GreenMail greenMail = new GreenMail(ServerSetupTest.SMTP_IMAP);
    try {
        greenMail.start();

        //Use random content to avoid potential residual lingering problems
        final String subject = GreenMailUtil.random();
        final String body = GreenMailUtil.random();
        MimeMessage message = createMimeMessage(subject, body, greenMail); // Construct message
        GreenMailUser user = greenMail.setUser("[email protected]", "waelc", "soooosecret");
        user.deliver(message);
        assertEquals(1, greenMail.getReceivedMessages().length);

        // --- Place your retrieve code here

    } finally {
        greenMail.stop();
    }
}
 
开发者ID:greenmail-mail-test,项目名称:greenmail,代码行数:22,代码来源:ExampleReceiveNoRuleTest.java

示例3: testSendAndWaitForIncomingMailsInBcc

import com.icegreen.greenmail.util.GreenMailUtil; //导入方法依赖的package包/类
@Test
public void testSendAndWaitForIncomingMailsInBcc() throws Throwable {
    String subject = GreenMailUtil.random();
    String body = GreenMailUtil.random();
    final MimeMessage message = createTextEmail("[email protected]", "[email protected]", subject, body, greenMail.getSmtp().getServerSetup());
    message.addRecipients(Message.RecipientType.BCC, "[email protected],[email protected]");

    assertEquals(0, greenMail.getReceivedMessages().length);

    GreenMailUtil.sendMimeMessage(message);

    assertTrue(greenMail.waitForIncomingEmail(1500, 3));

    MimeMessage[] emails = greenMail.getReceivedMessages();
    assertEquals(3, emails.length);
}
 
开发者ID:greenmail-mail-test,项目名称:greenmail,代码行数:17,代码来源:SmtpServerTest.java

示例4: testImapsReceive

import com.icegreen.greenmail.util.GreenMailUtil; //导入方法依赖的package包/类
@Test
public void testImapsReceive() throws Throwable {
    assertNotNull(greenMail.getImaps());
    final String subject = GreenMailUtil.random();
    final String body = GreenMailUtil.random();
    String to = "[email protected]";
    GreenMailUtil.sendTextEmailSecureTest(to, "[email protected]", subject, body);
    greenMail.waitForIncomingEmail(5000, 1);

    try (Retriever retriever = new Retriever(greenMail.getImaps())) {
        Message[] messages = retriever.getMessages(to);
        assertEquals(1, messages.length);
        assertEquals(subject, messages[0].getSubject());
        assertEquals(body, ((String) messages[0].getContent()).trim());
    }
}
 
开发者ID:greenmail-mail-test,项目名称:greenmail,代码行数:17,代码来源:ImapServerTest.java

示例5: testRetreiveSimpleWithNonDefaultPassword

import com.icegreen.greenmail.util.GreenMailUtil; //导入方法依赖的package包/类
@Test
public void testRetreiveSimpleWithNonDefaultPassword() throws Exception {
    assertNotNull(greenMail.getImap());
    final String to = "[email protected]";
    final String password = "donotharmanddontrecipricateharm";
    greenMail.setUser(to, password);
    final String subject = GreenMailUtil.random();
    final String body = GreenMailUtil.random();
    GreenMailUtil.sendTextEmailTest(to, "[email protected]", subject, body);
    greenMail.waitForIncomingEmail(5000, 1);

    try (Retriever retriever = new Retriever(greenMail.getImap())) {
        try {
            retriever.getMessages(to, "wrongpassword");
            fail("Expected failed login");
        } catch (Throwable e) {
            // ok
        }

        Message[] messages = retriever.getMessages(to, password);
        assertEquals(1, messages.length);
        assertEquals(subject, messages[0].getSubject());
        assertEquals(body, ((String) messages[0].getContent()).trim());
    }
}
 
开发者ID:greenmail-mail-test,项目名称:greenmail,代码行数:26,代码来源:ImapServerTest.java

示例6: testRetrieve

import com.icegreen.greenmail.util.GreenMailUtil; //导入方法依赖的package包/类
@Test
public void testRetrieve() throws Exception {
    assertNotNull(greenMail.getPop3());
    final String subject = GreenMailUtil.random();
    final String body = GreenMailUtil.random() + "\r\n" + GreenMailUtil.random() + "\r\n" + GreenMailUtil.random();
    String to = "[email protected]";
    GreenMailUtil.sendTextEmailTest(to, "[email protected]", subject, body);
    greenMail.waitForIncomingEmail(5000, 1);

    try (Retriever retriever = new Retriever(greenMail.getPop3())) {
        Message[] messages = retriever.getMessages(to);
        assertEquals(1, messages.length);
        assertEquals(subject, messages[0].getSubject());
        assertEquals(body, GreenMailUtil.getBody(messages[0]).trim());

        // UID
        POP3Folder f = (POP3Folder) messages[0].getFolder();
        assertNotEquals("UNKNOWN", f.getUID(messages[0]));
    }
}
 
开发者ID:greenmail-mail-test,项目名称:greenmail,代码行数:21,代码来源:Pop3ServerTest.java

示例7: testPop3sReceive

import com.icegreen.greenmail.util.GreenMailUtil; //导入方法依赖的package包/类
@Test
public void testPop3sReceive() throws Throwable {
    assertNotNull(greenMail.getPop3s());
    final String subject = GreenMailUtil.random();
    final String body = GreenMailUtil.random();
    String to = "[email protected]";
    GreenMailUtil.sendTextEmailSecureTest(to, "[email protected]", subject, body);
    greenMail.waitForIncomingEmail(5000, 1);

    try (Retriever retriever = new Retriever(greenMail.getPop3s())) {
        Message[] messages = retriever.getMessages(to);
        assertEquals(1, messages.length);
        assertEquals(subject, messages[0].getSubject());
        assertEquals(body, GreenMailUtil.getBody(messages[0]).trim());
    }
}
 
开发者ID:greenmail-mail-test,项目名称:greenmail,代码行数:17,代码来源:Pop3ServerTest.java

示例8: testRetrieveWithNonDefaultPassword

import com.icegreen.greenmail.util.GreenMailUtil; //导入方法依赖的package包/类
@Test
public void testRetrieveWithNonDefaultPassword() throws Exception {
    assertNotNull(greenMail.getPop3());
    final String to = "[email protected]calhost.com";
    final String password = "donotharmanddontrecipricateharm";
    greenMail.setUser(to, password);
    final String subject = GreenMailUtil.random();
    final String body = GreenMailUtil.random();
    GreenMailUtil.sendTextEmailTest(to, "[email protected]", subject, body);
    greenMail.waitForIncomingEmail(5000, 1);

    try (Retriever retriever = new Retriever(greenMail.getPop3())) {
        try {
            retriever.getMessages(to, "wrongpassword");
            fail("Expected authentication failure");
        } catch (Throwable e) {
            // ok
        }

        Message[] messages = retriever.getMessages(to, password);
        assertEquals(1, messages.length);
        assertEquals(subject, messages[0].getSubject());
        assertEquals(body, GreenMailUtil.getBody(messages[0]).trim());
    }
}
 
开发者ID:greenmail-mail-test,项目名称:greenmail,代码行数:26,代码来源:Pop3ServerTest.java

示例9: testPopAttachments

import com.icegreen.greenmail.util.GreenMailUtil; //导入方法依赖的package包/类
@Test
public void testPopAttachments() throws Exception{
	File folder = Files.createTempDir();
	
	String subject1 = GreenMailUtil.random();
	String body1 = GreenMailUtil.random();
	
	GreenMailUtil.sendTextEmailTest("[email protected]", "[email protected]", subject1, body1);
	
	String subject2 = GreenMailUtil.random();
	String body2 = GreenMailUtil.random();
	
	GreenMailUtil.sendAttachmentEmail("[email protected]", "[email protected]", subject2, body2, IOUtils.toByteArray(getClass().getResourceAsStream("lineReader.txt")), "text/plain", "lineReader.txt", "Test File", ServerSetupTest.SMTP);
			
	BaleenCollectionReader bcr = getCollectionReader(
			EmailReader.PARAM_PROTOCOL, "pop3",
			EmailReader.PARAM_WAIT, 5,
			EmailReader.PARAM_SERVER, greenMail.getPop3().getBindTo(),
			EmailReader.PARAM_PORT, greenMail.getPop3().getPort(),
			EmailReader.PARAM_USER, "[email protected]",
			EmailReader.PARAM_PASS, "password",
			EmailReader.PARAM_PROCESS, "attachments",
			EmailReader.PARAM_FOLDER, folder.getPath());

	bcr.initialize();
	
	assertTrue(bcr.doHasNext());
	bcr.getNext(jCas);
	
	assertTrue(jCas.getDocumentText().startsWith(FIRST_LINE));
	assertEquals(1, folder.list().length);
	
	jCas.reset();
	
	assertFalse(bcr.doHasNext());
	
	bcr.close();
	
	FileUtils.deleteDirectory(folder);
}
 
开发者ID:dstl,项目名称:baleen,代码行数:41,代码来源:EmailReaderTest.java

示例10: testPopLongWait

import com.icegreen.greenmail.util.GreenMailUtil; //导入方法依赖的package包/类
@Test
public void testPopLongWait() throws Exception{
	String subject = GreenMailUtil.random();
	String body = GreenMailUtil.random();
	
	String subject2 = GreenMailUtil.random();
	String body2 = GreenMailUtil.random();
	
	GreenMailUtil.sendTextEmailTest("[email protected]", "[email protected]", subject, body);
	GreenMailUtil.sendTextEmailTest("[email protected]", "[email protected]", subject2, body2);
	
	BaleenCollectionReader bcr = getCollectionReader(
			EmailReader.PARAM_PROTOCOL, "pop3",
			EmailReader.PARAM_WAIT, 15,
			EmailReader.PARAM_SERVER, greenMail.getPop3().getBindTo(),
			EmailReader.PARAM_PORT, greenMail.getPop3().getPort(),
			EmailReader.PARAM_USER, "[email protected]",
			EmailReader.PARAM_PASS, "password",
			EmailReader.PARAM_PROCESS, "content");

	bcr.initialize();
	
	assertTrue(bcr.doHasNext());
	bcr.getNext(jCas);
	
	jCas.reset();
	
	Thread.sleep(20000);
	
	assertTrue(bcr.doHasNext());
	bcr.getNext(jCas);
	
	jCas.reset();
	
	assertFalse(bcr.doHasNext());
	
	bcr.close();
}
 
开发者ID:dstl,项目名称:baleen,代码行数:39,代码来源:EmailReaderTest.java

示例11: testImapAttachments

import com.icegreen.greenmail.util.GreenMailUtil; //导入方法依赖的package包/类
@Test
public void testImapAttachments() throws Exception{
	File folder = Files.createTempDir();
	
	String subject1 = GreenMailUtil.random();
	String body1 = GreenMailUtil.random();
	
	GreenMailUtil.sendTextEmailTest("[email protected]", "[email protected]", subject1, body1);
	
	String subject2 = GreenMailUtil.random();
	String body2 = GreenMailUtil.random();
	
	GreenMailUtil.sendAttachmentEmail("[email protected]", "[email protected]", subject2, body2, IOUtils.toByteArray(getClass().getResourceAsStream("lineReader.txt")), "text/plain", "lineReader.txt", "Test File", ServerSetupTest.SMTP);
			
	BaleenCollectionReader bcr = getCollectionReader(
			EmailReader.PARAM_PROTOCOL, "imap",
			EmailReader.PARAM_WAIT, 5,
			EmailReader.PARAM_SERVER, greenMail.getImap().getBindTo(),
			EmailReader.PARAM_PORT, greenMail.getImap().getPort(),
			EmailReader.PARAM_USER, "[email protected]",
			EmailReader.PARAM_PASS, "password",
			EmailReader.PARAM_PROCESS, "attachments",
			EmailReader.PARAM_FOLDER, folder.getPath());

	bcr.initialize();
	
	assertTrue(bcr.doHasNext());
	bcr.getNext(jCas);
	
	assertTrue(jCas.getDocumentText().startsWith(FIRST_LINE));
	assertEquals(1, folder.list().length);
	
	jCas.reset();
	
	assertFalse(bcr.doHasNext());
	
	bcr.close();
	
	FileUtils.deleteDirectory(folder);
}
 
开发者ID:dstl,项目名称:baleen,代码行数:41,代码来源:EmailReaderTest.java

示例12: testSend

import com.icegreen.greenmail.util.GreenMailUtil; //导入方法依赖的package包/类
@Test
public void testSend() throws MessagingException, IOException {
    GreenMail greenMail = new GreenMail(ServerSetupTest.SMTP_IMAP);
    try {
        greenMail.start();

        //Use random content to avoid potential residual lingering problems
        final String subject = GreenMailUtil.random();
        final String body = GreenMailUtil.random();

        sendTestMails(subject, body); // Place your sending code here

        //wait for max 5s for 1 email to arrive
        //waitForIncomingEmail() is useful if you're sending stuff asynchronously in a separate thread
        assertTrue(greenMail.waitForIncomingEmail(5000, 2));

        //Retrieve using GreenMail API
        Message[] messages = greenMail.getReceivedMessages();
        assertEquals(2, messages.length);

        // Simple message
        assertEquals(subject, messages[0].getSubject());
        assertEquals(body, GreenMailUtil.getBody(messages[0]).trim());

        //if you send content as a 2 part multipart...
        assertTrue(messages[1].getContent() instanceof MimeMultipart);
        MimeMultipart mp = (MimeMultipart) messages[1].getContent();
        assertEquals(2, mp.getCount());
        assertEquals("body1", GreenMailUtil.getBody(mp.getBodyPart(0)).trim());
        assertEquals("body2", GreenMailUtil.getBody(mp.getBodyPart(1)).trim());
    } finally {
        greenMail.stop();
    }
}
 
开发者ID:greenmail-mail-test,项目名称:greenmail,代码行数:35,代码来源:ExampleSendNoRuleAdvTest.java

示例13: testSmtpServerReceiveWithSetup

import com.icegreen.greenmail.util.GreenMailUtil; //导入方法依赖的package包/类
@Test
public void testSmtpServerReceiveWithSetup() throws Throwable {
    assertEquals(0, greenMail.getReceivedMessages().length);

    String subject = GreenMailUtil.random();
    String body = GreenMailUtil.random();
    GreenMailUtil.sendTextEmailTest("[email protected]", "[email protected]", subject, body);
    greenMail.waitForIncomingEmail(1500, 1);
    MimeMessage[] emails = greenMail.getReceivedMessages();
    assertEquals(1, emails.length);
    assertEquals(subject, emails[0].getSubject());
    assertEquals(body, GreenMailUtil.getBody(emails[0]).trim());
}
 
开发者ID:greenmail-mail-test,项目名称:greenmail,代码行数:14,代码来源:SmtpServerTest.java

示例14: testSmtpsServerReceive

import com.icegreen.greenmail.util.GreenMailUtil; //导入方法依赖的package包/类
@Test
public void testSmtpsServerReceive() throws Throwable {
    assertEquals(0, greenMail.getReceivedMessages().length);

    String subject = GreenMailUtil.random();
    String body = GreenMailUtil.random();
    GreenMailUtil.sendTextEmailSecureTest("[email protected]", "[email protected]", subject, body);
    greenMail.waitForIncomingEmail(1500, 1);
    MimeMessage[] emails = greenMail.getReceivedMessages();
    assertEquals(1, emails.length);
    assertEquals(subject, emails[0].getSubject());
    assertEquals(body, GreenMailUtil.getBody(emails[0]).trim());
}
 
开发者ID:greenmail-mail-test,项目名称:greenmail,代码行数:14,代码来源:SmtpServerTest.java

示例15: testSmtpServerReceiveMultipart

import com.icegreen.greenmail.util.GreenMailUtil; //导入方法依赖的package包/类
@Test
public void testSmtpServerReceiveMultipart() throws Exception {
    assertEquals(0, greenMail.getReceivedMessages().length);

    String subject = GreenMailUtil.random();
    String body = GreenMailUtil.random();
    GreenMailUtil.sendAttachmentEmail("[email protected]", "[email protected]", subject, body, new byte[]{0, 1, 2}, "image/gif", "testimage_filename", "testimage_description", ServerSetupTest.SMTP);
    greenMail.waitForIncomingEmail(1500, 1);
    Message[] emails = greenMail.getReceivedMessages();
    assertEquals(1, emails.length);
    assertEquals(subject, emails[0].getSubject());

    Object o = emails[0].getContent();
    assertTrue(o instanceof MimeMultipart);
    MimeMultipart mp = (MimeMultipart) o;
    assertEquals(2, mp.getCount());
    BodyPart bp;
    bp = mp.getBodyPart(0);
    assertEquals(body, GreenMailUtil.getBody(bp).trim());

    bp = mp.getBodyPart(1);
    assertEquals("AAEC", GreenMailUtil.getBody(bp).trim());

    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    GreenMailUtil.copyStream(bp.getInputStream(), bout);
    byte[] gif = bout.toByteArray();
    for (int i = 0; i < gif.length; i++) {
        assertEquals(i, gif[i]);
    }
}
 
开发者ID:greenmail-mail-test,项目名称:greenmail,代码行数:31,代码来源:SmtpServerTest.java


注:本文中的com.icegreen.greenmail.util.GreenMailUtil.random方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。