View Javadoc
1   /*
2    * Copyright 2006-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.kuali.rice.ksb.messaging;
18  
19  import org.junit.Assert;
20  import org.junit.Before;
21  import org.junit.Test;
22  import org.kuali.rice.ksb.api.KsbApiConstants;
23  import org.kuali.rice.ksb.api.KsbApiServiceLocator;
24  import org.kuali.rice.ksb.api.bus.Endpoint;
25  import org.kuali.rice.ksb.api.bus.ServiceConfiguration;
26  import org.kuali.rice.ksb.api.bus.support.JavaServiceConfiguration;
27  import org.kuali.rice.ksb.messaging.remotedservices.EchoService;
28  import org.kuali.rice.ksb.messaging.serviceconnectors.HttpInvokerConnector;
29  import org.kuali.rice.ksb.server.TestClient1;
30  import org.kuali.rice.ksb.test.KSBTestCase;
31  
32  import javax.xml.namespace.QName;
33  import java.net.MalformedURLException;
34  import java.net.URL;
35  
36  /**
37   * simple test verifying HttpInvoker based service clients are working.
38   *
39   * <p>HttpInvoker-based services (services defined by JavaServiceDefinitions) are tested via http and https, with
40   * bus security and auth enabled</p>
41   *
42   * @author Kuali Rice Team (rice.collab@kuali.org)
43   *
44   */
45  public class HttpInvokerConnectorTest extends KSBTestCase {
46  
47      public boolean startClient1() {
48          return true;
49      }
50  
51      private static final QName serviceName = new QName("urn:TestCl1", "httpInvoker-echoServiceSecure");
52  
53      /**
54       * Make sure our registry is up to date with the services from TestClient1
55       */
56      @Before
57      public void setup() {
58          KsbApiServiceLocator.getServiceBus().synchronize();
59      }
60  
61      /**
62       * Tests a secured and auth-enabled HttpInvoker-based service with a simple call over http
63       */
64      @Test
65      public void testHttpInvokerServiceCall() {
66          Endpoint endpoint = KsbApiServiceLocator.getServiceBus().getEndpoint(serviceName);
67  
68          Assert.assertTrue(KsbApiConstants.ServiceTypes.HTTP_INVOKER.equals(
69                  endpoint.getServiceConfiguration().getType()));
70  
71          EchoService echoService = (EchoService)KsbApiServiceLocator.getServiceBus().getService(serviceName);
72  
73          Assert.assertTrue("foo".equals(echoService.echo("foo")));
74      }
75  
76      /**
77       * Tests a secured and auth-enabled HttpInvoker-based service with an https call
78       */
79      @Test
80      public void testSecureHttpInvokerServiceCall() throws MalformedURLException {
81          Endpoint endpoint = KsbApiServiceLocator.getServiceBus().getEndpoint(serviceName);
82  
83          Assert.assertTrue(KsbApiConstants.ServiceTypes.HTTP_INVOKER.equals(endpoint.getServiceConfiguration().getType()));
84  
85          // we need to build a custom URL to our https endpoint
86  
87          ServiceConfiguration serviceConfiguration = endpoint.getServiceConfiguration();
88          URL endpointUrl = serviceConfiguration.getEndpointUrl();
89          TestClient1.ConfigConstants configConstants = new TestClient1.ConfigConstants();
90  
91          URL httpsUrl = new URL("https", endpointUrl.getHost(), configConstants.SERVER_HTTPS_PORT, endpointUrl.getFile());
92  
93          // manually build our service proxy using the HttpInvokerConnector
94          HttpInvokerConnector connector = new HttpInvokerConnector((JavaServiceConfiguration)serviceConfiguration, httpsUrl);
95          EchoService httpsEchoService = (EchoService) connector.getService();
96  
97          // test the secure service call
98          Assert.assertTrue("foo".equals(httpsEchoService.echo("foo")));
99      }
100 
101 }