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));
}
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);
}
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());
}
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)));
}
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)));
}
Aggregations