Skip to content

Commit

Permalink
Added a simple migration test with the default configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
mpfeiffermway committed Apr 17, 2014
1 parent 2a64b3b commit 208fae4
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/assets/migrations/2.sql
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;
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);
}
}

0 comments on commit 208fae4

Please sign in to comment.