Unit testing freemarker templates




















It also allows for really easy separation of view and server technologies. So first, I assume that the reader already knows how to set up an annotation-driven Spring project. Lets create a controller that interacts with Person objects. However, by default it expects very specific URLs and very specific request methods. Thankfully, there are also a lot of configuration options that are built into this class, and we can modify it to fit our purposes. Now that everything is in order, we can simply hook it up to a ListGrid and edit, add, and delete rows and it will work successfully with our controller.

Code is Sexy Code Examples and More…. Skip to content. Home About. Tag: import java. IOException; import javax. Vector; import javax. ServletConfig; import freemarker. ServletTester; import org.

After; import org. Pianobar not picking up config file Posted on May 25, by vkubushyn. Posted in Random Tagged config , config file , pandora , pianobar , properties Leave a comment. The test renders the freemarker template using some mock information. I would like to render the template to an external file so that I can eyeball the results make sure the html is aligned, etc.

I am using a traditional maven project structure for this project. Does anyone have any suggestions on what would be the most appropriate directory to output this temporary test file from my unit test?

You can then clean it up as part of mvn clean. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Unit testing Freemarker template Ask Question. Asked 8 years, 3 months ago. Active 8 years, 3 months ago. Viewed times. Note that the root "src" is not included in it. We create a Configuration and set its template root directory.

Using that Configuration instance, we can build some templates, by calling its getTemplate method. Here, we are making our dummy template. Note that this template is not yet trnasformed into html. This will come after. This map must contain all the necessary information used by our macro, like the total number of pages and the current page. This information will be set in the test methods.

Unit testing Each test will be executed with the following steps: Set the information used by the pagination macro in the root map. Make FreeMarker generate html from our template. Feed HtmlUnit with our html to generate an HtmlPage instance. Declare some expectations, like the expected anchor tags representing page numbers. Get the anchor tags present in the pagination div and compare them to the expected ones.

Assert that the current page is present and is not a link. Remember the Template instance we created above? We'll use it to generate html. The method used for this is process Map, Writer. We'll output the html content into a StringWriter. The reason is that we want to use the output to generate an HtmlUnit HtmlPage.



0コメント

  • 1000 / 1000