Search in sources :

Example 1 with IObjectChecker

use of org.apache.wicket.core.util.objects.checker.IObjectChecker 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)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 OutputStream (java.io.OutputStream)1 CheckingObjectOutputStream (org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream)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 Test (org.junit.Test)1