Package org.apache.tapestry.ioc.services

Examples of org.apache.tapestry.ioc.services.ClassFab


    }

    @Test
    public void add_to_string() throws Exception
    {
        ClassFab cf = newClassFab("ToString", Object.class);

        cf.addToString("ToString Description");

        Class clazz = cf.createClass();

        Object instance = clazz.newInstance();

        assertEquals(instance.toString(), "ToString Description");
    }
View Full Code Here


    }

    @Test
    public void proxy_methods_to_delegate() throws Exception
    {
        ClassFab cf = newClassFab("Delegator", Object.class);

        cf.addField("_delegate", SampleService.class);
        cf.addConstructor(new Class[]
        { SampleService.class }, null, "_delegate = $1;");

        cf.proxyMethodsToDelegate(SampleService.class, "_delegate", "<Delegator>");

        SampleService delegate = newMock(SampleService.class);

        Class clazz = cf.createClass();

        SampleService proxy = (SampleService) clazz.getConstructors()[0].newInstance(delegate);

        expect(delegate.primitiveMethod(5)).andReturn(10);
View Full Code Here

    }

    @Test
    public void proxy_methods_to_delegate_with_to_string() throws Exception
    {
        ClassFab cf = newClassFab("ToStringDelegator", Object.class);

        cf.addField("_delegate", ToStringService.class);
        cf.addConstructor(new Class[]
        { ToStringService.class }, null, "_delegate = $1;");

        cf.proxyMethodsToDelegate(ToStringService.class, "_delegate", "<ToStringDelegator>");

        ToStringService delegate = new ToStringService()
        {
            @Override
            public String toString()
            {
                return "ACTUAL TO-STRING";
            }
        };

        Class clazz = cf.createClass();

        ToStringService proxy = (ToStringService) clazz.getConstructors()[0].newInstance(delegate);

        assertEquals(proxy.toString(), "ACTUAL TO-STRING");
    }
View Full Code Here

    }

    @Test
    public void add_constructor() throws Exception
    {
        ClassFab cf = newClassFab("ConstructableBean", Object.class);

        cf.addField("_stringValue", String.class);
        cf.addConstructor(new Class[]
        { String.class }, null, "{ _stringValue = $1; }");

        MethodSignature getStringValue = new MethodSignature(String.class, "getStringValue", null,
                null);

        cf.addMethod(Modifier.PUBLIC, getStringValue, "return _stringValue;");

        Class targetClass = cf.createClass();

        try
        {
            targetClass.newInstance();
            unreachable();
View Full Code Here

    }

    @Test
    public void add_constructor_from_base_class() throws Exception
    {
        ClassFab cf = newClassFab("MyIntHolder", AbstractIntWrapper.class);

        cf.addField("_intValue", int.class);
        cf.addConstructor(new Class[]
        { int.class }, null, "{ _intValue = $1; }");

        cf.addMethod(
                Modifier.PUBLIC,
                new MethodSignature(int.class, "getIntValue", null, null),
                "return _intValue;");

        Class targetClass = cf.createClass();
        Constructor c = targetClass.getConstructors()[0];

        AbstractIntWrapper targetBean = (AbstractIntWrapper) c.newInstance(new Object[]
        { new Integer(137) });
View Full Code Here

    }

    @Test
    public void invalid_super_class() throws Exception
    {
        ClassFab cf = newClassFab("InvalidSuperClass", List.class);

        try
        {
            cf.createClass();
            unreachable();
        }
        catch (RuntimeException ex)
        {
            assertExceptionSubstring(ex, "Unable to create class InvalidSuperClass");
View Full Code Here

    }

    @Test
    public void add_interface() throws Exception
    {
        ClassFab cf = newClassFab("SimpleService", Object.class);

        cf.addInterface(SimpleService.class);

        cf.addMethod(Modifier.PUBLIC, new MethodSignature(int.class, "add", new Class[]
        { int.class, int.class }, null), "return $1 + $2;");

        Class targetClass = cf.createClass();

        SimpleService s = (SimpleService) targetClass.newInstance();

        assertEquals(207, s.add(99, 108));
    }
View Full Code Here

    }

    @Test
    public void attempt_to_subclass_from_final_class() throws Exception
    {
        ClassFab cf = newClassFab("StringSubclass", String.class);

        try
        {
            cf.createClass();
        }
        catch (RuntimeException ex)
        {
            assertExceptionRegexp(
                    ex,
View Full Code Here

    }

    @Test
    public void create_class_within_non_default_package() throws Exception
    {
        ClassFab cf = newClassFab("org.apache.hivemind.InPackage", Object.class);

        Class c = cf.createClass();

        Object o = c.newInstance();

        assertEquals("org.apache.hivemind.InPackage", o.getClass().getName());
    }
View Full Code Here

    }

    @Test
    public void invalid_method_body() throws Exception
    {
        ClassFab cf = newClassFab("BadMethodBody", Object.class);

        cf.addInterface(Runnable.class);

        try
        {
            cf.addMethod(
                    Modifier.PUBLIC,
                    new MethodSignature(void.class, "run", null, null),
                    "fail;");
        }
        catch (RuntimeException ex)
View Full Code Here

TOP

Related Classes of org.apache.tapestry.ioc.services.ClassFab

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.