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.module.ibeans.annotations;
8   
9   import org.mule.module.ibeans.config.IBeanHolder;
10  import org.mule.module.ibeans.config.IBeansLoader;
11  
12  import java.util.Collection;
13  import java.util.Iterator;
14  import java.util.Set;
15  import java.util.TreeSet;
16  
17  import org.junit.Test;
18  
19  import static org.junit.Assert.assertEquals;
20  
21  public class IBeansHolderConfigBuilderTestCase extends AbstractIBeansTestCase
22  {
23      @Override
24      protected void doTearDown() throws Exception
25      {
26          System.getProperties().remove(IBeansLoader.SCAN_PACKAGES_PROPERTY);
27      }
28  
29      @Test
30      public void testConfigBuilder() throws Exception
31      {
32          Collection<IBeanHolder> col = muleContext.getRegistry().lookupObjects(IBeanHolder.class);
33          //Ensure IBeanHolder is comparable
34          Set<IBeanHolder> beans = new TreeSet<IBeanHolder>(col);
35  
36          int exprectedSize = 11;
37          assertEquals(exprectedSize, beans.size());
38          String[] ids = new String[exprectedSize];
39          int i = 0;
40          for (Iterator<IBeanHolder> iterator = beans.iterator(); iterator.hasNext(); i++)
41          {
42              IBeanHolder iBeanHolder = iterator.next();
43              ids[i] = iBeanHolder.getId();
44          }
45  
46          assertEquals("errorfilter", ids[0]);
47          //these are loaded from  a jar on the classpath, part test for MULE-5108
48          assertEquals("flickr", ids[1]);
49          assertEquals("flickrauthentication", ids[2]);
50          assertEquals("flickrsearch", ids[3]);
51          assertEquals("flickrupload", ids[4]);
52          assertEquals("hostip", ids[5]);
53          assertEquals("search", ids[6]);
54          assertEquals("testexception", ids[7]);
55          assertEquals("testimplicitpropertiesinfactory", ids[8]);
56          assertEquals("testparamsfactory", ids[9]);
57          assertEquals("testuri", ids[10]);
58      }
59  }