Validating TestCase email content extraction

The MessageParseTest example shows how this can be done.

deployTests()

This packages the required resources, a multipart/related TEXT and separately HTML notification, both to be tested:

@Deployment public static Archive<?> deployTests() { Archive<?> archive = ITBootstrap.buildArchive(MessageParseTest.class.getName()); try { ITBootstrap.addAssets(archive, DEFAULT_RESOURCES); ITBootstrap.addAssets(archive, new String[] {MULTIPART_RELATED_TEXT_TEST_CASE, MULTIPART_RELATED_HTML_TEST_CASE, MULTIPART_RELATED_PROFILE}); System.out.println(archive.toString(true)); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); System.exit(0); } return archive; }

testTextMessageContent()

Load the text from the Test Case email content:

@Test @InSequence(10) public void testTextMessageContent() throws Exception { InputStream is=getResourceAsStream(MULTIPART_RELATED_TEXT_TEST_CASE); Assert.assertNotNull("Unable to load resource: "+MULTIPART_RELATED_TEXT_TEST_CASE, is); MimeMessage message=reloadMessage(is); Assert.assertNotNull("Unable to load message: ", message); ITMailUtil mailUtils = fTestHarness.getMailUtil(); ProfileBean profileBean = installProfileXML(MULTIPART_RELATED_PROFILE, MessageParseTest.class+"-multipart-related", false); Assert.assertNotNull("Profile was null: ", profileBean); String content=mailUtils.getContent(message, profileBean); Assert.assertFalse("content was null", content.isEmpty()); Assert.assertTrue("content should contain 'Some example text'", content.indexOf("Some example text")!=-1); return; }

testHtmlMessageContent()

Load the wiki markup converted text from the HTML payload of the TestCase, according to HTML settings defined in the related profile:

@Test @InSequence(20) public void testHtmlMessageContent() throws Exception { InputStream is=getResourceAsStream(MULTIPART_RELATED_HTML_TEST_CASE); Assert.assertNotNull("Unable to load resource: "+MULTIPART_RELATED_HTML_TEST_CASE, is); MimeMessage message=reloadMessage(is); Assert.assertNotNull("Unable to load message: ", message); ITMailUtil mailUtils = fTestHarness.getMailUtil(); ProfileBean profileBean = getProfile(MessageParseTest.class+"-multipart-related"); Assert.assertNotNull("Profile was null: ", profileBean); String content=mailUtils.getContent(message, profileBean); Assert.assertFalse("content was null", content.isEmpty()); Assert.assertTrue("content should contain 'Some example text'", content.indexOf("Some example text")!=-1); return; }