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