001/**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.camel.component.test;
018
019import java.net.URI;
020import java.util.HashMap;
021import java.util.Map;
022
023import org.apache.camel.Endpoint;
024import org.apache.camel.impl.UriEndpointComponent;
025import org.apache.camel.util.CamelContextHelper;
026import org.apache.camel.util.ObjectHelper;
027import org.apache.camel.util.URISupport;
028import org.apache.camel.util.UnsafeUriCharactersEncoder;
029
030/**
031 * The <a href="http://camel.apache.org/test.html">Test Component</a> is for simplifying unit and integration tests.
032 *
033 * Component for testing by polling test messages from another endpoint on startup as the expected message bodies to
034 * receive during testing.
035 *
036 * @version 
037 */
038public class TestComponent extends UriEndpointComponent {
039
040    public TestComponent() {
041        super(TestEndpoint.class);
042    }
043
044    @Override
045    protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
046        Long timeout = getAndRemoveParameter(parameters, "timeout", Long.class);
047        TestEndpoint answer = new TestEndpoint(uri, this);
048        if (timeout != null) {
049            answer.setTimeout(timeout);
050        }
051        setProperties(answer, parameters);
052
053        // from the rest create a new uri with those parameters
054        String endpointUri = URISupport.appendParametersToURI(remaining, parameters);
055        Endpoint endpoint = CamelContextHelper.getMandatoryEndpoint(getCamelContext(), endpointUri);
056        answer.setExpectedMessageEndpoint(endpoint);
057        return answer;
058    }
059
060}