View Javadoc
1   /**
2    * 
3    */
4   package org.melati.poem.test;
5   
6   import java.sql.Types;
7   import java.util.Enumeration;
8   
9   import org.melati.poem.DisplayLevelPoemType;
10  import org.melati.poem.LongPoemType;
11  import org.melati.poem.TroidPoemType;
12  import org.melati.poem.ParsingPoemException;
13  import org.melati.poem.SQLPoemType;
14  
15  /**
16   * @author timp
17   * @since 21 Dec 2006
18   *
19   */
20  public class NotNullableLongPoemTypeTest extends SQLPoemTypeSpec<Long> {
21  
22    /**
23     * 
24     */
25    public NotNullableLongPoemTypeTest() {
26    }
27  
28    public NotNullableLongPoemTypeTest(String name) {
29      super(name);
30    }
31  
32    void setObjectUnderTest() {
33      it = new LongPoemType(false);
34    }
35    
36    /**
37     * Test method for {@link org.melati.poem.SQLType#quotedRaw(java.lang.Object)}.
38     */
39    public void testQuotedRaw() {
40      assertEquals(((SQLPoemType<Long>)it).sqlDefaultValue(getDb().getDbms()), 
41          ((SQLPoemType<Long>)it).quotedRaw(((SQLPoemType<Long>)it).rawOfString(
42                  ((SQLPoemType<Long>)it).sqlDefaultValue(getDb().getDbms()))));
43  
44    }
45  
46    public void testPossibleRaws() {
47      super.testPossibleRaws();
48      Enumeration<Long> them = it.possibleRaws();
49      assertNull(them);
50      ((LongPoemType)it).setRawRange(new Long(Long.MAX_VALUE -5), (Long)null);
51      them = it.possibleRaws();
52      int count = 0;
53      while(them.hasMoreElements()) {
54        them.nextElement();
55        count++;
56      }
57      if (it.getNullable())
58        assertEquals(6,count);
59      else 
60        assertEquals(5,count);
61      ((LongPoemType)it).setRawRange(new Long(2L), new Long(5L));
62      them = it.possibleRaws();
63      count = 0;
64      while(them.hasMoreElements()) {
65        them.nextElement();
66        count++;
67      }
68      if (it.getNullable())
69        assertEquals(4,count);
70      else
71        assertEquals(3,count);
72  
73    }
74  
75    public void testRawOfString() {
76      super.testRawOfString();
77      try{
78        it.rawOfString("kk");
79        fail("Should have blown up");
80      } catch (ParsingPoemException e) {
81        e = null;
82      }
83      
84    }
85    
86    /**
87     * Test method for
88     * {@link org.melati.poem.PoemType#canRepresent(org.melati.poem.PoemType)}.
89     */
90    public void testCanRepresent() {
91      DisplayLevelPoemType dl = new DisplayLevelPoemType();
92      assertNotNull(it.canRepresent(dl)); // We can represent an Integer
93      assertNull(dl.canRepresent(it));
94  
95    }
96  
97    
98    /**
99     * Longs can represent Integers and troids.
100    */
101   public void testCanRepresentTroid() { 
102     assertNotNull(it.canRepresent(TroidPoemType.it));
103   }
104   /**
105    * Test full constructor.
106    */
107   public void testFullConstructor() {
108     LongPoemType it2 = new MyLongPoemType(it.getNullable());
109     assertEquals(it.getNullable(),it2.getNullable());
110   }
111   class MyLongPoemType extends LongPoemType {
112 
113     public MyLongPoemType(boolean nullable) {
114       super(Types.BIGINT, "INT8", nullable);
115     }
116     
117   }
118 
119 }