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.config.spring.parsers;
8   
9   import org.mule.config.spring.parsers.beans.ChildBean;
10  import org.mule.config.spring.parsers.beans.OrphanBean;
11  
12  import java.util.List;
13  import java.util.Map;
14  
15  import org.junit.Test;
16  
17  import static org.junit.Assert.assertEquals;
18  import static org.junit.Assert.assertNotNull;
19  import static org.junit.Assert.assertTrue;
20  
21  public class MapMule2478TestCase extends AbstractNamespaceTestCase
22  {
23  
24      @Override
25      protected String getConfigResources()
26      {
27          return "org/mule/config/spring/parsers/map-mule-2478-test.xml";
28      }
29  
30      @Test
31      public void testDirectChild()
32      {
33          OrphanBean orphan = (OrphanBean) assertBeanExists("orphan", OrphanBean.class);
34          ChildBean child1 = (ChildBean) assertContentExists(orphan.getChild(), ChildBean.class);
35          assertEquals("string1", child1.getString());
36          assertNotNull(child1.getList());
37          assertEquals("list1", child1.getList().get(0));
38      }
39  
40      @Test
41      public void testMappedChild()
42      {
43          OrphanBean orphan = (OrphanBean) assertBeanExists("orphan", OrphanBean.class);
44          Map map = orphan.getMap();
45          assertNotNull(map);
46          assertTrue(map.containsKey("string"));
47          assertEquals("string2", map.get("string"));
48          assertTrue(map.containsKey("name"));
49          assertEquals("child2", map.get("name"));
50          assertTrue(map.containsKey("list"));
51          assertEquals("list2", ((List) map.get("list")).get(0));
52      }
53  
54  // TODO ComplexComponentDefinitionParser is not longer used, is there any way to rewrite/reuse the "factory" element for testing?
55  //    @Test
56  //    public void testFactory() throws Exception
57  //    {
58  //        OrphanBean orphan = (OrphanBean) assertBeanExists("orphan", OrphanBean.class);
59  //        ObjectFactory factory = (ObjectFactory) orphan.getObject();
60  //        assertNotNull(factory);
61  //        Object product = factory.getInstance();
62  //        assertNotNull(product);
63  //        assertTrue(product instanceof ChildBean);
64  //        ChildBean child3 = (ChildBean) product;
65  //        assertEquals("string3", child3.getString());
66  //        assertNotNull(child3.getList());
67  //        assertEquals("list3", child3.getList().get(0));
68  //    }
69  
70  }