/* * The MIT License * Copyright © 2014-2021 Ilkka Seppälä * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ package com.iluwatar.claimcheckpattern; import com.microsoft.azure.functions.HttpResponseMessage; import com.microsoft.azure.functions.HttpStatus; import com.microsoft.azure.functions.HttpStatusType; import java.util.HashMap; import java.util.Map; /** * The mock for HttpResponseMessage, can be used in unit tests to verify if the * returned response by HTTP trigger function is correct or not. */ public class HttpResponseMessageMock implements HttpResponseMessage { private int httpStatusCode; private HttpStatusType httpStatus; private Object body; private Map headers; public HttpResponseMessageMock(HttpStatusType status, Map headers, Object body) { this.httpStatus = status; this.httpStatusCode = status.value(); this.headers = headers; this.body = body; } @Override public HttpStatusType getStatus() { return this.httpStatus; } @Override public int getStatusCode() { return httpStatusCode; } @Override public String getHeader(String key) { return this.headers.get(key); } @Override public Object getBody() { return this.body; } public static class HttpResponseMessageBuilderMock implements HttpResponseMessage.Builder { private Object body; private int httpStatusCode; private Map headers = new HashMap<>(); private HttpStatusType httpStatus; public Builder status(HttpStatus status) { this.httpStatusCode = status.value(); this.httpStatus = status; return this; } @Override public Builder status(HttpStatusType httpStatusType) { this.httpStatusCode = httpStatusType.value(); this.httpStatus = httpStatusType; return this; } @Override public HttpResponseMessage.Builder header(String key, String value) { this.headers.put(key, value); return this; } @Override public HttpResponseMessage.Builder body(Object body) { this.body = body; return this; } @Override public HttpResponseMessage build() { return new HttpResponseMessageMock(this.httpStatus, this.headers, this.body); } } }