Search in sources :

Example 1 with XmlTag

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;
}
Also used : XmlPullParser(org.apache.wicket.markup.parser.XmlPullParser) XmlTag(org.apache.wicket.markup.parser.XmlTag)

Example 2 with XmlTag

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());
}
Also used : ComponentTag(org.apache.wicket.markup.ComponentTag) XmlTag(org.apache.wicket.markup.parser.XmlTag) Test(org.junit.Test)

Example 3 with XmlTag

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());
}
Also used : ComponentTag(org.apache.wicket.markup.ComponentTag) XmlTag(org.apache.wicket.markup.parser.XmlTag) Test(org.junit.Test)

Example 4 with XmlTag

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);
}
Also used : ComponentTag(org.apache.wicket.markup.ComponentTag) XmlTag(org.apache.wicket.markup.parser.XmlTag) Test(org.junit.Test)

Example 5 with XmlTag

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);
}
Also used : ComponentTag(org.apache.wicket.markup.ComponentTag) XmlTag(org.apache.wicket.markup.parser.XmlTag) Test(org.junit.Test)

Aggregations

XmlTag (org.apache.wicket.markup.parser.XmlTag)17 ComponentTag (org.apache.wicket.markup.ComponentTag)12 Test (org.junit.Test)11 XmlPullParser (org.apache.wicket.markup.parser.XmlPullParser)4 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)3 ArrayList (java.util.ArrayList)1 Stack (java.util.Stack)1 HeaderItem (org.apache.wicket.markup.head.HeaderItem)1 IHeaderResponse (org.apache.wicket.markup.head.IHeaderResponse)1 JavaScriptHeaderItem (org.apache.wicket.markup.head.JavaScriptHeaderItem)1 JavaScriptReferenceHeaderItem (org.apache.wicket.markup.head.JavaScriptReferenceHeaderItem)1 ResourceAggregator (org.apache.wicket.markup.head.ResourceAggregator)1 PackageResourceReference (org.apache.wicket.request.resource.PackageResourceReference)1 IResourceStream (org.apache.wicket.util.resource.IResourceStream)1