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