You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Stephan Coboos <cr...@gmx.net> on 2006/02/23 09:19:01 UTC

UnitTesting: callFunction is not working!

Hi,

I tried out the method callFunction() of SitemapComponentTestCase for Unit
testing some of my flowscript functions but on execution of the test case
class I got the error message below:

===============================================================

org.apache.avalon.framework.CascadingRuntimeException: Cannot get sitemap
service manager
	at
org.apache.cocoon.components.flow.javascript.fom.FOM_Cocoon.pushCallContext(
FOM_Cocoon.java:228)
	at
org.apache.cocoon.components.flow.javascript.fom.FOM_JavaScriptInterpreter.s
etupContext(FOM_JavaScriptInterpreter.java:571)
	at
org.apache.cocoon.components.flow.javascript.fom.FOM_JavaScriptInterpreter.c
allFunction(FOM_JavaScriptInterpreter.java:718)
	at
org.apache.cocoon.SitemapComponentTestCase.callFunction(SitemapComponentTest
Case.java:479)
	at
foo.bar.testing.flow.FlowscriptTestCase.testFooFunction(FlowscriptTestCase.j
ava:13)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at junit.framework.TestCase.runTest(TestCase.java:154)
	at junit.framework.TestCase.runBare(TestCase.java:127)
	at junit.framework.TestResult$1.protect(TestResult.java:106)
	at junit.framework.TestResult.runProtected(TestResult.java:124)
	at junit.framework.TestResult.run(TestResult.java:109)
	at junit.framework.TestCase.run(TestCase.java:118)
	at junit.framework.TestSuite.runTest(TestSuite.java:208)
	at junit.framework.TestSuite.run(TestSuite.java:203)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRu
nner.java:478)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.
java:344)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner
.java:196)
Caused by: org.apache.avalon.framework.context.ContextException: Unable to
resolve context key: sitemap-service-manager
	at
org.apache.avalon.framework.context.DefaultContext.get(DefaultContext.java:1
18)
	at
org.apache.cocoon.components.flow.javascript.fom.FOM_Cocoon.pushCallContext(
FOM_Cocoon.java:226)
	... 19 more


====================================================================

How can I set such a sitemap service manager key? Is there a mock class
availbale for this?

My xtext configuration looks like this (Is there something wrong?):

====================================================================

<?xml version="1.0" ?>
<testcase>


    <context>
        <entry name="environment-context"
class="org.apache.cocoon.environment.mock.MockContext" />
    </context>

    <roles>

        <role name="org.apache.cocoon.components.flow.Interpreter"
shorthand="flow-interpreters"
 
default-class="org.apache.cocoon.components.ExtendedComponentSelector" />

        <role name="org.apache.cocoon.components.flow.ContinuationsManager"
shorthand="continuations-manager"
 
default-class="org.apache.cocoon.components.flow.ContinuationsManagerImpl"
/>

        <!-- Running commands (Runnable) in background -->
        <role
default-class="org.apache.cocoon.components.thread.DefaultRunnableManager"
shorthand="runnable-manager"
            name="org.apache.cocoon.components.thread.RunnableManager" />

        <role name="org.apache.excalibur.source.SourceFactorySelector"
shorthand="source-factories"
 
default-class="org.apache.avalon.excalibur.component.ExcaliburComponentSelec
tor" />

        <role name="org.apache.excalibur.source.SourceResolver"
shorthand="source-resolver"
 
default-class="org.apache.excalibur.source.impl.SourceResolverImpl" />

    </roles>


    <components>

        <source-factories>
            <component-instance
class="org.apache.excalibur.source.impl.ResourceSourceFactory"
name="resource" />
            <component-instance
class="org.apache.excalibur.source.impl.URLSourceFactory" name="*" />
        </source-factories>

        <source-resolver
class="org.apache.excalibur.source.impl.SourceResolverImpl" />

        <!-- Register the necessary flow interpreters -->
        <flow-interpreters default="javascript" logger="flow">
            <!-- FOM (Flow Object Model) -->
            <component-instance
class="org.apache.cocoon.components.flow.javascript.fom.FOM_JavaScriptInterp
reter" name="javascript">
 
<load-on-startup>resource://org/apache/cocoon/components/flow/javascript/fom
/fom_system.js</load-on-startup>
                <reload-scripts>true</reload-scripts>
                <check-time>4000</check-time>
                <!--  <debugger>enabled</debugger> --><!-- JavaScript
Debugger support -->
            </component-instance>
        </flow-interpreters>

        <!-- Copied from cocoon.xconf -->
        <continuations-manager continuation-sharing-bug-compatible="false"
logger="flow.manager" session-bound-continuations="false"
            time-to-live="3600000">
            <expirations-check type="periodic">
                <offset>180000</offset>
                <period>180000</period>
            </expirations-check>
        </continuations-manager>


        <runnable-manager logger="core.runnable">

 
<thread-factory>org.apache.cocoon.components.thread.DefaultThreadFactory</th
read-factory>
            <thread-pools>
                <!--+
                    | This is the default thread pool. It's use fits best
for short
                    | running background tasks.
                    +-->
                <thread-pool>
                    <name>default</name>
                    <priority>NORM</priority>
                    <daemon>false</daemon>
                    <queue-size>-1</queue-size>
                    <max-pool-size>5</max-pool-size>
                    <min-pool-size>5</min-pool-size>
                    <keep-alive-time-ms>60000</keep-alive-time-ms>
                    <block-policy>ABORT</block-policy>
                    <shutdown-graceful>false</shutdown-graceful>
                    <shutdown-wait-time-ms>-1</shutdown-wait-time-ms>
                </thread-pool>
                <!--+
                    | This thread pool should be used for daemons
(permanently running
                    | threads).
                    +-->
                <thread-pool>
                    <name>daemon</name>
                    <priority>NORM</priority>
                    <daemon>true</daemon>
                    <queue-size>0</queue-size>
                    <max-pool-size>-1</max-pool-size>
                    <min-pool-size>1</min-pool-size>
                    <keep-alive-time-ms>60000</keep-alive-time-ms>
                    <block-policy>ABORT</block-policy>
                    <shutdown-graceful>false</shutdown-graceful>
                    <shutdown-wait-time-ms>-1</shutdown-wait-time-ms>
                </thread-pool>
            </thread-pools>
        </runnable-manager>
    </components>
</testcase>

======================================================================
My TestCase class:
======================================================================

package foo.bar.testing.flow;

import java.util.HashMap;

import org.apache.cocoon.SitemapComponentTestCase;

public class FlowscriptTestCase extends SitemapComponentTestCase {

	public void testFooFunction() throws Exception {
		this.callFunction("javascript", "E:/myFlowscript.js", "foo",
new HashMap());
	}	
}

======================================================================
My Flowscript:
======================================================================

function foo() {

    print("Hello World!");
}

======================================================================

Thank you for your help.

Regards
Stephan




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org