You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Martin Makundi (JIRA)" <ji...@apache.org> on 2009/05/10 07:38:45 UTC

[jira] Created: (WICKET-2269) A small change would allow WicketTesting attributeModifiers

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


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.


[jira] Commented: (WICKET-2269) A small change would allow WicketTesting attributeModifiers

Posted by "Martin Makundi (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-2269?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12707755#action_12707755 ] 

Martin Makundi commented on WICKET-2269:
----------------------------------------


Code-example of
A check that the attribute modifier performs the correct transformation
B check that the correct attribute modifier was added to the component

In B, do you only check the modifier class or also the attribute name?

A and B might be simple but they don't come 'off the top of my head'
so some (proven) lines of code would be nice.

**
Martin


> 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.


[jira] Commented: (WICKET-2269) A small change would allow WicketTesting attributeModifiers

Posted by "Igor Vaynberg (JIRA)" <ji...@apache.org>.
    [ 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.


[jira] Commented: (WICKET-2269) A small change would allow WicketTesting attributeModifiers

Posted by "Igor Vaynberg (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-2269?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12707890#action_12707890 ] 

Igor Vaynberg commented on WICKET-2269:
---------------------------------------

you can always write your own attribute modifiers which exposes whatever you want.

> 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.


[jira] Commented: (WICKET-2269) A small change would allow WicketTesting attributeModifiers

Posted by "Igor Vaynberg (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-2269?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12707751#action_12707751 ] 

Igor Vaynberg commented on WICKET-2269:
---------------------------------------

an example of which part?

> 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.


[jira] Commented: (WICKET-2269) A small change would allow WicketTesting attributeModifiers

Posted by "Martin Makundi (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-2269?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12707874#action_12707874 ] 

Martin Makundi commented on WICKET-2269:
----------------------------------------


It might still be that the behavior behaves wrong if only the
instanceof check passes.

For example, in my situation, I have a Wicket HTML report TABLE whose
colspan and rowspan configurations I need to test at runtime. The only
workaround I came up with was this: IModel<?> model = (IModel<?>)
getReplaceModelMethod.invoke(behavior);

If there is no other way to extract this information, maybe a small
modification would be in order in the wickettester classes. The
getReplaceModel -method is protected so one option would be to simply
have some test helper class which has access... but the actual method
for calling this helper could be in wicketTester.

For example,
wicketTester.assertAttributeModifier(component, key, value) ...
wicketTester.assertAttributeModifier(path, key, value) ...

**
Martin


> 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.


[jira] Resolved: (WICKET-2269) A small change would allow WicketTesting attributeModifiers

Posted by "Igor Vaynberg (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WICKET-2269?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Igor Vaynberg resolved WICKET-2269.
-----------------------------------

    Resolution: Won't Fix
      Assignee: Igor Vaynberg

this doesnt make any sense.

your test checks for two things: that the attribute modifier was added and that it has the correct model, but it checks this by testing the final output. this is not *unit* testing.

you can break this test down into two tests:
* check that the attribute modifier performs the correct transformation
* check that the correct attribute modifier was added to the component

this will allow you to test things in isolation.

testing the attribute modifier is trivial, instantiate it and call oncomponenttag() with a mock tag and check that the expectations on the mock are met.

the other check is also trivia, simply iterate over behaviors and make sure the right modifier is added to the component.

if you insist on cobbling up all these things into a single test that is fine, but then you should be checking the output. parse the output html, find the tag with the wicket id of the component that had the attribute modifier added to it and check for the correct attribute in the tag.

> 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.


[jira] Commented: (WICKET-2269) A small change would allow WicketTesting attributeModifiers

Posted by "Martin Makundi (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-2269?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12707889#action_12707889 ] 

Martin Makundi commented on WICKET-2269:
----------------------------------------


If I have several AttributeModifiers... I might not have the correct one.


All other components' models can be tested, why not attributemodifiers'?


I am JUnit testing.. but that's another topic alltogether.
Nevertheless, if I have several AttributeModifiers, I need to check it
is the correct one. Just any attribute and any value does not cut it.


Well.. I do not parse the component values, why should I have to parse
attributeModifiers? That sounds inconsistent.

**
Martin



> 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.


[jira] Commented: (WICKET-2269) A small change would allow WicketTesting attributeModifiers

Posted by "Martin Makundi (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-2269?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12707749#action_12707749 ] 

Martin Makundi commented on WICKET-2269:
----------------------------------------

Hi!

Is there an example code of this, I would happily incorporate it into



> 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.


[jira] Commented: (WICKET-2269) A small change would allow WicketTesting attributeModifiers

Posted by "Igor Vaynberg (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-2269?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12707888#action_12707888 ] 

Igor Vaynberg commented on WICKET-2269:
---------------------------------------

if the intanceof check passes - eg you added the behavior to the component, and you have unit tested the behavior to make sure it works - under what circumstances may this fail exactly?

we are not going to break encapsulation just so you can get to the model, you have a way to test the attributemodifier without it.

it really sounds like you are not unit testing, in that case use the other suggestion i gave you - test your code as a blackbox, parse the output, and make sure it is correct.

> 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.