summaryrefslogtreecommitdiffstats
path: root/updater_sample/tests
diff options
context:
space:
mode:
authorZhomart Mukhamejanov <zhomart@google.com>2018-05-01 21:05:22 +0200
committerGerrit Code Review <noreply-gerritcodereview@google.com>2018-05-01 21:05:22 +0200
commitaf5958818aa5319a131954b3e306ea20f08cff83 (patch)
treec7bdff9e0abf705aeb73156ac23036489496604c /updater_sample/tests
parentMerge "recovery: Split main() into recovery_main.cpp." (diff)
parentupdater_sample: Improve UpdateConfig (diff)
downloadandroid_bootable_recovery-af5958818aa5319a131954b3e306ea20f08cff83.tar
android_bootable_recovery-af5958818aa5319a131954b3e306ea20f08cff83.tar.gz
android_bootable_recovery-af5958818aa5319a131954b3e306ea20f08cff83.tar.bz2
android_bootable_recovery-af5958818aa5319a131954b3e306ea20f08cff83.tar.lz
android_bootable_recovery-af5958818aa5319a131954b3e306ea20f08cff83.tar.xz
android_bootable_recovery-af5958818aa5319a131954b3e306ea20f08cff83.tar.zst
android_bootable_recovery-af5958818aa5319a131954b3e306ea20f08cff83.zip
Diffstat (limited to 'updater_sample/tests')
-rw-r--r--updater_sample/tests/Android.mk8
-rw-r--r--updater_sample/tests/AndroidManifest.xml2
-rw-r--r--updater_sample/tests/res/raw/update_config_stream_001.json4
-rw-r--r--updater_sample/tests/src/com/example/android/systemupdatersample/UpdateConfigTest.java54
-rw-r--r--updater_sample/tests/src/com/example/android/systemupdatersample/util/UpdateConfigsTest.java4
5 files changed, 56 insertions, 16 deletions
diff --git a/updater_sample/tests/Android.mk b/updater_sample/tests/Android.mk
index 83082cda6..a1a4664dc 100644
--- a/updater_sample/tests/Android.mk
+++ b/updater_sample/tests/Android.mk
@@ -22,11 +22,15 @@ LOCAL_SDK_VERSION := system_current
LOCAL_MODULE_TAGS := tests
LOCAL_JAVA_LIBRARIES := \
android.test.base.stubs \
- android.test.runner.stubs
+ android.test.runner.stubs \
+ guava \
+ mockito-target-minus-junit4
LOCAL_STATIC_JAVA_LIBRARIES := android-support-test
LOCAL_INSTRUMENTATION_FOR := SystemUpdaterSample
LOCAL_PROGUARD_ENABLED := disabled
-LOCAL_SRC_FILES := $(call all-subdir-java-files)
+LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
include $(BUILD_PACKAGE)
diff --git a/updater_sample/tests/AndroidManifest.xml b/updater_sample/tests/AndroidManifest.xml
index 2392bb3af..76af5f1a9 100644
--- a/updater_sample/tests/AndroidManifest.xml
+++ b/updater_sample/tests/AndroidManifest.xml
@@ -17,6 +17,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.systemupdatersample.tests">
+ <uses-sdk android:minSdkVersion="27" android:targetSdkVersion="27" />
+
<!-- We add an application tag here just so that we can indicate that
this package needs to link against the android.test library,
which is needed when building test cases. -->
diff --git a/updater_sample/tests/res/raw/update_config_stream_001.json b/updater_sample/tests/res/raw/update_config_stream_001.json
index 965f737d7..a9afd331c 100644
--- a/updater_sample/tests/res/raw/update_config_stream_001.json
+++ b/updater_sample/tests/res/raw/update_config_stream_001.json
@@ -1,8 +1,8 @@
{
"name": "streaming-001",
"url": "http://foo.bar/update.zip",
- "type": "STREAMING",
- "streaming_metadata": {
+ "ab_install_type": "STREAMING",
+ "ab_streaming_metadata": {
"property_files": [
{
"filename": "payload.bin",
diff --git a/updater_sample/tests/src/com/example/android/systemupdatersample/UpdateConfigTest.java b/updater_sample/tests/src/com/example/android/systemupdatersample/UpdateConfigTest.java
index 87153715e..0975e76be 100644
--- a/updater_sample/tests/src/com/example/android/systemupdatersample/UpdateConfigTest.java
+++ b/updater_sample/tests/src/com/example/android/systemupdatersample/UpdateConfigTest.java
@@ -19,14 +19,23 @@ package com.example.android.systemupdatersample;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
+import android.content.Context;
+import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
+import com.example.android.systemupdatersample.tests.R;
+import com.google.common.io.CharStreams;
+
+import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
/**
* Tests for {@link UpdateConfig}
*/
@@ -36,27 +45,48 @@ public class UpdateConfigTest {
private static final String JSON_NON_STREAMING =
"{\"name\": \"vip update\", \"url\": \"file:///builds/a.zip\", "
- + " \"type\": \"NON_STREAMING\"}";
-
- private static final String JSON_STREAMING =
- "{\"name\": \"vip update 2\", \"url\": \"http://foo.bar/a.zip\", "
- + "\"type\": \"STREAMING\"}";
+ + " \"ab_install_type\": \"NON_STREAMING\"}";
@Rule
public final ExpectedException thrown = ExpectedException.none();
+ private Context mContext;
+ private Context mTargetContext;
+ private String mJsonStreaming001;
+
+ @Before
+ public void setUp() throws Exception {
+ mContext = InstrumentationRegistry.getContext();
+ mTargetContext = InstrumentationRegistry.getTargetContext();
+ mJsonStreaming001 = readResource(R.raw.update_config_stream_001);
+ }
+
@Test
- public void fromJson_parsesJsonConfigWithoutMetadata() throws Exception {
+ public void fromJson_parsesNonStreaming() throws Exception {
UpdateConfig config = UpdateConfig.fromJson(JSON_NON_STREAMING);
assertEquals("name is parsed", "vip update", config.getName());
assertEquals("stores raw json", JSON_NON_STREAMING, config.getRawJson());
- assertSame("type is parsed", UpdateConfig.TYPE_NON_STREAMING, config.getInstallType());
+ assertSame("type is parsed",
+ UpdateConfig.AB_INSTALL_TYPE_NON_STREAMING,
+ config.getInstallType());
assertEquals("url is parsed", "file:///builds/a.zip", config.getUrl());
}
@Test
+ public void fromJson_parsesStreaming() throws Exception {
+ UpdateConfig config = UpdateConfig.fromJson(mJsonStreaming001);
+ assertEquals("streaming-001", config.getName());
+ assertEquals("http://foo.bar/update.zip", config.getUrl());
+ assertSame(UpdateConfig.AB_INSTALL_TYPE_STREAMING, config.getInstallType());
+ assertEquals("payload.bin",
+ config.getStreamingMetadata().getPropertyFiles()[0].getFilename());
+ assertEquals(195, config.getStreamingMetadata().getPropertyFiles()[0].getOffset());
+ assertEquals(8, config.getStreamingMetadata().getPropertyFiles()[0].getSize());
+ }
+
+ @Test
public void getUpdatePackageFile_throwsErrorIfStreaming() throws Exception {
- UpdateConfig config = UpdateConfig.fromJson(JSON_STREAMING);
+ UpdateConfig config = UpdateConfig.fromJson(mJsonStreaming001);
thrown.expect(RuntimeException.class);
config.getUpdatePackageFile();
}
@@ -64,7 +94,7 @@ public class UpdateConfigTest {
@Test
public void getUpdatePackageFile_throwsErrorIfNotAFile() throws Exception {
String json = "{\"name\": \"upd\", \"url\": \"http://foo.bar\","
- + " \"type\": \"NON_STREAMING\"}";
+ + " \"ab_install_type\": \"NON_STREAMING\"}";
UpdateConfig config = UpdateConfig.fromJson(json);
thrown.expect(RuntimeException.class);
config.getUpdatePackageFile();
@@ -73,7 +103,11 @@ public class UpdateConfigTest {
@Test
public void getUpdatePackageFile_works() throws Exception {
UpdateConfig c = UpdateConfig.fromJson(JSON_NON_STREAMING);
- assertEquals("correct path", "/builds/a.zip", c.getUpdatePackageFile().getAbsolutePath());
+ assertEquals("/builds/a.zip", c.getUpdatePackageFile().getAbsolutePath());
}
+ private String readResource(int id) throws IOException {
+ return CharStreams.toString(new InputStreamReader(
+ mContext.getResources().openRawResource(id)));
+ }
}
diff --git a/updater_sample/tests/src/com/example/android/systemupdatersample/util/UpdateConfigsTest.java b/updater_sample/tests/src/com/example/android/systemupdatersample/util/UpdateConfigsTest.java
index 4aa8c6453..c85698c0f 100644
--- a/updater_sample/tests/src/com/example/android/systemupdatersample/util/UpdateConfigsTest.java
+++ b/updater_sample/tests/src/com/example/android/systemupdatersample/util/UpdateConfigsTest.java
@@ -54,8 +54,8 @@ public class UpdateConfigsTest {
@Test
public void configsToNames_extractsNames() {
List<UpdateConfig> configs = Arrays.asList(
- new UpdateConfig("blah", "http://", UpdateConfig.TYPE_NON_STREAMING),
- new UpdateConfig("blah 2", "http://", UpdateConfig.TYPE_STREAMING)
+ new UpdateConfig("blah", "http://", UpdateConfig.AB_INSTALL_TYPE_NON_STREAMING),
+ new UpdateConfig("blah 2", "http://", UpdateConfig.AB_INSTALL_TYPE_STREAMING)
);
String[] names = UpdateConfigs.configsToNames(configs);
assertArrayEquals(new String[] {"blah", "blah 2"}, names);