📄 cdbeantest.java
字号:
/**
* $Log: CDBeanTest.java,v $
* Revision 1.2 2003/02/07 11:31:07 mwulff
* no message
*
* Revision 1.1 2003/01/16 13:07:32 mwulff
* initial version
*
* Revision 1.5 2002/12/20 18:48:34 mwulff
* no message
*
* Revision 1.4 2002/12/15 16:50:48 mwulff
* adjusted to reorganisation of the client logging system
*
* Revision 1.3 2002/12/13 20:05:36 mwulff
* no message
*
* Revision 1.2 2002/12/12 11:37:29 mwulff
* no message
*
* Revision 1.1 2002/12/09 18:04:03 mwulff
* initial version
*
*/
package de.fhm.jkf.test.cl;
import java.util.Collection;
import java.util.Iterator;
import junit.framework.TestCase;
import junit.framework.TestResult;
import de.fhm.jkf.comm.cl.JKFFactory;
import de.fhm.jkf.comm.cl.ObjectFactory;
import de.fhm.jkf.resource.cl.JKFClient;
import de.fhm.jkf.resource.cl.JKFClientLogger;
import de.fhm.jkf.test.clsv.LocalCD;
/**
* @author marten wulff
*
* * <br><br><center><table border="1" width="80%"><hr>
* <strong><a href="http://jkf.sourceforge.net">The JKF Project</a></strong>
* <p>
* Copyright (C) 2002 by Marten Wulff
* <p>
* 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 (at your option) any later version.
* <p>
* 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.
* <p>
* You should have received a copy of the <a href="http://www.gnu.org/copyleft/lesser.html">
* GNU Lesser General Public License</a> along with this library; if not, write to
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
* <hr></table></center>
*/
public class CDBeanTest extends TestCase {
private final String jndiName = "bean/CD";
private ObjectFactory factory = null;
/**
* Constructor for CDBeanTest.
* @param arg0
*/
public CDBeanTest(String arg0) {
super(arg0);
}
/*
* @see TestCase#setUp()
*/
protected void setUp() throws Exception {
super.setUp();
// configure jkf
JKFClient.configure();
}
public TestResult run() {
TestResult result = new TestResult();
factory = JKFFactory.instance().getFactory();
if (JKFClientLogger.isDebugEnabled()) {
JKFClientLogger.debug(
"\n\n******************** "
+ this.getClass().getName()
+ " ***************************");
}
Object[] param = new Object[5];
LocalCD cd1 = null;
LocalCD cd2 = null;
LocalCD cd3 = null;
LocalCD cd4 = null;
// first step is creating some entity beans
/* if(JKFClientLogger.isDebugEnabled()) {
JKFClientLogger.debug("========== Creating EJBs ==========");
}
try {
param[0] = new Integer(1);
param[1] = new String("classic");
param[2] = new String("Verdi best of");
param[3] = new Float(25.95);
param[4] = new String("Verdi");
cd1 = (LocalCD)factory.createEJB(LocalCD.class, param, jndiName);
}catch(Exception ex) {
JKFClientLogger.error("Couldn't create Bean 1!: " + ex.getMessage(), ex);
}
try{
param[0] = new Integer(2);
param[1] = new String("classic");
param[2] = new String("Verdi second best of");
param[3] = new Float(33.85);
param[4] = new String("Verdi");
cd2 = (LocalCD)factory.createEJB(LocalCD.class, param, jndiName);
} catch (Exception ex) {
JKFClientLogger.error("Couldn't create Bean 2!: " + ex.getMessage(), ex);
}
if (JKFClientLogger.isDebugEnabled()) {
JKFClientLogger.debug("========== EJBs creation done ==========");
}*/
// now let's find the created entity beans by its primary key
try {
JKFClientLogger.debug("========== Finding EJB by primary key (id = 1) ==========");
param = new Object[1];
param[0] = new Integer(1);
cd3 =
(LocalCD) factory.findByPrimaryKey(
LocalCD.class,
param,
jndiName);
if (JKFClientLogger.isDebugEnabled()) {
JKFClientLogger.debug("Entity Bean found:");
JKFClientLogger.debug("ID: " + cd3.getId());
JKFClientLogger.debug("Title: " + cd3.getTitle());
JKFClientLogger.debug("Price: " + cd3.getPrice());
JKFClientLogger.debug("Artist: " + cd3.getArtist());
JKFClientLogger.debug("Genre: " + cd3.getGenre());
}
}catch(Exception ex) {
JKFClientLogger.error("Error finding EJB 1!:" + ex.getMessage(), ex);
}
try{
JKFClientLogger.debug("========== Finding EJB by primary key (id = 2) ==========");
param[0] = new Integer(2);
cd4 =
(LocalCD) factory.findByPrimaryKey(
LocalCD.class,
param,
jndiName);
if (JKFClientLogger.isDebugEnabled()) {
JKFClientLogger.debug("Entity Bean found:");
JKFClientLogger.debug("ID: " + cd4.getId());
JKFClientLogger.debug("Title: " + cd4.getTitle());
JKFClientLogger.debug("Price: " + cd4.getPrice());
JKFClientLogger.debug("Artist: " + cd4.getArtist());
JKFClientLogger.debug("Genre: " + cd4.getGenre());
}
} catch (Exception ex) {
JKFClientLogger.error("Couldn't find EJB 2!: " + ex.getMessage(), ex);
}
try{
JKFClientLogger.debug("========== Finding classic cds ==========");
param[0] = new String("classic");
// find by genre
Collection cds = factory.findByXXX(
LocalCD.class,
param,
jndiName,
"findByGenre");
Iterator it = cds.iterator();
LocalCD cd = null;
while(it.hasNext()) {
cd = (LocalCD)it.next();
if (JKFClientLogger.isDebugEnabled()) {
JKFClientLogger.debug("ID: " + cd.getId());
JKFClientLogger.debug("Title: " + cd.getTitle());
JKFClientLogger.debug("Price: " + cd.getPrice());
JKFClientLogger.debug("Artist: " + cd.getArtist());
JKFClientLogger.debug("Genre: " + cd.getGenre());
}
}
}catch(Exception ex) {
JKFClientLogger.error("Couldn't find Beans !!!", ex);
}
// deleting the created bean
/* JKFClientLogger.debug("========== Deleting EJBs ==========");
try{
if(cd1 != null) {
cd1.remove();
}else {
cd3.remove();
}
}catch(Exception ex) {
JKFClientLogger.error("Error removing EJB: " + ex.getMessage(), ex);
}
try{
if(cd2 != null) {
cd2.remove();
}else {
cd4.remove();
}
}catch(Exception ex) {
JKFClientLogger.error("Error removing EJB: " + ex.getMessage(), ex);
}
if (JKFClientLogger.isDebugEnabled()) {
JKFClientLogger.debug("========== EJBs deleted ==========");
} */
return result;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -