View Javadoc

1   /*
2    * $Id: InheritedPropertiesMule2458TestCase.java 22518 2011-07-22 07:00:22Z claude.mamo $
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.spring;
12  
13  import static org.junit.Assert.assertEquals;
14  import static org.junit.Assert.assertNotNull;
15  
16  import org.mule.api.endpoint.ImmutableEndpoint;
17  import org.mule.api.service.Service;
18  import org.mule.construct.Flow;
19  import org.mule.service.ServiceCompositeMessageSource;
20  import org.mule.tck.AbstractServiceAndFlowTestCase;
21  
22  import java.util.Arrays;
23  import java.util.Collection;
24  
25  import org.junit.Test;
26  import org.junit.runners.Parameterized.Parameters;
27  
28  public class InheritedPropertiesMule2458TestCase extends AbstractServiceAndFlowTestCase
29  {
30      public InheritedPropertiesMule2458TestCase(ConfigVariant variant, String configResources)
31      {
32          super(variant, configResources);
33      }
34  
35      @Parameters
36      public static Collection<Object[]> parameters()
37      {
38          return Arrays.asList(new Object[][]{
39              {ConfigVariant.SERVICE, "org/mule/test/spring/inherited-properties-mule-2458-test-service.xml"},
40              {ConfigVariant.FLOW, "org/mule/test/spring/inherited-properties-mule-2458-test-flow.xml"}
41          });
42      }      
43      
44      @Test
45      public void testProperties()
46      {
47          ImmutableEndpoint endpoint;
48          Object service = muleContext.getRegistry().lookupObject("service");
49          assertNotNull(service);
50                 
51          if (variant.equals(ConfigVariant.FLOW))
52          {
53              endpoint = (ImmutableEndpoint) ((Flow)service).getMessageSource();    
54          }
55          else
56          {
57              endpoint = ((ServiceCompositeMessageSource) ((Service) service).getMessageSource()).getEndpoints().get(0);
58          }       
59                 
60          assertNotNull(endpoint);
61          assertProperty(endpoint, "global-only", "global");
62          assertProperty(endpoint, "local-only", "local");
63          assertProperty(endpoint, "url-only", "url");
64  
65          assertProperty(endpoint, "global-and-local", "local");
66          assertProperty(endpoint, "global-and-url", "global");
67          assertProperty(endpoint, "local-and-url", "local");
68  
69          assertProperty(endpoint, "all", "local");
70      }
71  
72      protected void assertProperty(ImmutableEndpoint endpoint, String key, String value)
73      {
74          Object property = endpoint.getProperty(key);
75          assertNotNull("Property " + key + " is missing", property);
76          String actual = property.toString();
77          assertEquals("Unexpected value for " + key + ": " + actual + ", not " + value, value, actual);
78      }
79  }