01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.bean;
18:
19: import java.io.ByteArrayOutputStream;
20:
21: import org.apache.cocoon.bean.helpers.OutputStreamListener;
22:
23: import junit.framework.TestCase;
24:
25: /**
26: * <p>Test case for the CocoonBean.</p>
27: *
28: * <p>To function correctly, this test case expects a built webapp at
29: * <code>build/webapp/</code>, which includes the test-suite
30: * within it. Ensure this is included in build.properties by
31: * commenting out <code>exclude.webapp.test-suite=true</code>.</p>
32: *
33: * @version CVS $Id: CocoonBeanTestCase.java 433543 2006-08-22 06:22:54Z crossley $
34: */
35: public class CocoonBeanTestCase extends TestCase {
36:
37: /**
38: * Constructor for CocoonBeanTest.
39: * @param arg0
40: */
41: public CocoonBeanTestCase(String arg0) {
42: super (arg0);
43:
44: }
45:
46: public void testProcessToStream() throws Exception {
47: CocoonBean cocoon = getCocoonBean();
48: ByteArrayOutputStream baos = new ByteArrayOutputStream();
49: cocoon.processURI("test-suite/static-site/index.html", baos);
50: String result = baos.toString();
51: assertEquals(1603, result.length());
52: assertTrue(result.indexOf("Cocoon TestSuite") > -1);
53: assertTrue(result.indexOf("<h1>General information</h1>") > -1);
54: cocoon.dispose();
55: }
56:
57: private CocoonBean getCocoonBean() throws Exception {
58: CocoonBean cocoon = new CocoonBean();
59: cocoon.setContextDir("build/webapp");
60: cocoon.setConfigFile("WEB-INF/cocoon.xconf");
61: cocoon.setPrecompileOnly(false);
62: cocoon.setWorkDir("build/work");
63: cocoon.setLogKit("build/webapp/WEB-INF/logkit.xconf");
64: cocoon.setLogger("cli-test");
65: cocoon.setLogLevel("DEBUG");
66: //cocoon.setAgentOptions(*something*));
67: //cocoon.setAcceptOptions(*something*);
68: //cocoon.setDefaultFilename(*something*);
69: //listener.setReportFile(*something*);
70: cocoon.setFollowLinks(true);
71: cocoon.setConfirmExtensions(false);
72: //cocoon.addLoadedClasses(Arrays.asList(*something*));
73: //cocoon.addTargets(BeanConfigurator.processURIFile(*some file*), destDir);
74: cocoon.addListener(new OutputStreamListener(System.out));
75: cocoon.initialize();
76: return cocoon;
77: }
78: }
|