/** 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()); }
/** 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); }
/** 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); }
/** 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); }
/* * (non-Javadoc) * @see org.apache.wicket.Component#onComponentTag(org.apache.wicket.markup.ComponentTag) */ @Override protected void onComponentTag(ComponentTag tag) { super.onComponentTag(tag); // make sure that our JS button will render in the container of right tag tag.setName("div"); }