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