View Javadoc

1   /*
2    * $Id: SslInvalidKeystoreTestCase.java 22981 2011-09-19 13:18:55Z 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.transport.ssl;
12  
13  import org.mule.tck.junit4.FunctionalTestCase;
14  import org.mule.tck.junit4.rule.DynamicPort;
15  import org.mule.tck.testmodels.mule.TestExceptionStrategy;
16  import org.mule.tck.testmodels.mule.TestExceptionStrategy.ExceptionCallback;
17  import org.mule.transport.ConnectException;
18  
19  import org.junit.Rule;
20  import org.junit.Test;
21  
22  import static org.junit.Assert.assertNotNull;
23  import static org.junit.Assert.assertTrue;
24  
25  public class SslInvalidKeystoreTestCase extends FunctionalTestCase implements ExceptionCallback
26  {
27      @Rule
28      public DynamicPort port1 = new DynamicPort("port1");
29  
30      private Throwable exceptionFromSystemExceptionHandler;
31  
32      public SslInvalidKeystoreTestCase()
33      {
34          super();
35          setStartContext(false);
36      }
37  
38      @Override
39      protected String getConfigResources()
40      {
41          return "ssl-missing-keystore-config.xml";
42      }
43  
44      @Test
45      public void startingSslMessageReceiverWithoutKeystoreShouldThrowConnectException() throws Exception
46      {
47          TestExceptionStrategy exceptionListener = new TestExceptionStrategy();
48          exceptionListener.setExceptionCallback(this);
49  
50          muleContext.setExceptionListener(exceptionListener);
51          muleContext.start();
52  
53          assertNotNull(exceptionFromSystemExceptionHandler);
54          assertTrue(exceptionFromSystemExceptionHandler instanceof ConnectException);
55          assertTrue(exceptionFromSystemExceptionHandler.getMessage().contains("tls-key-store"));
56      }
57  
58      public void onException(Throwable t)
59      {
60          exceptionFromSystemExceptionHandler = t;
61      }
62  }