[
https://issues.apache.org/jira/browse/WICKET-2269?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12707830#action_12707830
]
Igor Vaynberg commented on WICKET-2269:
---------------------------------------
here is some code off the top of my head to test a simple attr modier:
Compoent comp=EasMock.createMock(Component.class);
ComponentTag tag=EasyMock.createMock(ComponentTag.class);
// make sure attr modifier checks if component is enabled
EasyMock.expect(comp.isEnabled()).andReturn(true);
tag.put("class","odd");
EasMock.replay(comp, tag);
new SimpleAttributeModifier("class","odd").onComponentTag(comp,tag);
EasyMock.verify(comp, tag);
// test modifier when comp is enabled
EasyMock.reset(comp, tag);
EasyMock.expect(comp.isEnabled()).andReturn(false);
new SimpleAttributeModifier("class","odd").onComponentTag(comp,tag);
EasyMock.verify(comp, tag);
as far as checking if a certain modifier has been added to the component - you
are right, just iterate over all behaviors using Component#getBehaviors() and
use an instanceof check.
> A small change would allow WicketTesting attributeModifiers
> -----------------------------------------------------------
>
> Key: WICKET-2269
> URL: https://issues.apache.org/jira/browse/WICKET-2269
> Project: Wicket
> Issue Type: Improvement
> Components: wicket
> Affects Versions: 1.4-RC2
> Reporter: Martin Makundi
> Assignee: Igor Vaynberg
> Original Estimate: 5h
> Remaining Estimate: 5h
>
> The workaround is as follows, because AttributeModifier.getReplaceModel
> -method is protected. This operation should somehow be supported in
> WicketTester:
> Workaround:
> private final static Method getReplaceModelMethod;
> static {
> try {
> getReplaceModelMethod =
> AttributeModifier.class.getDeclaredMethod("getReplaceModel");
> getReplaceModelMethod.setAccessible(true);
> } catch (Exception e) {
> e.printStackTrace();
> throw new RuntimeException(e);
> }
> }
> public void assertAttribute(String message, String expected, Component
> component, String attribute) {
> AttributeModifier behavior = getAttributeModifier(component, attribute);
> if (behavior != null) {
> try {
> IModel<?> model = (IModel<?>) getReplaceModelMethod.invoke(behavior);
> assertEquals(message, expected, model.getObject().toString());
> return;
> } catch (Exception e) {
> throw new RuntimeException(e);
> }
> }
>
> fail("Attribute not found.");
> }
> Usage example:
> assertAttribute("3", tableFooterCellWebMarkupComponent,
> WebPageConstants.COLSPAN);
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.