Search in sources :

Example 31 with InvalidBundleException

use of com.android.tools.build.bundletool.model.exceptions.InvalidBundleException in project bundletool by google.

the class AndroidManifestTest method getIsIncludedInFusing_missingIncludeAttribute_forSplit_throws.

@Test
public void getIsIncludedInFusing_missingIncludeAttribute_forSplit_throws() {
    // From Bundletool 0.3.4 onwards.
    AndroidManifest androidManifest = AndroidManifest.create(xmlNode(xmlElement("manifest", xmlAttribute("split", "feature1"), xmlNode(xmlElement(DISTRIBUTION_NAMESPACE_URI, "module", xmlNode(xmlElement(DISTRIBUTION_NAMESPACE_URI, "fusing")))))), BUNDLE_TOOL_0_3_4);
    InvalidBundleException exception = assertThrows(InvalidBundleException.class, androidManifest::getIsModuleIncludedInFusing);
    assertThat(exception).hasMessageThat().isEqualTo("<fusing> element is missing the 'include' attribute (split: 'feature1').");
}
Also used : InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) ManifestProtoUtils.androidManifest(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest) Test(org.junit.Test)

Example 32 with InvalidBundleException

use of com.android.tools.build.bundletool.model.exceptions.InvalidBundleException in project bundletool by google.

the class ManifestDeliveryElementTest method deliveryElement_typoInChildElement_throws_fastFollowEnabled.

@Test
public void deliveryElement_typoInChildElement_throws_fastFollowEnabled() {
    XmlNode nodeWithTypo = createAndroidManifestWithDeliveryElement(XmlProtoElementBuilder.create(DISTRIBUTION_NAMESPACE_URI, "delivery").addChildElement(XmlProtoElementBuilder.create(DISTRIBUTION_NAMESPACE_URI, "instal-time")));
    InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> ManifestDeliveryElement.fromManifestRootNode(nodeWithTypo, /* isFastFollowAllowed= */
    true));
    assertThat(exception).hasMessageThat().contains("Expected <dist:delivery> element to contain only <dist:install-time>, " + "<dist:on-demand>, <dist:fast-follow> elements but found: 'instal-time' " + "with namespace URI: 'http://schemas.android.com/apk/distribution'");
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) Test(org.junit.Test)

Example 33 with InvalidBundleException

use of com.android.tools.build.bundletool.model.exceptions.InvalidBundleException in project bundletool by google.

the class ManifestDeliveryElementTest method fastFollowElement_childElement_throws.

@Test
public void fastFollowElement_childElement_throws() {
    XmlNode nodeWithTypo = createAndroidManifestWithDeliveryElement(XmlProtoElementBuilder.create(DISTRIBUTION_NAMESPACE_URI, "delivery").addChildElement(XmlProtoElementBuilder.create(DISTRIBUTION_NAMESPACE_URI, "fast-follow").addChildElement(XmlProtoElementBuilder.create(DISTRIBUTION_NAMESPACE_URI, "conditions"))));
    InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> ManifestDeliveryElement.fromManifestRootNode(nodeWithTypo, /* isFastFollowAllowed= */
    true));
    assertThat(exception).hasMessageThat().contains("Expected <dist:fast-follow> element to have no child elements but found: " + "'conditions' with namespace URI: " + "'http://schemas.android.com/apk/distribution'");
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) Test(org.junit.Test)

Example 34 with InvalidBundleException

use of com.android.tools.build.bundletool.model.exceptions.InvalidBundleException in project bundletool by google.

the class ManifestDeliveryElementTest method deliveryElement_typoInChildElement_throws.

@Test
public void deliveryElement_typoInChildElement_throws() {
    XmlNode nodeWithTypo = createAndroidManifestWithDeliveryElement(XmlProtoElementBuilder.create(DISTRIBUTION_NAMESPACE_URI, "delivery").addChildElement(XmlProtoElementBuilder.create(DISTRIBUTION_NAMESPACE_URI, "instal-time")));
    InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> ManifestDeliveryElement.fromManifestRootNode(nodeWithTypo, /* isFastFollowAllowed= */
    false));
    assertThat(exception).hasMessageThat().contains("Expected <dist:delivery> element to contain only <dist:install-time>, " + "<dist:on-demand> elements but found: 'instal-time' with namespace URI: " + "'http://schemas.android.com/apk/distribution'");
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) Test(org.junit.Test)

Example 35 with InvalidBundleException

use of com.android.tools.build.bundletool.model.exceptions.InvalidBundleException in project bundletool by google.

the class ManifestDeliveryElementTest method userCountriesCondition_badCountryElementName_throws.

@Test
public void userCountriesCondition_badCountryElementName_throws() {
    XmlNode manifest = createAndroidManifestWithConditions(XmlProtoElementBuilder.create(DISTRIBUTION_NAMESPACE_URI, "user-countries").addChildElement(XmlProtoElementBuilder.create(DISTRIBUTION_NAMESPACE_URI, "country-typo").addAttribute(XmlProtoAttributeBuilder.create(DISTRIBUTION_NAMESPACE_URI, "code").setValueAsString("DE"))).build());
    Optional<ManifestDeliveryElement> deliveryElement = ManifestDeliveryElement.fromManifestRootNode(manifest, /* isFastFollowAllowed= */
    false);
    assertThat(deliveryElement).isPresent();
    InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> deliveryElement.get().getModuleConditions().getUserCountriesCondition());
    assertThat(exception).hasMessageThat().contains("Expected only <dist:country> elements inside <dist:user-countries>");
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) Test(org.junit.Test)

Aggregations

InvalidBundleException (com.android.tools.build.bundletool.model.exceptions.InvalidBundleException)188 Test (org.junit.Test)188 BundleModule (com.android.tools.build.bundletool.model.BundleModule)106 BundleModuleBuilder (com.android.tools.build.bundletool.testing.BundleModuleBuilder)69 ZipPath (com.android.tools.build.bundletool.model.ZipPath)28 AppBundle (com.android.tools.build.bundletool.model.AppBundle)17 XmlNode (com.android.aapt.Resources.XmlNode)14 Path (java.nio.file.Path)14 ManifestProtoUtils.androidManifest (com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest)12 ResourceTableBuilder (com.android.tools.build.bundletool.testing.ResourceTableBuilder)10 ResourceTable (com.android.aapt.Resources.ResourceTable)9 ZipFile (java.util.zip.ZipFile)9 ZipBuilder (com.android.tools.build.bundletool.io.ZipBuilder)8 AppBundleBuilder (com.android.tools.build.bundletool.testing.AppBundleBuilder)8 ApexImages (com.android.bundle.Files.ApexImages)6 NativeLibraries (com.android.bundle.Files.NativeLibraries)6 BundleConfigBuilder (com.android.tools.build.bundletool.testing.BundleConfigBuilder)6 Truth.assertThat (com.google.common.truth.Truth.assertThat)6 IOException (java.io.IOException)6 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)6