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.util.Map;
020
021import org.apache.camel.Endpoint;
022import org.apache.camel.impl.UriEndpointComponent;
023import org.apache.camel.util.CamelContextHelper;
024import org.apache.camel.util.URISupport;
025
026/**
027 * The <a href="http://camel.apache.org/test.html">Test Component</a> is for simplifying unit and integration tests.
028 *
029 * Component for testing by polling test messages from another endpoint on startup as the expected message bodies to
030 * receive during testing.
031 *
032 * @version 
033 */
034public class TestComponent extends UriEndpointComponent {
035
036    public TestComponent() {
037        super(TestEndpoint.class);
038    }
039
040    @Override
041    protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
042        Long timeout = getAndRemoveParameter(parameters, "timeout", Long.class);
043        TestEndpoint answer = new TestEndpoint(uri, this);
044        if (timeout != null) {
045            answer.setTimeout(timeout);
046        }
047        setProperties(answer, parameters);
048
049        // from the rest create a new uri with those parameters
050        String endpointUri = URISupport.appendParametersToURI(remaining, parameters);
051        Endpoint endpoint = CamelContextHelper.getMandatoryEndpoint(getCamelContext(), endpointUri);
052        answer.setExpectedMessageEndpoint(endpoint);
053        return answer;
054    }
055
056}