All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.consol.citrus.endpoint.AbstractEndpointBuilder Maven / Gradle / Ivy

There is a newer version: 3.4.1
Show newest version
/*
 * Copyright 2006-2016 the original author or authors.
 *
 * Licensed 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 com.consol.citrus.endpoint;

import com.consol.citrus.TestActor;
import com.consol.citrus.common.InitializingPhase;
import com.consol.citrus.exceptions.CitrusRuntimeException;
import com.consol.citrus.spi.ReferenceResolver;
import com.consol.citrus.spi.ReferenceResolverAware;

/**
 * @author Christoph Deppisch
 * @since 2.5
 */
public abstract class AbstractEndpointBuilder implements EndpointBuilder {

    /**
     * Sets the endpoint name.
     * @param endpointName
     * @return
     */
    public AbstractEndpointBuilder name(String endpointName) {
        getEndpoint().setName(endpointName);
        return this;
    }

    /**
     * Sets the endpoint actor.
     * @param actor
     * @return
     */
    public AbstractEndpointBuilder actor(TestActor actor) {
        getEndpoint().setActor(actor);
        return this;
    }

    /**
     * Initializes the endpoint.
     * @return
     */
    public AbstractEndpointBuilder initialize() {
        if (getEndpoint() instanceof InitializingPhase) {
            try {
                ((InitializingPhase) getEndpoint()).initialize();
            } catch (Exception e) {
                throw new CitrusRuntimeException("Failed to initialize server", e);
            }
        }

        return this;
    }

    /**
     * Sets the reference resolver.
     * @param referenceResolver
     * @return
     */
    public AbstractEndpointBuilder referenceResolver(ReferenceResolver referenceResolver) {
        if (getEndpoint() instanceof ReferenceResolverAware) {
            ((ReferenceResolverAware) getEndpoint()).setReferenceResolver(referenceResolver);
        }

        return this;
    }

    @Override
    public T build() {
        return getEndpoint();
    }

    @Override
    public boolean supports(Class endpointType) {
        return getEndpoint().getClass().equals(endpointType);
    }

    /**
     * Gets the target endpoint instance.
     * @return
     */
    protected abstract T getEndpoint();
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy