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());
}
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);
}
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));
}
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()));
}
Aggregations