コード例 #1
0
 /**
  * Test that a null model does not append an empty attribute
  * https://issues.apache.org/jira/browse/WICKET-3884
  */
 @Test
 public void nullModelDoesNotAppendEmptyAttribute() {
   AttributeModifier appender = AttributeModifier.append("class", null);
   XmlTag xmlTag = new XmlTag();
   ComponentTag tag = new ComponentTag(xmlTag);
   appender.replaceAttributeValue(null, tag);
   Map<String, Object> attributes = tag.getAttributes();
   assertTrue(attributes.isEmpty());
 }
コード例 #2
0
 /**
  * Tests {@link AttributeModifier#remove(String)}
  *
  * <p>https://issues.apache.org/jira/browse/WICKET-3934
  */
 @Test
 public void removeAttribute() {
   AttributeModifier appender = AttributeModifier.remove("class");
   XmlTag xmlTag = new XmlTag();
   ComponentTag tag = new ComponentTag(xmlTag);
   Map<String, Object> attributes = tag.getAttributes();
   attributes.put("class", "someValue");
   appender.replaceAttributeValue(null, tag);
   assertTrue(attributes.isEmpty());
 }
コード例 #3
0
 /** Test that a null model does not throw null pointers. */
 @Test
 public void nullModelDoesNotThrowNullPointerExceptions() {
   AttributeModifier modifier = new AttributeModifier("test", null);
   XmlTag xmlTag = new XmlTag();
   ComponentTag tag = new ComponentTag(xmlTag);
   tag.setId("foo");
   tag.setName("test");
   modifier.replaceAttributeValue(null, tag);
   Map<String, Object> attributes = tag.getAttributes();
   assertTrue(attributes.isEmpty());
 }
コード例 #4
0
 /**
  * Add an attribute with name equal (Object#equals()) to the special {@link
  * AttributeModifier#VALUELESS_ATTRIBUTE_REMOVE} but not identity equal
  *
  * <p>https://issues.apache.org/jira/browse/WICKET-3934
  */
 @Test
 public void appendSpecialAttribute() {
   String attrName = "attrName";
   AttributeModifier appender = AttributeModifier.append(attrName, "VA_REMOVE");
   XmlTag xmlTag = new XmlTag();
   ComponentTag tag = new ComponentTag(xmlTag);
   Map<String, Object> attributes = tag.getAttributes();
   attributes.put(attrName, "VA_REMOVE");
   appender.replaceAttributeValue(null, tag);
   assertFalse(attributes.isEmpty());
   assertEquals("VA_REMOVE VA_REMOVE", attributes.get(attrName));
 }
コード例 #5
0
 /** Test simple model replacement. */
 @Test
 public void testModelReplacement() {
   AttributeModifier modifier = new AttributeModifier("test", Model.of("Ellioth Smith Rocks"));
   XmlTag xmlTag = new XmlTag();
   ComponentTag tag = new ComponentTag(xmlTag);
   tag.setId("test");
   tag.setName("id");
   modifier.replaceAttributeValue(null, tag);
   Map<String, Object> attributes = tag.getAttributes();
   assertTrue(!attributes.isEmpty());
   String replacement = (String) attributes.get("test");
   assertNotNull(replacement);
   assertEquals("Ellioth Smith Rocks", replacement);
 }
コード例 #6
0
  /** Test that that the attribute modifier does nothing with not enabled. */
  @Test
  public void testNoNewValueWhenNotEnabled() {
    AttributeModifier modifier =
        new AttributeModifier("test", Model.of("Ellioth Smith Rocks")) {
          @Override
          public boolean isEnabled(Component component) {
            return false;
          }
        };

    XmlTag xmlTag = new XmlTag();
    ComponentTag tag = new ComponentTag(xmlTag);
    tag.setId("test");
    tag.setName("id");
    Map<String, Object> attributes = tag.getAttributes();
    attributes.put("test", "My mother rocks");
    modifier.replaceAttributeValue(null, tag);
    String replacement = (String) attributes.get("test");
    assertNotNull(replacement);
    assertEquals("My mother rocks", replacement);
  }
コード例 #7
0
  /** Test overriding newValue (and using a null model). */
  @Test
  public void testNewValue() {
    AttributeModifier modifier =
        new AttributeModifier("test", null) {
          private static final long serialVersionUID = 1L;

          @Override
          protected String newValue(String currentValue, String replacementValue) {
            return "the replacement";
          }
        };
    XmlTag xmlTag = new XmlTag();
    ComponentTag tag = new ComponentTag(xmlTag);
    tag.setId("test");
    tag.setName("id");
    modifier.replaceAttributeValue(null, tag);
    Map<String, Object> attributes = tag.getAttributes();
    assertTrue(!attributes.isEmpty());
    String replacement = (String) attributes.get("test");
    assertNotNull(replacement);
    assertEquals("the replacement", replacement);
  }