View Javadoc

1   /*
2    * $Id: MessagesTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
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.test.config;
12  
13  import org.mule.config.i18n.CoreMessages;
14  import org.mule.config.i18n.Message;
15  import org.mule.tck.AbstractMuleTestCase;
16  
17  import java.util.MissingResourceException;
18  
19  public class MessagesTestCase extends AbstractMuleTestCase
20  {
21      public void testMessageLoading() throws Exception
22      {
23          Message message = CoreMessages.authFailedForUser("Fred");
24          assertEquals("Authentication failed for principal Fred", message.getMessage());
25          assertEquals(135, message.getCode());
26      }
27  
28      public void testBadBundle()
29      {
30          try
31          {
32              InvalidMessageFactory.getInvalidMessage();
33              fail("should throw resource bundle not found exception");
34          }
35          catch (MissingResourceException e)
36          {
37              // IBM JDK6: Can't find resource for bundle ...
38              // Sun/IBM JDK5: Can't find bundle for base name ...
39              assertTrue(e.getMessage().matches(".*Can't find.*bundle.*"));
40          }
41      }
42  
43      public void testGoodBundle()
44      {
45          Message message = TestMessages.testMessage("one", "two", "three");
46          assertEquals("Testing, Testing, one, two, three", message.getMessage());
47          assertEquals(1, message.getCode());
48      }
49  }