01: /*
02: * JOnAS: Java(TM) Open Application Server
03: * Copyright (C) 1999 Bull S.A.
04: * Contact: jonas-team@objectweb.org
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2.1 of the License, or any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19: * USA
20: *
21: * --------------------------------------------------------------------------
22: * $Id: A_PKDate.java 4406 2004-03-19 11:57:20Z benoitf $
23: * --------------------------------------------------------------------------
24: */
25:
26: package org.objectweb.jonas.jtests.clients.entity;
27:
28: import java.text.DateFormat;
29: import java.text.SimpleDateFormat;
30: import java.util.Calendar;
31: import java.util.Date;
32:
33: import junit.framework.Assert;
34:
35: import org.objectweb.jonas.jtests.beans.ebasic.BDate;
36: import org.objectweb.jonas.jtests.beans.ebasic.BDateHome;
37: import org.objectweb.jonas.jtests.util.JTestCase;
38:
39: /**
40: * This set of test are all tests common to CMP version 1 and CMP version 2
41: * Here we test the possibility to have a primary key java.util.date
42: * Beans used: ebasic/BDate
43: * @author Philippe Coq (jonas team)
44: */
45: public abstract class A_PKDate extends JTestCase {
46:
47: public A_PKDate(String name) {
48: super (name);
49: }
50:
51: protected void setUp() {
52: super .setUp();
53: useBeans("ebasic", true);
54: }
55:
56: /**
57: * Return BDateHome, that can be either CMP version 1 or CMP version 2 bean.
58: */
59: abstract public BDateHome getBDateHome();
60:
61: /**
62: * Creation of a bean with PK that maps a single field java.util.date
63: */
64: public void testPkDateCreate() throws Exception {
65: Date d = null;
66: Calendar date = Calendar.getInstance();
67: date.set(2003, 02, 25);
68: d = date.getTime();
69: DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
70: BDate bd = getBDateHome().create(100, 200, d);
71: Assert.assertEquals("Date ", df.format(d), df.format(bd
72: .getField3()));
73:
74: // cleaning
75: bd.remove();
76:
77: }
78:
79: /**
80: * findByPrimaryKey of a bean with PK that maps a single field java.util.date
81: */
82: public void testPkDateFindByPrimaryKey() throws Exception {
83: Date d = null;
84: Calendar date = Calendar.getInstance();
85: date.set(2003, 02, 26);
86: DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
87: d = date.getTime();
88: BDate bd1 = getBDateHome().create(0, 1, d);
89: BDate bd2 = getBDateHome().findByPrimaryKey(d);
90: Assert.assertEquals("Date", df.format(d), df.format(bd2
91: .getField3()));
92: // cleaning
93: bd1.remove();
94: }
95:
96: }
|