Package hivemind.test.rules

Source Code of hivemind.test.rules.TestInvokeParentRule

// Copyright 2004, 2005 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 hivemind.test.rules;

import java.util.List;

import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.Registry;
import org.apache.hivemind.schema.SchemaProcessor;
import org.apache.hivemind.schema.rules.InvokeParentRule;
import org.apache.hivemind.xml.XmlTestCase;
import org.easymock.MockControl;

public class TestInvokeParentRule extends XmlTestCase
{

    public void testInvokeFailure() throws Exception
    {
        Registry r = buildFrameworkRegistry("InvokeFailure.xml");

        try
        {
            List l = (List) r.getConfiguration("hivemind.test.rules.InvokeFailure");

            l.size();

            unreachable();
        }
        catch (ApplicationRuntimeException ex)
        {
            assertExceptionSubstring(
                    ex,
                    "Unable to construct configuration hivemind.test.rules.InvokeFailure: Error invoking method failure on java.util.ArrayList");

            Throwable inner = findNestedException(ex);
            assertExceptionSubstring(inner, "failure");
        }

    }

    public void testNullParameter() throws Exception
    {
        InvokeParentRule rule = new InvokeParentRule("add");

        MockControl procControl = newControl(SchemaProcessor.class);
        SchemaProcessor proc = (SchemaProcessor) procControl.getMock();

        proc.peek(0);
        procControl.setReturnValue(null);

        MockControl listControl = newControl(List.class);
        List list = (List) listControl.getMock();

        proc.peek(1);
        procControl.setReturnValue(list);

        proc.isInBackwardCompatibilityModeForMaps();
        procControl.setReturnValue(false);
       
        list.add(null);
        listControl.setReturnValue(true);

        replayControls();

        rule.begin(proc, null);

        verifyControls();

        resetControls();

        rule = new InvokeParentRule("get");

        proc.peek(0);
        procControl.setReturnValue(null);

        proc.peek(1);
        procControl.setReturnValue(list);
       
        proc.isInBackwardCompatibilityModeForMaps();
        procControl.setReturnValue(false);
       
        replayControls();

        try
        {
            rule.begin(proc, null);

            fail();
        }
        catch (ApplicationRuntimeException e)
        {
            assertEquals(NoSuchMethodException.class, e.getCause().getClass());
        }

        verifyControls();
    }

    public void testGetMethod()
    {
        InvokeParentRule r = new InvokeParentRule();

        r.setMethodName("foo");

        assertEquals("foo", r.getMethodName());
    }

}
TOP

Related Classes of hivemind.test.rules.TestInvokeParentRule

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.