View Javadoc

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