View Javadoc

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