1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.myfaces.custom.stylesheet;
21
22 import java.io.IOException;
23 import java.io.StringWriter;
24
25 import javax.faces.FacesException;
26
27 import junit.framework.Test;
28
29 import org.apache.myfaces.test.AbstractTomahawkViewControllerTestCase;
30 import org.apache.shale.test.mock.MockResponseWriter;
31
32 public class StylesheetRendererTest extends AbstractTomahawkViewControllerTestCase
33 {
34
35 private MockResponseWriter writer ;
36 private Stylesheet stylesheet ;
37
38 public StylesheetRendererTest(String name)
39 {
40 super(name);
41 }
42
43 protected void setUp() throws Exception
44 {
45 super.setUp();
46 stylesheet = new Stylesheet();
47 stylesheet.setPath("test.css");
48 stylesheet.setMedia("printer");
49 writer = new MockResponseWriter(new StringWriter(), null, null);
50 facesContext.setResponseWriter(writer);
51
52
53
54
55 }
56
57 protected void tearDown() throws Exception
58 {
59 super.tearDown();
60 writer = null;
61 stylesheet = null;
62 }
63
64
65
66
67
68
69
70
71
72
73 public void testInline() throws IOException
74 {
75 stylesheet.setInline(true);
76 stylesheet.setPath("/styles/test.css");
77 stylesheet.encodeEnd(facesContext);
78 facesContext.renderResponse();
79
80 String output = writer.getWriter().toString();
81
82 assertTrue("looking for a <style>", output.trim().startsWith("<style"));
83 }
84
85
86
87
88 public void testInlineInvalid() throws IOException
89 {
90 stylesheet.setInline(true);
91 try
92 {
93 stylesheet.encodeEnd(facesContext);
94 fail("No exception was thrown for an invalid stylesheet path");
95 }
96 catch(FacesException e)
97 {
98
99 }
100 }
101
102 public void testLink() throws IOException
103 {
104
105 stylesheet.encodeEnd(facesContext);
106 facesContext.renderResponse();
107
108 String output = writer.getWriter().toString();
109
110 assertTrue("looking for a <link>", output.trim().startsWith("<link"));
111 }
112
113 }