KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > runtime > tck > QueryTck


1 /**
2  * Copyright (C) 2001-2004 France Telecom R&D
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18 package org.objectweb.speedo.runtime.tck;
19
20 import java.util.ArrayList JavaDoc;
21 import java.util.Collection JavaDoc;
22
23 import javax.jdo.JDOHelper;
24 import javax.jdo.PersistenceManager;
25 import javax.jdo.Query;
26 import javax.jdo.Transaction;
27
28 import junit.framework.Assert;
29
30 import org.objectweb.speedo.SpeedoTestHelper;
31 import org.objectweb.speedo.pobjects.basic.BasicA;
32 import org.objectweb.util.monolog.api.BasicLevel;
33
34
35
36 public class QueryTck extends SpeedoTestHelper {
37
38     private PersistenceManager pm;
39     private PersistenceManager pm1;
40     private Transaction transaction;
41     
42     
43     public QueryTck(String JavaDoc s) {
44         super(s);
45         pm = pmf.getPersistenceManager();
46     }
47
48     protected String JavaDoc getLoggerName() {
49         return LOG_NAME + ".rt.tck.QueryTck";
50     }
51
52     public void testGetObjectId() {
53         logger.log(BasicLevel.INFO, "testGetObjectId");
54         try {
55             Transaction tx = pm.currentTransaction();
56             tx.begin();
57             BasicA nba1 = new BasicA();
58             pm.makePersistent(nba1);
59
60             Object JavaDoc p2 = JDOHelper.getObjectId(nba1);
61             tx.commit();
62             
63             Assert.assertNotNull("bad getObjectId value", p2);
64
65         } catch (Exception JavaDoc ex) {
66             logger.log(BasicLevel.ERROR, "Unexception caught in testGetObjectId", ex);
67             fail(ex.getMessage());
68         }
69         
70     }
71
72     public void testDeclareVariables() {
73         logger.log(BasicLevel.INFO, "testDeclareVariables");
74         Transaction tx = pm.currentTransaction();
75         tx.begin();
76
77         Query query = pm.newQuery();
78
79         if(query == null) {
80             logger.log(BasicLevel.ERROR, "query is null");
81         }
82
83         query.setClass(BasicA.class);
84         query.setCandidates(pm.getExtent(BasicA.class, false));
85         query.declareParameters("Integer param1, Integer param2");
86         query.setFilter("f1 == param1 && f2 == param2");
87         
88         Object JavaDoc results = query.execute(new String JavaDoc(""), new java.lang.Integer JavaDoc(0));
89
90         // check query result
91
Collection JavaDoc expected = new ArrayList JavaDoc();
92         Object JavaDoc p3 = new BasicA();
93         expected.add(p3);
94 /*
95         insertExpected(expected);
96
97         
98
99         try {
100             checkQueryResultWithoutOrder(results);
101         } catch (Exception ex) {
102             logger.log(BasicLevel.ERROR, "Unexception caught in testDeclareVariables", ex);
103             fail(ex.getMessage());
104         }
105 */

106         tx.commit();
107         
108     }
109 }
110
111
Popular Tags