1   /*
2    * $Id: MuleModelTestCase.java 7963 2007-08-21 08:53:15Z dirk.olmes $
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.impl;
12  
13  import org.mule.tck.AbstractMuleTestCase;
14  import org.mule.umo.model.ModelException;
15  import org.mule.umo.model.UMOModel;
16  
17  import java.util.Iterator;
18  
19  public class MuleModelTestCase extends AbstractMuleTestCase
20  {
21  
22      public void testDescriptorAlreadyDefinedThrowsException() throws Exception
23      {
24          final String descriptorName = "TEST_COMPONENT_1";
25          MuleDescriptor descriptor = getTestDescriptor(descriptorName, "java.lang.Object");
26          MuleDescriptor duplicateDescriptor = getTestDescriptor(descriptorName, "java.lang.Object");
27          final UMOModel model = getDefaultModel();
28          model.registerComponent(descriptor);
29          try
30          {
31              // register it again with the same name
32              model.registerComponent(duplicateDescriptor);
33              fail("Trying to register a component descriptor with the same name "
34                   + "must have thrown an exception.");
35          }
36          catch (ModelException mex)
37          {
38              // expected
39              final String message = mex.getMessage();
40              assertTrue("Exception message should contain our descriptor name.",
41                  (message.indexOf("\"" + descriptorName + "\"") > -1));
42          }
43  
44          // count components (no direct method to count 'em)
45          int componentCount = 0;
46          for (Iterator it = model.getComponentNames(); it.hasNext();)
47          {
48              it.next();
49              componentCount++;
50          }
51  
52          assertEquals("Wrong number of components registered in the model.", 1, componentCount);
53      }
54  }