Search in sources :

Example 11 with RbvException

use of com.axway.ats.rbv.model.RbvException 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;
}
Also used : MimePackage(com.axway.ats.action.objects.MimePackage) RbvException(com.axway.ats.rbv.model.RbvException) PackageException(com.axway.ats.action.objects.model.PackageException)

Example 12 with RbvException

use of com.axway.ats.rbv.model.RbvException 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;
}
Also used : MimePackage(com.axway.ats.action.objects.MimePackage) RbvException(com.axway.ats.rbv.model.RbvException) PackageException(com.axway.ats.action.objects.model.PackageException) NoSuchHeaderException(com.axway.ats.action.objects.model.NoSuchHeaderException)

Example 13 with RbvException

use of com.axway.ats.rbv.model.RbvException in project ats-framework by Axway.

the class Test_FileSystemFolder method getAllMetadataExceptionExists.

@Test(expected = RbvException.class)
public void getAllMetadataExceptionExists() throws Exception {
    // constructor
    expectNew(FileSystemOperations.class, "localhost:0000").andThrow(new RbvException("Test"));
    replayAll();
    FileSystemFolder folder = new FileSystemFolder("localhost:0000", "some.path", null, true, false);
    folder.open();
    assertEquals(folder.getAllMetaData(), new ArrayList<MetaData>());
    verifyAll();
}
Also used : RbvException(com.axway.ats.rbv.model.RbvException) MetaData(com.axway.ats.rbv.MetaData) FileSystemMetaData(com.axway.ats.rbv.filesystem.FileSystemMetaData) FileSystemOperations(com.axway.ats.action.filesystem.FileSystemOperations) FileSystemFolder(com.axway.ats.rbv.filesystem.FileSystemFolder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) BaseTest(com.axway.ats.rbv.BaseTest) Test(org.junit.Test)

Example 14 with RbvException

use of com.axway.ats.rbv.model.RbvException in project ats-framework by Axway.

the class Test_RBVException method constructors.

@Test
public void constructors() {
    RbvException exception;
    exception = new RbvException("test");
    assertEquals("test", exception.getMessage());
    assertNull(exception.getCause());
    Exception helperException = new Exception();
    exception = new RbvException("test", helperException);
    assertEquals("test", exception.getMessage());
    assertEquals(helperException, exception.getCause());
    exception = new RbvException(helperException);
    assertEquals("java.lang.Exception", exception.getMessage());
    assertEquals(helperException, exception.getCause());
}
Also used : RbvException(com.axway.ats.rbv.model.RbvException) RbvException(com.axway.ats.rbv.model.RbvException) BaseTest(com.axway.ats.rbv.BaseTest) Test(org.junit.Test)

Example 15 with RbvException

use of com.axway.ats.rbv.model.RbvException in project ats-framework by Axway.

the class Monitor method start.

public synchronized void start(MonitorListener monitorListener) throws RbvException {
    if (isActive) {
        throw new RbvException("Monitor '" + name + "' is already running");
    }
    logExpectedBehaviour();
    pollAttemptsLeft = pollingParameters.getPollAttempts();
    actualResult = !expectedResult;
    matchedMetaData = new ArrayList<MetaData>();
    this.monitorListener = monitorListener;
    matchable.open();
    timer = new Timer();
    timer.schedule(new MonitorTimerTask(), pollingParameters.getInitialDelay(), pollingParameters.getPollInterval());
    isActive = true;
}
Also used : Timer(java.util.Timer) RbvException(com.axway.ats.rbv.model.RbvException)

Aggregations

RbvException (com.axway.ats.rbv.model.RbvException)15 PackageException (com.axway.ats.action.objects.model.PackageException)6 MimePackage (com.axway.ats.action.objects.MimePackage)5 BaseTest (com.axway.ats.rbv.BaseTest)3 MetaData (com.axway.ats.rbv.MetaData)3 MetaDataIncorrectException (com.axway.ats.rbv.model.MetaDataIncorrectException)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 InputStream (java.io.InputStream)2 Date (java.util.Date)2 FileSystemOperations (com.axway.ats.action.filesystem.FileSystemOperations)1 FilePackage (com.axway.ats.action.objects.FilePackage)1 NoSuchHeaderException (com.axway.ats.action.objects.model.NoSuchHeaderException)1 NoSuchMimePartException (com.axway.ats.action.objects.model.NoSuchMimePartException)1 ConfigurationException (com.axway.ats.config.exceptions.ConfigurationException)1 DbRecordValue (com.axway.ats.core.dbaccess.DbRecordValue)1 DbRecordValuesList (com.axway.ats.core.dbaccess.DbRecordValuesList)1 DbException (com.axway.ats.core.dbaccess.exceptions.DbException)1 Monitor (com.axway.ats.rbv.Monitor)1 PollingParameters (com.axway.ats.rbv.PollingParameters)1