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.AbstractBean;
10  import org.mule.tck.junit4.FunctionalTestCase;
11  import org.mule.util.ClassUtils;
12  
13  import java.util.List;
14  import java.util.Map;
15  
16  import org.junit.Test;
17  
18  import static org.junit.Assert.assertEquals;
19  import static org.junit.Assert.assertNotNull;
20  import static org.junit.Assert.assertTrue;
21  
22  public abstract class AbstractNamespaceTestCase extends FunctionalTestCase
23  {
24  
25      @Test
26      public void testParse()
27      {
28          // just parse the config
29      }
30  
31      protected Object assertBeanExists(String name, Class clazz)
32      {
33          Object bean = muleContext.getRegistry().lookupObject(name);
34          assertNotNull(name + " bean missing", bean);
35          assertTrue(bean.getClass().equals(clazz));
36          logger.debug("found bean " + name + "/" + ClassUtils.getSimpleName(bean.getClass()));
37          return bean;
38      }
39  
40      protected Object assertContentExists(Object object, Class clazz)
41      {
42          assertNotNull(ClassUtils.getSimpleName(clazz) + " content missing", object);
43          assertTrue(clazz.isAssignableFrom(object.getClass()));
44          logger.debug("found content " + ClassUtils.getSimpleName(object.getClass()));
45          return object;
46      }
47  
48      protected void assertBeanPopulated(AbstractBean bean, String name)
49      {
50          assertMapExists(bean.getMap(), name);
51          assertListExists(bean.getList(), name);
52          String string = bean.getString();
53          assertNotNull("string for " + name, string);
54          assertEquals(name + "String", string);
55      }
56  
57      protected void assertMapExists(Map map, String name)
58      {
59          assertNotNull("map for " + name, map);
60          assertMapEntryExists(map, name, 1);
61          assertMapEntryExists(map, name, 2);
62      }
63  
64      protected void assertMapEntryExists(Map map, String name, int index)
65      {
66          String key = "key" + index;
67          Object value = map.get(key);
68          assertNotNull(key + " returns null", value);
69          assertTrue(value instanceof String);
70          assertEquals(name + "Map" + index, value);
71      }
72  
73      protected void assertListExists(List list, String name)
74      {
75          assertNotNull("list for " + name, list);
76          assertListEntryExists(list, name, 1);
77          assertListEntryExists(list, name, 2);
78      }
79  
80      protected void assertListEntryExists(List list, String name, int index)
81      {
82          String value = name + "List" + index;
83          assertTrue(value, list.contains(value));
84      }
85  
86  }