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");
}
}
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();
}
}
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);
}
}
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'");
}
}
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));
}
}
Aggregations