Package org.apache.hivemind.service

Examples of org.apache.hivemind.service.MethodFab


    public void testExtendMethod() throws Exception
    {
        ClassFab cf = newClassFab("ExtendMethod", Object.class);

        MethodFab mf =
            cf.addMethod(
                Modifier.PUBLIC,
                new MethodSignature(int.class, "getValue", null, null),
                "return 1;");

        mf.extend("return 2 * $_;", false);

        Object bean = cf.createClass().newInstance();

        assertEquals(new Integer(2), PropertyUtils.read(bean, "value"));
    }
View Full Code Here


    public void testExtendMethodAlterReturn() throws Exception
    {
        ClassFab cf = newClassFab("ExtendMethodAlterReturn", Object.class);

        MethodFab mf =
            cf.addMethod(
                Modifier.PUBLIC,
                new MethodSignature(int.class, "getValue", null, null),
                "return 2;");

        mf.extend("$_ = 3 * $_;", false);

        Object bean = cf.createClass().newInstance();

        assertEquals(new Integer(6), PropertyUtils.read(bean, "value"));
    }
View Full Code Here

    public void testExtendMethodFailure() throws Exception
    {
        ClassFab cf = newClassFab("ExtendMethodFailure", Object.class);

        MethodFab mf =
            cf.addMethod(
                Modifier.PUBLIC,
                new MethodSignature(int.class, "getValue", null, null),
                "return 1;");

        try
        {
            mf.extend("$_ =", true);
            unreachable();
        }
        catch (ApplicationRuntimeException ex)
        {
            assertExceptionSubstring(
View Full Code Here

    {
        ClassFab cf = newClassFab("Fail", Object.class);

        cf.addInterface(FailService.class);

        MethodFab mf =
            cf.addMethod(
                Modifier.PUBLIC,
                new MethodSignature(void.class, "fail", null, null),
                "throw new java.lang.RuntimeException(\"Ouch!\");");

        mf.addCatch(RuntimeException.class, "throw new java.io.IOException($e.getMessage());");

        Class targetClass = cf.createClass();

        FailService fs = (FailService) targetClass.newInstance();
View Full Code Here

    {
        ClassFab cf = newClassFab("BadCatch", Object.class);

        cf.addInterface(Runnable.class);

        MethodFab mf =
            cf.addMethod(
                Modifier.PUBLIC,
                new MethodSignature(void.class, "run", null, null),
                "return;");

        try
        {
            mf.addCatch(RuntimeException.class, "woops!");
            unreachable();
        }
        catch (ApplicationRuntimeException ex)
        {
            assertExceptionSubstring(
View Full Code Here

                ex);
        }

        // Return a MethodFab so the caller can add catches.

        MethodFab result = new MethodFabImpl(_source, ms, method);

        _methods.put(ms, result);

        return result;
    }
View Full Code Here

    {
        Iterator i = _methods.values().iterator();
        while (i.hasNext())
        {

            MethodFab mf = (MethodFab) i.next();

            buffer.append("\n");
            buffer.append(mf);
            buffer.append("\n");
        }
View Full Code Here

                    ex), ex);
        }

        // Return a MethodFab so the caller can add catches.

        MethodFab result = new MethodFabImpl(getSource(), ms, method, body);

        _methods.put(ms, result);

        return result;
    }
View Full Code Here

        ClassFactory factory = (ClassFactory) factoryControl.getMock();

        MockControl cfc = newControl(ClassFab.class);
        ClassFab cf = (ClassFab) cfc.getMock();

        MethodFab mf = (MethodFab) newMock(MethodFab.class);

        MockControl fpc = newControl(ServiceImplementationFactoryParameters.class);
        ServiceImplementationFactoryParameters fp = (ServiceImplementationFactoryParameters) fpc
                .getMock();
View Full Code Here

        ClassFactory factory = (ClassFactory) factoryControl.getMock();

        MockControl cfc = newControl(ClassFab.class);
        ClassFab cf = (ClassFab) cfc.getMock();

        MethodFab mf = (MethodFab) newMock(MethodFab.class);

        MockControl fpc = newControl(ServiceImplementationFactoryParameters.class);
        ServiceImplementationFactoryParameters fp = (ServiceImplementationFactoryParameters) fpc
                .getMock();
View Full Code Here

TOP

Related Classes of org.apache.hivemind.service.MethodFab

Copyright © 2018 www.massapicom. 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.