KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > clients > entity > A_PKDate


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * 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,v 1.2 2004/03/19 11:57:15 benoitf Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.clients.entity;
27
28 import java.text.DateFormat JavaDoc;
29 import java.text.SimpleDateFormat JavaDoc;
30 import java.util.Calendar JavaDoc;
31 import java.util.Date JavaDoc;
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 JavaDoc 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
63     /**
64      * Creation of a bean with PK that maps a single field java.util.date
65      */

66     public void testPkDateCreate() throws Exception JavaDoc {
67     Date JavaDoc d = null;
68     Calendar JavaDoc date = Calendar.getInstance();
69     date.set(2003,02,25);
70     d = date.getTime();
71     DateFormat JavaDoc df = new SimpleDateFormat JavaDoc("MM/dd/yyyy");
72     BDate bd = getBDateHome().create(100,200, d);
73     Assert.assertEquals("Date ", df.format(d) , df.format(bd.getField3()));
74     
75     // cleaning
76
bd.remove();
77     
78     }
79
80     /**
81      * findByPrimaryKey of a bean with PK that maps a single field java.util.date
82      */

83     public void testPkDateFindByPrimaryKey() throws Exception JavaDoc {
84     Date JavaDoc d = null;
85     Calendar JavaDoc date = Calendar.getInstance();
86     date.set(2003,02,26);
87     DateFormat JavaDoc df = new SimpleDateFormat JavaDoc("MM/dd/yyyy");
88     d = date.getTime();
89     BDate bd1 = getBDateHome().create(0,1, d);
90     BDate bd2 = getBDateHome().findByPrimaryKey(d);
91     Assert.assertEquals("Date", df.format(d) , df.format(bd2.getField3()));
92     // cleaning
93
bd1.remove();
94     }
95
96
97 }
98
Popular Tags