From da7e23759660ebf76a184e4c4d981f11ef9e2653 Mon Sep 17 00:00:00 2001 From: Zhomart Mukhamejanov Date: Tue, 1 May 2018 12:50:55 -0700 Subject: updater_sample: Add streaming to PayloadSpec PayloadSpec - add streaming generator and tests - fix sample.json - fix tests - rename PackagePropertyFiles to PackageFiles, it has info not only about property files, and new name is shorter Bug: 77148467 Test: `mmma -j bootable/recovery/updater_sample` Change-Id: I9c1206c07c37183f13d3c25940f12981ca85b1b4 Signed-off-by: Zhomart Mukhamejanov --- .../example/android/systemupdatersample/util/PayloadSpecsTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'updater_sample/tests/src/com/example/android/systemupdatersample/util/PayloadSpecsTest.java') 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 6f06ca3e1..c13ba5556 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 @@ -16,8 +16,8 @@ package com.example.android.systemupdatersample.util; -import static com.example.android.systemupdatersample.util.PackagePropertyFiles.PAYLOAD_BINARY_FILE_NAME; -import static com.example.android.systemupdatersample.util.PackagePropertyFiles.PAYLOAD_PROPERTIES_FILE_NAME; +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 org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; -- cgit v1.2.3 From e606f6d3ff728ff4a1cb279aa9294a087fd57dd4 Mon Sep 17 00:00:00 2001 From: Zhomart Mukhamejanov Date: Wed, 2 May 2018 20:47:05 -0700 Subject: updater_sample: update tests - fix tools/gen_update_config.py - add tests for PayloadSpecs#forStreaming Test: junit4 Change-Id: Ife1980c5f72944ed35500aa820b30031fc99e820 Signed-off-by: Zhomart Mukhamejanov --- .../systemupdatersample/util/PayloadSpecsTest.java | 32 +++++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'updater_sample/tests/src/com/example/android/systemupdatersample/util/PayloadSpecsTest.java') 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; + } + } -- cgit v1.2.3