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

com.github.dreamhead.moco.rest.SubResourceSetting 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.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();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy