1   /*
2    * $Header: /cvsroot/jdbforms/dbforms/tests/test/org/dbforms/util/TestParseUtil.java,v 1.6 2004/10/17 07:02:30 hkollmann Exp $
3    * $Revision: 1.6 $
4    * $Date: 2004/10/17 07:02:30 $
5    *
6    * DbForms - a Rapid Application Development Framework
7    * Copyright (C) 2001 Joachim Peer <joepeer@excite.com>
8    *
9    * This library is free software; you can redistribute it and/or
10   * modify it under the terms of the GNU Lesser General Public
11   * License as published by the Free Software Foundation; either
12   * version 2.1 of the License, or (at your option) any later version.
13   *
14   * This library is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17   * Lesser General Public License for more details.
18   *
19   * You should have received a copy of the GNU Lesser General Public
20   * License along with this library; if not, write to the Free Software
21   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
22   */
23  
24  package org.dbforms.util;
25  
26  import java.util.*;
27  
28  
29  
30  /***
31   *  Description of the Class
32   *
33   * @author     epugh
34   * @created    May 3, 2002
35   */
36  public class TestParseUtil extends AbstractTestCase {
37     /***
38      * DOCUMENT ME!
39      *
40      * @throws Exception DOCUMENT ME!
41      */
42     public void testGetEmbeddedString() throws Exception {
43        String s = "ac_update_3_12";
44  
45        assertTrue(StringUtil.getEmbeddedString(s, 0, '_').equals("ac"));
46        assertTrue(StringUtil.getEmbeddedString(s, 1, '_').equals("update"));
47        assertTrue(StringUtil.getEmbeddedString(s, 2, '_').equals("3"));
48        assertTrue(StringUtil.getEmbeddedString(s, 3, '_').equals("12"));
49  
50        /*
51        try {
52          String result = ParseUtil.getEmbeddedString(s, 4, '_');
53         assertTrue("This should not be hit! result:" + result,result.equals("dodo"));
54         fail("Should not get here, should have exception");
55        }
56        catch (Exception e){}
57        */
58     }
59  
60  
61     /***
62      * DOCUMENT ME!
63      *
64      * @throws Exception DOCUMENT ME!
65      */
66     public void testGetEmbeddedStringAsInteger() throws Exception {
67        String s = "ac_update_3_12";
68  
69        assertTrue(StringUtil.getEmbeddedStringAsInteger(s, 2, '_') == 3);
70        assertTrue(StringUtil.getEmbeddedStringAsInteger(s, 3, '_') == 12);
71  
72        try {
73           int i = StringUtil.getEmbeddedStringAsInteger(s, 4, '_');
74           assertTrue("This should not be hit! result:" + i, i == 999);
75           fail("Should not get here, should have exception");
76        } catch (Exception e) {
77           ;
78        }
79     }
80  
81  
82     /***
83      * DOCUMENT ME!
84      *
85      * @throws Exception DOCUMENT ME!
86      */
87     public void testGetEmbeddedStringWithoutDots() throws Exception {
88        String s = "ac_update_3_12";
89  
90        assertTrue(StringUtil.getEmbeddedStringWithoutDots(s, 0, '_').equals("ac"));
91        assertTrue(StringUtil.getEmbeddedStringWithoutDots(s, 1, '_').equals("update"));
92        assertTrue(StringUtil.getEmbeddedStringWithoutDots(s, 2, '_').equals("3"));
93        assertTrue(StringUtil.getEmbeddedStringWithoutDots(s, 3, '_').equals("12"));
94  
95        /*
96        try {
97          String result = ParseUtil.getEmbeddedStringWithoutDots(s, 4, '_');
98         assertTrue("This should not be hit!  Should throw a runtime exception. result:" + result,result.equals("dodo"));
99         fail("Should not get here, should have exception");
100       }
101       catch (Exception e){}
102       */
103    }
104 
105 
106    /***
107     * DOCUMENT ME!
108     *
109     * @throws Exception DOCUMENT ME!
110     */
111    public void testSplitString() throws Exception {
112       Vector v = StringUtil.splitString("hello,there,this,is,delimited", ",");
113       assertTrue("Vector must have have 5 elements", v.size() == 5);
114       assertTrue("check elements", v.get(0).toString().equals("hello"));
115       assertTrue("check elements", v.get(1).toString().equals("there"));
116       assertTrue("check elements", v.get(2).toString().equals("this"));
117       assertTrue("check elements", v.get(3).toString().equals("is"));
118       assertTrue("check elements", v.get(4).toString().equals("delimited"));
119    }
120 }