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.client2; 014 015import org.apache.http.*; 016import org.apache.juneau.assertions.*; 017 018/** 019 * Used for fluent assertion calls against a response {@link StatusLine} object. 020 * 021 * <h5 class='section'>Example:</h5> 022 * <p class='bcode w800'> 023 * <jc>// Validates the response status code is 200 or 404.</jc> 024 * <jv>client</jv> 025 * .get(<jsf>URI</jsf>) 026 * .run() 027 * .assertStatus().code().isAny(200,404); 028 * </p> 029 */ 030public class RestResponseStatusLineAssertion extends FluentAssertion<RestResponse> { 031 032 private final StatusLine statusLine; 033 034 /** 035 * Constructor. 036 * 037 * @param statusLine The response status line. 038 * @param returns The object to return after the test. 039 */ 040 public RestResponseStatusLineAssertion(StatusLine statusLine, RestResponse returns) { 041 super(null, returns); 042 this.statusLine = statusLine; 043 } 044 045 /** 046 * Returns an assertion against the status code on the response status object. 047 * 048 * @return An assertion against the status code on the response status object. 049 */ 050 public FluentIntegerAssertion<RestResponse> code() { 051 return new FluentIntegerAssertion<>(this, statusLine.getStatusCode(), returns()); 052 } 053 054 /** 055 * Returns an assertion against the reason phrase on the response status object. 056 * 057 * @return An assertion against the reason phrase on the response status object. 058 */ 059 public FluentStringAssertion<RestResponse> reason() { 060 return new FluentStringAssertion<>(this, statusLine.getReasonPhrase(), returns()); 061 } 062 063 /** 064 * Returns an assertion against the protocol on the response status object. 065 * 066 * @return An assertion against the protocol on the response status object. 067 */ 068 public FluentStringAssertion<RestResponse> protocol() { 069 return new FluentStringAssertion<>(this, statusLine.getProtocolVersion().getProtocol(), returns()); 070 } 071 072 /** 073 * Returns an assertion against the protocol major version on the response status object. 074 * 075 * @return An assertion against the protocol major version on the response status object. 076 */ 077 public FluentIntegerAssertion<RestResponse> major() { 078 return new FluentIntegerAssertion<>(this, statusLine.getProtocolVersion().getMajor(), returns()); 079 } 080 081 /** 082 * Returns an assertion against the protocol minor version on the response status object. 083 * 084 * @return An assertion against the protocol minor version on the response status object. 085 */ 086 public FluentIntegerAssertion<RestResponse> minor() { 087 return new FluentIntegerAssertion<>(this, statusLine.getProtocolVersion().getMinor(), returns()); 088 } 089}