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

com.capitalone.dashboard.testutil.TestRestOperations Maven / Gradle / Ivy

There is a newer version: 4.0.2
Show newest version
package com.capitalone.dashboard.testutil;

import com.capitalone.dashboard.client.RestOperationsSupplier;
import org.springframework.http.HttpStatus;
import org.springframework.web.client.RestOperations;

import java.util.HashMap;
import java.util.Map;

public class TestRestOperations implements RestOperationsSupplier {
    TestRestTemplate template;

    private Map> response;

    public TestRestOperations(Map> response) {
        this.response = response;
    }

    public Map> getResponse() {
        return response;
    }

    public void addResponse(String key, TestResponse testResponse) {
        if (response == null) {
            response = new HashMap<>();
        }
        this.response.put(key, testResponse);
    }

    public void addResponse(String key, T body, HttpStatus httpStatus) {
        if (response == null) {
            response = new HashMap<>();
        }
        this.response.put(key, new TestResponse<>(body, httpStatus));
        if (template != null) {
            template.addResponse(key, new TestResponse<>(body, httpStatus));
        }
    }

    public TestRestTemplate getTemplate() {
        return template;
    }

    public void setTemplate(TestRestTemplate template) {
        this.template = template;
    }

    @Override
    public RestOperations get() {
        if (template == null) {
            template = new TestRestTemplate<>(response);
        }
        return template;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy