1   /**
2    * 
3    */
4   package org.melati.poem.test;
5   
6   import java.util.Enumeration;
7   import java.util.NoSuchElementException;
8   
9   import org.melati.poem.ResultSetEnumeration;
10  import org.melati.poem.RowDisappearedPoemException;
11  import org.melati.poem.User;
12  
13  /**
14   * @author timp
15   * @since 22 Jan 2007
16   *
17   */
18  public class ResultSetEnumerationTest extends PoemTestCase {
19  
20    /**
21     * Constructor.
22     * @param name
23     */
24    public ResultSetEnumerationTest(String name) {
25      super(name);
26    }
27  
28    /**
29     * {@inheritDoc}
30     * @see org.melati.poem.test.PoemTestCase#setUp()
31     */
32    protected void setUp() throws Exception {
33      super.setUp();
34    }
35  
36    /**
37     * {@inheritDoc}
38     * @see org.melati.poem.test.PoemTestCase#tearDown()
39     */
40    protected void tearDown() throws Exception {
41      super.tearDown();
42    }
43  
44    /**
45     * Test method for {@link org.melati.poem.ResultSetEnumeration#
46     *    ResultSetEnumeration(java.sql.ResultSet)}.
47     */
48    public void testResultSetEnumeration() {
49    }
50  
51    /**
52     * Test method for {@link org.melati.poem.ResultSetEnumeration#hasMoreElements()}.
53     */
54    public void testHasMoreElements() {
55      Enumeration rse = getDb().getUserTable().getLoginColumn().selectionWhereEq("_guest_");
56      while (rse.hasMoreElements()) {
57        rse.nextElement();
58      }
59    }
60  
61    /**
62     * Test of deviant useage.
63     * Test method for {@link org.melati.poem.ResultSetEnumeration#nextElement()}.
64     */
65    public void testNextElement() {
66      Enumeration rse = getDb().getUserTable().getLoginColumn().selectionWhereEq("_guest_");
67      rse.nextElement();
68      try { 
69        rse.nextElement();
70        fail("Should have blown up");
71      } catch (NoSuchElementException e) { 
72        e = null;
73      }
74      
75      // FIXME There should be a way to provoke RowDisappearedPoemException
76      User u = new User("tester","tester","tester");
77      getDb().getUserTable().create(u); 
78      Enumeration rse2 = getDb().getUserTable().troidSelection(null,null,false);
79      u.delete();
80      try { 
81        while(rse2.hasMoreElements()) { 
82          rse2.nextElement();
83        }
84        //fail("Should have blown up");
85      } catch (RowDisappearedPoemException e) {
86        e = null;
87      }
88    }
89  
90    /**
91     * Test method for {@link org.melati.poem.ResultSetEnumeration#skip()}.
92     */
93    public void testSkip() {
94      ResultSetEnumeration rse = (ResultSetEnumeration)getDb().getUserTable().getLoginColumn().selectionWhereEq("_guest_");
95      rse.skip();
96      try { 
97        rse.nextElement();
98        fail("Should have blown up");
99      } catch (NoSuchElementException e) { 
100       e = null;
101     }    
102     rse = (ResultSetEnumeration)getDb().getUserTable().getLoginColumn().selectionWhereEq("_guest_");
103     rse.skip();
104     try { 
105       rse.skip();
106       fail("Should have blown up");
107     } catch (NoSuchElementException e) { 
108       e = null;
109     }    
110   }
111 
112 }