Package org.mule.test.components

Source Code of org.mule.test.components.ServiceDescriptorTestCase

/*
* $Id: ServiceDescriptorTestCase.java 20321 2010-11-24 15:21:24Z dfeist $
* --------------------------------------------------------------------------------------
* Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
*
* The software in this package is published under the terms of the CPAL v1.0
* license, a copy of which has been included with this distribution in the
* LICENSE.txt file.
*/

package org.mule.test.components;

import org.mule.api.service.Service;
import org.mule.tck.FunctionalTestCase;
import org.mule.tck.testmodels.fruit.Orange;

public class ServiceDescriptorTestCase extends FunctionalTestCase
{
    protected String getConfigResources()
    {
        return "org/mule/test/components/service-factory-functional-test.xml";
    }

    public void testGenericObjectFactory() throws Exception
    {
        Service c = muleContext.getRegistry().lookupService("orange1");
       
        Object service =  getComponent(c);
        assertTrue("Service should be an Orange", service instanceof Orange);
        // Default values
        assertEquals(new Integer(10), ((Orange) service).getSegments());
    }
   
    public void testGenericObjectFactoryWithProperties() throws Exception
    {
        Service c = muleContext.getRegistry().lookupService("orange2");

        // Create an orange
        Object service =  getComponent(c);
        assertTrue("Service should be an Orange", service instanceof Orange);
        assertEquals(new Integer(8), ((Orange) service).getSegments());
        assertEquals("Florida Sunny", ((Orange) service).getBrand());

        // Create another orange
        service =  getComponent(c);
        assertTrue("Service should be an Orange", service instanceof Orange);
        assertEquals(new Integer(8), ((Orange) service).getSegments());
        assertEquals("Florida Sunny", ((Orange) service).getBrand());
    }
   
    public void testSingletonObjectFactory() throws Exception
    {
        Service c = muleContext.getRegistry().lookupService("orange3");
        Object service =  getComponent(c);
        assertTrue("Service should be an Orange", service instanceof Orange);
        // Default values
        assertEquals(new Integer(10), ((Orange) service).getSegments());
    }
   
    public void testSpringSingleton() throws Exception
    {
        Service c = muleContext.getRegistry().lookupService("orange4");
        Object service =  getComponent(c);
        assertTrue("Service should be an Orange", service instanceof Orange);
        // Default values
        assertEquals(new Integer(10), ((Orange) service).getSegments());
    }
   
    public void testSpringFactoryBean() throws Exception
    {
        Service c = muleContext.getRegistry().lookupService("orange5");
        Object service =  getComponent(c);
        assertNotNull(service);
        assertTrue("Service should be an Orange but is: " + service.getClass(), service instanceof Orange);
        assertEquals(new Integer(8), ((Orange) service).getSegments());
        assertEquals("Florida Sunny", ((Orange) service).getBrand());
    }

    public void testPojoAsFactoryBean() throws Exception
    {
        Service c = muleContext.getRegistry().lookupService("orange6");
        Object service =  getComponent(c);
        assertNotNull(service);
        assertTrue("Service should be an Orange but is: " + service.getClass(), service instanceof Orange);
        assertEquals("Florida Sunny", ((Orange) service).getBrand());
    }
}
TOP

Related Classes of org.mule.test.components.ServiceDescriptorTestCase

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.