001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
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    /**
027     * @author Miguel Pastor
028     * @author L??szl?? Csontos
029     */
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    }