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