001// *************************************************************************************************************************** 002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * 003// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * 004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * 005// * with the License. You may obtain a copy of the License at * 006// * * 007// * http://www.apache.org/licenses/LICENSE-2.0 * 008// * * 009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * 010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * 011// * specific language governing permissions and limitations under the License. * 012// *************************************************************************************************************************** 013package org.apache.juneau.rest.client; 014 015import org.apache.http.*; 016import org.apache.juneau.rest.client.assertion.*; 017 018/** 019 * An implementation of {@link StatusLine} that adds assertions methods. 020 * 021 * <h5 class='section'>See Also:</h5><ul> 022 * <li class='link'><a class="doclink" href="../../../../../index.html#juneau-rest-client">juneau-rest-client</a> 023 * </ul> 024 */ 025public class ResponseStatusLine implements StatusLine { 026 027 private final RestResponse response; 028 private final StatusLine inner; 029 030 /** 031 * Constructor. 032 * 033 * @param response The response that created this object. 034 * @param inner The status line returned by the underlying client. 035 */ 036 protected ResponseStatusLine(RestResponse response, StatusLine inner) { 037 this.response = response; 038 this.inner = inner; 039 } 040 041 @Override /* StatusLine */ 042 public ProtocolVersion getProtocolVersion() { 043 return inner.getProtocolVersion(); 044 } 045 046 @Override /* StatusLine */ 047 public int getStatusCode() { 048 return inner.getStatusCode(); 049 } 050 051 @Override /* StatusLine */ 052 public String getReasonPhrase() { 053 return inner.getReasonPhrase(); 054 } 055 056 //------------------------------------------------------------------------------------------------------------------ 057 // Assertions 058 //------------------------------------------------------------------------------------------------------------------ 059 060 /** 061 * Provides the ability to perform fluent-style assertions on this response status line. 062 * 063 * <h5 class='section'>Examples:</h5> 064 * <p class='bjava'> 065 * <jc>// Validates the content type header is provided.</jc> 066 * <jv>client</jv> 067 * .get(<jsf>URI</jsf>) 068 * .run() 069 * .getStatusLine().assertValue().asCode().is(200); 070 * </p> 071 * 072 * @return A new fluent assertion object. 073 */ 074 public FluentResponseStatusLineAssertion<ResponseStatusLine> assertValue() { 075 return new FluentResponseStatusLineAssertion<>(this, this); 076 } 077 078 /** 079 * Returns the response that created this object. 080 * 081 * @return The response that created this object. 082 */ 083 public RestResponse response() { 084 return response; 085 } 086 087 //------------------------------------------------------------------------------------------------------------------ 088 // Other methods 089 //------------------------------------------------------------------------------------------------------------------ 090 091 @Override /* Object */ 092 public String toString() { 093 return inner.toString(); 094 } 095}