01: /*
02: * Copyright 2007 Gerd Ziegler (www.gerdziegler.de)
03: * Licensed under the Apache License, Version 2.0 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at
06: * http://www.apache.org/licenses/LICENSE-2.0
07: * Unless required by applicable law or agreed to in writing,
08: * software distributed under the License is distributed on an
09: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
10: * either express or implied. See the License for the specific
11: * language governing permissions and limitations under the License.
12: * 22.09.2007
13: * @author www.gerdziegler.de
14: */
15: package org.ztemplates.test.render.css;
16:
17: import java.util.Properties;
18:
19: import junit.framework.TestCase;
20:
21: import org.apache.log4j.Logger;
22: import org.apache.velocity.app.Velocity;
23: import org.ztemplates.classpath.ZClassRepository;
24: import org.ztemplates.classpath.ZIClassRepository;
25: import org.ztemplates.render.ZRenderEngine;
26: import org.ztemplates.render.ZRenderEnvironment;
27: import org.ztemplates.web.css.ZCssEngine;
28:
29: public class CssTest extends TestCase {
30: static Logger log = Logger.getLogger(CssTest.class);
31:
32: private ZIClassRepository classes;
33:
34: protected void setUp() throws Exception {
35: super .setUp();
36: classes = new ZClassRepository(CssTest.class.getPackage()
37: .getName());
38:
39: Properties prop = new Properties();
40: prop.put("resource.loader", "classpath");
41: prop
42: .put("classpath.resource.loader.class",
43: "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
44: Velocity.init(prop);
45: }
46:
47: protected void tearDown() throws Exception {
48: super .tearDown();
49: classes = null;
50: }
51:
52: public void testCssId() throws Exception {
53: ZRenderEnvironment templateUtil = new ZRenderEnvironment(
54: classes);
55:
56: String cssId = templateUtil.computeCssId(Css1.class);
57: assertEquals("Css1", cssId);
58: }
59:
60: public void testMergeCss() throws Exception {
61: ZCssEngine cssFact = new ZCssEngine(new ZRenderEnvironment(
62: classes));
63: String css = cssFact.getCss();
64: assertTrue(css, css.indexOf("Css1") >= 0);
65: }
66:
67: public void testMergeCss1() throws Exception {
68: ZCssEngine cssFact = new ZCssEngine(new ZRenderEnvironment(
69: classes));
70: String css = cssFact.getCss();
71: assertTrue(css, css.indexOf("#Css1-bg") >= 0);
72: }
73:
74: public void testRenderTemplate() throws Exception {
75: ZRenderEngine re = new ZRenderEngine(new ZRenderEnvironment(
76: classes));
77: Css1 css1 = new Css1();
78: String merged = re.render(css1);
79: assertTrue(merged, merged.indexOf("Css1") >= 0);
80: }
81: }
|