View Javadoc

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