Search in sources :

Example 21 with XmlNode

use of com.android.aapt.Resources.XmlNode 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 22 with XmlNode

use of com.android.aapt.Resources.XmlNode 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 23 with XmlNode

use of com.android.aapt.Resources.XmlNode 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)

Example 24 with XmlNode

use of com.android.aapt.Resources.XmlNode in project bundletool by google.

the class ManifestDeliveryElementTest method deviceFeatureCondition_missingNamespace_throws.

@Test
public void deviceFeatureCondition_missingNamespace_throws() {
    XmlNode nodeWithTypo = createAndroidManifestWithDeliveryElement(XmlProtoElementBuilder.create(DISTRIBUTION_NAMESPACE_URI, "delivery").addChildElement(XmlProtoElementBuilder.create(DISTRIBUTION_NAMESPACE_URI, "install-time").addChildElement(XmlProtoElementBuilder.create(DISTRIBUTION_NAMESPACE_URI, "conditions").addChildElement(XmlProtoElementBuilder.create(DISTRIBUTION_NAMESPACE_URI, "device-feature").addAttribute(XmlProtoAttributeBuilder.create("name").setValueAsString("android.hardware.feature"))))));
    InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> ManifestDeliveryElement.fromManifestRootNode(nodeWithTypo, /* isFastFollowAllowed= */
    false).get().getModuleConditions());
    assertThat(exception).hasMessageThat().contains("Missing required 'dist:name' attribute in the 'device-feature' condition element.");
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) Test(org.junit.Test)

Example 25 with XmlNode

use of com.android.aapt.Resources.XmlNode in project bundletool by google.

the class ManifestDeliveryElementTest method minSdkCondition_missingNamespace_throws.

@Test
public void minSdkCondition_missingNamespace_throws() {
    XmlNode nodeWithTypo = createAndroidManifestWithDeliveryElement(XmlProtoElementBuilder.create(DISTRIBUTION_NAMESPACE_URI, "delivery").addChildElement(XmlProtoElementBuilder.create(DISTRIBUTION_NAMESPACE_URI, "install-time").addChildElement(XmlProtoElementBuilder.create(DISTRIBUTION_NAMESPACE_URI, "conditions").addChildElement(XmlProtoElementBuilder.create(DISTRIBUTION_NAMESPACE_URI, "min-sdk").addAttribute(XmlProtoAttributeBuilder.create("value").setValueAsDecimalInteger(21))))));
    InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> ManifestDeliveryElement.fromManifestRootNode(nodeWithTypo, /* isFastFollowAllowed= */
    false).get().getModuleConditions());
    assertThat(exception).hasMessageThat().contains("Missing required 'dist:value' attribute in the 'min-sdk' condition element.");
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) Test(org.junit.Test)

Aggregations

XmlNode (com.android.aapt.Resources.XmlNode)99 Test (org.junit.Test)91 XmlElement (com.android.aapt.Resources.XmlElement)28 AppBundle (com.android.tools.build.bundletool.model.AppBundle)27 ManifestProtoUtils.androidManifest (com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest)23 Truth.assertThat (com.google.common.truth.Truth.assertThat)23 RunWith (org.junit.runner.RunWith)23 ResourceTable (com.android.aapt.Resources.ResourceTable)21 ImmutableList (com.google.common.collect.ImmutableList)21 AndroidManifest (com.android.tools.build.bundletool.model.AndroidManifest)16 Nullable (javax.annotation.Nullable)16 Theories (org.junit.experimental.theories.Theories)16 ZipFile (java.util.zip.ZipFile)12 FileReference (com.android.aapt.Resources.FileReference)10 AppBundleBuilder (com.android.tools.build.bundletool.testing.AppBundleBuilder)10 Configuration (com.android.aapt.ConfigurationOuterClass.Configuration)9 Attribute (com.android.aapt.Resources.Attribute)9 Symbol (com.android.aapt.Resources.Attribute.Symbol)9 CompoundValue (com.android.aapt.Resources.CompoundValue)9 ConfigValue (com.android.aapt.Resources.ConfigValue)9