|
| 1 | +/* |
| 2 | + * Hibernate, Relational Persistence for Idiomatic Java |
| 3 | + * |
| 4 | + * Copyright (c) 2010, Red Hat Inc. or third-party contributors as |
| 5 | + * indicated by the @author tags or express copyright attribution |
| 6 | + * statements applied by the authors. All third-party contributions are |
| 7 | + * distributed under license by Red Hat Inc. |
| 8 | + * |
| 9 | + * This copyrighted material is made available to anyone wishing to use, modify, |
| 10 | + * copy, or redistribute it subject to the terms and conditions of the GNU |
| 11 | + * Lesser General Public License, as published by the Free Software Foundation. |
| 12 | + * |
| 13 | + * This program is distributed in the hope that it will be useful, |
| 14 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 15 | + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License |
| 16 | + * for more details. |
| 17 | + * |
| 18 | + * You should have received a copy of the GNU Lesser General Public License |
| 19 | + * along with this distribution; if not, write to: |
| 20 | + * Free Software Foundation, Inc. |
| 21 | + * 51 Franklin Street, Fifth Floor |
| 22 | + * Boston, MA 02110-1301 USA |
| 23 | + */ |
| 24 | +package org.hibernate.test.dialect.function; |
| 25 | + |
| 26 | +import static java.util.Calendar.MONTH; |
| 27 | +import static org.junit.Assert.assertEquals; |
| 28 | +import static org.junit.Assert.assertTrue; |
| 29 | + |
| 30 | +import java.math.BigDecimal; |
| 31 | +import java.util.Calendar; |
| 32 | +import java.util.Date; |
| 33 | + |
| 34 | +import org.hibernate.Query; |
| 35 | +import org.hibernate.dialect.SybaseASE15Dialect; |
| 36 | +import org.hibernate.testing.RequiresDialect; |
| 37 | +import org.hibernate.testing.TestForIssue; |
| 38 | +import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; |
| 39 | +import org.junit.Test; |
| 40 | + |
| 41 | +/** |
| 42 | + * |
| 43 | + * @author Richard H. Tingstad |
| 44 | + */ |
| 45 | +@RequiresDialect(value = { SybaseASE15Dialect.class }) |
| 46 | +public class SybaseASE15FunctionTest extends BaseCoreFunctionalTestCase { |
| 47 | + |
| 48 | + private Calendar calendar = Calendar.getInstance(); |
| 49 | + |
| 50 | + @Override |
| 51 | + public String[] getMappings() { |
| 52 | + return new String[] { "dialect/function/Product.hbm.xml" }; |
| 53 | + } |
| 54 | + |
| 55 | + @Override |
| 56 | + protected void prepareTest() throws Exception { |
| 57 | + Product product = new Product(); |
| 58 | + product.setPrice(new BigDecimal(0.5)); |
| 59 | + product.setDate(calendar.getTime()); |
| 60 | + openSession().save(product); |
| 61 | + } |
| 62 | + |
| 63 | + @Test |
| 64 | + public void testCharLengthFunction() { |
| 65 | + Query query = session.createQuery("select char_length('123456') from Product"); |
| 66 | + assertEquals(6, ((Number) query.uniqueResult()).intValue()); |
| 67 | + } |
| 68 | + |
| 69 | + @Test |
| 70 | + @TestForIssue(jiraKey = "HHH-7070") |
| 71 | + public void testDateaddFunction() { |
| 72 | + Query query = session.createQuery("select dateadd(dd, 1, p.date) from Product p"); |
| 73 | + assertTrue(calendar.getTime().before((Date) query.uniqueResult())); |
| 74 | + } |
| 75 | + |
| 76 | + @Test |
| 77 | + @TestForIssue(jiraKey = "HHH-7070") |
| 78 | + public void testDatepartFunction() { |
| 79 | + Query query = session.createQuery("select datepart(month, p.date) from Product p"); |
| 80 | + assertEquals(calendar.get(MONTH) + 1, ((Number) query.uniqueResult()).intValue()); |
| 81 | + } |
| 82 | + |
| 83 | + @Test |
| 84 | + @TestForIssue(jiraKey = "HHH-7070") |
| 85 | + public void testDatediffFunction() { |
| 86 | + Query query = session.createQuery("SELECT DATEDIFF( DAY, '1999/07/19 00:00', '1999/07/23 23:59' ) from Product"); |
| 87 | + assertEquals(4, ((Number) query.uniqueResult()).intValue()); |
| 88 | + } |
| 89 | + |
| 90 | + @Test |
| 91 | + @TestForIssue(jiraKey = "HHH-7070") |
| 92 | + public void testAtn2Function() { |
| 93 | + Query query = session.createQuery("select atn2(p.price, .48) from Product p"); |
| 94 | + assertEquals(0.805803, ((Number) query.uniqueResult()).doubleValue(), 0.000001); |
| 95 | + } |
| 96 | + |
| 97 | +} |
0 commit comments