use of com.axway.ats.action.objects.MimePackage in project ats-framework by Axway.
the class Test_Rfc822Headers method parseNestedNoBody.
/**
* Test getting text body (plain or html) not possible, because text/plain part is located on 3nd level,
* and on 2nd level are located unknown parts:
*
* - multipart/mixed;
* - multipart/mixed;
* - multipart/alternative;
* - text/plain
* - text/html
* - multipart/alternative;
* - text/myPlain
* - text/myHTML
*/
@Test
public void parseNestedNoBody() throws Exception {
String mailMessagePath = Test_MimePackage.class.getResource("nestedMessagesNoBody.eml").getPath();
MimePackage mimeMessage = PackageLoader.loadMimePackageFromFile(mailMessagePath);
assertEquals(2, mimeMessage.getRegularPartCount());
assertEquals(0, mimeMessage.getAttachmentPartCount());
// exists but nested 3 levels.
assertNull(mimeMessage.getPlainTextBody());
// exists but nested 3 levels.
assertNull(mimeMessage.getHtmlTextBody());
}
use of com.axway.ats.action.objects.MimePackage in project ats-framework by Axway.
the class AttachmentNameRule method performMatch.
@Override
protected boolean performMatch(MetaData metaData) throws RbvException {
//get the emailMessage
//the meta data type check already passed, so it is safe to cast
MimePackage emailMessage = getNeededMimePackage(metaData);
String attachmentFileName;
try {
attachmentFileName = emailMessage.getAttachmentFileName(attachmentIndex);
} catch (PackageException pe) {
throw new RbvException(pe);
}
//if there is no such file name return false
boolean actualResult = false;
if (attachmentFileName != null) {
actualResult = Pattern.compile(expectedValue).matcher(attachmentFileName).matches();
log.info("Actual attachment file name is '" + attachmentFileName + "'");
} else {
log.info("No attachment with name that matches '" + expectedValue + "' was found");
}
return actualResult;
}
use of com.axway.ats.action.objects.MimePackage in project ats-framework by Axway.
the class HeaderRule method performMatch.
@Override
protected boolean performMatch(MetaData metaData) throws RbvException {
//get the emailMessage
//the meta data type check already passed, so it is safe to cast
MimePackage emailMessage = getNeededMimePackage(metaData);
String[] headerValues;
try {
if (headerIndex == -1) {
// we are going to check all header values
if (partIndex == PART_MAIN_MESSAGE) {
headerValues = emailMessage.getHeaderValues(headerName);
} else {
headerValues = emailMessage.getPartHeaderValues(headerName, partIndex);
}
} else {
// we are going to check a particular header value
String headerValue;
if (partIndex == PART_MAIN_MESSAGE) {
headerValue = emailMessage.getHeader(headerName, headerIndex);
} else {
headerValue = emailMessage.getPartHeader(headerName, partIndex, headerIndex);
}
headerValues = new String[] { headerValue };
}
} catch (NoSuchHeaderException nshe) {
log.debug("Meta data has no header '" + headerName + "'");
//no such header, so return false
return false;
} catch (PackageException pe) {
throw new RbvException(pe);
}
//if there is no such header return false
boolean actualResult = false;
if (headerValues == null || headerValues.length == 0) {
log.info("No header '" + headerName + "' was found");
} else {
for (String headerValue : headerValues) {
switch(matchMode) {
case LEFT:
actualResult = headerValue.startsWith(expectedValue);
break;
case RIGHT:
actualResult = headerValue.endsWith(expectedValue);
break;
case EQUALS:
actualResult = headerValue.equals(expectedValue);
break;
case FIND:
actualResult = headerValue.indexOf(expectedValue) >= 0;
break;
case REGEX:
actualResult = Pattern.compile(expectedValue).matcher(headerValue).find();
break;
}
log.info("Actual value for header '" + headerName + "' is '" + headerValue + "'");
if (actualResult) {
// we matched a header value, stop iterating the rest of the values
break;
}
}
}
return actualResult;
}
use of com.axway.ats.action.objects.MimePackage in project ats-framework by Axway.
the class Test_StringInMimePartRule method isMatchRegexRegularPartUTF8Positive.
@Test
public void isMatchRegexRegularPartUTF8Positive() throws RbvException, PackageException {
MimePackage utf8Package = new MimePackage();
utf8Package.addPart("Изчерпателна информация", MimePackage.PART_TYPE_TEXT_PLAIN, "utf-8");
ImapMetaData utf8MetaData = new ImapMetaData(utf8Package);
//expected true
StringInMimePartRule rule = new StringInMimePartRule(".*информация$", true, 0, false, "isMatchRegexRegularPartPositive1", true);
assertTrue(rule.isMatch(utf8MetaData));
//expected false
rule = new StringInMimePartRule("Изчерпателна.*яа", true, 0, false, "isMatchRegexRegularPartPositive2", false);
assertTrue(rule.isMatch(utf8MetaData));
}
use of com.axway.ats.action.objects.MimePackage in project ats-framework by Axway.
the class Test_MimePartRule method isMatchRegularPartNoSuchPart.
@Test
public void isMatchRegularPartNoSuchPart() throws PackageException, RbvException {
mailMessage = new MimePackage(Test_MimePartRule.class.getResourceAsStream("mail_with_one_attachment.msg"));
metaData = new ImapMetaData(mailMessage);
//expected true
MimePartRule rule = new MimePartRule(expectedMailMessage, 2, false, "isMatchRegularPartNoSuchPart1", true);
assertFalse(rule.isMatch(metaData));
//expected false
rule = new MimePartRule(expectedMailMessage, 2, false, "isMatchRegularPartNoSuchPart2", false);
assertTrue(rule.isMatch(metaData));
}
Aggregations