Search in sources :

Example 61 with XmlNode

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))));
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) XmlElement(com.android.aapt.Resources.XmlElement) Test(org.junit.Test)

Example 62 with XmlNode

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();
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) ManifestProtoUtils.withUserCountriesCondition(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withUserCountriesCondition) Test(org.junit.Test)

Example 63 with XmlNode

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'");
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) Test(org.junit.Test)

Example 64 with XmlNode

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.");
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) Test(org.junit.Test)

Example 65 with XmlNode

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