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