Class AbstractViewElementTemplateTest

java.lang.Object
com.foreach.across.test.support.AbstractViewElementTemplateTest

@DirtiesContext @WebAppConfiguration("classpath:") @SpringJUnitConfig(classes=Config.class) public abstract class AbstractViewElementTemplateTest extends Object
Base integration test class for testing ViewElement rendering using Thymeleaf. This bootstraps an AcrossContext with web support and the WebTestModule enabled.

Will generate the output by running through the entire view resolving/Thymeleaf template stack and allows xml assertion to be used on the generated result, thus ignoring whitespace and attribute ordering.

See the renderAndExpect(Object, java.lang.String) method.

  • Field Details

    • CUSTOM_TEMPLATE

      public static final String CUSTOM_TEMPLATE
      Constants pointing to a custom template in across test library, along with the expected output if the template is being used.
      See Also:
    • CUSTOM_TEMPLATE_OUTPUT

      public static final String CUSTOM_TEMPLATE_OUTPUT
      See Also:
  • Constructor Details

    • AbstractViewElementTemplateTest

      public AbstractViewElementTemplateTest()
  • Method Details

    • initMvc

      @BeforeEach public void initMvc()
    • setCallback

      protected void setCallback(RenderViewElementController.Callback callback)

      Set the callback method to be called before rendering the view element. If set this way, the callback will be used for every test method. See renderAndExpect(Object, RenderViewElementController.Callback, String) to execute a callback a single time only.

      Set to null to remove the callback.

      Parameters:
      callback - to be executed before rendering
    • setTemplate

      protected void setTemplate(String template)
      Set a custom Thymeleaf template that should be used for rendering.
      Parameters:
      template - to use
    • renderAndExpect

      public void renderAndExpect(Object viewElement, String expectedContent)
      Renders a single ViewElement by dispatching it to the render controller. Verifies the generated content by using xml comparison.
      Parameters:
      viewElement - element to render
      expectedContent - xml body that should be generated
    • renderAndExpect

      public void renderAndExpect(Object viewElement, RenderViewElementController.Callback callback, String expectedContent)
      Renders a single ViewElement by dispatching it to the render controller. Verifies the generated content by using xml comparison.
      Parameters:
      viewElement - element to render
      callback - to be executed before rendering
      expectedContent - xml body that should be generated
    • render

      public String render(ViewElement viewElement)
      Returns:
      output that was rendered
    • render

      public String render(ViewElement viewElement, RenderViewElementController.Callback callback)
      Returns:
      output that was rendered
    • allowedXmlEntities

      protected Collection<String> allowedXmlEntities()
      Override this method to define the named entities that can be referenced in the xml.