@Test public void samplepageRendersSuccessfully() { // start and render the test page SamplePage page = tester.startPage(SamplePage.class, new PageParameters().add("Test", "asString")); // assert rendered page class tester.assertRenderedPage(SamplePage.class); ISerializer pageSerializer = getAndCheckSerializer(); byte[] data = pageSerializer.serialize(page); Assert.assertNotNull("The produced data should not be null!", data); Object object = pageSerializer.deserialize(data); Assert.assertTrue( "The deserialized page must be of type HomePage. Type: " + object.getClass(), object instanceof SamplePage); SamplePage samplePage = (SamplePage) object; tester.startPage(samplePage); // assert rendered page class tester.assertRenderedPage(SamplePage.class); }
private ISerializer getAndCheckSerializer() { ISerializer pageSerializer = tester.getApplication().getFrameworkSettings().getSerializer(); Assert.assertTrue( "The configured IObjectSerializer is not instance of FastSerializer! Type: " + pageSerializer.getClass(), pageSerializer instanceof FastWicketSerializer); return pageSerializer; }
@Test(expected = FastWicketSerialException.class) public void notSerializableComponentThrowsException() { NotSerializablePage page = tester.startPage(NotSerializablePage.class, new PageParameters().add("Test", "asString")); // assert rendered page class tester.assertRenderedPage(NotSerializablePage.class); ISerializer pageSerializer = getAndCheckSerializer(); pageSerializer.serialize(page); }
@Test public void homepageRendersSuccessfully() { // start and render the test page HomePage page = tester.startPage(HomePage.class); // assert rendered page class tester.assertRenderedPage(HomePage.class); ISerializer pageSerializer = getAndCheckSerializer(); byte[] data = pageSerializer.serialize(page); Assert.assertNotNull("The produced data should not be null!", data); // data length can fluctuate based on the object field values Assert.assertEquals("The produced data length is not correct!", 588, data.length); Object object = pageSerializer.deserialize(data); Assert.assertTrue( "The deserialized page must be of type HomePage. Type: " + object.getClass(), object instanceof HomePage); }