Search in sources :

Example 16 with ZipBuilder

use of com.android.tools.build.bundletool.io.ZipBuilder in project bundletool by google.

the class ValidatorRunnerTest method validateBundleZipFile_invokesRightSubValidatorMethods.

@Test
public void validateBundleZipFile_invokesRightSubValidatorMethods() throws Exception {
    Path bundlePath = new ZipBuilder().addDirectory(ZipPath.create("directory")).addFileWithContent(ZipPath.create("file.txt"), DUMMY_CONTENT).writeTo(tempFolder.resolve("bundle.aab"));
    try (ZipFile bundleZip = new ZipFile(bundlePath.toFile())) {
        new ValidatorRunner(ImmutableList.of(validator)).validateBundleZipFile(bundleZip);
        ArgumentCaptor<ZipEntry> zipEntryArgs = ArgumentCaptor.forClass(ZipEntry.class);
        verify(validator).validateBundleZipFile(eq(bundleZip));
        verify(validator, atLeastOnce()).validateBundleZipEntry(eq(bundleZip), zipEntryArgs.capture());
        verifyNoMoreInteractions(validator);
        assertThat(zipEntryArgs.getAllValues().stream().map(ZipEntry::getName)).containsExactly("directory/", "file.txt");
    }
}
Also used : ZipPath(com.android.tools.build.bundletool.model.ZipPath) Path(java.nio.file.Path) ZipFile(java.util.zip.ZipFile) ZipEntry(java.util.zip.ZipEntry) ZipBuilder(com.android.tools.build.bundletool.io.ZipBuilder) Test(org.junit.Test)

Example 17 with ZipBuilder

use of com.android.tools.build.bundletool.io.ZipBuilder in project bundletool by google.

the class ValidatorRunnerTest method validateBundle_invokesSubValidatorsInSequence.

@Test
public void validateBundle_invokesSubValidatorsInSequence() throws Exception {
    Path bundlePath = new ZipBuilder().addFileWithContent(ZipPath.create("BundleConfig.pb"), BUNDLE_CONFIG.toByteArray()).addFileWithProtoContent(ZipPath.create("moduleX/manifest/AndroidManifest.xml"), androidManifest("com.test.app", withSplitId("moduleX"))).addFileWithContent(ZipPath.create("moduleX/assets/file.txt"), DUMMY_CONTENT).addFileWithProtoContent(ZipPath.create("moduleY/manifest/AndroidManifest.xml"), androidManifest("com.test.app", withSplitId("moduleY"))).addFileWithContent(ZipPath.create("moduleY/assets/file.txt"), DUMMY_CONTENT).writeTo(tempFolder.resolve("bundle.aab"));
    try (ZipFile bundleZip = new ZipFile(bundlePath.toFile())) {
        AppBundle bundle = AppBundle.buildFromZip(bundleZip);
        ImmutableList<BundleModule> bundleFeatureModules = ImmutableList.copyOf(bundle.getFeatureModules().values());
        new ValidatorRunner(ImmutableList.of(validator, validator2)).validateBundle(bundle);
        InOrder order = Mockito.inOrder(validator, validator2);
        order.verify(validator).validateBundle(eq(bundle));
        order.verify(validator).validateAllModules(eq(bundleFeatureModules));
        order.verify(validator).validateModule(any());
        order.verify(validator, atLeastOnce()).validateModuleFile(any());
        order.verify(validator2).validateBundle(eq(bundle));
        order.verify(validator2).validateAllModules(eq(bundleFeatureModules));
        order.verify(validator2).validateModule(any());
        order.verify(validator2, atLeastOnce()).validateModuleFile(any());
        order.verifyNoMoreInteractions();
    }
}
Also used : ZipPath(com.android.tools.build.bundletool.model.ZipPath) Path(java.nio.file.Path) AppBundle(com.android.tools.build.bundletool.model.AppBundle) InOrder(org.mockito.InOrder) ZipFile(java.util.zip.ZipFile) ZipBuilder(com.android.tools.build.bundletool.io.ZipBuilder) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 18 with ZipBuilder

use of com.android.tools.build.bundletool.io.ZipBuilder in project bundletool by google.

the class ValidatorRunnerTest method validateModuleZipFile_invokesRightSubValidatorMethods.

@Test
public void validateModuleZipFile_invokesRightSubValidatorMethods() throws Exception {
    Path modulePath = new ZipBuilder().addDirectory(ZipPath.create("module")).addFileWithContent(ZipPath.create("module/file.txt"), DUMMY_CONTENT).writeTo(tempFolder.resolve("module.zip"));
    try (ZipFile moduleZip = new ZipFile(modulePath.toFile())) {
        new ValidatorRunner(ImmutableList.of(validator)).validateModuleZipFile(moduleZip);
        verify(validator).validateModuleZipFile(eq(moduleZip));
        verifyNoMoreInteractions(validator);
    }
}
Also used : ZipPath(com.android.tools.build.bundletool.model.ZipPath) Path(java.nio.file.Path) ZipFile(java.util.zip.ZipFile) ZipBuilder(com.android.tools.build.bundletool.io.ZipBuilder) Test(org.junit.Test)

Example 19 with ZipBuilder

use of com.android.tools.build.bundletool.io.ZipBuilder in project bundletool by google.

the class MandatoryFilesPresenceValidatorTest method bundleZipFile_withoutBundleConfig_throws.

@Test
public void bundleZipFile_withoutBundleConfig_throws() throws Exception {
    Path bundlePath = new ZipBuilder().addFileWithContent(ZipPath.create("base/manifest/AndroidManifest.xml"), DUMMY_CONTENT).writeTo(tempFolder.resolve("bundle.aab"));
    try (ZipFile bundleZip = new ZipFile(bundlePath.toFile())) {
        InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> new MandatoryFilesPresenceValidator(AppBundle.NON_MODULE_DIRECTORIES).validateBundleZipFile(bundleZip));
        assertThat(exception).hasMessageThat().contains("missing required file 'BundleConfig.pb'");
    }
}
Also used : ZipPath(com.android.tools.build.bundletool.model.ZipPath) Path(java.nio.file.Path) ZipFile(java.util.zip.ZipFile) ZipBuilder(com.android.tools.build.bundletool.io.ZipBuilder) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) Test(org.junit.Test)

Example 20 with ZipBuilder

use of com.android.tools.build.bundletool.io.ZipBuilder in project bundletool by google.

the class BundleZipValidatorTest method validateBundleZipEntry_file_ok.

@Test
public void validateBundleZipEntry_file_ok() throws Exception {
    Path bundlePath = new ZipBuilder().addFileWithContent(ZipPath.create("file.txt"), DUMMY_CONTENT).writeTo(tempFolder.resolve("bundle.aab"));
    try (ZipFile bundleZip = new ZipFile(bundlePath.toFile())) {
        ArrayList<? extends ZipEntry> entries = Collections.list(bundleZip.entries());
        // Sanity check.
        assertThat(entries).hasSize(1);
        new BundleZipValidator().validateBundleZipEntry(bundleZip, entries.get(0));
    }
}
Also used : ZipPath(com.android.tools.build.bundletool.model.ZipPath) Path(java.nio.file.Path) ZipFile(java.util.zip.ZipFile) ZipBuilder(com.android.tools.build.bundletool.io.ZipBuilder) Test(org.junit.Test)

Aggregations

ZipBuilder (com.android.tools.build.bundletool.io.ZipBuilder)44 Test (org.junit.Test)39 ZipPath (com.android.tools.build.bundletool.model.ZipPath)37 Path (java.nio.file.Path)37 ZipFile (java.util.zip.ZipFile)19 InvalidBundleException (com.android.tools.build.bundletool.model.exceptions.InvalidBundleException)11 BuildApksResult (com.android.bundle.Commands.BuildApksResult)5 ModuleSplit (com.android.tools.build.bundletool.model.ModuleSplit)5 ByteString (com.google.protobuf.ByteString)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 PrintStream (java.io.PrintStream)5 ZipEntry (java.util.zip.ZipEntry)5 XmlNode (com.android.aapt.Resources.XmlNode)4 Variant (com.android.bundle.Commands.Variant)4 ApksArchiveHelpers.createVariant (com.android.tools.build.bundletool.testing.ApksArchiveHelpers.createVariant)4 FlagParseException (com.android.tools.build.bundletool.flags.FlagParser.FlagParseException)3 ConfigurationSizes (com.android.tools.build.bundletool.model.ConfigurationSizes)3 InvalidCommandException (com.android.tools.build.bundletool.model.exceptions.InvalidCommandException)3 ApksArchiveHelpers.standaloneVariant (com.android.tools.build.bundletool.testing.ApksArchiveHelpers.standaloneVariant)3 ResourceTableBuilder (com.android.tools.build.bundletool.testing.ResourceTableBuilder)3