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.myfaces.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 public void testInline() throws IOException
68 {
69 stylesheet.setInline(true);
70 stylesheet.setPath("/styles/test.css");
71 stylesheet.encodeEnd(facesContext);
72 facesContext.renderResponse();
73
74 String output = writer.getWriter().toString();
75
76 assertTrue("looking for a <style>", output.trim().startsWith("<style"));
77 }
78
79
80
81
82 public void testInlineInvalid() throws IOException
83 {
84 stylesheet.setInline(true);
85 try
86 {
87 stylesheet.encodeEnd(facesContext);
88 fail("No exception was thrown for an invalid stylesheet path");
89 }
90 catch(FacesException e)
91 {
92
93 }
94 }
95
96 public void testLink() throws IOException
97 {
98
99 stylesheet.encodeEnd(facesContext);
100 facesContext.renderResponse();
101
102 String output = writer.getWriter().toString();
103
104 assertTrue("looking for a <link>", output.trim().startsWith("<link"));
105 }
106
107 }