diff --git a/.travis.yml b/.travis.yml index ab31f2699..717267d64 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,12 +5,16 @@ branches: language: android sudo: false +jdk: + - oraclejdk8 + android: components: - - build-tools-23.0.1 - - android-22 - - doc-23 - - extra-android-support + - tools + - platform-tools + - build-tools-25.0.2 + - android-25 + - doc-25 - extra-android-m2repository before_install: diff --git a/Parse/build.gradle b/Parse/build.gradle index df3417f79..26a9149f5 100644 --- a/Parse/build.gradle +++ b/Parse/build.gradle @@ -8,11 +8,11 @@ version = '1.13.2-SNAPSHOT' buildscript { repositories { - mavenCentral() + jcenter() } dependencies { - classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.0.1x' + classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.8.1' } } @@ -39,16 +39,16 @@ android { } } +ext.okhttpVersion = '3.6.0' dependencies { compile 'com.parse.bolts:bolts-tasks:1.4.0' + compile "com.squareup.okhttp3:okhttp:$okhttpVersion" + provided 'com.facebook.stetho:stetho:1.4.2' - provided 'com.squareup.okhttp3:okhttp:3.3.1' - provided 'com.facebook.stetho:stetho:1.3.0' - - testCompile 'org.robolectric:robolectric:3.0' - testCompile 'org.skyscreamer:jsonassert:1.2.3' + testCompile 'org.robolectric:robolectric:3.3' + testCompile 'org.skyscreamer:jsonassert:1.4.0' testCompile 'org.mockito:mockito-core:1.10.19' - testCompile 'com.squareup.okhttp3:mockwebserver:3.3.1' + testCompile "com.squareup.okhttp3:mockwebserver:$okhttpVersion" } android.libraryVariants.all { variant -> diff --git a/Parse/src/main/java/com/parse/NotificationCompat.java b/Parse/src/main/java/com/parse/NotificationCompat.java index 840025cd7..fea56c095 100644 --- a/Parse/src/main/java/com/parse/NotificationCompat.java +++ b/Parse/src/main/java/com/parse/NotificationCompat.java @@ -50,19 +50,22 @@ private static final NotificationCompatImpl IMPL; interface NotificationCompatImpl { - public Notification build(Builder b); + Notification build(Builder b); } static class NotificationCompatImplBase implements NotificationCompatImpl { @Override - public Notification build(Builder b) { - Notification result = (Notification) b.mNotification; - result.setLatestEventInfo(b.mContext, b.mContentTitle, b.mContentText, b.mContentIntent); + public Notification build(Builder builder) { + Notification result = builder.mNotification; + NotificationCompat.Builder newBuilder = new NotificationCompat.Builder(builder.mContext); + newBuilder.setContentTitle(builder.mContentTitle); + newBuilder.setContentText(builder.mContentText); + newBuilder.setContentIntent(builder.mContentIntent); // translate high priority requests into legacy flag - if (b.mPriority > PRIORITY_DEFAULT) { + if (builder.mPriority > PRIORITY_DEFAULT) { result.flags |= FLAG_HIGH_PRIORITY; } - return result; + return newBuilder.build(); } } diff --git a/Parse/src/main/java/com/parse/ParseApacheHttpClient.java b/Parse/src/main/java/com/parse/ParseApacheHttpClient.java deleted file mode 100644 index 57f5989e9..000000000 --- a/Parse/src/main/java/com/parse/ParseApacheHttpClient.java +++ /dev/null @@ -1,247 +0,0 @@ -/* - * Copyright (c) 2015-present, Parse, LLC. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ -package com.parse; - -import android.net.SSLCertificateSocketFactory; -import android.net.SSLSessionCache; -import android.net.http.AndroidHttpClient; - -import com.parse.http.ParseHttpBody; -import com.parse.http.ParseHttpRequest; -import com.parse.http.ParseHttpResponse; - -import org.apache.http.Header; -import org.apache.http.HttpEntity; -import org.apache.http.HttpHost; -import org.apache.http.HttpResponse; -import org.apache.http.client.methods.HttpDelete; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.client.methods.HttpPut; -import org.apache.http.client.methods.HttpUriRequest; -import org.apache.http.client.params.HttpClientParams; -import org.apache.http.conn.ClientConnectionManager; -import org.apache.http.conn.params.ConnManagerParams; -import org.apache.http.conn.params.ConnPerRouteBean; -import org.apache.http.conn.params.ConnRoutePNames; -import org.apache.http.conn.scheme.PlainSocketFactory; -import org.apache.http.conn.scheme.Scheme; -import org.apache.http.conn.scheme.SchemeRegistry; -import org.apache.http.entity.InputStreamEntity; -import org.apache.http.impl.client.DefaultHttpClient; -import org.apache.http.impl.client.DefaultHttpRequestRetryHandler; -import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager; -import org.apache.http.params.BasicHttpParams; -import org.apache.http.params.HttpConnectionParams; -import org.apache.http.params.HttpParams; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.HashMap; -import java.util.Map; - -/** - * An implementation of ParseHttpClient using Apache httpclient library - */ -@SuppressWarnings("deprecation") -/** package */ class ParseApacheHttpClient extends ParseHttpClient { - - private static final String CONTENT_ENCODING_HEADER = "Content-Encoding"; - - private DefaultHttpClient apacheClient; - - public ParseApacheHttpClient(int socketOperationTimeout, SSLSessionCache sslSessionCache) { - // Most of this is from AndroidHttpClient#newInstance() except [1] and [2] - HttpParams params = new BasicHttpParams(); - - // Turn off stale checking. Our connections break all the time anyway, - // and it's not worth it to pay the penalty of checking every time. - HttpConnectionParams.setStaleCheckingEnabled(params, false); - - HttpConnectionParams.setConnectionTimeout(params, socketOperationTimeout); - HttpConnectionParams.setSoTimeout(params, socketOperationTimeout); - HttpConnectionParams.setSocketBufferSize(params, 8192); - - // Don't handle redirects. We copy the setting from AndroidHttpClient. - // For detail, check https://quip.com/Px8jAxnaun2r - HttpClientParams.setRedirecting(params, false); - - // Register standard protocols. - SchemeRegistry schemeRegistry = new SchemeRegistry(); - schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); - schemeRegistry.register(new Scheme("https", SSLCertificateSocketFactory.getHttpSocketFactory( - socketOperationTimeout, sslSessionCache), 443)); - - // [1] AndroidHttpClient defaults to 2 connections per route. Not fun. AND you can't set these - // properties after AndroidHttpClient#newInstance(context) - String maxConnectionsStr = System.getProperty("http.maxConnections"); - if (maxConnectionsStr != null) { - int maxConnections = Integer.parseInt(maxConnectionsStr); - ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(maxConnections)); - ConnManagerParams.setMaxTotalConnections(params, maxConnections); - } - - // [2] Originally from ParseCommand, check proxy - String host = System.getProperty("http.proxyHost"); - String portString = System.getProperty("http.proxyPort"); - if (host != null && host.length() != 0 && portString != null && portString.length() != 0) { - int port = Integer.parseInt(portString); - HttpHost proxy = new HttpHost(host, port, "http"); - params.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); - } - - ClientConnectionManager manager = new ThreadSafeClientConnManager(params, schemeRegistry); - apacheClient = new DefaultHttpClient(manager, params); - - // Disable retry logic by ApacheHttpClient. When we leave the app idle for 3 - 5 min, the next - // request will always fail with NoHttpResponseException: The target server failed to respond, - // in this situation, the Apache httpClient will try to retry the request, - // however, since we use InputStreamEntity which is non-repeatable, we will see the - // NonRepeatableRequestException: Cannot retry request with a non-repeatable request entity. - // We disable the retry logic by ApacheHttpClient to expose the real issue - apacheClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false)); - } - - @Override - /* package */ ParseHttpResponse executeInternal(ParseHttpRequest parseRequest) throws IOException { - HttpUriRequest apacheRequest = getRequest(parseRequest); - - HttpResponse apacheResponse = apacheClient.execute(apacheRequest); - - return getResponse(apacheResponse); - } - - @Override - /* package */ ParseHttpResponse getResponse(HttpResponse apacheResponse) - throws IOException { - if (apacheResponse == null) { - throw new IllegalArgumentException( - "HttpResponse passed to getResponse should not be null." - ); - } - - // Status code - int statusCode = apacheResponse.getStatusLine().getStatusCode(); - - // Content - InputStream content = disableHttpLibraryAutoDecompress() ? - apacheResponse.getEntity().getContent() : - AndroidHttpClient.getUngzippedContent(apacheResponse.getEntity()); - - // Total size - int totalSize = -1; - Header[] contentLengthHeader = apacheResponse.getHeaders("Content-Length"); - // Some encodings, such as chunked encoding, forbid the - // content-length header. - if (contentLengthHeader.length > 0) { - totalSize = Integer.parseInt(contentLengthHeader[0].getValue()); - } - - // Reason phrase - String reasonPhrase = apacheResponse.getStatusLine().getReasonPhrase(); - - // Headers - Map headers = new HashMap<>(); - for (Header header : apacheResponse.getAllHeaders()) { - headers.put(header.getName(), header.getValue()); - } - // If we auto unzip the response stream, we should remove the content-encoding header - if (!disableHttpLibraryAutoDecompress()) { - headers.remove(CONTENT_ENCODING_HEADER); - } - - // Content type - String contentType = null; - HttpEntity entity = apacheResponse.getEntity(); - if (entity != null && entity.getContentType() != null) { - contentType = entity.getContentType().getValue(); - } - - return new ParseHttpResponse.Builder() - .setStatusCode(statusCode) - .setContent(content) - .setTotalSize(totalSize) - .setReasonPhrase(reasonPhrase) - .setHeaders(headers) - .setContentType(contentType) - .build(); - } - - @Override - /* package */ HttpUriRequest getRequest(ParseHttpRequest parseRequest) - throws IOException { - if (parseRequest == null) { - throw new IllegalArgumentException( - "ParseHttpRequest passed to getApacheRequest should not be null." - ); - } - - HttpUriRequest apacheRequest; - ParseHttpRequest.Method method = parseRequest.getMethod(); - String url = parseRequest.getUrl(); - switch (method) { - case GET: - apacheRequest = new HttpGet(url); - break; - case DELETE: - apacheRequest = new HttpDelete(url); - break; - case POST: - apacheRequest = new HttpPost(url); - break; - case PUT: - apacheRequest = new HttpPut(url); - break; - default: - // This case will never be reached since we have already handled this case in - // ParseRequest.newRequest(). - throw new IllegalStateException("Unsupported http method " + method.toString()); - } - - // Set header - for (Map.Entry entry : parseRequest.getAllHeaders().entrySet()) { - apacheRequest.setHeader(entry.getKey(), entry.getValue()); - } - AndroidHttpClient.modifyRequestToAcceptGzipResponse(apacheRequest); - - // Set entity - ParseHttpBody body = parseRequest.getBody(); - switch (method) { - case POST: - ((HttpPost) apacheRequest).setEntity(new ParseApacheHttpEntity(body)); - break; - case PUT: - ((HttpPut) apacheRequest).setEntity(new ParseApacheHttpEntity(body)); - break; - default: - break; - } - return apacheRequest; - } - - /** - * An wrapper of Apache InputStreamEntity. It takes a ParseHttpBody - * and transfer it to a HttpEntity - */ - private static class ParseApacheHttpEntity extends InputStreamEntity { - private ParseHttpBody parseBody; - - public ParseApacheHttpEntity(ParseHttpBody parseBody) throws IOException { - super(parseBody.getContent(), parseBody.getContentLength()); - super.setContentType(parseBody.getContentType()); - this.parseBody = parseBody; - } - - @Override - public void writeTo(OutputStream out) throws IOException { - parseBody.writeTo(out); - } - } -} diff --git a/Parse/src/main/java/com/parse/ParseHttpClient.java b/Parse/src/main/java/com/parse/ParseHttpClient.java index 249983eba..c2f17484b 100644 --- a/Parse/src/main/java/com/parse/ParseHttpClient.java +++ b/Parse/src/main/java/com/parse/ParseHttpClient.java @@ -9,7 +9,6 @@ package com.parse; import android.net.SSLSessionCache; -import android.os.Build; import com.parse.http.ParseHttpRequest; import com.parse.http.ParseHttpResponse; @@ -27,11 +26,9 @@ /** package */ abstract class ParseHttpClient { private static final String TAG = "com.parse.ParseHttpClient"; - private static final String APACHE_HTTPCLIENT_NAME = "org.apache.http"; private static final String URLCONNECTION_NAME = "net.java.URLConnection"; private static final String OKHTTP_NAME = "com.squareup.okhttp3"; - private static final String OKHTTPCLIENT_PATH = "okhttp3.OkHttpClient"; private static final String MAX_CONNECTIONS_PROPERTY_NAME = "http.maxConnections"; private static final String KEEP_ALIVE_PROPERTY_NAME = "http.keepAlive"; @@ -40,16 +37,8 @@ public static ParseHttpClient createClient(int socketOperationTimeout, SSLSessionCache sslSessionCache) { String httpClientLibraryName; ParseHttpClient httpClient; - if (hasOkHttpOnClasspath()) { - httpClientLibraryName = OKHTTP_NAME; - httpClient = new ParseOkHttpClient(socketOperationTimeout, sslSessionCache); - } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - httpClientLibraryName = URLCONNECTION_NAME; - httpClient = new ParseURLConnectionHttpClient(socketOperationTimeout, sslSessionCache); - } else { - httpClientLibraryName = APACHE_HTTPCLIENT_NAME; - httpClient = new ParseApacheHttpClient(socketOperationTimeout, sslSessionCache); - } + httpClientLibraryName = OKHTTP_NAME; + httpClient = new ParseOkHttpClient(socketOperationTimeout, sslSessionCache); PLog.i(TAG, "Using " + httpClientLibraryName + " library for networking communication."); return httpClient; } @@ -65,15 +54,6 @@ public static void setKeepAlive(boolean isKeepAlive) { System.setProperty(KEEP_ALIVE_PROPERTY_NAME, String.valueOf(isKeepAlive)); } - private static boolean hasOkHttpOnClasspath() { - try { - Class.forName(OKHTTPCLIENT_PATH); - return true; - } catch (ClassNotFoundException e) { - return false; - } - } - private boolean hasExecuted; // There is no need to keep locks for interceptor lists since they will only be changed before diff --git a/Parse/src/main/java/com/parse/ParseSQLiteCursor.java b/Parse/src/main/java/com/parse/ParseSQLiteCursor.java index a31e12072..2c542c613 100644 --- a/Parse/src/main/java/com/parse/ParseSQLiteCursor.java +++ b/Parse/src/main/java/com/parse/ParseSQLiteCursor.java @@ -257,4 +257,10 @@ public Bundle getExtras() { public Bundle respond(Bundle extras) { return cursor.respond(extras); } + + @TargetApi(Build.VERSION_CODES.M) + @Override + public void setExtras(Bundle bundle) { + cursor.setExtras(bundle); + } } diff --git a/Parse/src/main/java/com/parse/ParseURLConnectionHttpClient.java b/Parse/src/main/java/com/parse/ParseURLConnectionHttpClient.java deleted file mode 100644 index 53206fc7b..000000000 --- a/Parse/src/main/java/com/parse/ParseURLConnectionHttpClient.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (c) 2015-present, Parse, LLC. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ -package com.parse; - -import android.net.SSLCertificateSocketFactory; -import android.net.SSLSessionCache; - -import com.parse.http.ParseHttpBody; -import com.parse.http.ParseHttpRequest; -import com.parse.http.ParseHttpResponse; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.HttpURLConnection; -import java.net.URL; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.net.ssl.HttpsURLConnection; - -/** package */ class ParseURLConnectionHttpClient extends ParseHttpClient { - - private static final String ACCEPT_ENCODING_HEADER = "Accept-encoding"; - private static final String GZIP_ENCODING = "gzip"; - private static final String CONTENT_LENGTH_HEADER = "Content-Length"; - private static final String CONTENT_TYPE_HEADER = "Content-Type"; - - private int socketOperationTimeout; - - public ParseURLConnectionHttpClient(int socketOperationTimeout, SSLSessionCache sslSessionCache) { - this.socketOperationTimeout = socketOperationTimeout; - } - - @Override - /* package */ ParseHttpResponse executeInternal(ParseHttpRequest parseRequest) throws IOException { - HttpURLConnection connection = getRequest(parseRequest); - // Start network connection and write data to server if possible - ParseHttpBody body = parseRequest.getBody(); - if (body != null) { - OutputStream outputStream = connection.getOutputStream(); - body.writeTo(outputStream); - outputStream.flush(); - outputStream.close(); - } - - return getResponse(connection); - } - - @Override - /* package */ HttpURLConnection getRequest(ParseHttpRequest parseRequest) - throws IOException { - HttpURLConnection connection; - URL url = new URL(parseRequest.getUrl()); - - connection = (HttpURLConnection)url.openConnection(); - - connection.setRequestMethod(parseRequest.getMethod().toString()); - - connection.setConnectTimeout(socketOperationTimeout); - connection.setReadTimeout(socketOperationTimeout); - connection.setDoInput(true); - - // Don't handle redirects. We copy the setting from AndroidHttpClient. - // For detail, check https://quip.com/Px8jAxnaun2r - connection.setInstanceFollowRedirects(false); - - // Set header - for (Map.Entry entry : parseRequest.getAllHeaders().entrySet()) { - connection.setRequestProperty(entry.getKey(), entry.getValue()); - } - - // When URLConnection is powered by OkHttp, by adding this head, OkHttp will turn off its - // transparent decompress which will expose the raw network stream to our interceptors. - if (disableHttpLibraryAutoDecompress()) { - connection.setRequestProperty(ACCEPT_ENCODING_HEADER, GZIP_ENCODING); - } - // Set body - ParseHttpBody body = parseRequest.getBody(); - if (body != null) { - // Content type and content length - connection.setRequestProperty(CONTENT_LENGTH_HEADER, String.valueOf(body.getContentLength())); - connection.setRequestProperty(CONTENT_TYPE_HEADER, body.getContentType()); - // We need to set this in order to make URLConnection not buffer our request body so that our - // upload progress callback works. - connection.setFixedLengthStreamingMode(body.getContentLength()); - connection.setDoOutput(true); - } - return connection; - } - - @Override - /* package */ ParseHttpResponse getResponse(HttpURLConnection connection) - throws IOException { - // Status code - int statusCode = connection.getResponseCode(); - - // Content - InputStream content; - if (statusCode < 400) { - content = connection.getInputStream(); - } else { - content = connection.getErrorStream(); - } - - // Total size - int totalSize = connection.getContentLength(); - - // Reason phrase - String reasonPhrase = connection.getResponseMessage(); - - // Headers - Map headers = new HashMap<>(); - for (Map.Entry> entry : connection.getHeaderFields().entrySet()) { - // The status code's key from header entry is always null(like null=HTTP/1.1 200 OK), since we - // have already had statusCode in ParseHttpResponse, we just ignore this header entry. - if (entry.getKey() != null && entry.getValue().size() > 0) { - headers.put(entry.getKey(), entry.getValue() == null ? "" : entry.getValue().get(0)); - } - } - - // Content type - String contentType = connection.getContentType(); - - return new ParseHttpResponse.Builder() - .setStatusCode(statusCode) - .setContent(content) - .setTotalSize(totalSize) - .setReasonPhrase(reasonPhrase) - .setHeaders(headers) - .setContentType(contentType) - .build(); - } -} diff --git a/Parse/src/test/java/com/parse/LocalIdManagerTest.java b/Parse/src/test/java/com/parse/LocalIdManagerTest.java index a27236ad5..c91dc8f47 100644 --- a/Parse/src/test/java/com/parse/LocalIdManagerTest.java +++ b/Parse/src/test/java/com/parse/LocalIdManagerTest.java @@ -13,7 +13,7 @@ import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.junit.runner.RunWith; -import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import static org.junit.Assert.assertEquals; @@ -21,8 +21,8 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -@RunWith(RobolectricGradleTestRunner.class) -@Config(constants = BuildConfig.class, sdk = 21) +@RunWith(RobolectricTestRunner.class) +@Config(constants = BuildConfig.class, sdk = 23) public class LocalIdManagerTest { @Rule diff --git a/Parse/src/test/java/com/parse/NetworkObjectControllerTest.java b/Parse/src/test/java/com/parse/NetworkObjectControllerTest.java index 9bcb95d37..1724ea811 100644 --- a/Parse/src/test/java/com/parse/NetworkObjectControllerTest.java +++ b/Parse/src/test/java/com/parse/NetworkObjectControllerTest.java @@ -17,7 +17,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import java.io.ByteArrayInputStream; @@ -36,8 +36,8 @@ import static org.mockito.Mockito.when; // For Uri.encode -@RunWith(RobolectricGradleTestRunner.class) -@Config(constants = BuildConfig.class, sdk = 21) +@RunWith(RobolectricTestRunner.class) +@Config(constants = BuildConfig.class, sdk = 23) public class NetworkObjectControllerTest { @Before diff --git a/Parse/src/test/java/com/parse/NetworkSessionControllerTest.java b/Parse/src/test/java/com/parse/NetworkSessionControllerTest.java index f1f744925..e82e6e2e2 100644 --- a/Parse/src/test/java/com/parse/NetworkSessionControllerTest.java +++ b/Parse/src/test/java/com/parse/NetworkSessionControllerTest.java @@ -14,7 +14,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import java.net.MalformedURLException; @@ -26,8 +26,8 @@ import static org.junit.Assert.assertTrue; // For Uri.encode -@RunWith(RobolectricGradleTestRunner.class) -@Config(constants = BuildConfig.class, sdk = 21) +@RunWith(RobolectricTestRunner.class) +@Config(constants = BuildConfig.class, sdk = 23) public class NetworkSessionControllerTest { @Before diff --git a/Parse/src/test/java/com/parse/NetworkUserControllerTest.java b/Parse/src/test/java/com/parse/NetworkUserControllerTest.java index 908e4aef5..77e97b5bb 100644 --- a/Parse/src/test/java/com/parse/NetworkUserControllerTest.java +++ b/Parse/src/test/java/com/parse/NetworkUserControllerTest.java @@ -14,7 +14,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import java.net.MalformedURLException; @@ -27,8 +27,8 @@ import static org.junit.Assert.assertTrue; // For Uri.encode -@RunWith(RobolectricGradleTestRunner.class) -@Config(constants = BuildConfig.class, sdk = 21) +@RunWith(RobolectricTestRunner.class) +@Config(constants = BuildConfig.class, sdk = 23) public class NetworkUserControllerTest { @Before diff --git a/Parse/src/test/java/com/parse/ParseAnalyticsControllerTest.java b/Parse/src/test/java/com/parse/ParseAnalyticsControllerTest.java index f868a6e06..77ec0ed47 100644 --- a/Parse/src/test/java/com/parse/ParseAnalyticsControllerTest.java +++ b/Parse/src/test/java/com/parse/ParseAnalyticsControllerTest.java @@ -14,7 +14,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; -import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import java.net.MalformedURLException; @@ -35,8 +35,8 @@ import static org.mockito.Mockito.when; // For android.net.Uri -@RunWith(RobolectricGradleTestRunner.class) -@Config(constants = BuildConfig.class, sdk = 21) +@RunWith(RobolectricTestRunner.class) +@Config(constants = BuildConfig.class, sdk = 23) public class ParseAnalyticsControllerTest { @Before diff --git a/Parse/src/test/java/com/parse/ParseAnalyticsTest.java b/Parse/src/test/java/com/parse/ParseAnalyticsTest.java index ff832ce36..43d350edb 100644 --- a/Parse/src/test/java/com/parse/ParseAnalyticsTest.java +++ b/Parse/src/test/java/com/parse/ParseAnalyticsTest.java @@ -18,7 +18,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Matchers; -import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import java.util.HashMap; @@ -42,8 +42,8 @@ import static org.mockito.Mockito.when; // For android.os.BaseBundle -@RunWith(RobolectricGradleTestRunner.class) -@Config(constants = BuildConfig.class, sdk = 21) +@RunWith(RobolectricTestRunner.class) +@Config(constants = BuildConfig.class, sdk = 23) public class ParseAnalyticsTest { ParseAnalyticsController controller; diff --git a/Parse/src/test/java/com/parse/ParseApacheHttpClientTest.java b/Parse/src/test/java/com/parse/ParseApacheHttpClientTest.java deleted file mode 100644 index d97a7a3f6..000000000 --- a/Parse/src/test/java/com/parse/ParseApacheHttpClientTest.java +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright (c) 2015-present, Parse, LLC. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ -package com.parse; - -import com.parse.http.ParseHttpRequest; -import com.parse.http.ParseHttpResponse; - -import org.apache.http.ProtocolVersion; -import org.apache.http.client.methods.HttpDelete; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.client.methods.HttpPut; -import org.apache.http.client.methods.HttpUriRequest; -import org.apache.http.entity.StringEntity; -import org.apache.http.message.BasicHttpResponse; -import org.apache.http.message.BasicStatusLine; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.robolectric.RobolectricGradleTestRunner; -import org.robolectric.annotation.Config; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.verify; - -// For android.net.SSLCertificateSocketFactory -@RunWith(RobolectricGradleTestRunner.class) -@Config(constants = BuildConfig.class, sdk = 21) -public class ParseApacheHttpClientTest { - - @Test - public void tesGetApacheRequestType() throws IOException { - ParseApacheHttpClient parseClient = new ParseApacheHttpClient(10000, null); - ParseHttpRequest.Builder builder = new ParseHttpRequest.Builder(); - builder.setUrl("http://www.parse.com/"); - - // Get - ParseHttpRequest parseRequest = builder - .setMethod(ParseHttpRequest.Method.GET) - .setBody(null) - .build(); - HttpUriRequest apacheRequest = parseClient.getRequest(parseRequest); - assertTrue(apacheRequest instanceof HttpGet); - - // Post - parseRequest = builder - .setMethod(ParseHttpRequest.Method.POST) - .setBody(new ParseByteArrayHttpBody("test", "application/json")) - .build(); - apacheRequest = parseClient.getRequest(parseRequest); - assertTrue(apacheRequest instanceof HttpPost); - - // Delete - parseRequest = builder - .setMethod(ParseHttpRequest.Method.DELETE) - .setBody(null) - .build(); - apacheRequest = parseClient.getRequest(parseRequest); - assertTrue(apacheRequest instanceof HttpDelete); - - // Put - parseRequest = builder - .setMethod(ParseHttpRequest.Method.PUT) - .setBody(new ParseByteArrayHttpBody("test", "application/json")) - .build(); - apacheRequest = parseClient.getRequest(parseRequest); - assertTrue(apacheRequest instanceof HttpPut); - } - - @Test - public void testGetApacheRequest() throws IOException { - Map headers = new HashMap<>(); - String headerValue = "value"; - headers.put("name", headerValue); - - String url = "http://www.parse.com/"; - String content = "test"; - String contentType = "application/json"; - ParseHttpRequest parseRequest = new ParseHttpRequest.Builder() - .setUrl(url) - .setMethod(ParseHttpRequest.Method.POST) - .setBody(new ParseByteArrayHttpBody(content, contentType)) - .setHeaders(headers) - .build(); - - ParseApacheHttpClient parseClient = new ParseApacheHttpClient(10000, null); - HttpUriRequest apacheRequest = parseClient.getRequest(parseRequest); - - // Verify method - assertTrue(apacheRequest instanceof HttpPost); - // Verify URL - assertEquals(url, apacheRequest.getURI().toString()); - // Verify Headers - // We add gzip header to apacheRequest which does not contain in ParseRequest - assertEquals(2, apacheRequest.getAllHeaders().length); - assertEquals(1, apacheRequest.getHeaders("name").length); - assertEquals("name", apacheRequest.getHeaders("name")[0].getName()); - assertEquals(headerValue, apacheRequest.getHeaders("name")[0].getValue()); - // Verify Body - HttpPost apachePostRequest = (HttpPost)apacheRequest; - assertEquals(4, apachePostRequest.getEntity().getContentLength()); - assertEquals(contentType, apachePostRequest.getEntity().getContentType().getValue()); - // Can not read parseRequest body to compare since it has been read during - // creating apacheRequest - assertArrayEquals(content.getBytes(), - ParseIOUtils.toByteArray(apachePostRequest.getEntity().getContent())); - } - - @Test - public void testGetApacheRequestWithEmptyContentType() throws Exception { - String url = "http://www.parse.com/"; - String content = "test"; - ParseHttpRequest parseRequest = new ParseHttpRequest.Builder() - .setUrl(url) - .setMethod(ParseHttpRequest.Method.POST) - .setBody(new ParseByteArrayHttpBody(content, null)) - .build(); - - ParseApacheHttpClient parseClient = new ParseApacheHttpClient(10000, null); - HttpUriRequest apacheRequest = parseClient.getRequest(parseRequest); - - // Verify Content-Type - HttpPost apachePostRequest = (HttpPost)apacheRequest; - assertNull(apachePostRequest.getEntity().getContentType()); - } - - @Test - public void testGetParseResponse() throws IOException { - int statusCode = 200; - String reasonPhrase = "test reason"; - ProtocolVersion protocol = new ProtocolVersion("HTTP", 1, 1); - BasicStatusLine line = new BasicStatusLine(protocol, statusCode, reasonPhrase); - BasicHttpResponse apacheResponse = new BasicHttpResponse(line); - String content = "content"; - StringEntity entity = new StringEntity(content); - apacheResponse.setEntity(entity); - apacheResponse.setHeader("Content-Length", String.valueOf(entity.getContentLength())); - - ParseApacheHttpClient parseClient = new ParseApacheHttpClient(10000, null); - ParseHttpResponse parseResponse = parseClient.getResponse(apacheResponse); - - // Verify status code - assertEquals(statusCode, parseResponse.getStatusCode()); - // Verify reason phrase - assertEquals(reasonPhrase, parseResponse.getReasonPhrase()); - // Verify content length - assertEquals(7, parseResponse.getTotalSize()); - // Verify content - // Can not read apacheResponse entity to compare since it has been read during - // creating parseResponse - assertArrayEquals(content.getBytes(), ParseIOUtils.toByteArray(parseResponse.getContent())); - } -} diff --git a/Parse/src/test/java/com/parse/ParseCloudTest.java b/Parse/src/test/java/com/parse/ParseCloudTest.java index 4b2b9afc8..4a8d052eb 100644 --- a/Parse/src/test/java/com/parse/ParseCloudTest.java +++ b/Parse/src/test/java/com/parse/ParseCloudTest.java @@ -12,7 +12,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import java.util.Arrays; @@ -39,8 +39,8 @@ import static org.mockito.Mockito.when; // For android.os.Looper -@RunWith(RobolectricGradleTestRunner.class) -@Config(constants = BuildConfig.class, sdk = 21) +@RunWith(RobolectricTestRunner.class) +@Config(constants = BuildConfig.class, sdk = 23) public class ParseCloudTest { @Before diff --git a/Parse/src/test/java/com/parse/ParseCoderTest.java b/Parse/src/test/java/com/parse/ParseCoderTest.java index b094af964..13eb9f530 100644 --- a/Parse/src/test/java/com/parse/ParseCoderTest.java +++ b/Parse/src/test/java/com/parse/ParseCoderTest.java @@ -11,14 +11,14 @@ import org.json.JSONObject; import org.junit.Test; import org.junit.runner.RunWith; -import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import static org.junit.Assert.assertEquals; // For android.util.Base64 -@RunWith(RobolectricGradleTestRunner.class) -@Config(constants = BuildConfig.class, sdk = 21) +@RunWith(RobolectricTestRunner.class) +@Config(constants = BuildConfig.class, sdk = 23) public class ParseCoderTest { @Test diff --git a/Parse/src/test/java/com/parse/ParseConfigTest.java b/Parse/src/test/java/com/parse/ParseConfigTest.java index abf42f68d..d664b3a10 100644 --- a/Parse/src/test/java/com/parse/ParseConfigTest.java +++ b/Parse/src/test/java/com/parse/ParseConfigTest.java @@ -14,7 +14,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import org.skyscreamer.jsonassert.JSONCompareMode; @@ -46,8 +46,8 @@ // For android.os.Looper -@RunWith(RobolectricGradleTestRunner.class) -@Config(constants = BuildConfig.class, sdk = 21) +@RunWith(RobolectricTestRunner.class) +@Config(constants = BuildConfig.class, sdk = 23) public class ParseConfigTest { @Before diff --git a/Parse/src/test/java/com/parse/ParseCorePluginsTest.java b/Parse/src/test/java/com/parse/ParseCorePluginsTest.java index 1edd03914..0b8a43dea 100644 --- a/Parse/src/test/java/com/parse/ParseCorePluginsTest.java +++ b/Parse/src/test/java/com/parse/ParseCorePluginsTest.java @@ -12,7 +12,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import java.util.List; @@ -24,8 +24,8 @@ import static org.junit.Assert.assertThat; // For org.apache.http -@RunWith(RobolectricGradleTestRunner.class) -@Config(constants = BuildConfig.class, sdk = 21) +@RunWith(RobolectricTestRunner.class) +@Config(constants = BuildConfig.class, sdk = 23) public class ParseCorePluginsTest { @Before diff --git a/Parse/src/test/java/com/parse/ParseDecoderTest.java b/Parse/src/test/java/com/parse/ParseDecoderTest.java index 70d8e80ca..8a8cc3920 100644 --- a/Parse/src/test/java/com/parse/ParseDecoderTest.java +++ b/Parse/src/test/java/com/parse/ParseDecoderTest.java @@ -15,7 +15,7 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; -import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import java.util.Date; @@ -29,8 +29,8 @@ import static org.junit.Assert.assertSame; // For android.util.Base64 -@RunWith(RobolectricGradleTestRunner.class) -@Config(constants = BuildConfig.class, sdk = 21) +@RunWith(RobolectricTestRunner.class) +@Config(constants = BuildConfig.class, sdk = 23) public class ParseDecoderTest { @Rule diff --git a/Parse/src/test/java/com/parse/ParseDecompressInterceptorTest.java b/Parse/src/test/java/com/parse/ParseDecompressInterceptorTest.java index 1482bb104..dc91e58a9 100644 --- a/Parse/src/test/java/com/parse/ParseDecompressInterceptorTest.java +++ b/Parse/src/test/java/com/parse/ParseDecompressInterceptorTest.java @@ -15,7 +15,7 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import java.io.ByteArrayInputStream; @@ -29,8 +29,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; -@RunWith(RobolectricGradleTestRunner.class) -@Config(constants = BuildConfig.class, sdk = 21) +@RunWith(RobolectricTestRunner.class) +@Config(constants = BuildConfig.class, sdk = 23) public class ParseDecompressInterceptorTest { @Test diff --git a/Parse/src/test/java/com/parse/ParseEncoderTest.java b/Parse/src/test/java/com/parse/ParseEncoderTest.java index 5de06ef24..50cf0e38b 100644 --- a/Parse/src/test/java/com/parse/ParseEncoderTest.java +++ b/Parse/src/test/java/com/parse/ParseEncoderTest.java @@ -16,7 +16,7 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; -import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import java.util.ArrayList; @@ -29,8 +29,8 @@ import static org.junit.Assert.assertTrue; // For android.util.Base64 -@RunWith(RobolectricGradleTestRunner.class) -@Config(constants = BuildConfig.class, sdk = 21) +@RunWith(RobolectricTestRunner.class) +@Config(constants = BuildConfig.class, sdk = 23) public class ParseEncoderTest { ParseEncoderTestClass testClassObject = null; diff --git a/Parse/src/test/java/com/parse/ParseFileControllerTest.java b/Parse/src/test/java/com/parse/ParseFileControllerTest.java index 79f352081..d0a7ba319 100644 --- a/Parse/src/test/java/com/parse/ParseFileControllerTest.java +++ b/Parse/src/test/java/com/parse/ParseFileControllerTest.java @@ -18,7 +18,7 @@ import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.junit.runner.RunWith; -import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import java.io.ByteArrayInputStream; @@ -42,8 +42,8 @@ import static org.mockito.Mockito.when; // For org.json -@RunWith(RobolectricGradleTestRunner.class) -@Config(constants = BuildConfig.class, sdk = 21) +@RunWith(RobolectricTestRunner.class) +@Config(constants = BuildConfig.class, sdk = 23) public class ParseFileControllerTest { @Before diff --git a/Parse/src/test/java/com/parse/ParseFileStateTest.java b/Parse/src/test/java/com/parse/ParseFileStateTest.java index 7a2bebc31..5a7613fe0 100644 --- a/Parse/src/test/java/com/parse/ParseFileStateTest.java +++ b/Parse/src/test/java/com/parse/ParseFileStateTest.java @@ -14,7 +14,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import static org.junit.Assert.assertEquals; @@ -23,8 +23,8 @@ import static org.robolectric.Shadows.shadowOf; // For android.webkit.MimeTypeMap -@RunWith(RobolectricGradleTestRunner.class) -@Config(constants = BuildConfig.class, sdk = 21) +@RunWith(RobolectricTestRunner.class) +@Config(constants = BuildConfig.class, sdk = 23) public class ParseFileStateTest { @Before diff --git a/Parse/src/test/java/com/parse/ParseFileUtilsTest.java b/Parse/src/test/java/com/parse/ParseFileUtilsTest.java index cf84dd631..fd9d7abbb 100644 --- a/Parse/src/test/java/com/parse/ParseFileUtilsTest.java +++ b/Parse/src/test/java/com/parse/ParseFileUtilsTest.java @@ -13,7 +13,7 @@ import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.junit.runner.RunWith; -import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import java.io.BufferedOutputStream; @@ -26,8 +26,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -@RunWith(RobolectricGradleTestRunner.class) -@Config(constants = BuildConfig.class, sdk = 21) +@RunWith(RobolectricTestRunner.class) +@Config(constants = BuildConfig.class, sdk = 23) public class ParseFileUtilsTest { private static final String TEST_STRING = "this is a test string"; diff --git a/Parse/src/test/java/com/parse/ParseHttpClientTest.java b/Parse/src/test/java/com/parse/ParseHttpClientTest.java index 27da20c5d..b372eabc5 100644 --- a/Parse/src/test/java/com/parse/ParseHttpClientTest.java +++ b/Parse/src/test/java/com/parse/ParseHttpClientTest.java @@ -10,15 +10,11 @@ import com.parse.http.ParseHttpRequest; import com.parse.http.ParseHttpResponse; -import okhttp3.Headers; -import okhttp3.mockwebserver.MockResponse; -import okhttp3.mockwebserver.MockWebServer; -import okhttp3.mockwebserver.RecordedRequest; import org.json.JSONObject; import org.junit.Test; import org.junit.runner.RunWith; -import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import java.io.ByteArrayOutputStream; @@ -27,6 +23,10 @@ import java.util.Set; import java.util.zip.GZIPOutputStream; +import okhttp3.Headers; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; import okio.Buffer; import static org.junit.Assert.assertArrayEquals; @@ -35,51 +35,24 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -@RunWith(RobolectricGradleTestRunner.class) -@Config(constants = BuildConfig.class, sdk = 21) +@RunWith(RobolectricTestRunner.class) +@Config(constants = BuildConfig.class, sdk = 23) public class ParseHttpClientTest { // We can not use ParameterizedRobolectricTestRunner right now since Robolectric use // default java classloader when we construct the parameters. However // SSLCertificateSocketFactory is only mocked under Robolectric classloader. - @Test - public void testParseApacheHttpClientExecuteWithSuccessResponse() throws Exception { - doSingleParseHttpClientExecuteWithResponse( - 200, "OK", "Success", new ParseApacheHttpClient(10000, null)); - } - - @Test - public void testParseURLConnectionHttpClientExecuteWithSuccessResponse() throws Exception { - doSingleParseHttpClientExecuteWithResponse( - 200, "OK", "Success", new ParseURLConnectionHttpClient(10000, null)); } - @Test public void testParseOkHttpClientExecuteWithSuccessResponse() throws Exception { doSingleParseHttpClientExecuteWithResponse( 200, "OK", "Success", new ParseOkHttpClient(10000, null)); } - @Test - public void testParseApacheHttpClientExecuteWithErrorResponse() throws Exception { - doSingleParseHttpClientExecuteWithResponse( - 404, "NOT FOUND", "Error", new ParseApacheHttpClient(10000, null)); } - - @Test - public void testParseURLConnectionHttpClientExecuteWithErrorResponse() throws Exception { - doSingleParseHttpClientExecuteWithResponse( - 404, "NOT FOUND", "Error", new ParseURLConnectionHttpClient(10000, null)); } - @Test public void testParseOkHttpClientExecuteWithErrorResponse() throws Exception { doSingleParseHttpClientExecuteWithResponse( 404, "NOT FOUND", "Error", new ParseOkHttpClient(10000, null)); } - @Test - public void testParseApacheHttpClientExecuteWithGzipResponse() throws Exception { - doSingleParseHttpClientExecuteWithGzipResponse( - 200, "OK", "Success", new ParseApacheHttpClient(10000, null)); - } - // TODO(mengyan): Add testParseURLConnectionHttpClientExecuteWithGzipResponse, right now we can // not do that since in unit test env, URLConnection does not use OKHttp internally, so there is // no transparent ungzip diff --git a/Parse/src/test/java/com/parse/ParseInstallationTest.java b/Parse/src/test/java/com/parse/ParseInstallationTest.java index 9aa74a18d..f71ac0de1 100644 --- a/Parse/src/test/java/com/parse/ParseInstallationTest.java +++ b/Parse/src/test/java/com/parse/ParseInstallationTest.java @@ -17,7 +17,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; import org.robolectric.res.builder.RobolectricPackageManager; @@ -39,8 +39,8 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -@RunWith(RobolectricGradleTestRunner.class) -@Config(constants = BuildConfig.class, sdk = 21) +@RunWith(RobolectricTestRunner.class) +@Config(constants = BuildConfig.class, sdk = 23) public class ParseInstallationTest { private static final String KEY_INSTALLATION_ID = "installationId"; private static final String KEY_DEVICE_TYPE = "deviceType"; diff --git a/Parse/src/test/java/com/parse/ParseOkHttpClientTest.java b/Parse/src/test/java/com/parse/ParseOkHttpClientTest.java index 5bfcc7186..7f7825089 100644 --- a/Parse/src/test/java/com/parse/ParseOkHttpClientTest.java +++ b/Parse/src/test/java/com/parse/ParseOkHttpClientTest.java @@ -16,7 +16,7 @@ import org.json.JSONObject; import org.junit.Test; import org.junit.runner.RunWith; -import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import java.io.ByteArrayInputStream; @@ -45,8 +45,8 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -@RunWith(RobolectricGradleTestRunner.class) -@Config(constants = BuildConfig.class, sdk = 21) +@RunWith(RobolectricTestRunner.class) +@Config(constants = BuildConfig.class, sdk = 23) public class ParseOkHttpClientTest { private MockWebServer server = new MockWebServer(); diff --git a/Parse/src/test/java/com/parse/ParsePushControllerTest.java b/Parse/src/test/java/com/parse/ParsePushControllerTest.java index e1a2dec23..6c9e8e437 100644 --- a/Parse/src/test/java/com/parse/ParsePushControllerTest.java +++ b/Parse/src/test/java/com/parse/ParsePushControllerTest.java @@ -18,7 +18,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import org.skyscreamer.jsonassert.JSONCompareMode; @@ -44,8 +44,8 @@ import static org.skyscreamer.jsonassert.JSONAssert.assertEquals; // For SSLSessionCache -@RunWith(RobolectricGradleTestRunner.class) -@Config(constants = BuildConfig.class, sdk = 21) +@RunWith(RobolectricTestRunner.class) +@Config(constants = BuildConfig.class, sdk = 23) public class ParsePushControllerTest { @Before diff --git a/Parse/src/test/java/com/parse/ParsePushTest.java b/Parse/src/test/java/com/parse/ParsePushTest.java index 3e9a8aa71..e12474aeb 100644 --- a/Parse/src/test/java/com/parse/ParsePushTest.java +++ b/Parse/src/test/java/com/parse/ParsePushTest.java @@ -14,7 +14,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; -import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import org.skyscreamer.jsonassert.JSONCompareMode; @@ -38,8 +38,8 @@ import static org.mockito.Mockito.when; import static org.skyscreamer.jsonassert.JSONAssert.assertEquals; -@RunWith(RobolectricGradleTestRunner.class) -@Config(constants = BuildConfig.class, sdk = 21) +@RunWith(RobolectricTestRunner.class) +@Config(constants = BuildConfig.class, sdk = 23) public class ParsePushTest { @Before diff --git a/Parse/src/test/java/com/parse/ParseQueryStateTest.java b/Parse/src/test/java/com/parse/ParseQueryStateTest.java index a9877ff76..f1980e952 100644 --- a/Parse/src/test/java/com/parse/ParseQueryStateTest.java +++ b/Parse/src/test/java/com/parse/ParseQueryStateTest.java @@ -12,7 +12,7 @@ import org.json.JSONObject; import org.junit.Test; import org.junit.runner.RunWith; -import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import org.skyscreamer.jsonassert.JSONAssert; import org.skyscreamer.jsonassert.JSONCompareMode; @@ -28,8 +28,8 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -@RunWith(RobolectricGradleTestRunner.class) -@Config(constants = BuildConfig.class, sdk = 21) +@RunWith(RobolectricTestRunner.class) +@Config(constants = BuildConfig.class, sdk = 23) public class ParseQueryStateTest { @Test diff --git a/Parse/src/test/java/com/parse/ParseRESTCommandTest.java b/Parse/src/test/java/com/parse/ParseRESTCommandTest.java index e5fa0e738..4dabbd069 100644 --- a/Parse/src/test/java/com/parse/ParseRESTCommandTest.java +++ b/Parse/src/test/java/com/parse/ParseRESTCommandTest.java @@ -19,7 +19,7 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; -import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import org.skyscreamer.jsonassert.JSONCompareMode; @@ -46,8 +46,8 @@ import static org.skyscreamer.jsonassert.JSONAssert.assertEquals; // For org.json -@RunWith(RobolectricGradleTestRunner.class) -@Config(constants = BuildConfig.class, sdk = 21) +@RunWith(RobolectricTestRunner.class) +@Config(constants = BuildConfig.class, sdk = 23) @SuppressWarnings("ThrowableResultOfMethodCallIgnored") public class ParseRESTCommandTest { diff --git a/Parse/src/test/java/com/parse/ParseURLConnectionHttpClientTest.java b/Parse/src/test/java/com/parse/ParseURLConnectionHttpClientTest.java deleted file mode 100644 index d35959a19..000000000 --- a/Parse/src/test/java/com/parse/ParseURLConnectionHttpClientTest.java +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Copyright (c) 2015-present, Parse, LLC. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ -package com.parse; - -import com.parse.http.ParseHttpRequest; -import com.parse.http.ParseHttpResponse; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.robolectric.RobolectricGradleTestRunner; -import org.robolectric.annotation.Config; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.net.HttpURLConnection; -import java.util.HashMap; -import java.util.Map; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.mockito.Mockito.verify; - -// For android.net.SSLCertificateSocketFactory -@RunWith(RobolectricGradleTestRunner.class) -@Config(constants = BuildConfig.class, sdk = 21) -public class ParseURLConnectionHttpClientTest { - - @Test - public void testGetURLConnectionType() throws IOException { - ParseURLConnectionHttpClient parseClient = new ParseURLConnectionHttpClient(10000, null); - ParseHttpRequest.Builder builder = new ParseHttpRequest.Builder(); - builder.setUrl("http://www.parse.com"); - - // Get - ParseHttpRequest parseRequest = builder - .setMethod(ParseHttpRequest.Method.GET) - .setBody(null) - .build(); - HttpURLConnection connection = parseClient.getRequest(parseRequest); - assertEquals(ParseHttpRequest.Method.GET.toString(), connection.getRequestMethod()); - - // Post - parseRequest = builder - .setMethod(ParseHttpRequest.Method.POST) - .setBody(new ParseByteArrayHttpBody("test", "application/json")) - .build(); - connection = parseClient.getRequest(parseRequest); - assertEquals(ParseHttpRequest.Method.POST.toString(), connection.getRequestMethod()); - - // Delete - parseRequest = builder - .setMethod(ParseHttpRequest.Method.DELETE) - .setBody(null) - .build(); - connection = parseClient.getRequest(parseRequest); - assertEquals(ParseHttpRequest.Method.DELETE.toString(), connection.getRequestMethod()); - - // Put - parseRequest = builder - .setMethod(ParseHttpRequest.Method.PUT) - .setBody(new ParseByteArrayHttpBody("test", "application/json")) - .build(); - connection = parseClient.getRequest(parseRequest); - assertEquals(ParseHttpRequest.Method.PUT.toString(), connection.getRequestMethod()); - } - - @Test - public void testGetURLConnectionRequest() throws IOException { - Map headers = new HashMap<>(); - String headerName = "name"; - String headerValue = "value"; - headers.put(headerName, headerValue); - - String url = "http://www.parse.com"; - String content = "test"; - String contentType = "application/json"; - ParseHttpRequest parseRequest = new ParseHttpRequest.Builder() - .setUrl(url) - .setMethod(ParseHttpRequest.Method.POST) - .setBody(new ParseByteArrayHttpBody(content, contentType)) - .setHeaders(headers) - .build(); - - ParseURLConnectionHttpClient parseClient = new ParseURLConnectionHttpClient(10000, null); - HttpURLConnection connection = parseClient.getRequest(parseRequest); - - // Verify method - assertEquals(ParseHttpRequest.Method.POST.toString(), connection.getRequestMethod()); - // Verify URL - assertEquals(url, connection.getURL().toString()); - // Verify Headers - assertEquals(headerValue, connection.getRequestProperty(headerName)); - // Verify Content-Type - assertEquals(contentType, connection.getRequestProperty("Content-Type")); - // For URLConnection, in order to set body, we have to open the connection. However, since we do - // not do network operation in ParseHttpRequest.getRequest(), the request body actually has not - // been set after ParseHttpRequest.getRequest(). Thus we can not verify request body and - // content length here. - } - - @Test - public void testGetURLConnectionRequestWithEmptyContentType() throws Exception { - String url = "http://www.parse.com/"; - String content = "test"; - ParseHttpRequest parseRequest = new ParseHttpRequest.Builder() - .setUrl(url) - .setMethod(ParseHttpRequest.Method.POST) - .setBody(new ParseByteArrayHttpBody(content, null)) - .build(); - - ParseURLConnectionHttpClient parseClient = new ParseURLConnectionHttpClient(10000, null); - HttpURLConnection connection = parseClient.getRequest(parseRequest); - - // Verify Content-Type - assertNull(connection.getRequestProperty("Content-Type")); - } - - @Test - public void testGetParseResponse() throws IOException { - // Test normal response (status code < 400) - int statusCode = 200; - String reasonPhrase = "test reason"; - String content = "content"; - int contentLength = content.length(); - HttpURLConnection connection = Mockito.mock(HttpURLConnection.class); - Mockito.when(connection.getResponseCode()).thenReturn(statusCode); - Mockito.when(connection.getResponseMessage()).thenReturn(reasonPhrase); - Mockito.when(connection.getContentLength()).thenReturn(contentLength); - Mockito.when(connection.getInputStream()) - .thenReturn(new ByteArrayInputStream(content.getBytes())); - - ParseURLConnectionHttpClient parseClient = new ParseURLConnectionHttpClient(10000, null); - ParseHttpResponse parseResponse = parseClient.getResponse(connection); - - // Verify status code - assertEquals(statusCode, parseResponse.getStatusCode()); - // Verify reason phrase - assertEquals(reasonPhrase, parseResponse.getReasonPhrase()); - // Verify content length - assertEquals(contentLength, parseResponse.getTotalSize()); - // Verify content - assertArrayEquals(content.getBytes(), ParseIOUtils.toByteArray(parseResponse.getContent())); - - // Test error response (status code >= 400) - statusCode = 400; - reasonPhrase = "error"; - content = "error"; - contentLength = content.length(); - connection = Mockito.mock(HttpURLConnection.class); - Mockito.when(connection.getResponseCode()).thenReturn(statusCode); - Mockito.when(connection.getResponseMessage()).thenReturn(reasonPhrase); - Mockito.when(connection.getContentLength()).thenReturn(contentLength); - Mockito.when(connection.getErrorStream()) - .thenReturn(new ByteArrayInputStream(content.getBytes())); - - parseClient = new ParseURLConnectionHttpClient(10000, null); - parseResponse = parseClient.getResponse(connection); - - // Verify status code - assertEquals(statusCode, parseResponse.getStatusCode()); - // Verify reason phrase - assertEquals(reasonPhrase, parseResponse.getReasonPhrase()); - // Verify content length - assertEquals(contentLength, parseResponse.getTotalSize()); - // Verify content - assertArrayEquals(content.getBytes(), ParseIOUtils.toByteArray(parseResponse.getContent())); - } -} diff --git a/Parse/src/test/java/com/parse/ParseUserTest.java b/Parse/src/test/java/com/parse/ParseUserTest.java index 0808d191e..6c20edc38 100644 --- a/Parse/src/test/java/com/parse/ParseUserTest.java +++ b/Parse/src/test/java/com/parse/ParseUserTest.java @@ -17,7 +17,7 @@ import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Matchers; -import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import java.util.Collections; @@ -49,8 +49,8 @@ import static org.mockito.Mockito.when; // For ParseExecutors.main() -@RunWith(RobolectricGradleTestRunner.class) -@Config(constants = BuildConfig.class, sdk = 21) +@RunWith(RobolectricTestRunner.class) +@Config(constants = BuildConfig.class, sdk = 23) public class ParseUserTest { @Rule diff --git a/ParseStarterProject/build.gradle b/ParseStarterProject/build.gradle index 277619b43..520fe990d 100644 --- a/ParseStarterProject/build.gradle +++ b/ParseStarterProject/build.gradle @@ -20,8 +20,8 @@ android { } dependencies { - compile 'com.android.support:appcompat-v7:22.2.0' + compile 'com.android.support:appcompat-v7:25.2.0' - compile 'com.parse.bolts:bolts-tasks:1.3.0' + compile 'com.parse.bolts:bolts-tasks:1.4.0' compile project(':Parse') } diff --git a/build.gradle b/build.gradle index 517ca2cc8..504a2e38b 100644 --- a/build.gradle +++ b/build.gradle @@ -1,23 +1,25 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. +apply plugin: 'com.github.ben-manes.versions' buildscript { repositories { - mavenCentral() + jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.1.0' + classpath 'com.android.tools.build:gradle:2.3.0' + classpath 'com.github.ben-manes:gradle-versions-plugin:0.14.0' } } allprojects { repositories { - mavenCentral() + jcenter() } } ext { - compileSdkVersion = 22 - buildToolsVersion = "23.0.1" + compileSdkVersion = 25 + buildToolsVersion = "25.0.2" minSdkVersion = 9 - targetSdkVersion = 23 + targetSdkVersion = 25 } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 15e861ba8..5736d52c4 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Thu Nov 06 11:00:14 PST 2014 +#Tue Mar 07 11:56:45 CST 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip