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

        MethodSignature sig = new MethodSignature(Map.class, "doTheNasty", new Class[]
        { int.class, String.class }, new Class[]
        { InstantiationException.class, IllegalAccessException.class });

        MethodFab mf = cf.addMethod(
                Modifier.PUBLIC + Modifier.FINAL + Modifier.SYNCHRONIZED,
                sig,
                "{ return _map; }");

        mf.addCatch(NullPointerException.class, "return null;");
        mf.extend("_map.clear();", true);

        String toString = cf.toString();

        contains(
                toString,
View Full Code Here

    MethodSignature sig = new MethodSignature(returnClass, "run", null,
        null);

    MockControl control = newControl(ClassFab.class);
    ClassFab cf = (ClassFab) control.getMock();
    MethodFab mf = (MethodFab) newMock(MethodFab.class);

    cf.addMethod(Modifier.PUBLIC, sig, expectedBody);
    control.setReturnValue(mf);

    replayControls();
View Full Code Here

    {
        MethodSignature sig = new MethodSignature(returnClass, "run", null, null);

        MockControl control = newControl(ClassFab.class);
        ClassFab cf = (ClassFab) control.getMock();
        MethodFab mf = (MethodFab) newMock(MethodFab.class);

        cf.addMethod(Modifier.PUBLIC, sig, expectedBody);
        control.setReturnValue(mf);

        replayControls();
View Full Code Here

            builder.addln("return result;");
        }

        builder.end();

        MethodFab methodFab = classFab.addMethod(Modifier.PUBLIC, sig, builder.toString());

        builder.clear();

        builder.begin();
        builder.add("org.apache.hivemind.service.impl.LoggingUtils.exception(_log, ");
        builder.addQuoted(methodName);
        builder.addln(", $e);");
        builder.addln("throw $e;");
        builder.end();

        String body = builder.toString();

        Class[] exceptions = sig.getExceptionTypes();

        int count = exceptions.length;

        for (int i = 0; i < count; i++)
        {
            methodFab.addCatch(exceptions[i], body);
        }

        // Catch and log any runtime exceptions, in addition to the
        // checked exceptions.

        methodFab.addCatch(RuntimeException.class, body);
    }
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.