Skip to content

Commit 208fae4

Browse files
committed
Added a simple migration test with the default configuration.
1 parent 2a64b3b commit 208fae4

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

tests/assets/migrations/2.sql

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
CREATE TABLE IF NOT EXISTS MockMigration
2+
(
3+
Id INTEGER AUTO_INCREMENT PRIMARY KEY,
4+
Column TEXT NOT NULL
5+
);
6+
7+
INSERT INTO MockMigration
8+
(
9+
Id,
10+
Column
11+
)
12+
VALUES
13+
(
14+
1,
15+
'text'
16+
);
17+
18+
DROP TABLE IF EXISTS MockMigration;
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
2+
package com.activeandroid.test.parser;
3+
4+
import android.database.SQLException;
5+
import android.database.sqlite.SQLiteDatabase;
6+
7+
import com.activeandroid.Configuration;
8+
import com.activeandroid.DatabaseHelper;
9+
import com.activeandroid.test.ActiveAndroidTestCase;
10+
11+
12+
public class ParserConfigurationTest extends ActiveAndroidTestCase {
13+
14+
/**
15+
* Should try to use the legacy parser by default, which is be unable to handle the SQL script.
16+
*/
17+
public void testLegacyMigration() {
18+
19+
try {
20+
Configuration configuration = new Configuration.Builder(getContext())
21+
.setDatabaseName("migration.db")
22+
.setDatabaseVersion(2)
23+
.create();
24+
25+
DatabaseHelper helper = new DatabaseHelper(configuration);
26+
SQLiteDatabase db = helper.getWritableDatabase();
27+
helper.onUpgrade(db, 1, 2);
28+
29+
fail("Should not be able to parse the SQL script.");
30+
31+
} catch (SQLException e) {
32+
final String message = e.getMessage();
33+
34+
assertNotNull(message);
35+
assertTrue(message.contains("syntax error"));
36+
assertTrue(message.contains("near \"MockMigration\""));
37+
}
38+
}
39+
40+
/**
41+
* Should use the new parser if configured to do so.
42+
*/
43+
public void testDelimitedMigration() {
44+
Configuration configuration = new Configuration.Builder(getContext())
45+
.setSqlParser(Configuration.SQL_PARSER_DELIMITED)
46+
.setDatabaseName("migration.db")
47+
.setDatabaseVersion(2)
48+
.create();
49+
50+
DatabaseHelper helper = new DatabaseHelper(configuration);
51+
SQLiteDatabase db = helper.getWritableDatabase();
52+
helper.onUpgrade(db, 1, 2);
53+
}
54+
}

0 commit comments

Comments
 (0)