001: /**
002: * Copyright (C) 2001-2004 France Telecom R&D
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */package org.objectweb.speedo.runtime.tck;
018:
019: import java.util.ArrayList;
020: import java.util.Collection;
021:
022: import javax.jdo.JDOHelper;
023: import javax.jdo.PersistenceManager;
024: import javax.jdo.Query;
025: import javax.jdo.Transaction;
026:
027: import junit.framework.Assert;
028:
029: import org.objectweb.speedo.SpeedoTestHelper;
030: import org.objectweb.speedo.pobjects.basic.BasicA;
031: import org.objectweb.util.monolog.api.BasicLevel;
032:
033: public class QueryTck extends SpeedoTestHelper {
034:
035: private PersistenceManager pm;
036: private PersistenceManager pm1;
037: private Transaction transaction;
038:
039: public QueryTck(String s) {
040: super (s);
041: pm = pmf.getPersistenceManager();
042: }
043:
044: protected String getLoggerName() {
045: return LOG_NAME + ".rt.tck.QueryTck";
046: }
047:
048: public void testGetObjectId() {
049: logger.log(BasicLevel.INFO, "testGetObjectId");
050: try {
051: Transaction tx = pm.currentTransaction();
052: tx.begin();
053: BasicA nba1 = new BasicA();
054: pm.makePersistent(nba1);
055:
056: Object p2 = JDOHelper.getObjectId(nba1);
057: tx.commit();
058:
059: Assert.assertNotNull("bad getObjectId value", p2);
060:
061: } catch (Exception ex) {
062: logger.log(BasicLevel.ERROR,
063: "Unexception caught in testGetObjectId", ex);
064: fail(ex.getMessage());
065: }
066:
067: }
068:
069: public void testDeclareVariables() {
070: logger.log(BasicLevel.INFO, "testDeclareVariables");
071: Transaction tx = pm.currentTransaction();
072: tx.begin();
073:
074: Query query = pm.newQuery();
075:
076: if (query == null) {
077: logger.log(BasicLevel.ERROR, "query is null");
078: }
079:
080: query.setClass(BasicA.class);
081: query.setCandidates(pm.getExtent(BasicA.class, false));
082: query.declareParameters("Integer param1, Integer param2");
083: query.setFilter("f1 == param1 && f2 == param2");
084:
085: Object results = query.execute(new String(""),
086: new java.lang.Integer(0));
087:
088: // check query result
089: Collection expected = new ArrayList();
090: Object p3 = new BasicA();
091: expected.add(p3);
092: /*
093: insertExpected(expected);
094:
095:
096:
097: try {
098: checkQueryResultWithoutOrder(results);
099: } catch (Exception ex) {
100: logger.log(BasicLevel.ERROR, "Unexception caught in testDeclareVariables", ex);
101: fail(ex.getMessage());
102: }
103: */
104: tx.commit();
105:
106: }
107: }
|