com.github.dreamhead.moco.rest.SubResourceSetting 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.rest;
import com.github.dreamhead.moco.HttpRequest;
import com.github.dreamhead.moco.ResponseHandler;
import com.github.dreamhead.moco.RestIdMatcher;
import com.github.dreamhead.moco.RestSetting;
import com.google.common.base.Optional;
import static com.github.dreamhead.moco.util.URLs.join;
public final class SubResourceSetting implements RestSetting {
private final RestIdMatcher id;
private final String name;
private final Iterable settings;
public SubResourceSetting(final RestIdMatcher id,
final String name,
final Iterable settings) {
this.id = id;
this.name = name;
this.settings = settings;
}
@Override
public boolean isSimple() {
return false;
}
@Override
public Optional getMatched(final RestIdMatcher resourceName, final HttpRequest httpRequest) {
for (RestSetting setting : settings) {
RestIdMatcher idMatcher = RestIdMatchers.match(join(resourceName.resourceUri(),
this.id.resourceUri(),
this.name));
Optional responseHandler = setting.getMatched(idMatcher,
httpRequest);
if (responseHandler.isPresent()) {
return responseHandler;
}
}
return Optional.absent();
}
}