Search in sources :

Example 1 with StringResourceStream

use of org.apache.wicket.util.resource.StringResourceStream in project wicket by apache.

the class ResponseIOExceptionTest method giveUpRespondingOnIOExceptions.

/**
 * WICKET-3570
 */
@Test
public void giveUpRespondingOnIOExceptions() {
    TestRequestCycleListener testRequestCycleListener = new TestRequestCycleListener();
    tester.getApplication().getRequestCycleListeners().add(testRequestCycleListener);
    tester.startResource(new ResourceStreamResource(new StringResourceStream("asdf")));
    assertThat(testRequestCycleListener.lastExceptionRequestHandlerResolved, instanceOf(EmptyRequestHandler.class));
}
Also used : EmptyRequestHandler(org.apache.wicket.request.handler.EmptyRequestHandler) ResourceStreamResource(org.apache.wicket.request.resource.ResourceStreamResource) StringResourceStream(org.apache.wicket.util.resource.StringResourceStream) Test(org.junit.Test)

Example 2 with StringResourceStream

use of org.apache.wicket.util.resource.StringResourceStream in project wicket by apache.

the class XmlPullParserTest method encoding.

/**
 * @throws Exception
 */
@Test
public final void encoding() throws Exception {
    final XmlPullParser parser = new XmlPullParser();
    parser.parse(new StringResourceStream("<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>").getInputStream(), null);
    assertEquals("iso-8859-1", parser.getEncoding());
    XmlTag tag = parser.nextTag();
    assertNull(tag);
    parser.parse(new StringResourceStream("<?xml version=\"1.0\" encoding='iso-8859-1' ?> test test").getInputStream(), null);
    assertEquals("iso-8859-1", parser.getEncoding());
    tag = parser.nextTag();
    assertNull(tag);
    // re-order and move close (remove whitespaces
    parser.parse(new StringResourceStream("   <?xml encoding='iso-8859-1'version=\"1.0\"?> test test").getInputStream(), null);
    assertEquals("iso-8859-1", parser.getEncoding());
    tag = parser.nextTag();
    assertNull(tag);
    // attribute value must be enclosed by ""
    parser.parse(new StringResourceStream("<?xml encoding=iso-8859-1 ?> test test").getInputStream(), null);
    assertEquals("iso-8859-1", parser.getEncoding());
    // Invaluid encoding
    Exception ex = null;
    try {
        parser.parse(new StringResourceStream("<?xml encoding='XXX' ?>").getInputStream(), null);
    } catch (UnsupportedEncodingException e) {
        ex = e;
    }
    assertNotNull(ex);
    // no extra characters allowed before <?xml>
    // TODO General: I'd certainly prefer an exception
    parser.parse(new StringResourceStream("xxxx <?xml encoding='iso-8859-1' ?>").getInputStream(), null);
    assertNull(parser.getEncoding());
    tag = parser.nextTag();
    assertNull(tag);
    // no extra characters allowed before <?xml>
    // Are comments allowed preceding the encoding string?
    parser.parse(new StringResourceStream("<!-- Comment --> <?xml encoding='iso-8859-1' ?>").getInputStream(), null);
    assertNull(parser.getEncoding());
    tag = parser.nextTag();
    assertNull(tag);
    // 'test' is not a valid attribut. But we currently don't test it.
    parser.parse(new StringResourceStream("<?xml test='123' >").getInputStream(), null);
    assertNull(parser.getEncoding());
    tag = parser.nextTag();
    assertNull(tag);
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) StringResourceStream(org.apache.wicket.util.resource.StringResourceStream) ParseException(java.text.ParseException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Test(org.junit.Test)

Example 3 with StringResourceStream

use of org.apache.wicket.util.resource.StringResourceStream in project wicket by apache.

the class VelocityPanel method getMarkupResourceStream.

/**
 * {@inheritDoc}
 */
@Override
public final IResourceStream getMarkupResourceStream(final MarkupContainer container, final Class<?> containerClass) {
    Reader reader = getTemplateReader();
    if (reader == null) {
        throw new WicketRuntimeException("could not find velocity template for panel: " + this);
    }
    // evaluate the template and return a new StringResourceStream
    StringBuilder sb = new StringBuilder();
    sb.append("<wicket:panel>");
    sb.append(evaluateVelocityTemplate(reader));
    sb.append("</wicket:panel>");
    return new StringResourceStream(sb.toString());
}
Also used : WicketRuntimeException(org.apache.wicket.WicketRuntimeException) Reader(java.io.Reader) StringReader(java.io.StringReader) StringResourceStream(org.apache.wicket.util.resource.StringResourceStream) IStringResourceStream(org.apache.wicket.util.resource.IStringResourceStream)

Example 4 with StringResourceStream

use of org.apache.wicket.util.resource.StringResourceStream in project wicket by apache.

the class ButtonTest method whenButtonElement_thenModelObjectIsUsedAsTextContent.

/**
 * https://issues.apache.org/jira/browse/WICKET-6225
 */
@Test
public void whenButtonElement_thenModelObjectIsUsedAsTextContent() {
    tester.getApplication().getMarkupSettings().setStripWicketTags(false);
    String text = "some text & another text";
    TestPage testPage = new TestPage(Model.of(text)) {

        @Override
        public IResourceStream getMarkupResourceStream(MarkupContainer container, Class<?> containerClass) {
            return new StringResourceStream("<html><body>" + "<form wicket:id=\"form\"><button wicket:id=\"button\"></button></form></body></html>");
        }
    };
    tester.startPage(testPage);
    TagTester buttonTagTester = tester.getTagByWicketId("button");
    assertThat(buttonTagTester, is(notNullValue()));
    assertThat(buttonTagTester.getAttribute("value"), is(nullValue()));
    assertThat(buttonTagTester.getValue(), is(equalTo(text)));
}
Also used : MarkupContainer(org.apache.wicket.MarkupContainer) StringResourceStream(org.apache.wicket.util.resource.StringResourceStream) TagTester(org.apache.wicket.util.tester.TagTester) Test(org.junit.Test)

Example 5 with StringResourceStream

use of org.apache.wicket.util.resource.StringResourceStream in project wicket by apache.

the class ButtonTest method whenButtonElementWithoutModelObject_thenUseTextContentFromHtml.

/**
 * https://issues.apache.org/jira/browse/WICKET-6225
 */
@Test
public void whenButtonElementWithoutModelObject_thenUseTextContentFromHtml() {
    tester.getApplication().getMarkupSettings().setStripWicketTags(false);
    String text = "some text & another text";
    final String textInHtml = "Button label in HTML";
    TestPage testPage = new TestPage(Model.of("")) {

        @Override
        public IResourceStream getMarkupResourceStream(MarkupContainer container, Class<?> containerClass) {
            return new StringResourceStream("<html><body>" + "<form wicket:id=\"form\"><button wicket:id=\"button\">" + textInHtml + "</button></form></body></html>");
        }
    };
    tester.startPage(testPage);
    TagTester buttonTagTester = tester.getTagByWicketId("button");
    assertThat(buttonTagTester, is(notNullValue()));
    assertThat(buttonTagTester.getAttribute("value"), is(nullValue()));
    assertThat(buttonTagTester.getValue(), is(equalTo(textInHtml)));
}
Also used : MarkupContainer(org.apache.wicket.MarkupContainer) StringResourceStream(org.apache.wicket.util.resource.StringResourceStream) TagTester(org.apache.wicket.util.tester.TagTester) Test(org.junit.Test)

Aggregations

StringResourceStream (org.apache.wicket.util.resource.StringResourceStream)13 Test (org.junit.Test)9 MarkupContainer (org.apache.wicket.MarkupContainer)4 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)3 WebPage (org.apache.wicket.markup.html.WebPage)3 ParseException (java.text.ParseException)2 IMarkupResourceStreamProvider (org.apache.wicket.markup.IMarkupResourceStreamProvider)2 TagTester (org.apache.wicket.util.tester.TagTester)2 Template (freemarker.template.Template)1 IOException (java.io.IOException)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Page (org.apache.wicket.Page)1 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)1 AjaxSubmitLink (org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink)1 IResourceStreamLocator (org.apache.wicket.core.util.resource.locator.IResourceStreamLocator)1 CachingResourceStreamLocator (org.apache.wicket.core.util.resource.locator.caching.CachingResourceStreamLocator)1 ContainerInfo (org.apache.wicket.markup.ContainerInfo)1 MarkupParser (org.apache.wicket.markup.MarkupParser)1