Search in sources :

Example 16 with PageContext

use of jakarta.servlet.jsp.PageContext in project spring-framework by spring-projects.

the class MessageTagTests method messageTagWithCodeAndArguments.

@Test
void messageTagWithCodeAndArguments() throws JspException {
    PageContext pc = createPageContext();
    final StringBuilder message = new StringBuilder();
    MessageTag tag = new MessageTag() {

        @Override
        protected void writeMessage(String msg) {
            message.append(msg);
        }
    };
    tag.setPageContext(pc);
    tag.setCode("testArgs");
    tag.setArguments("arg1,arg2");
    assertThat(tag.doStartTag() == Tag.EVAL_BODY_INCLUDE).as("Correct doStartTag return value").isTrue();
    assertThat(tag.doEndTag()).as("Correct doEndTag return value").isEqualTo(Tag.EVAL_PAGE);
    assertThat(message.toString()).as("Correct message").isEqualTo("test arg1 message arg2");
}
Also used : PageContext(jakarta.servlet.jsp.PageContext) Test(org.junit.jupiter.api.Test)

Example 17 with PageContext

use of jakarta.servlet.jsp.PageContext in project spring-framework by spring-projects.

the class MessageTagTests method messageTagWithCodeAndArgumentAndNestedArgument.

@Test
void messageTagWithCodeAndArgumentAndNestedArgument() throws JspException {
    PageContext pc = createPageContext();
    final StringBuilder message = new StringBuilder();
    MessageTag tag = new MessageTag() {

        @Override
        protected void writeMessage(String msg) {
            message.append(msg);
        }
    };
    tag.setPageContext(pc);
    tag.setCode("testArgs");
    assertThat(tag.doStartTag() == Tag.EVAL_BODY_INCLUDE).as("Correct doStartTag return value").isTrue();
    tag.setArguments(5);
    tag.addArgument(7);
    assertThat(tag.doEndTag()).as("Correct doEndTag return value").isEqualTo(Tag.EVAL_PAGE);
    assertThat(message.toString()).as("Correct message").isEqualTo("test 5 message 7");
}
Also used : PageContext(jakarta.servlet.jsp.PageContext) Test(org.junit.jupiter.api.Test)

Example 18 with PageContext

use of jakarta.servlet.jsp.PageContext in project spring-framework by spring-projects.

the class MessageTagTests method messageTagWithCode.

@Test
void messageTagWithCode() throws JspException {
    PageContext pc = createPageContext();
    final StringBuilder message = new StringBuilder();
    MessageTag tag = new MessageTag() {

        @Override
        protected void writeMessage(String msg) {
            message.append(msg);
        }
    };
    tag.setPageContext(pc);
    tag.setCode("test");
    assertThat(tag.doStartTag() == Tag.EVAL_BODY_INCLUDE).as("Correct doStartTag return value").isTrue();
    assertThat(tag.doEndTag()).as("Correct doEndTag return value").isEqualTo(Tag.EVAL_PAGE);
    assertThat(message.toString()).as("Correct message").isEqualTo("test message");
}
Also used : PageContext(jakarta.servlet.jsp.PageContext) Test(org.junit.jupiter.api.Test)

Example 19 with PageContext

use of jakarta.servlet.jsp.PageContext in project spring-framework by spring-projects.

the class MessageTagTests method messageTagWithCodeAndText.

@Test
void messageTagWithCodeAndText() throws JspException {
    PageContext pc = createPageContext();
    final StringBuilder message = new StringBuilder();
    MessageTag tag = new MessageTag() {

        @Override
        protected void writeMessage(String msg) {
            message.append(msg);
        }
    };
    tag.setPageContext(pc);
    tag.setCode("test");
    tag.setText("testtext");
    assertThat(tag.doStartTag() == Tag.EVAL_BODY_INCLUDE).as("Correct doStartTag return value").isTrue();
    assertThat(tag.doEndTag()).as("Correct doEndTag return value").isEqualTo(Tag.EVAL_PAGE);
    assertThat((message.toString())).as("Correct message").isEqualTo("test message");
}
Also used : PageContext(jakarta.servlet.jsp.PageContext) Test(org.junit.jupiter.api.Test)

Example 20 with PageContext

use of jakarta.servlet.jsp.PageContext in project spring-framework by spring-projects.

the class ThemeTagTests method themeTag.

@Test
@SuppressWarnings("serial")
void themeTag() throws JspException {
    PageContext pc = createPageContext();
    final StringBuilder message = new StringBuilder();
    ThemeTag tag = new ThemeTag() {

        @Override
        protected void writeMessage(String msg) {
            message.append(msg);
        }
    };
    tag.setPageContext(pc);
    tag.setCode("themetest");
    assertThat(tag.doStartTag() == Tag.EVAL_BODY_INCLUDE).as("Correct doStartTag return value").isTrue();
    assertThat(tag.doEndTag()).as("Correct doEndTag return value").isEqualTo(Tag.EVAL_PAGE);
    assertThat(message.toString()).isEqualTo("theme test message");
}
Also used : PageContext(jakarta.servlet.jsp.PageContext) Test(org.junit.jupiter.api.Test)

Aggregations

PageContext (jakarta.servlet.jsp.PageContext)70 Test (org.junit.jupiter.api.Test)62 IndexedTestBean (org.springframework.beans.testfixture.beans.IndexedTestBean)28 NestedTestBean (org.springframework.beans.testfixture.beans.NestedTestBean)27 TestBean (org.springframework.beans.testfixture.beans.TestBean)27 ServletRequestDataBinder (org.springframework.web.bind.ServletRequestDataBinder)22 BindStatus (org.springframework.web.servlet.support.BindStatus)19 Errors (org.springframework.validation.Errors)17 DateFormat (java.text.DateFormat)6 SimpleDateFormat (java.text.SimpleDateFormat)6 CustomDateEditor (org.springframework.beans.propertyeditors.CustomDateEditor)6 JspContext (jakarta.servlet.jsp.JspContext)4 DefaultMessageSourceResolvable (org.springframework.context.support.DefaultMessageSourceResolvable)3 BeforeEach (org.junit.jupiter.api.BeforeEach)2 MessageSourceResolvable (org.springframework.context.MessageSourceResolvable)2 RequestContext (org.springframework.web.servlet.support.RequestContext)2 MockServletContext (org.springframework.web.testfixture.servlet.MockServletContext)2 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)1 JspException (jakarta.servlet.jsp.JspException)1 FeatureDescriptor (java.beans.FeatureDescriptor)1