/*
 * JOnAS: Java(TM) Open Application Server
 * Copyright (C) 1999 Bull S.A.
 * Contact: jonas-team@objectweb.org
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 *
 * --------------------------------------------------------------------------
 * $Id$
 * --------------------------------------------------------------------------
 */

package org.objectweb.jonas.jtests.clients.entity;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import junit.framework.Assert;

import org.objectweb.jonas.jtests.beans.ebasic.BDate;
import org.objectweb.jonas.jtests.beans.ebasic.BDateHome;
import org.objectweb.jonas.jtests.util.JTestCase;

/**
 * This set of test are all tests common to CMP version 1 and CMP version 2
 * Here we test the possibility to have a primary key java.util.date
 * Beans used: ebasic/BDate
 * @author Philippe Coq (jonas team)
 */
public abstract class A_PKDate extends JTestCase {

    public A_PKDate(String name) {
	super(name);
    }

    protected void setUp() {
	super.setUp();
	useBeans("ebasic", true);
    }

    /**
     * Return BDateHome, that can be either CMP version 1 or CMP version 2 bean.
     */
    abstract public BDateHome getBDateHome();



    /**
     * Creation of a bean with PK that maps a single field java.util.date
     */
    public void testPkDateCreate() throws Exception {
	Date d = null;
	Calendar date = Calendar.getInstance();
	date.set(2003,02,25);
	d = date.getTime();
	DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
	BDate bd = getBDateHome().create(100,200, d);
	Assert.assertEquals("Date ", df.format(d) , df.format(bd.getField3()));
	
	// cleaning
	bd.remove();
	
    }

    /**
     * findByPrimaryKey of a bean with PK that maps a single field java.util.date
     */
    public void testPkDateFindByPrimaryKey() throws Exception {
	Date d = null;
	Calendar date = Calendar.getInstance();
	date.set(2003,02,26);
	DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
	d = date.getTime();
	BDate bd1 = getBDateHome().create(0,1, d);
	BDate bd2 = getBDateHome().findByPrimaryKey(d);
	Assert.assertEquals("Date", df.format(d) , df.format(bd2.getField3()));
	// cleaning
	bd1.remove();
    }


}
