-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a simple migration test with the default configuration.
- Loading branch information
1 parent
2a64b3b
commit 208fae4
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
CREATE TABLE IF NOT EXISTS MockMigration | ||
( | ||
Id INTEGER AUTO_INCREMENT PRIMARY KEY, | ||
Column TEXT NOT NULL | ||
); | ||
|
||
INSERT INTO MockMigration | ||
( | ||
Id, | ||
Column | ||
) | ||
VALUES | ||
( | ||
1, | ||
'text' | ||
); | ||
|
||
DROP TABLE IF EXISTS MockMigration; |
54 changes: 54 additions & 0 deletions
54
tests/src/com/activeandroid/test/parser/ParserConfigurationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
|
||
package com.activeandroid.test.parser; | ||
|
||
import android.database.SQLException; | ||
import android.database.sqlite.SQLiteDatabase; | ||
|
||
import com.activeandroid.Configuration; | ||
import com.activeandroid.DatabaseHelper; | ||
import com.activeandroid.test.ActiveAndroidTestCase; | ||
|
||
|
||
public class ParserConfigurationTest extends ActiveAndroidTestCase { | ||
|
||
/** | ||
* Should try to use the legacy parser by default, which is be unable to handle the SQL script. | ||
*/ | ||
public void testLegacyMigration() { | ||
|
||
try { | ||
Configuration configuration = new Configuration.Builder(getContext()) | ||
.setDatabaseName("migration.db") | ||
.setDatabaseVersion(2) | ||
.create(); | ||
|
||
DatabaseHelper helper = new DatabaseHelper(configuration); | ||
SQLiteDatabase db = helper.getWritableDatabase(); | ||
helper.onUpgrade(db, 1, 2); | ||
|
||
fail("Should not be able to parse the SQL script."); | ||
|
||
} catch (SQLException e) { | ||
final String message = e.getMessage(); | ||
|
||
assertNotNull(message); | ||
assertTrue(message.contains("syntax error")); | ||
assertTrue(message.contains("near \"MockMigration\"")); | ||
} | ||
} | ||
|
||
/** | ||
* Should use the new parser if configured to do so. | ||
*/ | ||
public void testDelimitedMigration() { | ||
Configuration configuration = new Configuration.Builder(getContext()) | ||
.setSqlParser(Configuration.SQL_PARSER_DELIMITED) | ||
.setDatabaseName("migration.db") | ||
.setDatabaseVersion(2) | ||
.create(); | ||
|
||
DatabaseHelper helper = new DatabaseHelper(configuration); | ||
SQLiteDatabase db = helper.getWritableDatabase(); | ||
helper.onUpgrade(db, 1, 2); | ||
} | ||
} |