001
014
015 package com.liferay.portal.dao.db;
016
017 import com.liferay.portal.kernel.dao.db.DB;
018 import com.liferay.portal.kernel.util.StringBundler;
019 import com.liferay.portal.kernel.util.StringPool;
020
021 import java.io.IOException;
022
023 import org.junit.Assert;
024 import org.junit.Test;
025
026
030 public abstract class BaseDBTestCase {
031
032 @Test
033 public void testReplaceTemplate() throws IOException {
034 StringBundler sb = new StringBundler(5);
035
036 sb.append("select * from SomeTable where someColumn1 = ");
037 sb.append(_db.getTemplateFalse());
038 sb.append(" and someColumn2 = ");
039 sb.append(_db.getTemplateTrue());
040 sb.append(StringPool.NEW_LINE);
041
042 Assert.assertEquals(sb.toString(), buildSQL(_BOOLEAN_LITERAL_QUERY));
043 Assert.assertEquals(
044 _BOOLEAN_PATTERN_QUERY + StringPool.NEW_LINE,
045 buildSQL(_BOOLEAN_PATTERN_QUERY));
046 }
047
048 protected String buildSQL(String query) throws IOException {
049 return _db.buildSQL(query);
050 }
051
052 protected abstract DB getDB();
053
054 protected static final String RENAME_TABLE_QUERY = "alter_table_name a b";
055
056 private static final String _BOOLEAN_LITERAL_QUERY =
057 "select * from SomeTable where someColumn1 = FALSE and someColumn2 = " +
058 "TRUE";
059
060 private static final String _BOOLEAN_PATTERN_QUERY =
061 "select * from SomeTable where someColumn1 = [$FALSE$] and " +
062 "someColumn2 = [$TRUE$]";
063
064 private final DB _db = getDB();
065
066 }