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