net.paslavsky.springrest.MetadataBuilder.java Source code

Java tutorial

Introduction

Here is the source code for net.paslavsky.springrest.MetadataBuilder.java

Source

/*
 * Copyright (c) 2014 Andrey Paslavsky.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.paslavsky.springrest;

import org.springframework.http.HttpMethod;

import java.util.HashMap;

/**
* This class help to build {@link net.paslavsky.springrest.RestMethodMetadata} for tests
*
* @author Andrey Paslavsky
* @version 1.0
*/
class MetadataBuilder {
    private final RestMethodMetadata metadata;

    MetadataBuilder() {
        metadata = new RestMethodMetadata();
        metadata.setHttpMethod(HttpMethod.GET);
        metadata.setMethodReturnType(Void.TYPE);
        metadata.setResponseClass(Void.class);
        metadata.setQueryParameters(new HashMap<String, Integer>());
        metadata.setUriVarParameters(new HashMap<String, Integer>());
        metadata.setRequestHeaderParameters(new HashMap<String, Integer>());
    }

    MetadataBuilder addQueryParameter(String name, Integer paramNo) {
        metadata.getQueryParameters().put(name, paramNo);
        return this;
    }

    MetadataBuilder addUriVarParameter(String name, Integer paramNo) {
        metadata.getUriVarParameters().put(name, paramNo);
        return this;
    }

    MetadataBuilder addRequestHeaderParameter(String name, Integer paramNo) {
        metadata.getRequestHeaderParameters().put(name, paramNo);
        return this;
    }

    MetadataBuilder setCommonPath(String commonPath) {
        metadata.setCommonPath(commonPath);
        return this;
    }

    MetadataBuilder setHttpMethod(HttpMethod httpMethod) {
        metadata.setHttpMethod(httpMethod);
        return this;
    }

    MetadataBuilder setResponseClass(Class<?> responseClass) {
        metadata.setResponseClass(responseClass);
        return this;
    }

    MetadataBuilder setMethodReturnType(Class<?> methodReturnType) {
        metadata.setMethodReturnType(methodReturnType);
        return this;
    }

    MetadataBuilder setAdditionalPath(String additionalPath) {
        metadata.setAdditionalPath(additionalPath);
        return this;
    }

    MetadataBuilder setRequestParameter(Integer requestParameter) {
        metadata.setRequestParameter(requestParameter);
        return this;
    }

    RestMethodMetadata build() {
        return metadata;
    }
}