Search in sources :

Example 1 with CheckingObjectOutputStream

use of org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream in project wicket by apache.

the class SerializableCheckerTest method valueMap.

/**
 * Test {@link ValueMap} serializability.
 *
 * @throws IOException
 */
@Test
public void valueMap() throws IOException {
    CheckingObjectOutputStream checker = new CheckingObjectOutputStream(new ByteArrayOutputStream(), new ObjectSerializationChecker(new NotSerializableException()));
    checker.writeObject(new ValueMap());
}
Also used : NotSerializableException(java.io.NotSerializableException) ObjectSerializationChecker(org.apache.wicket.core.util.objects.checker.ObjectSerializationChecker) ValueMap(org.apache.wicket.util.value.ValueMap) CheckingObjectOutputStream(org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream) Test(org.junit.Test)

Example 2 with CheckingObjectOutputStream

use of org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream in project wicket by apache.

the class JavaSerializerTest method notDetachedModel.

/**
 * https://issues.apache.org/jira/browse/WICKET-4812
 *
 * Tests that the serialization fails when a checking ObjectOutputStream is
 * used with NotDetachedModelChecker and there is a non-detached LoadableDetachableModel
 * in the object tree.
 */
@Test
public void notDetachedModel() {
    JavaSerializer serializer = new JavaSerializer("JavaSerializerTest") {

        @Override
        protected ObjectOutputStream newObjectOutputStream(OutputStream out) throws IOException {
            IObjectChecker checker = new NotDetachedModelChecker();
            return new CheckingObjectOutputStream(out, checker);
        }
    };
    IModel<String> model = new NotDetachedModel();
    model.getObject();
    WebComponent component = new WebComponent("id", model);
    byte[] serialized = serializer.serialize(component);
    assertNull("The produced byte[] must be null if there was an error", serialized);
}
Also used : WebComponent(org.apache.wicket.markup.html.WebComponent) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CheckingObjectOutputStream(org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) CheckingObjectOutputStream(org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream) IObjectChecker(org.apache.wicket.core.util.objects.checker.IObjectChecker) NotDetachedModelChecker(org.apache.wicket.core.util.objects.checker.NotDetachedModelChecker) Test(org.junit.Test)

Example 3 with CheckingObjectOutputStream

use of org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream in project wicket by apache.

the class SerializableCheckerTest method checkObjectsByIdentity.

/**
 * Asserts that {@link org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream}
 * will check an instance just once, despite it occurs more than once in the object tree
 *
 * https://issues.apache.org/jira/browse/WICKET-5642
 *
 * @throws IOException
 */
@Test
public void checkObjectsByIdentity() throws IOException {
    CountingChecker countingChecker = new CountingChecker();
    CheckingObjectOutputStream outputStream = new CheckingObjectOutputStream(new ByteArrayOutputStream(), countingChecker);
    final IdentityTestType type = new IdentityTestType();
    type.member = new SerializableTypeWithMember(type);
    outputStream.writeObject(type);
    assertThat(countingChecker.getCount(), is(2));
}
Also used : CheckingObjectOutputStream(org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream) Test(org.junit.Test)

Example 4 with CheckingObjectOutputStream

use of org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream in project wicket by apache.

the class SerializableCheckerTest method nonSerializableTypeDetection.

/**
 * @throws IOException
 */
@Test
public void nonSerializableTypeDetection() throws IOException {
    CheckingObjectOutputStream checker = new CheckingObjectOutputStream(new ByteArrayOutputStream(), new ObjectSerializationChecker(new NotSerializableException()));
    String exceptionMessage = null;
    try {
        checker.writeObject(new TestType2());
    } catch (CheckingObjectOutputStream.ObjectCheckException e) {
        exceptionMessage = e.getMessage();
    }
    assertTrue(exceptionMessage.contains(NonSerializableType.class.getName()));
}
Also used : NotSerializableException(java.io.NotSerializableException) ObjectSerializationChecker(org.apache.wicket.core.util.objects.checker.ObjectSerializationChecker) CheckingObjectOutputStream(org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream) Test(org.junit.Test)

Aggregations

CheckingObjectOutputStream (org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream)4 Test (org.junit.Test)4 NotSerializableException (java.io.NotSerializableException)2 ObjectSerializationChecker (org.apache.wicket.core.util.objects.checker.ObjectSerializationChecker)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 OutputStream (java.io.OutputStream)1 IObjectChecker (org.apache.wicket.core.util.objects.checker.IObjectChecker)1 NotDetachedModelChecker (org.apache.wicket.core.util.objects.checker.NotDetachedModelChecker)1 WebComponent (org.apache.wicket.markup.html.WebComponent)1 ValueMap (org.apache.wicket.util.value.ValueMap)1