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: F_EtypeOsqlts4pkEC2.java 5006 2004-06-25 05:29:51Z joaninh $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.jtests.clients.entity;
025:
026: import java.sql.Timestamp;
027: import javax.naming.NamingException;
028: import javax.rmi.PortableRemoteObject;
029:
030: import junit.framework.Test;
031: import junit.framework.TestSuite;
032:
033: import org.objectweb.jonas.jtests.beans.etype.osqlts4pk.Osqlts4pk;
034: import org.objectweb.jonas.jtests.beans.etype.osqlts4pk.Osqlts4pkHome;
035: import org.objectweb.jonas.jtests.beans.etype.osqlts4pk.Pk;
036: import org.objectweb.jonas.jtests.util.JTestCase;
037:
038: /**
039: * This is a test suite about java.sql.Timestamp field of entity bean CMP
040: * version 2. Beans used: etype/osqlts4pk
041: * @author Helene Joanin
042: */
043:
044: public class F_EtypeOsqlts4pkEC2 extends JTestCase {
045:
046: private static String BEAN_HOME = "EtypeOsqlts4pkEC2Home";
047:
048: protected static Osqlts4pkHome home = null;
049:
050: private static final long ONE_HOUR = 60L * 60L * 1000L;
051: private static final long ONE_DAY = 24L * ONE_HOUR;
052:
053: public F_EtypeOsqlts4pkEC2(String name) {
054: super (name);
055: }
056:
057: protected void setUp() {
058: super .setUp();
059: useBeans("osqlts4pk", false);
060: }
061:
062: public Osqlts4pkHome getHome() {
063: if (home == null) {
064: try {
065: home = (Osqlts4pkHome) PortableRemoteObject.narrow(ictx
066: .lookup(BEAN_HOME), Osqlts4pkHome.class);
067: } catch (NamingException e) {
068: fail("Cannot get bean home: " + BEAN_HOME);
069: }
070: // init here tables if CMP2
071: try {
072: home.create(new Timestamp(ONE_DAY), "pk1");
073: home.create(new Timestamp(2 * ONE_DAY), "pk2");
074: home.create(new Timestamp(3 * ONE_DAY), "pk3");
075: home.create(new Timestamp(4 * ONE_DAY), "pk4");
076: home.create(new Timestamp(5 * ONE_DAY), "pk5");
077: home.create(new Timestamp(12 * ONE_DAY), "pktoremove");
078: } catch (Exception i) {
079: }
080: }
081: return home;
082: }
083:
084: /**
085: * findByPrimaryKey() test
086: */
087: public void testSqlTs4pkFindByPk() throws Exception {
088: Pk pk = new Pk(new Timestamp(ONE_DAY));
089: Osqlts4pk bean = getHome().findByPrimaryKey(pk);
090: assertEquals("Pk", pk.id, bean.getId());
091: }
092:
093: /**
094: * findByDate() test
095: */
096: public void testSqlTs4pkFindDate() throws Exception {
097: Pk pk = new Pk(new Timestamp(5 * ONE_DAY));
098: Osqlts4pk bean = getHome().findByPrimaryKey(pk);
099: assertEquals("Pk", pk.id, bean.getId());
100: }
101:
102: /**
103: * create() test
104: */
105: public void testSqlTs4pkCreate() throws Exception {
106: Timestamp pk = new Timestamp(1959 * ONE_DAY);
107: String f1 = "pkcreated";
108: Osqlts4pk bean = getHome().create(pk, f1);
109: assertEquals("Pk", pk, bean.getId());
110: assertEquals("F1", f1, bean.getF1());
111: // cleaning
112: bean.remove();
113: }
114:
115: public static Test suite() {
116: return new TestSuite(F_EtypeOsqlts4pkEC2.class);
117: }
118:
119: public static void main(String args[]) {
120: String testtorun = null;
121: // Get args
122: for (int argn = 0; argn < args.length; argn++) {
123: String s_arg = args[argn];
124: Integer i_arg;
125: if (s_arg.equals("-n")) {
126: testtorun = args[++argn];
127: }
128: }
129: if (testtorun == null) {
130: junit.textui.TestRunner.run(suite());
131: } else {
132: junit.textui.TestRunner.run(new F_EtypeOsqlts4pkEC2(
133: testtorun));
134: }
135: }
136: }
|