summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZhomart Mukhamejanov <zhomart@google.com>2018-05-04 02:02:23 +0200
committerandroid-build-merger <android-build-merger@google.com>2018-05-04 02:02:23 +0200
commit44a3a0b9f104a410f6e57409c239176517825962 (patch)
treee269b40fdb1f830abd65d31f873b08f9b4e31a23
parentMerge "updater_sample: update ui and README, clean-up" am: 9c544a2bc6 am: c36f5ff1c7 (diff)
parentMerge "updater_sample: update tests" am: 219445a320 (diff)
downloadandroid_bootable_recovery-44a3a0b9f104a410f6e57409c239176517825962.tar
android_bootable_recovery-44a3a0b9f104a410f6e57409c239176517825962.tar.gz
android_bootable_recovery-44a3a0b9f104a410f6e57409c239176517825962.tar.bz2
android_bootable_recovery-44a3a0b9f104a410f6e57409c239176517825962.tar.lz
android_bootable_recovery-44a3a0b9f104a410f6e57409c239176517825962.tar.xz
android_bootable_recovery-44a3a0b9f104a410f6e57409c239176517825962.tar.zst
android_bootable_recovery-44a3a0b9f104a410f6e57409c239176517825962.zip
-rw-r--r--updater_sample/tests/src/com/example/android/systemupdatersample/util/PayloadSpecsTest.java32
-rw-r--r--updater_sample/tests/src/com/example/android/systemupdatersample/util/UpdateConfigsTest.java10
-rwxr-xr-xupdater_sample/tools/gen_update_config.py2
3 files changed, 29 insertions, 15 deletions
diff --git a/updater_sample/tests/src/com/example/android/systemupdatersample/util/PayloadSpecsTest.java b/updater_sample/tests/src/com/example/android/systemupdatersample/util/PayloadSpecsTest.java
index c13ba5556..2912e209e 100644
--- a/updater_sample/tests/src/com/example/android/systemupdatersample/util/PayloadSpecsTest.java
+++ b/updater_sample/tests/src/com/example/android/systemupdatersample/util/PayloadSpecsTest.java
@@ -17,7 +17,8 @@
package com.example.android.systemupdatersample.util;
import static com.example.android.systemupdatersample.util.PackageFiles.PAYLOAD_BINARY_FILE_NAME;
-import static com.example.android.systemupdatersample.util.PackageFiles.PAYLOAD_PROPERTIES_FILE_NAME;
+import static com.example.android.systemupdatersample.util.PackageFiles
+ .PAYLOAD_PROPERTIES_FILE_NAME;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
@@ -28,6 +29,8 @@ import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import com.example.android.systemupdatersample.PayloadSpec;
+import com.google.common.base.Charsets;
+import com.google.common.io.Files;
import org.junit.Before;
import org.junit.Rule;
@@ -56,16 +59,16 @@ public class PayloadSpecsTest {
private File mTestDir;
- private Context mContext;
+ private Context mTargetContext;
@Rule
public final ExpectedException thrown = ExpectedException.none();
@Before
public void setUp() {
- mContext = InstrumentationRegistry.getTargetContext();
+ mTargetContext = InstrumentationRegistry.getTargetContext();
- mTestDir = mContext.getFilesDir();
+ mTestDir = mTargetContext.getFilesDir();
}
@Test
@@ -87,6 +90,21 @@ public class PayloadSpecsTest {
PayloadSpecs.forNonStreaming(new File("/fake/news.zip"));
}
+ @Test
+ public void forStreaming_works() throws Exception {
+ String url = "http://a.com/b.zip";
+ long offset = 45;
+ long size = 200;
+ File propertiesFile = createMockPropertiesFile();
+
+ PayloadSpec spec = PayloadSpecs.forStreaming(url, offset, size, propertiesFile);
+ assertEquals("same url", url, spec.getUrl());
+ assertEquals("same offset", offset, spec.getOffset());
+ assertEquals("same size", size, spec.getSize());
+ assertArrayEquals("correct properties",
+ new String[]{"k1=val1", "key2=val2"}, spec.getProperties().toArray(new String[0]));
+ }
+
/**
* Creates package zip file that contains payload.bin and payload_properties.txt
*/
@@ -114,4 +132,10 @@ public class PayloadSpecsTest {
return testFile;
}
+ private File createMockPropertiesFile() throws IOException {
+ File propertiesFile = new File(mTestDir, PackageFiles.PAYLOAD_PROPERTIES_FILE_NAME);
+ Files.asCharSink(propertiesFile, Charsets.UTF_8).write(PROPERTIES_CONTENTS);
+ return propertiesFile;
+ }
+
}
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 c85698c0f..4ccae9380 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
@@ -18,14 +18,11 @@ package com.example.android.systemupdatersample.util;
import static org.junit.Assert.assertArrayEquals;
-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.UpdateConfig;
-import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -41,16 +38,9 @@ import java.util.List;
@SmallTest
public class UpdateConfigsTest {
- private Context mContext;
-
@Rule
public final ExpectedException thrown = ExpectedException.none();
- @Before
- public void setUp() {
- mContext = InstrumentationRegistry.getTargetContext();
- }
-
@Test
public void configsToNames_extractsNames() {
List<UpdateConfig> configs = Arrays.asList(
diff --git a/updater_sample/tools/gen_update_config.py b/updater_sample/tools/gen_update_config.py
index cb9bd0119..057812479 100755
--- a/updater_sample/tools/gen_update_config.py
+++ b/updater_sample/tools/gen_update_config.py
@@ -17,7 +17,7 @@
"""
Given a OTA package file, produces update config JSON file.
-Example: tools/gen_update.config.py \\
+Example: tools/gen_update_config.py \\
--ab_install_type=STREAMING \\
ota-build-001.zip \\
my-config-001.json \\