KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > bean > CocoonBeanTestCase


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.bean;
17
18 import java.io.ByteArrayOutputStream JavaDoc;
19
20 import org.apache.cocoon.bean.helpers.OutputStreamListener;
21
22 import junit.framework.TestCase;
23
24 /**
25  * <p>Test case for the CocoonBean.</p>
26  *
27  * <p>To function correctly, this test case expects a built webapp at
28  * <code>build/webapp/</code>, which includes the test-suite
29  * within it. Ensure this is included in build.properties by
30  * commenting out <code>exclude.webapp.test-suite=true</code>.</p>
31  *
32  * @version CVS $Id: CocoonBeanTestCase.java 30932 2004-07-29 17:35:38Z vgritsenko $
33  */

34 public class CocoonBeanTestCase extends TestCase {
35
36     /**
37      * Constructor for CocoonBeanTest.
38      * @param arg0
39      */

40     public CocoonBeanTestCase(String JavaDoc arg0) {
41         super(arg0);
42         
43     }
44     
45     public void testProcessToStream() throws Exception JavaDoc {
46         CocoonBean cocoon = getCocoonBean();
47         ByteArrayOutputStream JavaDoc baos = new ByteArrayOutputStream JavaDoc();
48         cocoon.processURI("test-suite/static-site/index.html", baos);
49         String JavaDoc result = baos.toString();
50         assertEquals(1603, result.length());
51         assertTrue(result.indexOf("Cocoon TestSuite")>-1);
52         assertTrue(result.indexOf("<h1>General information</h1>")>-1);
53         cocoon.dispose();
54     }
55     
56     private CocoonBean getCocoonBean() throws Exception JavaDoc {
57         CocoonBean cocoon = new CocoonBean();
58         cocoon.setContextDir("build/webapp");
59         cocoon.setConfigFile("WEB-INF/cocoon.xconf");
60         cocoon.setPrecompileOnly(false);
61         cocoon.setWorkDir("build/work");
62         cocoon.setLogKit("build/webapp/WEB-INF/logkit.xconf");
63         cocoon.setLogger("cli-test");
64         cocoon.setLogLevel("DEBUG");
65         //cocoon.setAgentOptions(*something*));
66
//cocoon.setAcceptOptions(*something*);
67
//cocoon.setDefaultFilename(*something*);
68
//listener.setReportFile(*something*);
69
cocoon.setFollowLinks(true);
70         cocoon.setConfirmExtensions(false);
71         //cocoon.addLoadedClasses(Arrays.asList(*something*));
72
//cocoon.addTargets(BeanConfigurator.processURIFile(*some file*), destDir);
73
cocoon.addListener(new OutputStreamListener(System.out));
74         cocoon.initialize();
75         return cocoon;
76     }
77 }
78
Popular Tags