View Javadoc

1   /*
2    * $Id: ProxyServiceConfigurationTestCase.java 22377 2011-07-11 12:41:42Z 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.module.cxf.support;
12  
13  import org.mule.MuleServer;
14  import org.mule.tck.junit4.AbstractMuleTestCase;
15  import org.mule.util.ExceptionUtils;
16  
17  import java.net.URL;
18  
19  import org.apache.cxf.service.factory.ServiceConstructionException;
20  import org.junit.Test;
21  
22  import static org.junit.Assert.assertTrue;
23  import static org.junit.Assert.fail;
24  
25  public class ProxyServiceConfigurationTestCase extends AbstractMuleTestCase
26  {
27  
28      @Test
29      public void testGetEndpointName_CorrectNameSpace()
30      {
31          String configFilePath = "/org/mule/module/cxf/support/test-proxy-mule-config-correct-namespace.xml";
32          startServer(configFilePath);
33      }
34  
35      @Test
36      public void testGetEndpointName_NoNameSpace()
37      {
38          String configFilePath = "/org/mule/module/cxf/support/test-proxy-mule-config-no-namespace.xml";
39          try
40          {
41              startServer(configFilePath);
42              fail("It should have failed because no namespace was specified");
43          }
44          catch (RuntimeException e)
45          {
46              Throwable rootCause = ExceptionUtils.getRootCause(e);
47              assertTrue("Exception must be of type " + ServiceConstructionException.class + ", instead of "
48                         + rootCause, rootCause instanceof ServiceConstructionException);
49          }
50      }
51  
52      private void startServer(String configFilePath)
53      {
54          URL configURL = this.getClass().getResource(configFilePath);
55          MuleServer muleServer = new MuleServer(configURL.toString())
56          {
57              @Override
58              public void shutdown(Throwable e)
59              {
60                  throw new RuntimeException(e);
61              }
62          };
63          muleServer.start(false, false);
64      }
65  
66  }