|
6 | 6 | import freemarker.template.TemplateException;
|
7 | 7 | import org.javalite.activejdbc.test.ActiveJDBCTest;
|
8 | 8 | import org.javalite.activejdbc.test_models.Person;
|
| 9 | +import org.javalite.activejdbc.test_models.Student; |
9 | 10 | import org.junit.Before;
|
10 | 11 | import org.junit.Test;
|
11 | 12 |
|
@@ -33,7 +34,7 @@ public void beforeTest(){
|
33 | 34 |
|
34 | 35 |
|
35 | 36 | @Test
|
36 |
| - public void shouldRenderSingleIntance() throws IOException, TemplateException { |
| 37 | + public void shouldRenderSingleInstance() throws IOException, TemplateException { |
37 | 38 | deleteAndPopulateTable("people");
|
38 | 39 |
|
39 | 40 | Person smith = Person.findFirst("last_name = ?", "Smith");
|
@@ -75,39 +76,34 @@ public void shouldRenderList() throws IOException, TemplateException {
|
75 | 76 |
|
76 | 77 | @Test
|
77 | 78 | public void shouldRenderRowProcessor() throws IOException, TemplateException {
|
78 |
| - deleteAndPopulateTable("people"); |
| 79 | + deleteAndPopulateTable("students"); |
79 | 80 |
|
80 |
| - Person smith = Person.findFirst("last_name = ?", "Smith"); |
81 |
| - smith.set("graduation_date", null).saveIt(); |
| 81 | + Student cary = Student.findFirst("last_name = ?", "Cary"); |
| 82 | + cary.set("enrollment_date", null).saveIt(); |
82 | 83 |
|
83 |
| - List<Map> people = new ArrayList<>(); |
84 |
| - Base.find("select * from people order by id").with(new RowListenerAdapter() { |
| 84 | + List<Map> students = new ArrayList<>(); |
| 85 | + Base.find("select * from students order by id").with(new RowListenerAdapter() { |
85 | 86 | @Override
|
86 | 87 | public void onNext(Map<String, Object> row) {
|
87 |
| - people.add(row); |
| 88 | + students.add(row); |
88 | 89 | }
|
89 | 90 | });
|
90 | 91 |
|
91 |
| - |
92 |
| - Template template = config.getTemplate("src/test/resources/list.ftl"); |
| 92 | + Template template = config.getTemplate("src/test/resources/list_row.ftl"); |
93 | 93 |
|
94 | 94 | StringWriter writer = new StringWriter();
|
95 |
| - template.process(map("people", people), writer); |
| 95 | + template.process(map("students", students), writer); |
96 | 96 | String processedTemplate = writer.toString().trim();
|
97 | 97 | if(System.getProperty("os.name").contains("indows")) {
|
98 | 98 | processedTemplate = processedTemplate.replaceAll("\r\n", "\n");
|
99 | 99 | }
|
100 | 100 |
|
101 | 101 | if(driver().equals("org.sqlite.JDBC")){
|
102 |
| - the(processedTemplate).shouldBeEqual("Person: John Smith, graduation date: \n" + |
103 |
| - "Person: Leylah Jonston, graduation date: 1974-04-03\n" + |
104 |
| - "Person: Muhammad Ali, graduation date: 1963-01-04\n" + |
105 |
| - "Person: Joe Pesci, graduation date: 1964-02-23"); |
| 102 | + the(processedTemplate).shouldBeEqual("Student: Jim Cary, enrollment date:\n" + |
| 103 | + "Student: John Carpenter, enrollment date: 1987-01-29 13:00:00"); |
106 | 104 | }else {
|
107 |
| - the(processedTemplate).shouldBeEqual("Person: John Smith, graduation date: \n" + |
108 |
| - "Person: Leylah Jonston, graduation date: Apr 3, 1974\n" + |
109 |
| - "Person: Muhammad Ali, graduation date: Jan 4, 1963\n" + |
110 |
| - "Person: Joe Pesci, graduation date: Feb 23, 1964"); |
| 105 | + the(processedTemplate).shouldBeEqual("Student: Jim Cary, enrollment date:\n" + |
| 106 | + "Student: John Carpenter, enrollment date: Jan 29, 1987 1:00:00 PM"); |
111 | 107 | }
|
112 | 108 | }
|
113 | 109 | }
|
0 commit comments