1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.turbine.modules;
21
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.fail;
24 import static org.mockito.Mockito.mock;
25
26 import javax.servlet.ServletConfig;
27 import javax.servlet.http.HttpServletRequest;
28 import javax.servlet.http.HttpServletResponse;
29
30 import org.apache.turbine.modules.layouts.TestVelocityOnlyLayout;
31 import org.apache.turbine.pipeline.PipelineData;
32 import org.apache.turbine.test.BaseTestCase;
33 import org.apache.turbine.util.RunData;
34 import org.apache.turbine.util.TurbineConfig;
35 import org.junit.AfterClass;
36 import org.junit.Before;
37 import org.junit.BeforeClass;
38 import org.junit.Test;
39
40
41
42
43 public class LayoutLoaderTest extends BaseTestCase
44 {
45 private static TurbineConfig tc = null;
46 private ServletConfig config = null;
47 private HttpServletRequest request = null;
48 private HttpServletResponse response = null;
49
50 @BeforeClass
51 public static void init()
52 {
53 tc = new TurbineConfig(
54 ".",
55 "/conf/test/CompleteTurbineResources.properties");
56 tc.initialize();
57 }
58
59 @Before
60 public void setUpBefore() throws Exception
61 {
62 config = mock(ServletConfig.class);
63 request = getMockRequest();
64 response = mock(HttpServletResponse.class);
65 }
66
67
68
69
70 @AfterClass
71 public static void tearDown() throws Exception
72 {
73 if (tc != null)
74 {
75 tc.dispose();
76 }
77 }
78
79 @Test
80 public void testPipelineDataContainsRunData()
81 {
82 try
83 {
84 RunData data = getRunData(request, response, config);
85 PipelineData pipelineData = data;
86 data.setLayout("TestVelocityOnlyLayout");
87 int numberOfCalls = TestVelocityOnlyLayout.numberOfCalls;
88 try
89 {
90 LayoutLoader.getInstance().exec(pipelineData, data.getLayout());
91 }
92 catch (Exception e)
93 {
94 e.printStackTrace();
95 fail("Should not have thrown an exception.");
96 }
97 assertEquals(numberOfCalls + 1, TestVelocityOnlyLayout.numberOfCalls);
98 }
99 catch (Exception e)
100 {
101 e.printStackTrace();
102 fail("Should not have thrown an exception.");
103 }
104 }
105
106 @Test
107 public void testDoBuildWithRunData()
108 {
109 try
110 {
111 RunData data = getRunData(request, response, config);
112 data.setLayout("TestVelocityOnlyLayout");
113 int numberOfCalls = TestVelocityOnlyLayout.numberOfCalls;
114 try
115 {
116 LayoutLoader.getInstance().exec(data, data.getLayout());
117 }
118 catch (Exception e)
119 {
120 e.printStackTrace();
121 fail("Should not have thrown an exception.");
122 }
123 assertEquals(numberOfCalls + 1, TestVelocityOnlyLayout.numberOfCalls);
124 }
125 catch (Exception e)
126 {
127 e.printStackTrace();
128 fail("Should not have thrown an exception.");
129 }
130 }
131 }