"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/HttpTestUtils.java" between
httpcomponents-client-5.2-src.tar.gz and httpcomponents-client-5.2.1-src.tar.gz

About: Apache HttpComponents Client provides reusable components for client-side authentication, HTTP state management, and HTTP connection management. Java sources.

HttpTestUtils.java  (httpcomponents-client-5.2-src):HttpTestUtils.java  (httpcomponents-client-5.2.1-src)
skipping to change at line 35 skipping to change at line 35
* *
*/ */
package org.apache.hc.client5.http.impl.cache; package org.apache.hc.client5.http.impl.cache;
import java.io.InputStream; import java.io.InputStream;
import java.time.Duration; import java.time.Duration;
import java.time.Instant; import java.time.Instant;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.Random; import java.util.Random;
import org.apache.hc.client5.http.cache.HttpCacheEntry; import org.apache.hc.client5.http.cache.HttpCacheEntry;
import org.apache.hc.client5.http.utils.DateUtils; import org.apache.hc.client5.http.utils.DateUtils;
import org.apache.hc.core5.http.ClassicHttpRequest; import org.apache.hc.core5.http.ClassicHttpRequest;
import org.apache.hc.core5.http.ClassicHttpResponse; import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.Header; import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HeaderElement; import org.apache.hc.core5.http.HeaderElement;
import org.apache.hc.core5.http.HttpEntity; import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.HttpHeaders; import org.apache.hc.core5.http.HttpHeaders;
skipping to change at line 58 skipping to change at line 59
import org.apache.hc.core5.http.HttpStatus; import org.apache.hc.core5.http.HttpStatus;
import org.apache.hc.core5.http.HttpVersion; import org.apache.hc.core5.http.HttpVersion;
import org.apache.hc.core5.http.Method; import org.apache.hc.core5.http.Method;
import org.apache.hc.core5.http.ProtocolVersion; import org.apache.hc.core5.http.ProtocolVersion;
import org.apache.hc.core5.http.io.entity.ByteArrayEntity; import org.apache.hc.core5.http.io.entity.ByteArrayEntity;
import org.apache.hc.core5.http.message.BasicClassicHttpRequest; import org.apache.hc.core5.http.message.BasicClassicHttpRequest;
import org.apache.hc.core5.http.message.BasicClassicHttpResponse; import org.apache.hc.core5.http.message.BasicClassicHttpResponse;
import org.apache.hc.core5.http.message.BasicHeader; import org.apache.hc.core5.http.message.BasicHeader;
import org.apache.hc.core5.http.message.MessageSupport; import org.apache.hc.core5.http.message.MessageSupport;
import org.apache.hc.core5.util.ByteArrayBuffer; import org.apache.hc.core5.util.ByteArrayBuffer;
import org.apache.hc.core5.util.LangUtils;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
public class HttpTestUtils { public class HttpTestUtils {
/* /*
* "The following HTTP/1.1 headers are hop-by-hop headers..." * "The following HTTP/1.1 headers are hop-by-hop headers..."
* *
* @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.5.1 * @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.5.1
*/ */
private static final String[] HOP_BY_HOP_HEADERS = { "Connection", "Keep-Ali ve", "Proxy-Authenticate", private static final String[] HOP_BY_HOP_HEADERS = { "Connection", "Keep-Ali ve", "Proxy-Authenticate",
skipping to change at line 191 skipping to change at line 191
* its request been handled directly by the origin server." * its request been handled directly by the origin server."
* *
* @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec1.html#sec1.3 * @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec1.html#sec1.3
*/ */
public static boolean semanticallyTransparent( public static boolean semanticallyTransparent(
final ClassicHttpResponse r1, final ClassicHttpResponse r2) throws E xception { final ClassicHttpResponse r1, final ClassicHttpResponse r2) throws E xception {
final boolean entitiesEquivalent = equivalent(r1.getEntity(), r2.getEnti ty()); final boolean entitiesEquivalent = equivalent(r1.getEntity(), r2.getEnti ty());
if (!entitiesEquivalent) { if (!entitiesEquivalent) {
return false; return false;
} }
final boolean statusLinesEquivalent = LangUtils.equals(r1.getReasonPhras e(), r2.getReasonPhrase()) final boolean statusLinesEquivalent = Objects.equals(r1.getReasonPhrase( ), r2.getReasonPhrase())
&& r1.getCode() == r2.getCode(); && r1.getCode() == r2.getCode();
if (!statusLinesEquivalent) { if (!statusLinesEquivalent) {
return false; return false;
} }
return isEndToEndHeaderSubset(r1, r2); return isEndToEndHeaderSubset(r1, r2);
} }
/* Assertions.asserts that protocol versions equivalent. */ /* Assertions.asserts that protocol versions equivalent. */
public static boolean equivalent(final ProtocolVersion v1, final ProtocolVer sion v2) { public static boolean equivalent(final ProtocolVersion v1, final ProtocolVer sion v2) {
return LangUtils.equals(v1 != null ? v1 : HttpVersion.DEFAULT, v2 != nul l ? v2 : HttpVersion.DEFAULT ); return Objects.equals(v1 != null ? v1 : HttpVersion.DEFAULT, v2 != null ? v2 : HttpVersion.DEFAULT );
} }
/* Assertions.asserts that two requests are morally equivalent. */ /* Assertions.asserts that two requests are morally equivalent. */
public static boolean equivalent(final HttpRequest r1, final HttpRequest r2) { public static boolean equivalent(final HttpRequest r1, final HttpRequest r2) {
return equivalent(r1.getVersion(), r2.getVersion()) && return equivalent(r1.getVersion(), r2.getVersion()) &&
LangUtils.equals(r1.getMethod(), r2.getMethod()) && Objects.equals(r1.getMethod(), r2.getMethod()) &&
LangUtils.equals(r1.getRequestUri(), r2.getRequestUri()) && Objects.equals(r1.getRequestUri(), r2.getRequestUri()) &&
isEndToEndHeaderSubset(r1, r2); isEndToEndHeaderSubset(r1, r2);
} }
/* Assertions.asserts that two requests are morally equivalent. */ /* Assertions.asserts that two requests are morally equivalent. */
public static boolean equivalent(final HttpResponse r1, final HttpResponse r 2) { public static boolean equivalent(final HttpResponse r1, final HttpResponse r 2) {
return equivalent(r1.getVersion(), r2.getVersion()) && return equivalent(r1.getVersion(), r2.getVersion()) &&
r1.getCode() == r2.getCode() && r1.getCode() == r2.getCode() &&
LangUtils.equals(r1.getReasonPhrase(), r2.getReasonPhrase()) && Objects.equals(r1.getReasonPhrase(), r2.getReasonPhrase()) &&
isEndToEndHeaderSubset(r1, r2); isEndToEndHeaderSubset(r1, r2);
} }
public static byte[] getRandomBytes(final int nbytes) { public static byte[] getRandomBytes(final int nbytes) {
final byte[] bytes = new byte[nbytes]; final byte[] bytes = new byte[nbytes];
new Random().nextBytes(bytes); new Random().nextBytes(bytes);
return bytes; return bytes;
} }
public static ByteArrayBuffer getRandomBuffer(final int nbytes) { public static ByteArrayBuffer getRandomBuffer(final int nbytes) {
 End of changes. 6 change blocks. 
6 lines changed or deleted 6 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)