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

com.github.dreamhead.moco.resource.reader.TemplateRequest 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.resource.reader;

import com.github.dreamhead.moco.HttpProtocolVersion;
import com.github.dreamhead.moco.HttpRequest;
import com.github.dreamhead.moco.Request;
import com.github.dreamhead.moco.model.DefaultHttpRequest;
import com.github.dreamhead.moco.model.MessageContent;
import com.google.common.collect.ImmutableMap;

public class TemplateRequest {
    private Request request;

    public TemplateRequest(final Request request) {
        this.request = request;
    }

    public MessageContent getContent() {
        return this.request.getContent();
    }

    public HttpProtocolVersion getVersion() {
        if (this.request instanceof HttpRequest) {
            return ((HttpRequest) this.request).getVersion();
        }

        throw new IllegalArgumentException("Request is not HTTP request");
    }

    public ImmutableMap getHeaders() {
        if (this.request instanceof HttpRequest) {
            return ((HttpRequest) this.request).getHeaders();
        }

        throw new IllegalArgumentException("Request is not HTTP request");
    }

    public String getUri() {
        if (this.request instanceof HttpRequest) {
            return ((HttpRequest) this.request).getUri();
        }

        throw new IllegalArgumentException("Request is not HTTP request");
    }

    public String getMethod() {
        if (this.request instanceof HttpRequest) {
            return ((HttpRequest) this.request).getMethod();
        }

        throw new IllegalArgumentException("Request is not HTTP request");
    }

    public ImmutableMap getQueries() {
        if (this.request instanceof HttpRequest) {
            HttpRequest httpRequest = (HttpRequest) this.request;
            ImmutableMap.Builder builder = ImmutableMap.builder();
            ImmutableMap queries = httpRequest.getQueries();
            for (String key : queries.keySet()) {
                builder.put(key, queries.get(key)[0]);
            }

            return builder.build();
        }

        throw new IllegalArgumentException("Request is not HTTP request");
    }

    public ImmutableMap getForms() {
        if (this.request instanceof DefaultHttpRequest) {
            return ((DefaultHttpRequest) this.request).getForms();
        }

        throw new IllegalArgumentException("Request is not HTTP request");
    }

    public ImmutableMap getCookies() {
        if (this.request instanceof DefaultHttpRequest) {
            return ((DefaultHttpRequest) this.request).getCookies();
        }

        throw new IllegalArgumentException("Request is not HTTP request");
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy