use of org.apache.wicket.markup.parser.XmlTag in project wicket by apache.
the class BaseWicketTester method getWicketAjaxBaseUrlEncodedInLastResponse.
/**
* This method tries to parse the last response to return the encoded base URL and will throw an
* exception if there none was encoded.
*
* @return Wicket-Ajax-BaseURL set on last response by {@link AbstractDefaultAjaxBehavior}
* @throws IOException
* @throws ResourceStreamNotFoundException
* @throws ParseException
*/
public String getWicketAjaxBaseUrlEncodedInLastResponse() throws IOException, ResourceStreamNotFoundException, ParseException {
XmlPullParser parser = new XmlPullParser();
parser.parse(getLastResponseAsString());
XmlTag tag;
while ((tag = parser.nextTag()) != null) {
if (tag.isOpen() && tag.getName().equals("script") && "wicket-ajax-base-url".equals(tag.getAttribute("id"))) {
parser.next();
return parser.getString().toString().split("\\\"")[1];
}
}
fail("Last response has no AJAX base URL set by AbstractDefaultAjaxBehavior.");
return null;
}
use of org.apache.wicket.markup.parser.XmlTag in project wicket by apache.
the class AttributeModifierTest method nullModelDoesNotAppendEmptyAttribute.
/**
* 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());
}
use of org.apache.wicket.markup.parser.XmlTag in project wicket by apache.
the class AttributeModifierTest method nullModelDoesNotThrowNullPointerExceptions.
/**
* 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());
}
use of org.apache.wicket.markup.parser.XmlTag in project wicket by apache.
the class AttributeModifierTest method testModelReplacementOverwritingExistingAttributeValue.
/**
* Test that the current attribute is overwritten by the one that the model provides.
*/
@Test
public void testModelReplacementOverwritingExistingAttributeValue() {
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");
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("Ellioth Smith Rocks", replacement);
}
use of org.apache.wicket.markup.parser.XmlTag in project wicket by apache.
the class AttributeModifierTest method testNoNewValueWhenNotEnabled.
/**
* 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);
}
Aggregations