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

com.github.dreamhead.moco.parser.model.MountSetting Maven / Gradle / Ivy

Go to download

Moco is a 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.parser.model;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.github.dreamhead.moco.ResponseHandler;
import com.github.dreamhead.moco.mount.MountPredicate;
import com.google.common.base.Function;
import com.google.common.base.MoreObjects;

import java.util.List;

import static com.github.dreamhead.moco.MocoMount.exclude;
import static com.github.dreamhead.moco.MocoMount.include;
import static com.google.common.collect.ImmutableList.of;
import static com.google.common.collect.Iterables.concat;
import static com.google.common.collect.Iterables.toArray;
import static com.google.common.collect.Iterables.transform;

@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
public class MountSetting extends ResponseSetting {
    private String dir;
    private String uri;
    private List includes = of();
    private List excludes = of();

    public String getDir() {
        return dir;
    }

    public String getUri() {
        return uri;
    }

    public MountPredicate[] getMountPredicates() {
        return toArray(concat(
                transform(includes, toInclude()),
                transform(excludes, toExclude())), MountPredicate.class);
    }

    private Function toInclude() {
        return new Function() {
            @Override
            public MountPredicate apply(final String input) {
                return include(input);
            }
        };
    }

    private Function toExclude() {
        return new Function() {
            @Override
            public MountPredicate apply(final String input) {
                return exclude(input);
            }
        };
    }

    public ResponseHandler getResponseHandler() {
        return this.asResponseSetting().getResponseHandler();
    }

    @Override
    public String toString() {
        return MoreObjects.toStringHelper(this)
                .omitNullValues()
                .add("dir", dir)
                .add("uri", uri)
                .add("includes", toStringList(includes))
                .add("excludes", toStringList(excludes))
                .add("response", super.toString())
                .toString();
    }

    private List toStringList(final List includes) {
        if (includes.isEmpty()) {
            return null;
        }

        return includes;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy