use of org.apache.wicket.markup.html.WebComponent in project wicket by apache.
the class AjaxTimerBehaviorTest method addedInAjaxSetsTimout.
/**
* Tests timer behavior in a component added to an AjaxRequestTarget
*/
@Test
public void addedInAjaxSetsTimout() {
Duration dur = Duration.seconds(20);
final AjaxSelfUpdatingTimerBehavior timer = new AjaxSelfUpdatingTimerBehavior(dur);
final MockPageWithLinkAndComponent page = new MockPageWithLinkAndComponent();
page.add(new WebComponent(MockPageWithLinkAndComponent.COMPONENT_ID).setOutputMarkupId(true));
page.add(new AjaxLink<Void>(MockPageWithLinkAndComponent.LINK_ID) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
WebMarkupContainer wmc = new WebMarkupContainer(MockPageWithLinkAndComponent.COMPONENT_ID);
wmc.setOutputMarkupId(true);
wmc.add(timer);
page.replace(wmc);
target.add(wmc);
}
});
tester.startPage(page);
tester.clickLink(MockPageWithLinkAndComponent.LINK_ID);
// first render sets timeout
assertMatches("Wicket.Timer.set", 1);
tester.executeBehavior(timer);
assertMatches("Wicket.Timer.set", 1);
}
use of org.apache.wicket.markup.html.WebComponent in project wicket by apache.
the class ComponentTest method modelChange.
/**
* https://issues.apache.org/jira/browse/WICKET-4483
*
* setDefaultModel() should call modelChanging/modelChanged only if the new model
* is different that the old one. The same as setDefaultModelObject().
*/
@Test
public void modelChange() {
final AtomicBoolean modelChanging = new AtomicBoolean(false);
final AtomicBoolean modelChanged = new AtomicBoolean(false);
WebComponent component = new WebComponent("someId") {
@Override
protected void onModelChanging() {
super.onModelChanging();
modelChanging.set(true);
}
@Override
protected void onModelChanged() {
super.onModelChanged();
modelChanged.set(true);
}
};
assertNull(component.getDefaultModel());
IModel<Integer> model = Model.of(1);
// set a model which is different that the old one (old = null, new = non-null)
component.setDefaultModel(model);
assertTrue(modelChanging.getAndSet(false));
assertTrue(modelChanged.getAndSet(false));
// set the same instance - no change notifications should happen
component.setDefaultModel(model);
assertFalse(modelChanging.get());
assertFalse(modelChanged.get());
}
use of org.apache.wicket.markup.html.WebComponent in project wicket by apache.
the class ComponentTest method isStateless.
/**
* https://issues.apache.org/jira/browse/WICKET-4468
*
* Verifies that a stateful component can pretend to be stateless if both conditions are
* fulfilled:
* <ol>
* <li>it is either invisible or disabled (or both)</li>
* <li>it cannot call any listener interface method while invisible/disabled</li>
* </ol>
*/
@Test
public void isStateless() {
Behavior statefulBehavior = new Behavior() {
@Override
public boolean getStatelessHint(Component component) {
return false;
}
};
WebComponent component = new WebComponent("someId");
// by default every component is stateless
assertTrue(component.isStateless());
// make the component stateful
component.add(statefulBehavior);
assertFalse(component.isStateless());
// invisible component cannot be requested by default so it
// can pretend being stateless
component.setVisible(false);
assertTrue(component.isStateless());
// same for disabled component
component.setVisible(true).setEnabled(false);
assertTrue(component.isStateless());
// make the component such that it can call listener interface
// methods no matter whether it is visible or enabled
component = new WebComponent("someId") {
@Override
public boolean canCallListener() {
return true;
}
};
component.add(statefulBehavior);
component.setVisible(false);
assertFalse(component.isStateless());
// do the same set of tests on a component that is stateful "by itself"
// rather than from a behavior
Link<Void> link = new Link<Void>("someId") {
@Override
public void onClick() {
}
};
// Links are stateful by default
assertFalse(link.isStateless());
// make the link invisible
link.setVisible(false);
// invisible link cannot be requested by default so it
// can pretend being stateless
assertTrue(link.isStateless());
// same for disabled link
link.setVisible(true).setEnabled(false);
assertTrue(link.isStateless());
// make the link such that it can call listener interface
// methods no matter whether it is visible or enabled
link = new Link<Void>("someId") {
@Override
public boolean canCallListener() {
return true;
}
@Override
public void onClick() {
}
};
link.setVisible(false);
assertFalse(link.isStateless());
}
use of org.apache.wicket.markup.html.WebComponent in project wicket by apache.
the class DifferentPageCheckerTest method serializingAnotherPage.
/**
* https://issues.apache.org/jira/browse/WICKET-5634
*
* Tests that the serialization fails when a checking ObjectOutputStream is
* used with DifferentPageChecker and there is a component in the object tree that
* keeps a reference to a page which is not component.getPage()..
*/
@Test
public void serializingAnotherPage() {
JavaSerializer serializer = new JavaSerializer("JavaSerializerTest") {
@Override
protected ObjectOutputStream newObjectOutputStream(OutputStream out) throws IOException {
IObjectChecker checker = new DifferentPageChecker();
return new CheckingObjectOutputStream(out, checker);
}
};
WebComponent component = new ComponentThatKeepsAReferenceToAnotherPage(MockPageWithLink.LINK_ID);
MockPageWithLink rootPage = new MockPageWithLink();
rootPage.add(component);
byte[] serialized = serializer.serialize(rootPage);
assertNull("The produced byte[] must be null if there was an error", serialized);
}
use of org.apache.wicket.markup.html.WebComponent in project wicket by apache.
the class OrphanComponentCheckerTest method checkOrphanComponent.
@Test
public void checkOrphanComponent() {
WebComponent component = new WebComponent("a");
IObjectChecker checker = new OrphanComponentChecker();
IObjectChecker.Result result = checker.check(component);
assertEquals(IObjectChecker.Result.Status.FAILURE, result.status);
assertEquals("A component without a parent is detected.", result.reason);
WebPage parent = new TestPage_1();
parent.add(component);
IObjectChecker.Result result2 = checker.check(component);
assertEquals(IObjectChecker.Result.SUCCESS, result2);
}
Aggregations