com.github.dreamhead.moco.setting.HttpSetting Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of moco-core Show documentation
Show all versions of moco-core Show documentation
Moco is an easy setup stub framework, mainly focusing on testing and integration.
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.github.dreamhead.moco.util.Configs.configItems;
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
@SuppressWarnings("unchecked")
public Setting apply(final MocoConfig config) {
RequestMatcher appliedMatcher = configItem(this.matcher, config);
if (config.isFor(MocoConfig.URI_ID) && this.matcher == appliedMatcher) {
appliedMatcher = new AndRequestMatcher(of(appliedMatcher, InternalApis.context((String) config.apply(""))));
}
HttpSetting setting = new HttpSetting(appliedMatcher);
setting.handler = configItem(this.handler, config);
setting.eventTriggers = configItems(eventTriggers, config);
return setting;
}
@Override
public HttpResponseSetting redirectTo(final String url) {
return delegate.redirectTo(this, url);
}
@Override
public HttpResponseSetting redirectTo(final Resource url) {
return delegate.redirectTo(this, url);
}
}