Letter Case of the database
Databases have different letter cases for the name of the elements. For example, the name of the table can be upper case either the name is inputted in upper case or not. So this concept (and feature too) is here to manage these shades.
It is possible to declare a LetterCase with a AssertDbConnection with LetterCase.
The concept of LetterCase is composed of CaseConversion and CaseComparison.
CaseConversion
The CaseConversion is used when getting a name with letter case from database : a table name, a column name or a primary key name.
There are three conversions modes : UPPER which converts to upper case ("Name" becomes "NAME"), LOWER which converts to lower case ("Name" becomes "name") and NO which keeps the case ("Name" remains "Name").
Each name (table, column and primary key) got from the database is converted using a CaseConversion.
CaseComparison
The CaseComparison is used when comparing something with letter case from database or with a parameter.
There are two comparison modes : IGNORE which compares String`s by ignoring the case (`"Name" is considered equal to "NAME") and STRICT which compares String`s strictly (`"Name" is considered different from "NAME").
During navigation (e.g. from table to column) and assertion (e.g. on column name), the name are compared using a CaseComparison.
LetterCase
A LetterCase is created with the getLetterCase static method which has a CaseConversion and a CaseComparison as parameters.
LetterCase letterCase = LetterCase.getLetterCase(CaseConversions.NO, CaseComparisons.IGNORE);
In AssertJ-DB, there are three different uses of a LetterCase : the table name, the column name and the primary key name. That is the reason why the AssertDbConnection have three LetterCase parameters.
The LetterCase on the tables is used :
-
to convert the table name : when a name is got from the database like for the Table instantiation or for the table with changes found with Changes.
-
to compare the table name : for the instantiation when the table is search in the database for Table, for navigation (e.g. from changes to a change on a table) or for a assertion (like isOnTable(String name)).
The LetterCase on the columns is used :
-
to convert the column name : when a column name is got from the database for a table or a request
-
to compare the column name : for the navigation (e.g. from a table to a column) or for a assertion (like hasColumnName(String columnName)).
The LetterCase on the primary keys is used :
-
to convert the primary key name : when a primary key name is got from the database for a table
-
to compare the primary key name : for a assertion (like hasPksNames(String… names)).
The default settings for LetterCase in AssertDbConnection are :
In this example, the two connections are equivalent :
AssertDbConnection jdbcConnection = AssertDbConnectionFactory.of("jdbc:h2:mem:test", "sa", "").create();
Table table = jdbcConnection.table("members").build();
LetterCase tableLetterCase = LetterCase.getLetterCase(CaseConversions.NO, CaseComparisons.IGNORE);
LetterCase columnLetterCase = LetterCase.getLetterCase(CaseConversions.UPPER, CaseComparisons.IGNORE);
LetterCase pkLetterCase = LetterCase.getLetterCase(CaseConversions.UPPER, CaseComparisons.IGNORE);
AssertDbConnection connectionWithLC = AssertDbConnectionFactory.of("jdbc:h2:mem:test", "sa", "")
.letterCase(tableLetterCase, columnLetterCase, pkLetterCase)
.create();
Table tableWithLC = connectionWithLC.table("members").build();
Note that the letter case is extensible because the getLetterCase static method’s parameters are instances of the CaseConversion and the CaseComparison interfaces. So this is not limited to the implementations in the corresponding enumerations.