View Javadoc

1   /*
2    * $Id: ServiceDescriptorServiceTestCase.java 22478 2011-07-20 16:01:18Z justin.calleja $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.test.components;
12  
13  import org.mule.api.service.Service;
14  import org.mule.tck.junit4.FunctionalTestCase;
15  import org.mule.tck.testmodels.fruit.Orange;
16  
17  import org.junit.Test;
18  
19  import static org.junit.Assert.assertEquals;
20  import static org.junit.Assert.assertNotNull;
21  import static org.junit.Assert.assertTrue;
22  
23  public class ServiceDescriptorServiceTestCase extends FunctionalTestCase
24  {
25  
26      @Override
27      protected String getConfigResources()
28      {
29          return "org/mule/test/components/service-factory-functional-test-service.xml";
30      }
31  
32      @Test
33      public void testGenericObjectFactory() throws Exception
34      {
35          Service c = muleContext.getRegistry().lookupService("orange1");
36          
37          Object service =  getComponent(c);
38          assertTrue("Service should be an Orange", service instanceof Orange);
39          // Default values
40          assertEquals(new Integer(10), ((Orange) service).getSegments());
41      }
42      
43      @Test
44      public void testGenericObjectFactoryWithProperties() throws Exception
45      {
46          Service c = muleContext.getRegistry().lookupService("orange2");
47  
48          // Create an orange
49          Object service =  getComponent(c);
50          assertTrue("Service should be an Orange", service instanceof Orange);
51          assertEquals(new Integer(8), ((Orange) service).getSegments());
52          assertEquals("Florida Sunny", ((Orange) service).getBrand());
53  
54          // Create another orange
55          service =  getComponent(c);
56          assertTrue("Service should be an Orange", service instanceof Orange);
57          assertEquals(new Integer(8), ((Orange) service).getSegments());
58          assertEquals("Florida Sunny", ((Orange) service).getBrand());
59      }
60      
61      @Test
62      public void testSingletonObjectFactory() throws Exception
63      {
64          Service c = muleContext.getRegistry().lookupService("orange3");
65          Object service =  getComponent(c);
66          assertTrue("Service should be an Orange", service instanceof Orange);
67          // Default values
68          assertEquals(new Integer(10), ((Orange) service).getSegments());
69      }
70      
71      @Test
72      public void testSpringSingleton() throws Exception
73      {
74          Service c = muleContext.getRegistry().lookupService("orange4");
75          Object service =  getComponent(c);
76          assertTrue("Service should be an Orange", service instanceof Orange);
77          // Default values
78          assertEquals(new Integer(10), ((Orange) service).getSegments());
79      }
80      
81      @Test
82      public void testSpringFactoryBean() throws Exception
83      {
84          Service c = muleContext.getRegistry().lookupService("orange5");
85          Object service =  getComponent(c);
86          assertNotNull(service);
87          assertTrue("Service should be an Orange but is: " + service.getClass(), service instanceof Orange);
88          assertEquals(new Integer(8), ((Orange) service).getSegments());
89          assertEquals("Florida Sunny", ((Orange) service).getBrand());
90      }
91  
92      @Test
93      public void testPojoAsFactoryBean() throws Exception
94      {
95          Service c = muleContext.getRegistry().lookupService("orange6");
96          Object service =  getComponent(c);
97          assertNotNull(service);
98          assertTrue("Service should be an Orange but is: " + service.getClass(), service instanceof Orange);
99          assertEquals("Florida Sunny", ((Orange) service).getBrand());
100     }
101 }