Search in sources :

Example 16 with PlatformException

use of org.eclipse.scout.rt.platform.exception.PlatformException in project scout.rt by eclipse.

the class SmartFieldLookupTest method testTextLookupWithExceptions.

@SuppressWarnings("unchecked")
@Test(expected = PlatformException.class)
public void testTextLookupWithExceptions() {
    m_field.setLookupCall(new TestLookupCall());
    when(m_mock_service.getDataByText(any(ILookupCall.class))).thenThrow(new PlatformException("lookup error"));
    m_field.callTextLookup("test", 10);
}
Also used : TestLookupCall(org.eclipse.scout.rt.client.ui.form.fields.smartfield.fixture.TestLookupCall) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) ILookupCall(org.eclipse.scout.rt.shared.services.lookup.ILookupCall) Test(org.junit.Test)

Example 17 with PlatformException

use of org.eclipse.scout.rt.platform.exception.PlatformException in project scout.rt by eclipse.

the class SmartFieldLookupTest method testTextLookupExceptions_InBackground.

@SuppressWarnings("unchecked")
@Test
public void testTextLookupExceptions_InBackground() throws InterruptedException {
    m_field.setLookupCall(new TestLookupCall());
    final String errorText = "lookup error";
    when(m_mock_service.getDataByText(any(ILookupCall.class))).thenThrow(new PlatformException(errorText));
    final IBlockingCondition bc = Jobs.newBlockingCondition(true);
    ILookupRowFetchedCallback callback = new ILookupRowFetchedCallback<Long>() {

        @Override
        public void onSuccess(List<? extends ILookupRow<Long>> rows) {
            Assert.fail("no exception thrown");
            bc.setBlocking(false);
        }

        @Override
        public void onFailure(RuntimeException exception) {
            assertTrue(exception instanceof PlatformException);
            assertEquals(errorText, exception.getMessage());
            bc.setBlocking(false);
        }
    };
    m_field.callTextLookupInBackground("", 10, callback);
    bc.waitFor();
}
Also used : TestLookupCall(org.eclipse.scout.rt.client.ui.form.fields.smartfield.fixture.TestLookupCall) ILookupRow(org.eclipse.scout.rt.shared.services.lookup.ILookupRow) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) ILookupRowFetchedCallback(org.eclipse.scout.rt.shared.services.lookup.ILookupRowFetchedCallback) ArrayList(java.util.ArrayList) List(java.util.List) ILookupCall(org.eclipse.scout.rt.shared.services.lookup.ILookupCall) IBlockingCondition(org.eclipse.scout.rt.platform.job.IBlockingCondition) Test(org.junit.Test)

Example 18 with PlatformException

use of org.eclipse.scout.rt.platform.exception.PlatformException in project scout.rt by eclipse.

the class SmartFieldLookupTest method testSubtreeLookupExceptions_InBackground.

@SuppressWarnings("unchecked")
@Test
public void testSubtreeLookupExceptions_InBackground() throws InterruptedException {
    final IBlockingCondition bc = Jobs.newBlockingCondition(true);
    m_field.setLookupCall(new TestLookupCall());
    when(m_mock_service.getDataByRec(any(ILookupCall.class))).thenThrow(new PlatformException("lookup error"));
    IFuture<List<ILookupRow<Long>>> rows = m_field.callSubTreeLookupInBackground(1L, TriState.TRUE, false);
    rows.whenDone(new IDoneHandler<List<ILookupRow<Long>>>() {

        @Override
        public void onDone(DoneEvent<List<ILookupRow<Long>>> event) {
            assertTrue(event.getException() instanceof RuntimeException);
            assertEquals("lookup error", event.getException().getMessage());
            bc.setBlocking(false);
        }
    }, ClientRunContexts.copyCurrent());
    bc.waitFor();
}
Also used : TestLookupCall(org.eclipse.scout.rt.client.ui.form.fields.smartfield.fixture.TestLookupCall) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) ArrayList(java.util.ArrayList) List(java.util.List) IBlockingCondition(org.eclipse.scout.rt.platform.job.IBlockingCondition) ILookupCall(org.eclipse.scout.rt.shared.services.lookup.ILookupCall) Test(org.junit.Test)

Example 19 with PlatformException

use of org.eclipse.scout.rt.platform.exception.PlatformException in project scout.rt by eclipse.

the class JmsMomImplementor method createDefaultMarshaller.

@SuppressWarnings("unchecked")
protected IMarshaller createDefaultMarshaller(final Map<Object, Object> properties) {
    Object prop = properties.get(MARSHALLER);
    if (prop instanceof IMarshaller) {
        return (IMarshaller) prop;
    } else {
        Class<? extends IMarshaller> marshallerClass;
        String marshallerClassName = ObjectUtility.toString(prop);
        if (marshallerClassName != null) {
            try {
                marshallerClass = (Class<? extends IMarshaller>) Class.forName(marshallerClassName);
            } catch (final ClassNotFoundException | ClassCastException e) {
                throw new PlatformException("Failed to load class specified by environment property '{}' [value={}]", MARSHALLER, marshallerClassName, e);
            }
        } else {
            marshallerClass = CONFIG.getPropertyValue(DefaultMarshallerProperty.class);
        }
        return BEANS.get(marshallerClass);
    }
}
Also used : IMarshaller(org.eclipse.scout.rt.mom.api.marshaller.IMarshaller) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException)

Example 20 with PlatformException

use of org.eclipse.scout.rt.platform.exception.PlatformException in project scout.rt by eclipse.

the class MalwareScanner method scan.

/**
 * This {@link MalwareScanner} copies the resource to be scanned into the TEMP folder, reads it back in and verifies
 * the equality of the two streams.
 * <p>
 * Override this {@link Bean} in order to implement another scanning strategy.
 *
 * @throws PlatformException
 *           if the resource is valid and the scanner did not find any issues
 */
public void scan(BinaryResource res) {
    if (res == null) {
        return;
    }
    File f = null;
    try {
        byte[] expected = res.getContent();
        if (expected == null || expected.length == 0) {
            return;
        }
        f = IOUtility.createTempFile("malware-scan", ".tmp", expected);
        byte[] actual;
        try (FileInputStream in = new FileInputStream(f)) {
            actual = IOUtility.readBytes(in, expected.length);
        }
        if (!Arrays.equals(expected, actual)) {
            throwUnsafeResource(res);
        }
    } catch (Exception e) {
        // NOSONAR each on-site malware scanner may behave differently, e.g. StreamCorruptedException, FileNotFoundException, ...
        throwUnsafeResource(res);
    } finally {
        IOUtility.deleteFile(f);
    }
}
Also used : File(java.io.File) FileInputStream(java.io.FileInputStream) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException)

Aggregations

PlatformException (org.eclipse.scout.rt.platform.exception.PlatformException)35 Test (org.junit.Test)13 IRunnable (org.eclipse.scout.rt.platform.util.concurrent.IRunnable)9 IOException (java.io.IOException)8 FileInputStream (java.io.FileInputStream)4 ProcessingException (org.eclipse.scout.rt.platform.exception.ProcessingException)4 VetoException (org.eclipse.scout.rt.platform.exception.VetoException)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 InputStream (java.io.InputStream)3 URL (java.net.URL)3 ArrayList (java.util.ArrayList)3 TestLookupCall (org.eclipse.scout.rt.client.ui.form.fields.smartfield.fixture.TestLookupCall)3 AssertionException (org.eclipse.scout.rt.platform.util.Assertions.AssertionException)3 ILookupCall (org.eclipse.scout.rt.shared.services.lookup.ILookupCall)3 File (java.io.File)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 List (java.util.List)2 ExecutionException (java.util.concurrent.ExecutionException)2 BeanMetaData (org.eclipse.scout.rt.platform.BeanMetaData)2