use of com.android.tools.build.bundletool.io.ZipBuilder in project bundletool by google.
the class BuildBundleCommandTest method runsBundleFilesValidator_rogueFileInModuleRoot_throws.
// Tests bellow validate that specific validators are run for the input modules. For the lack
// of better options, for each validator there is a single test that is most representative of
// the validator.
@Test
public void runsBundleFilesValidator_rogueFileInModuleRoot_throws() throws Exception {
Path module = new ZipBuilder().addFileWithContent(ZipPath.create("rogue.txt"), "".getBytes(UTF_8)).addFileWithProtoContent(ZipPath.create("manifest/AndroidManifest.xml"), androidManifest(PKG_NAME)).writeTo(tmpDir.resolve("base.zip"));
BuildBundleCommand command = BuildBundleCommand.builder().setOutputPath(bundlePath).setModulesPaths(ImmutableList.of(module)).build();
InvalidBundleException exception = assertThrows(InvalidBundleException.class, command::execute);
assertThat(exception).hasMessageThat().contains("Module files can be only in pre-defined directories");
}
use of com.android.tools.build.bundletool.io.ZipBuilder in project bundletool by google.
the class BuildSdkApksCommandTest method overwriteNotSetOutputFileAlreadyExists_throws.
@Test
public void overwriteNotSetOutputFileAlreadyExists_throws() throws Exception {
createBasicZipBuilderWithManifest().writeTo(sdkBundlePath);
new ZipBuilder().addFileWithContent(ZipPath.create("BundleConfig.pb"), BUNDLE_CONFIG.toByteArray()).writeTo(outputFilePath);
BuildSdkApksCommand command = BuildSdkApksCommand.fromFlags(getDefaultFlagsWithAdditionalFlags());
Exception e = assertThrows(IllegalArgumentException.class, command::execute);
assertThat(e).hasMessageThat().contains("already exists");
}
use of com.android.tools.build.bundletool.io.ZipBuilder in project bundletool by google.
the class SdkBundleTest method createBasicZipBuilderWithManifest.
private ZipBuilder createBasicZipBuilderWithManifest() {
ZipBuilder zipBuilder = new ZipBuilder();
zipBuilder.addFileWithContent(ZipPath.create("BundleConfig.pb"), BUNDLE_CONFIG.toByteArray()).addFileWithProtoContent(ZipPath.create("base/manifest/AndroidManifest.xml"), MANIFEST).addFileWithContent(ZipPath.create("base/dex/classes.dex"), DUMMY_CONTENT).addFileWithContent(ZipPath.create("BUNDLE-METADATA/some.namespace/metadata1"), new byte[] { 0x01 });
return zipBuilder;
}
use of com.android.tools.build.bundletool.io.ZipBuilder in project bundletool by google.
the class BundleZipValidatorTest method validateBundleZipEntry_directory_throws.
@Test
public void validateBundleZipEntry_directory_throws() throws Exception {
Path bundlePath = new ZipBuilder().addDirectory(ZipPath.create("directory")).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);
InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> new BundleZipValidator().validateBundleZipEntry(bundleZip, entries.get(0)));
assertThat(exception).hasMessageThat().contains("zip file contains directory zip entry");
}
}
use of com.android.tools.build.bundletool.io.ZipBuilder in project bundletool by google.
the class ValidatorRunnerTest method validateSdkBundleZipFile_invokesRightSubValidatorMethods.
@Test
public void validateSdkBundleZipFile_invokesRightSubValidatorMethods() throws Exception {
Path bundlePath = new ZipBuilder().addDirectory(ZipPath.create("directory")).addFileWithContent(ZipPath.create("file.txt"), DUMMY_CONTENT).writeTo(tempFolder.resolve("bundle.asb"));
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");
}
}
Aggregations