Search in sources :

Example 66 with XmlNode

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

the class ManifestDeliveryElementTest method moduleConditions_typoInElement_throws.

@Test
public void moduleConditions_typoInElement_throws() {
    XmlNode nodeWithTypo = createAndroidManifestWithDeliveryElement(XmlProtoElementBuilder.create(DISTRIBUTION_NAMESPACE_URI, "delivery").addChildElement(XmlProtoElementBuilder.create(DISTRIBUTION_NAMESPACE_URI, "install-time").addChildElement(XmlProtoElementBuilder.create(DISTRIBUTION_NAMESPACE_URI, "condtions"))));
    InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> ManifestDeliveryElement.fromManifestRootNode(nodeWithTypo, /* isFastFollowAllowed= */
    false));
    assertThat(exception).hasMessageThat().contains("Expected <dist:install-time> element to contain only <dist:conditions> or " + "<dist:removable> element but found: 'condtions' 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 67 with XmlNode

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

the class ManifestDeliveryElementTest method userCountriesCondition_parsesExclusionOk.

@Test
public void userCountriesCondition_parsesExclusionOk() {
    XmlNode manifest = createAndroidManifestWithConditions(XmlProtoElementBuilder.create(DISTRIBUTION_NAMESPACE_URI, "user-countries").addAttribute(XmlProtoAttributeBuilder.create(DISTRIBUTION_NAMESPACE_URI, "exclude").setValueAsBoolean(true)).addChildElement(createCountryCodeEntry("FR")).addChildElement(createCountryCodeEntry("SN")).build());
    Optional<ManifestDeliveryElement> deliveryElement = ManifestDeliveryElement.fromManifestRootNode(manifest, /* isFastFollowAllowed= */
    false);
    assertThat(deliveryElement).isPresent();
    Optional<UserCountriesCondition> userCountriesCondition = deliveryElement.get().getModuleConditions().getUserCountriesCondition();
    assertThat(userCountriesCondition).isPresent();
    assertThat(userCountriesCondition.get().getCountries()).containsExactly("FR", "SN");
    assertThat(userCountriesCondition.get().getExclude()).isTrue();
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) ManifestProtoUtils.withUserCountriesCondition(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withUserCountriesCondition) Test(org.junit.Test)

Example 68 with XmlNode

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

the class ManifestDeliveryElementTest method onDemandElement_missingNamespace_throws.

@Test
public void onDemandElement_missingNamespace_throws() {
    XmlNode nodeWithTypo = createAndroidManifestWithDeliveryElement(XmlProtoElementBuilder.create(DISTRIBUTION_NAMESPACE_URI, "delivery").addChildElement(XmlProtoElementBuilder.create("on-demand")));
    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: 'on-demand' with namespace not provided");
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) Test(org.junit.Test)

Example 69 with XmlNode

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

the class ManifestDeliveryElementTest method userCountriesCondition_missingCodeAttribute_throws.

@Test
public void userCountriesCondition_missingCodeAttribute_throws() {
    XmlNode manifest = createAndroidManifestWithConditions(XmlProtoElementBuilder.create(DISTRIBUTION_NAMESPACE_URI, "user-countries").addChildElement(XmlProtoElementBuilder.create(DISTRIBUTION_NAMESPACE_URI, "country").addAttribute(XmlProtoAttributeBuilder.create(DISTRIBUTION_NAMESPACE_URI, "code-typo").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("<dist:country> element is expected to have 'dist:code' attribute");
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) Test(org.junit.Test)

Example 70 with XmlNode

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

the class ManifestEditorTest method setFeatureSplitWithExistingSplit_forNonBaseSplit.

@Test
public void setFeatureSplitWithExistingSplit_forNonBaseSplit() throws Exception {
    AndroidManifest androidManifest = AndroidManifest.create(xmlNode(xmlElement("manifest", xmlAttribute("split", "differentSplit"), xmlNode(xmlElement("application")))));
    AndroidManifest editedManifest = androidManifest.toEditor().setSplitIdForFeatureSplit("feature1").save();
    XmlNode manifestRoot = editedManifest.getManifestRoot().getProto();
    assertThat(manifestRoot.hasElement()).isTrue();
    XmlElement manifestElement = manifestRoot.getElement();
    assertThat(manifestElement.getName()).isEqualTo("manifest");
    assertThat(manifestElement.getChildList()).containsExactly(xmlNode(xmlElement("application")));
    assertThat(manifestElement.getAttributeList()).containsExactly(xmlBooleanAttribute(ANDROID_NAMESPACE_URI, "isFeatureSplit", IS_FEATURE_SPLIT_RESOURCE_ID, true), xmlAttribute("split", "feature1"));
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) XmlElement(com.android.aapt.Resources.XmlElement) 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