KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > examples > HelloSnipMacroExample


1 /*
2  * This file is part of "SnipSnap Radeox Rendering Engine".
3  *
4  * Copyright (c) 2002 Stephan J. Schmidt, Matthias L. Jugel
5  * All Rights Reserved.
6  *
7  * Please visit http://radeox.org/ for updates and contact.
8  *
9  * --LICENSE NOTICE--
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with this library; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23  * --LICENSE NOTICE--
24  */

25
26 package examples;
27
28 import junit.framework.Test;
29 import junit.framework.TestCase;
30 import junit.framework.TestSuite;
31 import org.radeox.macro.Macro;
32 import org.radeox.api.engine.context.RenderContext;
33 import org.snipsnap.render.context.SnipRenderContext;
34 import org.snipsnap.render.macro.parameter.SnipMacroParameter;
35 import org.snipsnap.snip.Snip;
36 import org.snipsnap.snip.SnipImpl;
37 import org.snipsnap.snip.SnipSpace;
38 import org.snipsnap.test.mock.MockSnipSpace;
39
40 import java.io.IOException JavaDoc;
41 import java.io.StringWriter JavaDoc;
42
43 /**
44  * Example which shows howto get the Snip from the context.
45  *
46  * @author Stephan J. Schmidt
47  * @version $Id: HelloSnipMacroExample.java 1606 2004-05-17 10:56:18Z leo $
48  */

49
50 public class HelloSnipMacroExample extends TestCase {
51
52   public HelloSnipMacroExample(String JavaDoc name) {
53     super(name);
54   }
55
56   protected void setUp() throws Exception JavaDoc {
57     super.setUp();
58   }
59
60   public static Test suite() {
61     return new TestSuite(HelloSnipMacroExample.class);
62   }
63
64   public void testHelloSnipMacro() {
65     SnipSpace space = new MockSnipSpace();
66     Snip snip = new SnipImpl("HelloSnip","HelloSnip");
67
68     RenderContext context = new SnipRenderContext(snip, space);
69     SnipMacroParameter parameter = new SnipMacroParameter(context);
70
71     Macro macro = new HelloSnipMacro();
72     StringWriter JavaDoc writer = new StringWriter JavaDoc();
73     try {
74       macro.execute(writer, parameter);
75     } catch (IllegalArgumentException JavaDoc e) {
76       e.printStackTrace();
77
78     } catch (IOException JavaDoc e) {
79       e.printStackTrace();
80     }
81     assertEquals("HelloSnipMacro renders correct.", "hello", writer.toString());
82   }
83 }
84
Popular Tags