1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.templating.jsp.cms;
35
36 import static org.hamcrest.CoreMatchers.containsString;
37 import static org.junit.Assert.*;
38
39 import info.magnolia.jcr.util.NodeTypes;
40 import info.magnolia.rendering.template.configured.ConfiguredAreaDefinition;
41 import info.magnolia.rendering.template.configured.ConfiguredTemplateDefinition;
42 import info.magnolia.rendering.template.variation.DefaultRenderableVariationResolver;
43 import info.magnolia.rendering.template.variation.RenderableVariationResolver;
44 import info.magnolia.templating.jsp.AbstractTagTestCase;
45 import info.magnolia.test.ComponentsTestUtil;
46
47 import javax.jcr.Node;
48
49 import org.junit.Before;
50 import org.junit.Test;
51
52 import com.meterware.httpunit.GetMethodWebRequest;
53 import com.meterware.httpunit.WebRequest;
54 import com.meterware.httpunit.WebResponse;
55
56
57
58
59 public class AreaBarTagTest extends AbstractTagTestCase {
60
61 private String jspUrl;
62
63 @Override
64 @Before
65 public void setUp() throws Exception {
66 super.setUp();
67 String jspPath = getClass().getName().replace('.', '/') + ".jsp";
68 jspUrl = "http://localhost" + CONTEXT + "/" + jspPath;
69
70 ConfiguredTemplateDefinition renderableDefinition = new ConfiguredTemplateDefinition();
71 ConfiguredAreaDefinition areaDefinition = new ConfiguredAreaDefinition();
72 renderableDefinition.addArea("stage", areaDefinition);
73 setRenderableDefinition(renderableDefinition);
74
75 ComponentsTestUtil.setImplementation(RenderableVariationResolver.class, DefaultRenderableVariationResolver.class);
76 }
77
78 @Test
79 public void testRenderSimpleBarWithoutAreaNode() throws Exception {
80
81 final WebRequest request = new GetMethodWebRequest(jspUrl);
82 final WebResponse response = runner.getResponse(request);
83
84
85 final String responseStr = response.getText();
86
87
88 assertNotNull(responseStr);
89 assertThat(
90 responseStr,
91 containsString("<!-- cms:area content=\"website:/foo/bar/paragraphs/1/stage\" name=\"stage\" availableComponents=\"\" type=\"list\" "
92 + "label=\"Stage\" inherit=\"false\" optional=\"false\" showAddButton=\"true\" showNewComponentArea=\"true\" -->"));
93 }
94
95 @Test
96 public void testRenderSimpleBar() throws Exception {
97
98 Node paragraph1 = getSession().getNode("/foo/bar/paragraphs/1");
99
100 paragraph1.addNode("stage", NodeTypes.Area.NAME);
101
102 final WebRequest request = new GetMethodWebRequest(jspUrl);
103 final WebResponse response = runner.getResponse(request);
104
105
106 final String responseStr = response.getText();
107
108
109 assertNotNull(responseStr);
110 assertThat(
111 responseStr,
112 containsString("<!-- cms:area content=\"website:/foo/bar/paragraphs/1/stage\" name=\"stage\" availableComponents=\"\" type=\"list\" "
113 + "label=\"Stage\" inherit=\"false\" optional=\"false\" showAddButton=\"true\" showNewComponentArea=\"true\" -->"));
114
115 }
116
117 }