~raginggoblin/infolog/infolog

« back to all changes in this revision

Viewing changes to InfologServer/lib/hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/dialect/function/AnsiTrimEmulationFunctionTest.java

  • Committer: Raging Goblin
  • Date: 2013-11-16 16:51:32 UTC
  • Revision ID: raging_goblin-20131116165132-weujnptzc88uy4ah
Mavenized the project, now using shared project InfologSync

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Hibernate, Relational Persistence for Idiomatic Java
3
 
 *
4
 
 * Copyright (c) 2009, Red Hat Middleware LLC 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 Middleware LLC.
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 java.util.List;
27
 
import java.util.ArrayList;
28
 
 
29
 
import junit.framework.TestCase;
30
 
 
31
 
import org.hibernate.dialect.function.AnsiTrimEmulationFunction;
32
 
 
33
 
/**
34
 
 * TODO : javadoc
35
 
 *
36
 
 * @author Steve Ebersole
37
 
 */
38
 
public class AnsiTrimEmulationFunctionTest extends TestCase {
39
 
        private static final String trimSource = "a.column";
40
 
 
41
 
        public void testBasicSqlServerProcessing() {
42
 
                AnsiTrimEmulationFunction function = new AnsiTrimEmulationFunction();
43
 
 
44
 
                performBasicSpaceTrimmingTests( function );
45
 
 
46
 
                final String expectedTrimPrep = "replace(replace(a.column,' ','${space}$'),'-',' ')";
47
 
                final String expectedPostTrimPrefix = "replace(replace(";
48
 
                final String expectedPostTrimSuffix = ",' ','-'),'${space}$',' ')";
49
 
 
50
 
                // -> trim(LEADING '-' FROM a.column)
51
 
                String rendered = function.render( argList( "LEADING", "'-'", "FROM", trimSource ), null );
52
 
                String expected = expectedPostTrimPrefix + "ltrim(" + expectedTrimPrep + ")" + expectedPostTrimSuffix;
53
 
                assertEquals( expected, rendered );
54
 
 
55
 
                // -> trim(TRAILING '-' FROM a.column)
56
 
                rendered = function.render( argList( "TRAILING", "'-'", "FROM", trimSource ), null );
57
 
                expected = expectedPostTrimPrefix + "rtrim(" + expectedTrimPrep + ")" + expectedPostTrimSuffix;
58
 
                assertEquals( expected, rendered );
59
 
 
60
 
                // -> trim(BOTH '-' FROM a.column)
61
 
                rendered = function.render( argList( "BOTH", "'-'", "FROM", trimSource ), null );
62
 
                expected = expectedPostTrimPrefix + "ltrim(rtrim(" + expectedTrimPrep + "))" + expectedPostTrimSuffix;
63
 
                assertEquals( expected, rendered );
64
 
 
65
 
                // -> trim('-' FROM a.column)
66
 
                rendered = function.render( argList( "'-'", "FROM", trimSource ), null );
67
 
                expected = expectedPostTrimPrefix + "ltrim(rtrim(" + expectedTrimPrep + "))" + expectedPostTrimSuffix;
68
 
                assertEquals( expected, rendered );
69
 
        }
70
 
 
71
 
        public void testBasicSybaseProcessing() {
72
 
                AnsiTrimEmulationFunction function = new AnsiTrimEmulationFunction(
73
 
                                AnsiTrimEmulationFunction.LTRIM,
74
 
                                AnsiTrimEmulationFunction.RTRIM,
75
 
                                "str_replace"
76
 
                );
77
 
 
78
 
                performBasicSpaceTrimmingTests( function );
79
 
 
80
 
                final String expectedTrimPrep = "str_replace(str_replace(a.column,' ','${space}$'),'-',' ')";
81
 
                final String expectedPostTrimPrefix = "str_replace(str_replace(";
82
 
                final String expectedPostTrimSuffix = ",' ','-'),'${space}$',' ')";
83
 
 
84
 
                // -> trim(LEADING '-' FROM a.column)
85
 
                String rendered = function.render( argList( "LEADING", "'-'", "FROM", trimSource ), null );
86
 
                String expected = expectedPostTrimPrefix + "ltrim(" + expectedTrimPrep + ")" + expectedPostTrimSuffix;
87
 
                assertEquals( expected, rendered );
88
 
 
89
 
                // -> trim(TRAILING '-' FROM a.column)
90
 
                rendered = function.render( argList( "TRAILING", "'-'", "FROM", trimSource ), null );
91
 
                expected = expectedPostTrimPrefix + "rtrim(" + expectedTrimPrep + ")" + expectedPostTrimSuffix;
92
 
                assertEquals( expected, rendered );
93
 
 
94
 
                // -> trim(BOTH '-' FROM a.column)
95
 
                rendered = function.render( argList( "BOTH", "'-'", "FROM", trimSource ), null );
96
 
                expected = expectedPostTrimPrefix + "ltrim(rtrim(" + expectedTrimPrep + "))" + expectedPostTrimSuffix;
97
 
                assertEquals( expected, rendered );
98
 
 
99
 
                // -> trim('-' FROM a.column)
100
 
                rendered = function.render( argList( "'-'", "FROM", trimSource ), null );
101
 
                expected = expectedPostTrimPrefix + "ltrim(rtrim(" + expectedTrimPrep + "))" + expectedPostTrimSuffix;
102
 
                assertEquals( expected, rendered );
103
 
        }
104
 
 
105
 
        private void performBasicSpaceTrimmingTests(AnsiTrimEmulationFunction function) {
106
 
                // -> trim(a.column)
107
 
                String rendered = function.render( argList( trimSource ), null );
108
 
                assertEquals( "ltrim(rtrim(a.column))", rendered );
109
 
 
110
 
                // -> trim(FROM a.column)
111
 
                rendered = function.render( argList( "FROM", trimSource ), null );
112
 
                assertEquals( "ltrim(rtrim(a.column))", rendered );
113
 
 
114
 
                // -> trim(BOTH FROM a.column)
115
 
                rendered = function.render( argList( "BOTH", "FROM", trimSource ), null );
116
 
                assertEquals( "ltrim(rtrim(a.column))", rendered );
117
 
 
118
 
                // -> trim(BOTH ' ' FROM a.column)
119
 
                rendered = function.render( argList( "BOTH", "' '", "FROM", trimSource ), null );
120
 
                assertEquals( "ltrim(rtrim(a.column))", rendered );
121
 
 
122
 
                // -> trim(LEADING FROM a.column)
123
 
                rendered = function.render( argList( "LEADING", "FROM", trimSource ), null );
124
 
                assertEquals( "ltrim(a.column)", rendered );
125
 
 
126
 
                // -> trim(LEADING ' ' FROM a.column)
127
 
                rendered = function.render( argList( "LEADING", "' '", "FROM", trimSource ), null );
128
 
                assertEquals( "ltrim(a.column)", rendered );
129
 
 
130
 
                // -> trim(TRAILING FROM a.column)
131
 
                rendered = function.render( argList( "TRAILING", "FROM", trimSource ), null );
132
 
                assertEquals( "rtrim(a.column)", rendered );
133
 
 
134
 
                // -> trim(TRAILING ' ' FROM a.column)
135
 
                rendered = function.render( argList( "TRAILING", "' '", "FROM", trimSource ), null );
136
 
                assertEquals( "rtrim(a.column)", rendered );
137
 
        }
138
 
 
139
 
        private List argList(String arg) {
140
 
                ArrayList args = new ArrayList();
141
 
                args.add( arg );
142
 
                return args;
143
 
        }
144
 
 
145
 
        private List argList(String arg1, String arg2) {
146
 
                ArrayList args = new ArrayList();
147
 
                args.add( arg1 );
148
 
                args.add( arg2 );
149
 
                return args;
150
 
        }
151
 
 
152
 
        private List argList(String arg1, String arg2, String arg3) {
153
 
                ArrayList args = new ArrayList();
154
 
                args.add( arg1 );
155
 
                args.add( arg2 );
156
 
                args.add( arg3 );
157
 
                return args;
158
 
        }
159
 
 
160
 
        private List argList(String arg1, String arg2, String arg3, String arg4) {
161
 
                ArrayList args = new ArrayList();
162
 
                args.add( arg1 );
163
 
                args.add( arg2 );
164
 
                args.add( arg3 );
165
 
                args.add( arg4 );
166
 
                return args;
167
 
        }
168
 
 
169
 
}