Package org.apache.agila.impl

Source Code of org.apache.agila.impl.NodeContextImplTestCase

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


package org.apache.agila.impl;

import junit.framework.TestCase;
import org.apache.agila.services.TimerService;
import org.apache.agila.services.notification.NotificationService;
import org.apache.agila.services.task.TaskService;
import org.apache.agila.impl.memory.TimerServiceImpl;
import org.apache.agila.impl.memory.TaskServiceImpl;
import org.apache.agila.impl.memory.NotificationServiceImpl;
import org.apache.agila.model.node.HelloWorldActivity;
import org.apache.agila.model.Binding;
import org.apache.agila.model.Node;

import java.util.Map;
import java.util.HashMap;

public class NodeContextImplTestCase extends TestCase {

    private NodeContextImpl context;
    private Node node;

    public void testJexlResolver() {
        String expression = "n1 + n2 + n3";
        Map vars = new HashMap();
        vars.put( "n1", new Integer( 5 ) );
        vars.put( "n2", new Integer( 6 ) );
        vars.put( "n3", new Integer( 7 ) );

        assertNotNull( "NodeContextImpl should not be null.", context );

        try {
            Object result = context.jexlResolver( expression, vars );
            assertNotNull( "Result should not be null.", result );
            assertEquals( "", new Long( 18 ), (Long)result );
        }
        catch(Exception e) {
            e.printStackTrace();
            fail(e.getMessage());
        }
    }

    public void testStaticBinding() {

        assertEquals("cheese", "edam", context.getBoundValue("cheese"));

        // can't change static bindings
        // TODO this should probably barf

        context.setBoundValue("cheese", "cheddar");
        assertEquals("cheese", "edam", context.getBoundValue("cheese"));
    }

    public void testDynamicBinding() {

        context.setBoundValue("drink", "wine");
        assertEquals("drink", "wine", context.getBoundValue("drink"));
    }

    public void testRawParameters(){
        Map mp = new HashMap();
        context.setAppData(mp);
        assertEquals(mp, context.getAppData());
    }

    public void testExecutionToken(){
        // TODO fix this test case
        /*
        Token t = new TokenImpl();
        context.setCurrentExecutionToken(t);
        assertEquals(t, context.getCurrentExecutionToken());
        */
    }

    public void testTimerService(){
        TimerService ts = new TimerServiceImpl();
        context.setTimerService(ts);
        assertEquals(ts, context.getTimerService());
    }

    public void testTaskService() {
        TaskService tskServ = new TaskServiceImpl();
        context.setTaskService(tskServ);
        assertEquals(tskServ,context.getTaskService());
    }

    protected void setUp() throws Exception {
        super.setUp();
        TimerService ts = new TimerServiceImpl();
        TaskService tskServ = new TaskServiceImpl();
        NotificationService notifyService = new NotificationServiceImpl();

        node = new HelloWorldActivity();

        node.addBinding(new Binding("cheese", "edam", Binding.STATIC, true, true));

        node.addBinding(new Binding("drink", "drink", Binding.EL, true, true));

        context = new NodeContextImpl(node, new InstanceImpl(), ts, tskServ, notifyService );
    }

    protected void tearDown() throws Exception {
        super.tearDown();
    }
}
TOP

Related Classes of org.apache.agila.impl.NodeContextImplTestCase

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.