use of com.android.aapt.Resources.XmlNode in project bundletool by google.
the class ManifestEditorTest method setMinSdkVersion_nonExistingElement_created.
@Test
public void setMinSdkVersion_nonExistingElement_created() throws Exception {
AndroidManifest androidManifest = AndroidManifest.create(xmlNode(xmlElement("manifest")));
AndroidManifest editedManifest = androidManifest.toEditor().setMinSdkVersion(123).save();
XmlNode editedManifestRoot = editedManifest.getManifestRoot().getProto();
assertThat(editedManifestRoot.hasElement()).isTrue();
XmlElement manifestElement = editedManifestRoot.getElement();
assertThat(manifestElement.getName()).isEqualTo("manifest");
assertThat(manifestElement.getChildList()).containsExactly(xmlNode(xmlElement("uses-sdk", xmlDecimalIntegerAttribute(ANDROID_NAMESPACE_URI, "minSdkVersion", MIN_SDK_VERSION_RESOURCE_ID, 123))));
}
use of com.android.aapt.Resources.XmlNode in project bundletool by google.
the class ManifestDeliveryElementTest method userCountriesCondition_parsesOk.
@Test
public void userCountriesCondition_parsesOk() {
XmlNode manifest = createAndroidManifestWithConditions(XmlProtoElementBuilder.create(DISTRIBUTION_NAMESPACE_URI, "user-countries").addChildElement(createCountryCodeEntry("pl")).addChildElement(createCountryCodeEntry("GB")).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("PL", "GB");
assertThat(userCountriesCondition.get().getExclude()).isFalse();
}
use of com.android.aapt.Resources.XmlNode in project bundletool by google.
the class ManifestDeliveryElementTest method onDemandElement_childElement_throws.
@Test
public void onDemandElement_childElement_throws() {
XmlNode nodeWithTypo = createAndroidManifestWithDeliveryElement(XmlProtoElementBuilder.create(DISTRIBUTION_NAMESPACE_URI, "delivery").addChildElement(XmlProtoElementBuilder.create(DISTRIBUTION_NAMESPACE_URI, "on-demand").addChildElement(XmlProtoElementBuilder.create(DISTRIBUTION_NAMESPACE_URI, "conditions"))));
InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> ManifestDeliveryElement.fromManifestRootNode(nodeWithTypo, /* isFastFollowAllowed= */
false));
assertThat(exception).hasMessageThat().contains("Expected <dist:on-demand> element to have no child elements but found: " + "'conditions' 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 conditionsElement_missingNamespace_throws.
@Test
public void conditionsElement_missingNamespace_throws() {
XmlNode nodeWithTypo = createAndroidManifestWithDeliveryElement(XmlProtoElementBuilder.create(DISTRIBUTION_NAMESPACE_URI, "delivery").addChildElement(XmlProtoElementBuilder.create(DISTRIBUTION_NAMESPACE_URI, "install-time").addChildElement(XmlProtoElementBuilder.create("conditions"))));
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: 'conditions' with namespace not provided.");
}
use of com.android.aapt.Resources.XmlNode in project bundletool by google.
the class ManifestDeliveryElementTest method installTimeElement_missingNamespace_throws.
@Test
public void installTimeElement_missingNamespace_throws() {
XmlNode nodeWithTypo = createAndroidManifestWithDeliveryElement(XmlProtoElementBuilder.create(DISTRIBUTION_NAMESPACE_URI, "delivery").addChildElement(XmlProtoElementBuilder.create("install-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: 'install-time' with namespace not " + "provided");
}
Aggregations