use of com.microsoft.azure.mobile.utils.storage.StorageHelper.DatabaseStorage in project mobile-center-sdk-android by Microsoft.
the class StorageHelperAndroidTest method databaseStorageInMemoryDB.
/* This is a hack to test database failure by passing a weird table name which is actually valid.
SQLite database allows to create a table that contains period (.) but it doesn't actually create the table and doesn't raise any exceptions.
This test method will then be able to test in-memory database by accessing a table which is not created.
Only tested on emulator so it might not work in the future or on any other devices. */
@Test
public void databaseStorageInMemoryDB() throws IOException {
Log.i(TAG, "Testing Database Storage switch over to in-memory database");
/* Get instance to access database. */
DatabaseStorage databaseStorage = DatabaseStorage.getDatabaseStorage("test-databaseStorageInMemoryDB", "test.databaseStorageInMemoryDB", 1, mSchema, new DatabaseStorage.DatabaseErrorListener() {
@Override
public void onError(String operation, RuntimeException e) {
/* Do not handle any errors. This is simulating errors so this is expected. */
}
});
//noinspection TryFinallyCanBeTryWithResources (try with resources statement is API >= 19)
try {
runDatabaseStorageTest(databaseStorage, true);
} finally {
/* Close. */
//noinspection ThrowFromFinallyBlock
databaseStorage.close();
}
}
use of com.microsoft.azure.mobile.utils.storage.StorageHelper.DatabaseStorage in project mobile-center-sdk-android by Microsoft.
the class StorageHelperAndroidTest method databaseStorageScannerRemove.
@Test(expected = UnsupportedOperationException.class)
public void databaseStorageScannerRemove() throws IOException {
Log.i(TAG, "Testing Database Storage Exceptions");
/* Get instance to access database. */
DatabaseStorage databaseStorage = DatabaseStorage.getDatabaseStorage("test-databaseStorageScannerRemove", "databaseStorageScannerRemove", 1, mSchema, new DatabaseStorage.DatabaseErrorListener() {
@Override
public void onError(String operation, RuntimeException e) {
throw e;
}
});
//noinspection TryFinallyCanBeTryWithResources (try with resources statement is API >= 19)
try {
databaseStorage.getScanner().iterator().remove();
} finally {
/* Close. */
//noinspection ThrowFromFinallyBlock
databaseStorage.close();
}
}
use of com.microsoft.azure.mobile.utils.storage.StorageHelper.DatabaseStorage in project mobile-center-sdk-android by Microsoft.
the class StorageHelperAndroidTest method databaseStorageUpgrade.
@Test
public void databaseStorageUpgrade() throws IOException {
Log.i(TAG, "Testing Database Storage Upgrade");
/* Create a schema for v1. */
ContentValues schema = new ContentValues();
schema.put("COL_STRING", "");
/* Create a row for v1. */
ContentValues oldVersionValue = new ContentValues();
oldVersionValue.put("COL_STRING", "Hello World");
/* Get instance to access database. */
DatabaseStorage databaseStorage = DatabaseStorage.getDatabaseStorage("test-databaseStorageUpgrade", "databaseStorageUpgrade", 1, schema, new DatabaseStorage.DatabaseErrorListener() {
@Override
public void onError(String operation, RuntimeException e) {
throw e;
}
});
try {
/* Database will always create a column for identifiers so default length of all tables is 1. */
assertEquals(2, databaseStorage.getColumnNames().length);
} finally {
/* Close. */
//noinspection ThrowFromFinallyBlock
databaseStorage.close();
}
/* Get instance to access database with a newer schema. */
databaseStorage = DatabaseStorage.getDatabaseStorage("test-databaseStorageUpgrade", "databaseStorageUpgrade", 2, mSchema, new DatabaseStorage.DatabaseErrorListener() {
@Override
public void onError(String operation, RuntimeException e) {
throw e;
}
});
try {
assertEquals(11, databaseStorage.getColumnNames().length);
} finally {
/* Close. */
//noinspection ThrowFromFinallyBlock
databaseStorage.close();
}
}
use of com.microsoft.azure.mobile.utils.storage.StorageHelper.DatabaseStorage in project mobile-center-sdk-android by Microsoft.
the class StorageHelperAndroidTest method databaseStorageScannerNext.
@Test(expected = NoSuchElementException.class)
public void databaseStorageScannerNext() throws IOException {
Log.i(TAG, "Testing Database Storage Exceptions");
/* Get instance to access database. */
DatabaseStorage databaseStorage = DatabaseStorage.getDatabaseStorage("test-databaseStorageScannerNext", "databaseStorageScannerNext", 1, mSchema, new DatabaseStorage.DatabaseErrorListener() {
@Override
public void onError(String operation, RuntimeException e) {
throw e;
}
});
//noinspection TryFinallyCanBeTryWithResources (try with resources statement is API >= 19)
try {
databaseStorage.getScanner().iterator().next();
} finally {
/* Close. */
//noinspection ThrowFromFinallyBlock
databaseStorage.close();
}
}
use of com.microsoft.azure.mobile.utils.storage.StorageHelper.DatabaseStorage in project mobile-center-sdk-android by Microsoft.
the class StorageHelperAndroidTest method databaseStorage.
@Test
public void databaseStorage() throws IOException {
Log.i(TAG, "Testing Database Storage");
/* Get instance to access database. */
DatabaseStorage databaseStorage = DatabaseStorage.getDatabaseStorage("test-databaseStorage", "databaseStorage", 1, mSchema, new DatabaseStorage.DatabaseErrorListener() {
@Override
public void onError(String operation, RuntimeException e) {
throw e;
}
});
//noinspection TryFinallyCanBeTryWithResources (try with resources statement is API >= 19)
try {
runDatabaseStorageTest(databaseStorage, false);
} finally {
/* Close. */
//noinspection ThrowFromFinallyBlock
databaseStorage.close();
}
}
Aggregations