/* * Hibernate, Relational Persistence for Idiomatic Java * * Copyright (c) 2011, Red Hat Inc. or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors. All third-party contributions are * distributed under license by Red Hat Inc.. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.hibernate.dialect; import java.sql.Types; import org.junit.Test; import org.hibernate.mapping.Column; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseUnitTestCase; import static org.junit.Assert.assertEquals; /** * DB2 dialect related test cases * * @author Hardy Ferentschik */ public class DB2DialectTestCase extends BaseUnitTestCase { private final DB2Dialect dialect = new DB2Dialect(); @Test @TestForIssue(jiraKey = "HHH-6866") public void testGetDefaultBinaryTypeName() { String actual = dialect.getTypeName( Types.BINARY ); assertEquals( "The default column length is 255, but char length on DB2 is limited to 254", "varchar($l) for bit data", actual ); } @Test @TestForIssue(jiraKey = "HHH-6866") public void testGetExplicitBinaryTypeName() { // lower bound String actual = dialect.getTypeName( Types.BINARY, 1, Column.DEFAULT_PRECISION, Column.DEFAULT_SCALE ); assertEquals( "Wrong binary type", "char(1) for bit data", actual ); // upper bound actual = dialect.getTypeName( Types.BINARY, 254, Column.DEFAULT_PRECISION, Column.DEFAULT_SCALE ); assertEquals( "Wrong binary type. 254 is the max length in DB2", "char(254) for bit data", actual ); // exceeding upper bound actual = dialect.getTypeName( Types.BINARY, 255, Column.DEFAULT_PRECISION, Column.DEFAULT_SCALE ); assertEquals( "Wrong binary type. Should be varchar for length > 254", "varchar(255) for bit data", actual ); } }