Search in sources :

Example 36 with InvalidBundleException

use of com.android.tools.build.bundletool.model.exceptions.InvalidBundleException 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 37 with InvalidBundleException

use of com.android.tools.build.bundletool.model.exceptions.InvalidBundleException in project bundletool by google.

the class ManifestDeliveryElementTest method getModuleConditions_multipleMinSdkCondition_throws.

@Test
public void getModuleConditions_multipleMinSdkCondition_throws() {
    Optional<ManifestDeliveryElement> element = ManifestDeliveryElement.fromManifestRootNode(androidManifest("com.test.app", withMinSdkCondition(24), withMinSdkCondition(28)), /* isFastFollowAllowed= */
    false);
    assertThat(element).isPresent();
    InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> element.get().getModuleConditions());
    assertThat(exception).hasMessageThat().contains("Multiple '<dist:min-sdk>' conditions are not supported.");
}
Also used : InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) Test(org.junit.Test)

Example 38 with InvalidBundleException

use of com.android.tools.build.bundletool.model.exceptions.InvalidBundleException in project bundletool by google.

the class ManifestDeliveryElementTest method moduleConditions_wrongElementInsideDeviceGroupsCondition_throws.

@Test
public void moduleConditions_wrongElementInsideDeviceGroupsCondition_throws() {
    XmlProtoElement badDeviceGroupCondition = XmlProtoElementBuilder.create(DISTRIBUTION_NAMESPACE_URI, "device-groups").addChildElement(XmlProtoElementBuilder.create(DISTRIBUTION_NAMESPACE_URI, "wrong")).build();
    Optional<ManifestDeliveryElement> element = ManifestDeliveryElement.fromManifestRootNode(createAndroidManifestWithConditions(badDeviceGroupCondition), /* isFastFollowAllowed= */
    false);
    assertThat(element).isPresent();
    InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> element.get().getModuleConditions());
    assertThat(exception).hasMessageThat().contains("Expected only '<dist:device-group>' elements inside '<dist:device-groups>', but found" + " 'wrong'");
}
Also used : InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) XmlProtoElement(com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoElement) Test(org.junit.Test)

Example 39 with InvalidBundleException

use of com.android.tools.build.bundletool.model.exceptions.InvalidBundleException in project bundletool by google.

the class ManifestDeliveryElementTest method moduleConditions_wrongDeviceGroupName_throws.

@Test
public void moduleConditions_wrongDeviceGroupName_throws() {
    Optional<ManifestDeliveryElement> element = ManifestDeliveryElement.fromManifestRootNode(androidManifest("com.test.app", withDeviceGroupsCondition(ImmutableList.of("group!!!"))), /* isFastFollowAllowed= */
    false);
    assertThat(element).isPresent();
    InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> element.get().getModuleConditions());
    assertThat(exception).hasMessageThat().isEqualTo("Device group names should start with a letter and contain only " + "letters, numbers and underscores. Found group named 'group!!!' in " + "'<dist:device-group>' element.");
}
Also used : InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) Test(org.junit.Test)

Example 40 with InvalidBundleException

use of com.android.tools.build.bundletool.model.exceptions.InvalidBundleException 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

InvalidBundleException (com.android.tools.build.bundletool.model.exceptions.InvalidBundleException)188 Test (org.junit.Test)188 BundleModule (com.android.tools.build.bundletool.model.BundleModule)106 BundleModuleBuilder (com.android.tools.build.bundletool.testing.BundleModuleBuilder)69 ZipPath (com.android.tools.build.bundletool.model.ZipPath)28 AppBundle (com.android.tools.build.bundletool.model.AppBundle)17 XmlNode (com.android.aapt.Resources.XmlNode)14 Path (java.nio.file.Path)14 ManifestProtoUtils.androidManifest (com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest)12 ResourceTableBuilder (com.android.tools.build.bundletool.testing.ResourceTableBuilder)10 ResourceTable (com.android.aapt.Resources.ResourceTable)9 ZipFile (java.util.zip.ZipFile)9 ZipBuilder (com.android.tools.build.bundletool.io.ZipBuilder)8 AppBundleBuilder (com.android.tools.build.bundletool.testing.AppBundleBuilder)8 ApexImages (com.android.bundle.Files.ApexImages)6 NativeLibraries (com.android.bundle.Files.NativeLibraries)6 BundleConfigBuilder (com.android.tools.build.bundletool.testing.BundleConfigBuilder)6 Truth.assertThat (com.google.common.truth.Truth.assertThat)6 IOException (java.io.IOException)6 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)6