Skip to content

Commit

Permalink
0004821: Added unit tests for massageForLimitOffset() (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-miller-jumpmind committed Feb 10, 2021
1 parent 9769e29 commit 8a7b97a
Showing 1 changed file with 35 additions and 0 deletions.
Expand Up @@ -47,6 +47,7 @@
import org.jumpmind.db.platform.PermissionType;
import org.jumpmind.db.platform.oracle.OracleDdlBuilder;
import org.jumpmind.db.sql.ISqlTemplate;
import org.jumpmind.db.sql.Row;
import org.jumpmind.db.sql.SqlScript;
import org.junit.Before;
import org.junit.BeforeClass;
Expand Down Expand Up @@ -359,4 +360,38 @@ public void testEnumType() {
}
}
}

@Test
public void testMassageForLimitOffset() {
if (platform.supportsLimitOffset()) {
ISqlTemplate template = platform.getSqlTemplate();
String insertSql = "insert into \"" + UPPERCASE_TABLE + "\" (\"id\",\"text\") values(null,?)";
insertSql = insertSql.replaceAll("\"", platform.getDatabaseInfo().getDelimiterToken());
for (char letter = 'a'; letter <= 'z'; letter++) {
template.insertWithGeneratedKey(insertSql, "ID", getSequenceName(platform),
new Object[] { String.valueOf(letter) }, new int[] { Types.VARCHAR });
}

String selectSql = "select \"text\" from \"" + UPPERCASE_TABLE + "\" order by \"id\" asc";

String testSql = platform.massageForLimitOffset(selectSql, 5, 0);
List<Row> testResult = template.query(testSql);
assertNotNull("The result set was null when testing the limit", testResult);
assertEquals("The result set wasn't correctly limited when testing the limit", 5, testResult.size());
assertEquals("The result set was unnecessarily offset", "a", testResult.get(0).getString("text"));

testSql = platform.massageForLimitOffset(selectSql, 30, 5);
testResult = template.query(testSql);
assertNotNull("The result set was null when testing the offset", testResult);
assertEquals("The result set was unnecessarily limited", 21, testResult.size());
assertEquals("The result set wasn't correctly offset when testing the offset", "f", testResult.get(0).getString("text"));

testSql = platform.massageForLimitOffset(selectSql, 5, 5);
testResult = template.query(testSql);
assertNotNull("The result set wasn't correctly limited when ", testResult);
assertEquals("The result set wasn't correctly limited when testing the limit and offset", 5, testResult.size());
assertEquals("The result set wasn't correctly offset when testing the limit and offset", "f",
testResult.get(0).getString("text"));
}
}
}

0 comments on commit 8a7b97a

Please sign in to comment.