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.classic;
018
019import org.apache.http.*;
020import org.apache.juneau.rest.client.classic.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/JuneauRestClient">juneau-rest-client-classic</a>
027 * </ul>
028 */
029@SuppressWarnings({
030   "resource" // response is owned by the RestCall that created this status line; lifecycle managed externally
031})
032public class ResponseStatusLine implements StatusLine {
033
034   private final RestResponse response;
035   private final StatusLine inner;
036
037   /**
038    * Constructor.
039    *
040    * @param response The response that created this object.
041    * @param inner The status line returned by the underlying client.
042    */
043   protected ResponseStatusLine(RestResponse response, StatusLine inner) {
044      this.response = response;
045      this.inner = inner;
046   }
047
048   /**
049    * Provides the ability to perform fluent-style assertions on this response status line.
050    *
051    * <h5 class='section'>Examples:</h5>
052    * <p class='bjava'>
053    *    <jc>// Validates the content type header is provided.</jc>
054    *    <jv>client</jv>
055    *       .get(<jsf>URI</jsf>)
056    *       .run()
057    *       .getStatusLine().assertValue().asCode().is(200);
058    * </p>
059    *
060    * @return A new fluent assertion object.
061    */
062   public FluentResponseStatusLineAssertion<ResponseStatusLine> assertValue() {
063      return new FluentResponseStatusLineAssertion<>(this, this);
064   }
065
066   @Override /* Overridden from StatusLine */
067   public ProtocolVersion getProtocolVersion() { return inner.getProtocolVersion(); }
068
069   @Override /* Overridden from StatusLine */
070   public String getReasonPhrase() { return inner.getReasonPhrase(); }
071
072   @Override /* Overridden from StatusLine */
073   public int getStatusCode() { return inner.getStatusCode(); }
074
075   /**
076    * Returns the response that created this object.
077    *
078    * @return The response that created this object.
079    */
080   public RestResponse response() {
081      return response;
082   }
083
084   @Override /* Overridden from Object */
085   public String toString() {
086      return inner.toString();
087   }
088}