001: /*
002: * User: mrettig
003: * Date: Jun 28, 2002
004: * Time: 3:36:40 PM
005: */
006: package net.sourceforge.jaxor.tests;
007:
008: import junit.framework.TestCase;
009: import net.sourceforge.jaxor.mappers.*;
010: import net.sourceforge.jaxor.parser.Attribute;
011: import net.sourceforge.jaxor.parser.Jaxor;
012:
013: import java.sql.Timestamp;
014: import java.util.Properties;
015:
016: public class AttributeTest extends TestCase {
017:
018: private Attribute attribute;
019:
020: protected void setUp() throws Exception {
021: super .setUp();
022: attribute = new Attribute("ACCOUNT_CUSTODIAN_ID", Long.class
023: .getName(), false);
024: }
025:
026: public void testIsPrimitive() {
027: assertFalse(attribute.isPrimitive());
028: attribute.setType("long");
029: assertTrue(attribute.isPrimitive());
030: }
031:
032: public void testAlias() {
033: assertEquals("AccountCustodianId", attribute.getJavaName());
034: attribute.setAlias("AccountCustodian");
035: assertEquals("AccountCustodian", attribute.getJavaName());
036: }
037:
038: public void testConvertDatabaseNameUppercase() {
039: assertEquals("AccountCustodianId", attribute.getJavaName());
040: }
041:
042: public void testConvertDatabaseNameLowercase() {
043: assertEquals("AccountCustodianId", attribute.getJavaName());
044: }
045:
046: public void testConvertDatabaseNameOneWord() {
047: attribute.setName("account");
048: assertEquals("Account", attribute.getJavaName());
049: }
050:
051: public void testConvertDatabaseNameOneCharacter() {
052: attribute.setName("a");
053: assertEquals("A", attribute.getJavaName());
054: }
055:
056: public void testCamelCase() {
057: attribute.setName("bdsDataDoo");
058: assertEquals("BdsDataDoo", attribute.getJavaName());
059: }
060:
061: public void testGetMapper() {
062: Properties mapperRegistry = new Properties();
063: mapperRegistry.put("java.lang.Long", "LongMapper");
064: Jaxor jaxor = new Jaxor();
065: jaxor.setMapperProps(mapperRegistry);
066: assertEquals("LongMapper", attribute.getMapperName(jaxor));
067: }
068:
069: public void testAliasToStringNull() {
070: attribute.setAlias(null);
071: assertEquals("\"AccountCustodianId\"", attribute
072: .getPropertyAsString());
073: }
074:
075: public void testAliasToStringWithValue() {
076: attribute.setAlias("Alias");
077: assertEquals("\"Alias\"", attribute.getPropertyAsString());
078: }
079:
080: public void testTimestampInsert() {
081: Attribute att = new Attribute();
082: att.setType("timestamp-insert");
083: assertEquals(Timestamp.class.getName(), att.getType());
084: assertEquals(TimestampInsertFieldAdapter.class.getName(), att
085: .getFieldAdapter());
086: assertFalse(att.isNullable());
087: }
088:
089: public void testTimestampUpdate() {
090: Attribute att = new Attribute();
091: att.setType("timestamp-UPDATE");
092: assertEquals(Timestamp.class.getName(), att.getType());
093: assertEquals(TimestampUpdateFieldAdapter.class.getName(), att
094: .getFieldAdapter());
095: assertTrue(att.isNullable());
096: }
097:
098: public void testTimestamp() {
099: Attribute att = new Attribute();
100: att.setType("timestamp");
101: assertEquals(Timestamp.class.getName(), att.getType());
102: assertEquals(TimestampFieldAdapter.class.getName(), att
103: .getFieldAdapter());
104: assertFalse(att.isNullable());
105: }
106:
107: public void testUserInsert() {
108: Attribute att = new Attribute();
109: att.setType("user-insert");
110: assertEquals(String.class.getName(), att.getType());
111: assertEquals(UserInsertFieldAdapter.class.getName(), att
112: .getFieldAdapter());
113: assertFalse(att.isNullable());
114: }
115:
116: public void testUserUpdate() {
117: Attribute att = new Attribute();
118: att.setType("user-UPDATE");
119: assertEquals(String.class.getName(), att.getType());
120: assertEquals(UserUpdateFieldAdapter.class.getName(), att
121: .getFieldAdapter());
122: assertTrue(att.isNullable());
123: }
124:
125: public void testUser() {
126: Attribute att = new Attribute();
127: att.setType("user");
128: assertEquals(String.class.getName(), att.getType());
129: assertEquals(UserFieldAdapter.class.getName(), att
130: .getFieldAdapter());
131: assertFalse(att.isNullable());
132: }
133:
134: public void testVersion() {
135: Attribute att = new Attribute();
136: att.setType("Version");
137: assertEquals(Long.class.getName(), att.getType());
138: assertEquals(LongVersionFieldAdapter.class.getName(), att
139: .getFieldAdapter());
140: assertFalse(att.isNullable());
141: }
142: }
|