From 963e3eeb003093b3934dab7f1c73a4c46d75321c Mon Sep 17 00:00:00 2001 From: Zhomart Mukhamejanov Date: Thu, 26 Apr 2018 21:07:05 -0700 Subject: updater_sample: Improve UpdateConfig UpdateConfig: - constant names changed - added parsing streaming metadata - added InnerFile to describe a file in zip Android.mk - added guava tests fixed Test: using junit4 Change-Id: Ibe3c8a3bde20259b0eea9a79aca4b22ed7b048f4 Signed-off-by: Zhomart Mukhamejanov --- .../example/android/systemupdatersample/util/UpdateConfigsTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'updater_sample/tests/src/com/example/android/systemupdatersample/util') 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 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); -- cgit v1.2.3 From 93535dd033024f9fb9413dba56bb5fa49abcba0b Mon Sep 17 00:00:00 2001 From: Zhomart Mukhamejanov Date: Thu, 26 Apr 2018 16:10:12 -0700 Subject: updater_sample: add FileDownloader Test: unit tests Change-Id: I10933e7172d7ebc34c7cf5e4274625d7b8399246 Signed-off-by: Zhomart Mukhamejanov --- .../util/FileDownloaderTest.java | 80 ++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 updater_sample/tests/src/com/example/android/systemupdatersample/util/FileDownloaderTest.java (limited to 'updater_sample/tests/src/com/example/android/systemupdatersample/util') diff --git a/updater_sample/tests/src/com/example/android/systemupdatersample/util/FileDownloaderTest.java b/updater_sample/tests/src/com/example/android/systemupdatersample/util/FileDownloaderTest.java new file mode 100644 index 000000000..df47c8ca8 --- /dev/null +++ b/updater_sample/tests/src/com/example/android/systemupdatersample/util/FileDownloaderTest.java @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.android.systemupdatersample.util; + +import static junit.framework.Assert.assertEquals; + +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 org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; + +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Paths; + +/** + * Tests for {@link FileDownloader} + */ +@RunWith(AndroidJUnit4.class) +@SmallTest +public class FileDownloaderTest { + + @Rule + public final ExpectedException thrown = ExpectedException.none(); + + private Context mTestContext; + private Context mTargetContext; + + @Before + public void setUp() { + mTestContext = InstrumentationRegistry.getContext(); + mTargetContext = InstrumentationRegistry.getTargetContext(); + } + + @Test + public void download_downloadsChunkOfZip() throws Exception { + // Prepare the target file + File packageFile = Paths + .get(mTargetContext.getCacheDir().getAbsolutePath(), "ota.zip") + .toFile(); + Files.delete(packageFile.toPath()); + Files.copy(mTestContext.getResources().openRawResource(R.raw.ota_002_package), + packageFile.toPath()); + String url = "file://" + packageFile.getAbsolutePath(); + // prepare where to download + File outFile = Paths + .get(mTargetContext.getCacheDir().getAbsolutePath(), "care_map.txt") + .toFile(); + Files.delete(outFile.toPath()); + // download a chunk of ota.zip + FileDownloader downloader = new FileDownloader(url, 160, 8, outFile); + downloader.download(); + String downloadedContent = String.join("\n", Files.readAllLines(outFile.toPath())); + // Look at tools/create_test_ota.py + assertEquals("CARE_MAP", downloadedContent); + } + +} -- cgit v1.2.3 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/FileDownloaderTest.java | 2 +- .../example/android/systemupdatersample/util/PayloadSpecsTest.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'updater_sample/tests/src/com/example/android/systemupdatersample/util') diff --git a/updater_sample/tests/src/com/example/android/systemupdatersample/util/FileDownloaderTest.java b/updater_sample/tests/src/com/example/android/systemupdatersample/util/FileDownloaderTest.java index df47c8ca8..dc7ec09e1 100644 --- a/updater_sample/tests/src/com/example/android/systemupdatersample/util/FileDownloaderTest.java +++ b/updater_sample/tests/src/com/example/android/systemupdatersample/util/FileDownloaderTest.java @@ -73,7 +73,7 @@ public class FileDownloaderTest { FileDownloader downloader = new FileDownloader(url, 160, 8, outFile); downloader.download(); String downloadedContent = String.join("\n", Files.readAllLines(outFile.toPath())); - // Look at tools/create_test_ota.py + // archive contains text files with uppercase filenames assertEquals("CARE_MAP", downloadedContent); } 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 f7a70388ee22e5971ea19caef5208c1da2282ee4 Mon Sep 17 00:00:00 2001 From: Zhomart Mukhamejanov Date: Wed, 2 May 2018 20:37:12 -0700 Subject: updater_sample: update ui and README, clean-up - ui: add text view for latest completion (error) code - update README.md - update MainActivity.java - remove AbNonStreamingUpdate Test: mmma bootable/recovery/updater_sample Change-Id: Ie9bb64211c57d536036b04f13896e4937c392b6e Signed-off-by: Zhomart Mukhamejanov --- .../example/android/systemupdatersample/util/FileDownloaderTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'updater_sample/tests/src/com/example/android/systemupdatersample/util') diff --git a/updater_sample/tests/src/com/example/android/systemupdatersample/util/FileDownloaderTest.java b/updater_sample/tests/src/com/example/android/systemupdatersample/util/FileDownloaderTest.java index dc7ec09e1..80506ee6d 100644 --- a/updater_sample/tests/src/com/example/android/systemupdatersample/util/FileDownloaderTest.java +++ b/updater_sample/tests/src/com/example/android/systemupdatersample/util/FileDownloaderTest.java @@ -60,7 +60,7 @@ public class FileDownloaderTest { File packageFile = Paths .get(mTargetContext.getCacheDir().getAbsolutePath(), "ota.zip") .toFile(); - Files.delete(packageFile.toPath()); + Files.deleteIfExists(packageFile.toPath()); Files.copy(mTestContext.getResources().openRawResource(R.raw.ota_002_package), packageFile.toPath()); String url = "file://" + packageFile.getAbsolutePath(); @@ -68,7 +68,7 @@ public class FileDownloaderTest { File outFile = Paths .get(mTargetContext.getCacheDir().getAbsolutePath(), "care_map.txt") .toFile(); - Files.delete(outFile.toPath()); + Files.deleteIfExists(outFile.toPath()); // download a chunk of ota.zip FileDownloader downloader = new FileDownloader(url, 160, 8, outFile); downloader.download(); -- 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 +++++++++++++++++++--- .../util/UpdateConfigsTest.java | 10 ------- 2 files changed, 28 insertions(+), 14 deletions(-) (limited to 'updater_sample/tests/src/com/example/android/systemupdatersample/util') 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 configs = Arrays.asList( -- cgit v1.2.3