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   /**
046    * Provides the ability to perform fluent-style assertions on this response status line.
047    *
048    * <h5 class='section'>Examples:</h5>
049    * <p class='bjava'>
050    *    <jc>// Validates the content type header is provided.</jc>
051    *    <jv>client</jv>
052    *       .get(<jsf>URI</jsf>)
053    *       .run()
054    *       .getStatusLine().assertValue().asCode().is(200);
055    * </p>
056    *
057    * @return A new fluent assertion object.
058    */
059   public FluentResponseStatusLineAssertion<ResponseStatusLine> assertValue() {
060      return new FluentResponseStatusLineAssertion<>(this, this);
061   }
062
063   @Override /* Overridden from StatusLine */
064   public ProtocolVersion getProtocolVersion() { return inner.getProtocolVersion(); }
065
066   @Override /* Overridden from StatusLine */
067   public String getReasonPhrase() { return inner.getReasonPhrase(); }
068
069   @Override /* Overridden from StatusLine */
070   public int getStatusCode() { return inner.getStatusCode(); }
071
072   /**
073    * Returns the response that created this object.
074    *
075    * @return The response that created this object.
076    */
077   public RestResponse response() {
078      return response;
079   }
080
081   @Override /* Overridden from Object */
082   public String toString() {
083      return inner.toString();
084   }
085}