1
0
mirror of https://github.com/square/okhttp.git synced 2025-07-31 05:04:26 +03:00

Android Additional Tests (#6420)

This commit is contained in:
Yuri Schimke
2020-11-15 06:42:22 +00:00
committed by GitHub
parent 4adcb33d1b
commit ff959f8fd5
10 changed files with 44 additions and 11 deletions

View File

@ -31,6 +31,10 @@ repositories {
}
}
def isIDE = properties.containsKey('android.injected.invoked.from.ide') ||
(System.getenv("XPC_SERVICE_NAME") ?: "").contains("intellij") ||
System.getenv("IDEA_INITIAL_DIRECTORY") != null
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
@ -60,6 +64,17 @@ android {
'notPackage': 'org.bouncycastle'
])
}
if (!isIDE) {
sourceSets {
named("androidTest") {
it.java.srcDirs += project.file("../okhttp-brotli/src/test/java")
it.java.srcDirs += project.file("../okhttp-dnsoverhttps/src/test/java")
it.java.srcDirs += project.file("../okhttp-logging-interceptor/src/test/java")
it.java.srcDirs += project.file("../okhttp-sse/src/test/java")
}
}
}
}
dependencies {
@ -77,10 +92,12 @@ dependencies {
androidTestImplementation "org.bouncycastle:bctls-jdk15to18:${versions.bouncycastle}"
androidTestImplementation "org.conscrypt:conscrypt-android:2.5.1"
androidTestImplementation project(':mockwebserver-junit5')
androidTestImplementation project(':okhttp-tls')
androidTestImplementation project(':okhttp-brotli')
androidTestImplementation project(':okhttp-dnsoverhttps')
androidTestImplementation project(':okhttp-logging-interceptor')
androidTestImplementation project(':okhttp-sse')
androidTestImplementation project(':okhttp-testing-support')
androidTestImplementation project(':okhttp-tls')
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
androidTestImplementation 'org.apache.httpcomponents.client5:httpclient5:5.0'

View File

@ -331,6 +331,7 @@ class OkHttpTest(val server: MockWebServer) {
}
@Test
@Disabled("cleartext required for additional okhttp wide tests")
fun testHttpRequestBlocked() {
assumeTrue(Build.VERSION.SDK_INT >= 23)
@ -671,6 +672,7 @@ class OkHttpTest(val server: MockWebServer) {
}
@Test
@Disabled("TODO: currently logging okhttp3.internal.concurrent.TaskRunner, okhttp3.internal.http2.Http2")
fun testLoggingLevels() {
enableTls()

View File

@ -1,4 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="okhttp.android.test">
<application
android:usesCleartextTraffic="true" />
<uses-permission android:name="android.permission.INTERNET" />
</manifest>

View File

@ -15,7 +15,7 @@ dependencies {
testImplementation project(':okhttp-testing-support')
testImplementation project(':mockwebserver-deprecated')
testRuntimeOnly project(':mockwebserver-junit5')
testImplementation project(':mockwebserver-junit5')
testImplementation deps.conscrypt
testImplementation deps.junit
testImplementation deps.assertj

View File

@ -26,6 +26,7 @@ import java.util.concurrent.TimeUnit;
import mockwebserver3.MockResponse;
import mockwebserver3.MockWebServer;
import mockwebserver3.RecordedRequest;
import mockwebserver3.junit5.internal.MockWebServerExtension;
import okhttp3.Cache;
import okhttp3.Dns;
import okhttp3.HttpUrl;
@ -36,6 +37,7 @@ import okio.Buffer;
import okio.ByteString;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.RegisterExtension;
import static java.util.Arrays.asList;
@ -43,6 +45,7 @@ import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
@ExtendWith(MockWebServerExtension.class)
public class DnsOverHttpsTest {
@RegisterExtension public final PlatformRule platform = new PlatformRule();

View File

@ -17,7 +17,7 @@ dependencies {
testCompileOnly deps.jsr305
testImplementation deps.junit
testImplementation project(':mockwebserver')
testRuntimeOnly project(':mockwebserver-junit5')
testImplementation project(':mockwebserver-junit5')
testImplementation project(':okhttp-testing-support')
testImplementation project(':okhttp-tls')
testImplementation deps.assertj

View File

@ -22,6 +22,7 @@ import java.util.List;
import java.util.regex.Pattern;
import javax.annotation.Nullable;
import javax.net.ssl.HostnameVerifier;
import mockwebserver3.junit5.internal.MockWebServerExtension;
import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.MediaType;
@ -42,6 +43,7 @@ import okio.BufferedSink;
import okio.ByteString;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.RegisterExtension;
import static okhttp3.tls.internal.TlsUtil.localhost;
@ -50,6 +52,7 @@ import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeThat;
@ExtendWith(MockWebServerExtension.class)
public final class HttpLoggingInterceptorTest {
private static final MediaType PLAIN = MediaType.get("text/plain; charset=utf-8");

View File

@ -17,6 +17,7 @@ package okhttp3.logging;
import java.io.IOException;
import java.net.UnknownHostException;
import mockwebserver3.junit5.internal.MockWebServerExtension;
import okhttp3.Call;
import okhttp3.EventListener;
import okhttp3.HttpUrl;
@ -33,6 +34,7 @@ import mockwebserver3.SocketPolicy;
import okhttp3.tls.HandshakeCertificates;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.RegisterExtension;
import static java.util.Arrays.asList;
@ -42,6 +44,7 @@ import static okhttp3.tls.internal.TlsUtil.localhost;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
@ExtendWith(MockWebServerExtension.class)
public final class LoggingEventListenerTest {
private static final MediaType PLAIN = MediaType.get("text/plain");
@ -98,7 +101,7 @@ public final class LoggingEventListenerTest {
.assertLogMatch(
"responseHeadersEnd: Response\\{protocol=http/1\\.1, code=200, message=OK, url="
+ url
+ "}")
+ "\\}")
.assertLogMatch("responseBodyStart")
.assertLogMatch("responseBodyEnd: byteCount=6")
.assertLogMatch("connectionReleased")
@ -135,7 +138,7 @@ public final class LoggingEventListenerTest {
.assertLogMatch(
"responseHeadersEnd: Response\\{protocol=http/1\\.1, code=200, message=OK, url="
+ url
+ "}")
+ "\\}")
.assertLogMatch("responseBodyStart")
.assertLogMatch("responseBodyEnd: byteCount=0")
.assertLogMatch("connectionReleased")
@ -177,12 +180,12 @@ public final class LoggingEventListenerTest {
+ url.host()
+ ":\\d+, proxy=DIRECT hostAddress="
+ url.host()
+ "/.+ cipherSuite=.+ protocol=h2}")
+ "/.+ cipherSuite=.+ protocol=h2\\}")
.assertLogMatch("requestHeadersStart")
.assertLogMatch("requestHeadersEnd")
.assertLogMatch("responseHeadersStart")
.assertLogMatch(
"responseHeadersEnd: Response\\{protocol=h2, code=200, message=, url=" + url + "}")
"responseHeadersEnd: Response\\{protocol=h2, code=200, message=, url=" + url + "\\}")
.assertLogMatch("responseBodyStart")
.assertLogMatch("responseBodyEnd: byteCount=0")
.assertLogMatch("connectionReleased")
@ -257,10 +260,10 @@ public final class LoggingEventListenerTest {
listener.satisfactionFailure(call, response);
logRecorder
.assertLogMatch("cacheConditionalHit: Response\\{protocol=h2, code=200, message=, url=" + url + "}")
.assertLogMatch("cacheHit: Response\\{protocol=h2, code=200, message=, url=" + url + "}")
.assertLogMatch("cacheConditionalHit: Response\\{protocol=h2, code=200, message=, url=" + url + "\\}")
.assertLogMatch("cacheHit: Response\\{protocol=h2, code=200, message=, url=" + url + "\\}")
.assertLogMatch("cacheMiss")
.assertLogMatch("satisfactionFailure: Response\\{protocol=h2, code=200, message=, url=" + url + "}")
.assertLogMatch("satisfactionFailure: Response\\{protocol=h2, code=200, message=, url=" + url + "\\}")
.assertNoMoreLogs();
}

View File

@ -16,7 +16,7 @@ dependencies {
testImplementation project(':okhttp-testing-support')
testImplementation project(':mockwebserver')
testRuntimeOnly project(':mockwebserver-junit5')
testImplementation project(':mockwebserver-junit5')
testImplementation deps.junit
testImplementation deps.assertj
testCompileOnly deps.jsr305

View File

@ -19,6 +19,7 @@ import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import mockwebserver3.MockResponse;
import mockwebserver3.MockWebServer;
import mockwebserver3.junit5.internal.MockWebServerExtension;
import okhttp3.OkHttpClient;
import okhttp3.OkHttpClientTestRule;
import okhttp3.Request;
@ -28,10 +29,12 @@ import okhttp3.testing.PlatformRule;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.RegisterExtension;
import static org.assertj.core.api.Assertions.assertThat;
@ExtendWith(MockWebServerExtension.class)
public final class EventSourceHttpTest {
@RegisterExtension public final PlatformRule platform = new PlatformRule();