Search in sources :

Example 1 with MockResponseWriter

use of org.apache.myfaces.test.mock.MockResponseWriter in project myfaces-build-tools by apache.

the class OddNumberValidatorTest method setUp.

public void setUp() throws Exception {
    super.setUp();
    oddNumValidator = new OddNumberValidator();
    writer = new MockResponseWriter(new StringWriter(), null, null);
    facesContext.setResponseWriter(writer);
}
Also used : StringWriter(java.io.StringWriter) MockResponseWriter(org.apache.myfaces.test.mock.MockResponseWriter)

Example 2 with MockResponseWriter

use of org.apache.myfaces.test.mock.MockResponseWriter in project myfaces by apache.

the class UITestCase method testRelativePaths.

@Test
public void testRelativePaths() throws Exception {
    UIViewRoot root = facesContext.getViewRoot();
    vdl.buildView(facesContext, root, "parent.xml");
    StringWriter sw = new StringWriter();
    MockResponseWriter mrw = new MockResponseWriter(sw);
    facesContext.setResponseWriter(mrw);
    root.encodeAll(facesContext);
    sw.flush();
    Assert.assertTrue(sw.toString().equals("Hello World!"));
// System.out.println("************************");
// System.out.println(sw.toString());
// System.out.println("************************");
}
Also used : StringWriter(java.io.StringWriter) MockResponseWriter(org.apache.myfaces.test.mock.MockResponseWriter) UIViewRoot(jakarta.faces.component.UIViewRoot) Test(org.junit.Test)

Example 3 with MockResponseWriter

use of org.apache.myfaces.test.mock.MockResponseWriter in project myfaces by apache.

the class UITestCase method testCompositionTemplate.

@Test
public void testCompositionTemplate() throws Exception {
    UIViewRoot root = facesContext.getViewRoot();
    vdl.buildView(facesContext, root, "composition-template.xml");
    StringWriter sw = new StringWriter();
    MockResponseWriter mrw = new MockResponseWriter(sw);
    facesContext.setResponseWriter(mrw);
    root.encodeAll(facesContext);
    sw.flush();
    String response = sw.toString();
    Assert.assertTrue(response.contains("New Title"));
    Assert.assertTrue(response.contains("New Body"));
}
Also used : StringWriter(java.io.StringWriter) MockResponseWriter(org.apache.myfaces.test.mock.MockResponseWriter) UIViewRoot(jakarta.faces.component.UIViewRoot) Test(org.junit.Test)

Example 4 with MockResponseWriter

use of org.apache.myfaces.test.mock.MockResponseWriter in project myfaces by apache.

the class CompositionTestCase method testComposition3EmptyComposition.

/**
 * An empty ui:composition does not means the content of a ui:insert without
 * name to be rendered
 *
 * @throws Exception
 */
@Test
public void testComposition3EmptyComposition() throws Exception {
    UIViewRoot root = facesContext.getViewRoot();
    vdl.buildView(facesContext, root, "composition3.xhtml");
    StringWriter sw = new StringWriter();
    MockResponseWriter mrw = new MockResponseWriter(sw);
    facesContext.setResponseWriter(mrw);
    root.encodeAll(facesContext);
    sw.flush();
    String response = sw.toString();
    Assert.assertFalse(response.contains("This fragment will not be inserted"));
    Assert.assertFalse(response.contains("THIS SHOULD NOT BE RENDERED"));
}
Also used : StringWriter(java.io.StringWriter) MockResponseWriter(org.apache.myfaces.test.mock.MockResponseWriter) UIViewRoot(jakarta.faces.component.UIViewRoot) Test(org.junit.Test)

Example 5 with MockResponseWriter

use of org.apache.myfaces.test.mock.MockResponseWriter in project myfaces by apache.

the class CompositionTestCase method testComposition2EmptyComposition.

/**
 * An empty ui:composition does not means the content of a ui:insert without
 * name to be rendered
 *
 * @throws Exception
 */
@Test
public void testComposition2EmptyComposition() throws Exception {
    UIViewRoot root = facesContext.getViewRoot();
    vdl.buildView(facesContext, root, "composition2.xhtml");
    StringWriter sw = new StringWriter();
    MockResponseWriter mrw = new MockResponseWriter(sw);
    facesContext.setResponseWriter(mrw);
    root.encodeAll(facesContext);
    sw.flush();
    String response = sw.toString();
    Assert.assertFalse(response.contains("This fragment will not be inserted"));
    Assert.assertFalse(response.contains("THIS SHOULD NOT BE RENDERED"));
}
Also used : StringWriter(java.io.StringWriter) MockResponseWriter(org.apache.myfaces.test.mock.MockResponseWriter) UIViewRoot(jakarta.faces.component.UIViewRoot) Test(org.junit.Test)

Aggregations

MockResponseWriter (org.apache.myfaces.test.mock.MockResponseWriter)128 StringWriter (java.io.StringWriter)116 Test (org.junit.Test)98 UIViewRoot (jakarta.faces.component.UIViewRoot)94 UIComponent (jakarta.faces.component.UIComponent)39 UINamingContainer (jakarta.faces.component.UINamingContainer)13 HelloWorld (org.apache.myfaces.view.facelets.bean.HelloWorld)11 HtmlRenderedAttr (org.apache.myfaces.test.utils.HtmlRenderedAttr)9 HtmlOutputText (jakarta.faces.component.html.HtmlOutputText)8 FacesContext (jakarta.faces.context.FacesContext)6 FastWriter (org.apache.myfaces.util.lang.FastWriter)6 HtmlCommandButton (jakarta.faces.component.html.HtmlCommandButton)5 ArrayList (java.util.ArrayList)5 Collection (java.util.Collection)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 MethodExpression (jakarta.el.MethodExpression)4 FacesMessage (jakarta.faces.application.FacesMessage)4 HtmlForm (jakarta.faces.component.html.HtmlForm)4 HtmlInputText (jakarta.faces.component.html.HtmlInputText)4