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

com.github.dreamhead.moco.setting.HttpSetting Maven / Gradle / Ivy

Go to download

Moco is an easy setup stub framework, mainly focusing on testing and integration.

There is a newer version: 1.5.0
Show newest version
package com.github.dreamhead.moco.setting;

import com.github.dreamhead.moco.HttpResponseSetting;
import com.github.dreamhead.moco.MocoConfig;
import com.github.dreamhead.moco.RequestMatcher;
import com.github.dreamhead.moco.internal.InternalApis;
import com.github.dreamhead.moco.matcher.AndRequestMatcher;
import com.github.dreamhead.moco.resource.Resource;
import com.github.dreamhead.moco.util.RedirectDelegate;

import static com.github.dreamhead.moco.util.Configs.configItem;
import static com.google.common.collect.ImmutableList.of;

public class HttpSetting extends BaseSetting
        implements Setting, HttpResponseSetting {
    private final RedirectDelegate delegate = new RedirectDelegate();

    public HttpSetting(final RequestMatcher matcher) {
        super(matcher);
    }

    @Override
    protected BaseSetting createSetting(final RequestMatcher matcher) {
        return new HttpSetting(matcher);
    }

    @SuppressWarnings("unchecked")
    protected RequestMatcher configMatcher(final RequestMatcher matcher, final MocoConfig config) {
        RequestMatcher appliedMatcher = configItem(matcher, config);
        if (config.isFor(MocoConfig.URI_ID) && matcher == appliedMatcher) {
            return new AndRequestMatcher(of(appliedMatcher, InternalApis.context((String) config.apply(""))));
        }

        return appliedMatcher;
    }

    @Override
    public HttpResponseSetting redirectTo(final String url) {
        return delegate.redirectTo(this, url);
    }

    @Override
    public HttpResponseSetting redirectTo(final Resource url) {
        return delegate.redirectTo(this, url);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy