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