f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott/*
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott * The contents of this file are subject to the terms of the Common Development and
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott * Distribution License (the License). You may not use this file except in compliance with the
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott * License.
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott *
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott * specific language governing permission and limitations under the License.
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott *
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott * When distributing Covered Software, include this CDDL Header Notice in each file and include
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott * Header, with the fields enclosed by brackets [] replaced by your own identifying
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott * information: "Portions copyright [year] [name of copyright owner]".
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott *
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott * Copyright 2014 ForgeRock AS.
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott */
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshottpackage org.forgerock.http.client.response;
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshottimport org.testng.annotations.Test;
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshottimport java.util.HashMap;
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshottimport java.util.Map;
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshottimport static org.testng.Assert.assertSame;
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshottimport static org.testng.Assert.assertTrue;
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshottpublic class SimpleHttpClientResponseTest {
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott @Test
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott public void shouldConstructSimpleRequestWithCorrectMethod() {
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott Integer statusCode = new Integer(200);
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott String reasonPhrase = "OK";
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott String messageBody = "Example message body";
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott Map<String,String> headers = new HashMap<String, String>();
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott headers.put("key", "value");
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott Map<String,String> cookies = new HashMap<String, String>();
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott cookies.put("key", "value");
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott HttpClientResponse response = new SimpleHttpClientResponse(statusCode, reasonPhrase, headers, messageBody,
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott cookies);
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott assertSame(response.getStatusCode(), statusCode, "Response status code should match set status code");
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott assertSame(response.getReasonPhrase(), reasonPhrase, "Response reason phrase should match set reason phrase");
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott assertSame(response.getEntity(), messageBody, "Response entity should match set entity");
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott assertSame(response.getHeaders(), headers, "Response headers should match set headers");
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott assertSame(response.getCookies(), cookies, "Response cookies should match set cookies");
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott assertTrue(response.hasHeaders(), "Response should have headers");
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott assertTrue(response.hasCookies(), "Response should have cookies");
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott }
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott}