001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: A_EtypeOsqldate.java 6739 2005-05-11 15:29:07Z ashah $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.jtests.clients.entity;
027:
028: import java.sql.Date;
029: import java.util.Collection;
030: import java.util.Iterator;
031: import javax.ejb.FinderException;
032:
033: import org.objectweb.jonas.jtests.beans.etype.osqldate.Osqldate;
034: import org.objectweb.jonas.jtests.beans.etype.osqldate.OsqldateHome;
035: import org.objectweb.jonas.jtests.util.JTestCase;
036:
037: /**
038: * This set of test are common to CMP version 1 and CMP version 2
039: * These are tests about java.lang.Utildate field of entity bean .
040: * Beans used: etype/osqldate
041: * @author Helene Joanin
042: */
043: public abstract class A_EtypeOsqldate extends JTestCase {
044:
045: public A_EtypeOsqldate(String name) {
046: super (name);
047: }
048:
049: protected void setUp() {
050: super .setUp();
051: useBeans("osqldate", true);
052: }
053:
054: /**
055: * Return OsqldateHome, that can be either CMP version 1 or CMP version 2 bean.
056: */
057: abstract public OsqldateHome getHome();
058:
059: /**
060: * findByPrimaryKey() test
061: */
062: public void testSqlDateFindByPk() throws Exception {
063: String pk = "pk1";
064: Osqldate bean = getHome().findByPrimaryKey(pk);
065: assertEquals("Pk", pk, bean.getPk());
066: }
067:
068: /**
069: * findByF1() test
070: */
071: public void testSqlDateFindByF1() throws Exception {
072: Date d5 = Date.valueOf("1970-01-05");
073: Collection cBeans = getHome().findByF1(d5);
074: int nb = 0;
075: Iterator iBeans = cBeans.iterator();
076: while (iBeans.hasNext()) {
077: Osqldate bean = (Osqldate) javax.rmi.PortableRemoteObject
078: .narrow(iBeans.next(), Osqldate.class);
079: Date f1 = bean.getF1();
080: assertTrue("F1", d5.equals(f1));
081: nb++;
082: }
083: assertEquals("Beans number: ", 2, nb);
084: }
085:
086: /**
087: * getF1() test
088: */
089: public void testSqlDateGetF1() throws Exception {
090: String pk = "pk2";
091: Osqldate bean = getHome().findByPrimaryKey(pk);
092: Date d2 = Date.valueOf("1970-01-02");
093: Date f1 = bean.getF1();
094: assertEquals("Pk", pk, bean.getPk());
095: assertEquals("F1", d2, f1);
096: }
097:
098: /**
099: * getF1Null() test: f1 with a 'null' value
100: */
101: public void testSqlDateGetF1Null() throws Exception {
102: String pk = "pknull";
103: Osqldate bean = getHome().findByPrimaryKey(pk);
104: Date f1 = bean.getF1();
105: assertEquals("Pk", pk, bean.getPk());
106: assertNull("F1 not null", f1);
107: }
108:
109: /**
110: * setF1() test
111: */
112: public void testSqlDateSetF1() throws Exception {
113: String pk = "pk3";
114: Osqldate bean = getHome().findByPrimaryKey(pk);
115: Date f1 = Date.valueOf("1970-01-30");
116: bean.setF1(f1);
117: assertEquals("Pk", pk, bean.getPk());
118: assertEquals("F1", f1, bean.getF1());
119: }
120:
121: /**
122: * setF1Null() test: f1 with a 'null' value
123: */
124: public void testSqlDateSetF1Null() throws Exception {
125: String pk = "pkchangenull";
126: Osqldate bean = getHome().findByPrimaryKey(pk);
127: bean.setF1(null);
128: assertEquals("Pk", pk, bean.getPk());
129: assertNull("F1", bean.getF1());
130: }
131:
132: /**
133: * create() test
134: */
135: public void testSqlDateCreate() throws Exception {
136: String pk = "pkcreated";
137: Date f1 = Date.valueOf("1975-05-13");
138: Osqldate bean = getHome().create(pk, f1);
139: assertEquals("Pk", pk, bean.getPk());
140: assertEquals("F1", f1, bean.getF1());
141: bean = getHome().findByPrimaryKey(pk);
142: // cleaning
143: bean.remove();
144: }
145:
146: /**
147: * remove() test
148: */
149: public void testSqlDateRemove() throws Exception {
150: String pk = "pktoremove";
151: Osqldate bean = getHome().findByPrimaryKey(pk);
152: Date f1 = bean.getF1();
153: bean.remove();
154: try {
155: getHome().findByPrimaryKey(pk);
156: fail("not removed");
157: } catch (FinderException e) {
158: // ok
159: }
160: // cleaning
161: getHome().create(pk, f1);
162: }
163:
164: }
|