root/trunk/test/unit/dbnp/query/SearchTests.groovy @ 1473

Revision 1473, 2.5 KB (checked in by s.h.sikkema@…, 3 years ago)

Fixed tests and removed obsolete ones so grails test-app works with all tests passed

  • Property svn:keywords set to Rev Author Date
Line 
1package dbnp.query
2
3import grails.test.*
4import org.dbnp.gdt.TemplateFieldType
5import org.dbnp.gdt.RelTime
6
7/**
8 * SearchTests Test
9 *
10 * Description of my test
11 *
12 * @author  your email (+name?)
13 * @since       2010mmdd
14 * @package     ???
15 *
16 * Revision information:
17 * $Rev$
18 * $Author$
19 * $Date$
20 */
21class SearchTests extends GrailsUnitTestCase {
22    protected void setUp() {
23        super.setUp()
24                mockLogging( Search );
25    }
26
27    protected void tearDown() {
28        super.tearDown()
29    }
30
31    void testPrepare() {
32                // Test prepare method for dates
33                Date d = Date.parse( "yyyy-MM-dd", "1982-10-21" );
34                assert !d.equals( Search.prepare( "21-10-1982", TemplateFieldType.DATE ) )
35                assert !d.equals( Search.prepare( "21-10-82", TemplateFieldType.DATE ) )
36                assert d.equals( Search.prepare( "1982-10-21 00:00:00", TemplateFieldType.DATE ) )
37                assert d.equals( Search.prepare( "1982-10-21", TemplateFieldType.DATE ) )
38               
39                // Test prepare method for RelTime
40                assertEquals new RelTime( 0 ), Search.prepare( "", TemplateFieldType.RELTIME )
41                assertEquals new RelTime( 3600 ), Search.prepare( "1h", TemplateFieldType.RELTIME )
42                assertEquals new RelTime( 3600 ), Search.prepare( "60m", TemplateFieldType.RELTIME )
43                assertEquals new RelTime( 3600 ), Search.prepare( "3600", TemplateFieldType.RELTIME )
44                assertEquals "abc", Search.prepare( "abc", TemplateFieldType.RELTIME )
45               
46                // Test prepare method for Double
47                assertEquals new Double( 100.1 ), Search.prepare( "100.1", TemplateFieldType.DOUBLE )
48                assertEquals new Double( 0.0 ), Search.prepare( "0", TemplateFieldType.DOUBLE )
49                assertEquals new Double( 100.0 ), Search.prepare( "100", TemplateFieldType.DOUBLE )
50                assertEquals new Double( -100.1 ), Search.prepare( "-100.1", TemplateFieldType.DOUBLE )
51               
52                // Test prepare method for Long
53                assertEquals new Long( 100 ), Search.prepare( "100", TemplateFieldType.LONG )
54                assertEquals new Long( 0 ), Search.prepare( "0", TemplateFieldType.LONG )
55                assertEquals new Long( -100 ), Search.prepare( "-100", TemplateFieldType.LONG )
56                assertEquals "3.8", Search.prepare( "3.8", TemplateFieldType.LONG )     // Can't be parsed into long
57                assertEquals "4.2", Search.prepare( "4.2", TemplateFieldType.LONG )     // Can't be parsed into long
58               
59                // Test prepare method for Boolean
60                assertEquals Boolean.TRUE, Search.prepare( "true", TemplateFieldType.BOOLEAN )
61                assertEquals Boolean.FALSE, Search.prepare( "false", TemplateFieldType.BOOLEAN )
62                assertEquals Boolean.FALSE, Search.prepare( "", TemplateFieldType.BOOLEAN )
63                assertEquals Boolean.FALSE, Search.prepare( "test", TemplateFieldType.BOOLEAN )
64    }
65
66}
Note: See TracBrowser for help on using the browser.