Skip to content

Commit

Permalink
Make sure the migrations are ordered correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
jrftrifork committed Aug 28, 2012
1 parent 2dd6e1e commit 7ce4b16
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
Expand Up @@ -17,6 +17,13 @@ public class Migration implements Comparable<Migration> {

private static final Pattern migrationNamePattern = Pattern.compile(".*/?V(\\d{8}_\\d{4})__(.*).sql");

protected Migration(String version, String description, Resource sqlSource) {
// used for testing
this.version = version;
this.description = description;
this.sqlSource = sqlSource;
}

public Migration(Resource sqlSource) {
this.sqlSource = sqlSource;
parseResourcename();
Expand Down
@@ -1,10 +1,45 @@
package dk.nsi.sdm4.core.persistence.migration;

import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertTrue;

public class MigrationComparableTest {
private Migration migration2;
private Migration migration1;
private Migration migration3;
private Migration migrationTime1;
private Migration migrationTime2;

@Before
public void setup() {
migration1 = new Migration("20120728_0101", null, null);
migration2 = new Migration("20120828_0101", null, null);
migration3 = new Migration("20120901_0101", null, null);

migrationTime1 = new Migration("20120901_0101", null, null);
migrationTime2 = new Migration("20120901_0102", null, null);
}


@Test
public void comparesDifferentMonthsCorrectly() {
assertTrue(migration1.compareTo(migration2) < 0);
}

@Test
public void comparesTheVersionsAsDates() {
public void doesNotJustUseTheDayOfMonth() {
assertTrue(migration2.compareTo(migration3) < 0);
}

@Test
public void canCrossSeveralMonths() {
assertTrue(migration3.compareTo(migration1) > 0);
}

@Test
public void understandsTimestampPartOfVersion() {
assertTrue(migrationTime1.compareTo(migrationTime2) < 0);
}
}

0 comments on commit 7ce4b16

Please sign in to comment.