Package org.apache.camel.component.cxf.jaxrs

Source Code of org.apache.camel.component.cxf.jaxrs.CxfRsEndpointTest

/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements.  See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License.  You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.component.cxf.jaxrs;

import org.apache.camel.component.cxf.CXFTestSupport;
import org.apache.camel.component.cxf.jaxrs.testbean.CustomerService;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
import org.apache.cxf.jaxrs.provider.json.JSONProvider;
import org.junit.Test;

public class CxfRsEndpointTest extends CamelTestSupport {
    private static final String CTX = CXFTestSupport.getPort1() + "/CxfRsEndpointTest";
   
    @Test
    public void testCreateCxfRsEndpoint() throws Exception {
        String endpointUri = "cxfrs://http://localhost:" + CTX + ""
            + "?loggingFeatureEnabled=true&loggingSizeLimit=200"
            + "&resourceClasses=org.apache.camel.component.cxf.jaxrs.testbean.CustomerService,"
            + "java.lang.String,org.apache.camel.component.cxf.jaxrs.testbean.Order";
           
        CxfRsComponent component = new CxfRsComponent(context);
        CxfRsEndpoint endpoint = (CxfRsEndpoint)component.createEndpoint(endpointUri);
       
        assertNotNull("The endpoint should not be null ", endpoint);
        assertEquals("Get a wrong address ", endpointUri, endpoint.getEndpointUri());
        assertEquals("Get a wrong size of resouces classes", 3, endpoint.getResourceClasses().size());
        assertEquals("Get a wrong resources class", CustomerService.class, endpoint.getResourceClasses().get(0));
        assertEquals("Get a wrong loggingFeatureEnabled setting", true, endpoint.isLoggingFeatureEnabled());
        assertEquals("Get a wrong loggingSizeLimit setting", 200, endpoint.getLoggingSizeLimit());
    }
   
    @Test
    public void testCxfRsEndpointParameters() throws Exception {
        CxfRsComponent component = new CxfRsComponent(context);
        String endpointUri = "cxfrs://http://localhost:" + CTX + "/templatetest/TID/ranges/start=0;end=1?"
            + "httpClientAPI=true&loggingFeatureEnabled=true&loggingSizeLimit=200&q1=11&q2=12";
        CxfRsEndpoint endpoint = (CxfRsEndpoint)component.createEndpoint(endpointUri);
       
        assertEquals("Get a wrong URI ", endpointUri, endpoint.getEndpointUri());
        assertEquals("Get a wrong usingClientAPI option", true, endpoint.isHttpClientAPI());
        assertNotNull("The Parameter should not be null" + endpoint.getParameters());
        assertEquals("Get a wrong parameter map", "{q1=11, q2=12}", endpoint.getParameters().toString());
    }
   
    @Test
    public void testCxfRsEndpointResourceClass() throws Exception {
        String endpointUri = "cxfrs://http://localhost:" + CTX + ""
            + "?resourceClass=org.apache.camel.component.cxf.jaxrs.testbean.CustomerService";
           
        CxfRsComponent component = new CxfRsComponent(context);
        CxfRsEndpoint endpoint = (CxfRsEndpoint)component.createEndpoint(endpointUri);
       
        assertNotNull("The endpoint should not be null ", endpoint);
        assertEquals("Get a wrong address ", endpointUri, endpoint.getEndpointUri());
        assertEquals("Get a wrong size of resouces classes", 1, endpoint.getResourceClasses().size());
        assertEquals("Get a wrong resources class", CustomerService.class, endpoint.getResourceClasses().get(0));
    }
   
    @Test
    public void testCxfRsEndpointSetProvider() throws Exception {

        String endpointUri = "cxfrs://http://localhost:" + CTX + ""
                             + "?resourceClass=org.apache.camel.component.cxf.jaxrs.testbean.CustomerService";

        CxfRsComponent component = new CxfRsComponent(context);
        CxfRsEndpoint endpoint = (CxfRsEndpoint)component.createEndpoint(endpointUri);
        JSONProvider<?> jsonProvider = new JSONProvider<Object>();
        jsonProvider.setDropRootElement(true);
        jsonProvider.setSupportUnwrapped(true);
        endpoint.setProvider(jsonProvider);
        JAXRSServerFactoryBean sfb = endpoint.createJAXRSServerFactoryBean();
        assertEquals("Get a wrong proider size", 1, sfb.getProviders().size());
        JAXRSClientFactoryBean cfb = endpoint.createJAXRSClientFactoryBean();
        assertEquals("Get a wrong proider size", 1, cfb.getProviders().size());
    }

}
TOP

Related Classes of org.apache.camel.component.cxf.jaxrs.CxfRsEndpointTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.