1   /**
2    * 
3    */
4   package org.melati.poem.test;
5   
6   import java.util.Enumeration;
7   
8   import org.melati.poem.BooleanPoemType;
9   import org.melati.poem.ParsingPoemException;
10  import org.melati.poem.SQLPoemType;
11  
12  /**
13   * @author timp
14   * @since 21 Dec 2006
15   *
16   */
17  public class NotNullableBooleanPoemTypeTest extends SQLPoemTypeSpec {
18  
19    /**
20     * 
21     */
22    public NotNullableBooleanPoemTypeTest() {
23    }
24  
25    /**
26     * @param name
27     */
28    public NotNullableBooleanPoemTypeTest(String name) {
29      super(name);
30    }
31  
32    /**
33     * {@inheritDoc}
34     * @see org.melati.poem.test.SQLPoemTypeSpec#setObjectUnderTest()
35     */
36    void setObjectUnderTest() {
37      it = new BooleanPoemType(false);
38    }
39  
40    /**
41     * Test method for
42     * {@link org.melati.poem.PoemType#rawOfString(java.lang.String)}.
43     */
44    public void testRawOfString() {
45      super.testRawOfString();
46      assertEquals(Boolean.TRUE,it.rawOfString("t")); 
47      assertEquals(Boolean.TRUE,it.rawOfString("T")); 
48      assertEquals(Boolean.TRUE,it.rawOfString("y")); 
49      assertEquals(Boolean.TRUE,it.rawOfString("Y")); 
50      assertEquals(Boolean.TRUE,it.rawOfString("1")); 
51      assertEquals(Boolean.TRUE,it.rawOfString("true")); 
52      assertEquals(Boolean.TRUE,it.rawOfString("yes")); 
53      assertEquals(Boolean.FALSE,it.rawOfString("f")); 
54      assertEquals(Boolean.FALSE,it.rawOfString("F")); 
55      assertEquals(Boolean.FALSE,it.rawOfString("n")); 
56      assertEquals(Boolean.FALSE,it.rawOfString("N")); 
57      assertEquals(Boolean.FALSE,it.rawOfString("0")); 
58      assertEquals(Boolean.FALSE,it.rawOfString("false")); 
59      assertEquals(Boolean.FALSE,it.rawOfString("no")); 
60      try{
61        it.rawOfString("9");
62        fail("Should have blown up");
63      } catch (ParsingPoemException e) {
64        e = null;
65      }
66      try{
67        it.rawOfString("frue");
68        fail("Should have blown up");
69      } catch (ParsingPoemException e) {
70        e = null;
71      }
72    }
73  
74    /**
75     * Test method for {@link org.melati.poem.SQLType#quotedRaw(java.lang.Object)}.
76     * FIXME - this should probably be '0' not false.
77     */
78    public void testQuotedRaw() {
79      assertEquals("false", 
80          ((SQLPoemType)it).quotedRaw(((SQLPoemType)it).rawOfString(
81                  ((SQLPoemType)it).sqlDefaultValue(getDb().getDbms()))));
82  
83    }
84  
85    public void testPossibleRaws() {
86      super.testPossibleRaws();
87      Enumeration them = it.possibleRaws();
88      int counter = 0;
89      while(them.hasMoreElements()) {
90        them.nextElement();
91        counter++;
92      }
93      if (it.getNullable())
94        assertEquals(3,counter);
95      else
96        assertEquals(2,counter);
97    }
98  
99    public void testGetRaw() {
100     super.testGetRaw();
101     Boolean nullable = getDb().getUserTable().getNameColumn().getColumnInfo().getNullable();
102     assertEquals(Boolean.FALSE, nullable);
103   }
104 
105   public void testSetRaw() {
106     super.testSetRaw();
107     Boolean nullable = getDb().getUserTable().getNameColumn().getColumnInfo().getNullable();
108     assertEquals(Boolean.FALSE, nullable);
109     getDb().getUserTable().getNameColumn().getColumnInfo().setNullable(Boolean.TRUE);
110     nullable = getDb().getUserTable().getNameColumn().getColumnInfo().getNullable();
111     assertEquals(Boolean.TRUE, nullable);
112     getDb().getUserTable().getNameColumn().getColumnInfo().setNullable(Boolean.FALSE);
113     nullable = getDb().getUserTable().getNameColumn().getColumnInfo().getNullable();
114     assertEquals(Boolean.FALSE, nullable);
115     nullable = getDb().getUserTable().getNameColumn().getColumnInfo().getNullable();
116     assertEquals(Boolean.FALSE, nullable);
117   }
118   
119   
120 
121 
122 }