001: /**
002: *
003: * Licensed to the Apache Software Foundation (ASF) under one or more
004: * contributor license agreements. See the NOTICE file distributed with
005: * this work for additional information regarding copyright ownership.
006: * The ASF licenses this file to You under the Apache License, Version 2.0
007: * (the "License"); you may not use this file except in compliance with
008: * the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */package org.apache.openejb.test.entity.cmp2;
018:
019: import org.apache.openejb.test.entity.ejbql.QueryHome;
020: import org.apache.openejb.test.entity.ejbql.QueryDataHome;
021: import org.apache.openejb.test.entity.ejbql.QueryDataLocal;
022: import org.apache.openejb.test.entity.ejbql.QueryDataRemote;
023:
024: import javax.rmi.PortableRemoteObject;
025: import java.util.Collection;
026: import java.util.Arrays;
027: import java.util.TreeSet;
028: import java.util.ArrayList;
029: import java.util.List;
030:
031: public class EjbqlLocalTest extends Cmp2TestClient {
032: private QueryHome queryHome;
033:
034: public EjbqlLocalTest() {
035: super ("EJBQLTest.");
036: }
037:
038: protected void setUp() throws Exception {
039: super .setUp();
040: Object obj = initialContext
041: .lookup("client/tests/entity/ejbql/Query");
042: queryHome = (QueryHome) PortableRemoteObject.narrow(obj,
043: QueryHome.class);
044: obj = initialContext
045: .lookup("client/tests/entity/ejbql/QueryData");
046: QueryDataHome queryDataHome = (QueryDataHome) PortableRemoteObject
047: .narrow(obj, QueryDataHome.class);
048:
049: queryDataHome.create(0);
050: queryDataHome.create(1);
051: queryDataHome.create(2);
052: queryDataHome.create(3);
053: }
054:
055: protected void tearDown() throws Exception {
056: super .tearDown();
057: }
058:
059: /**
060: * Select a single string field
061: */
062: public void testSelectSingleStringField() throws Exception {
063: String result = queryHome.selectSingleStringField("2");
064: assertEquals("2", result);
065: }
066:
067: /**
068: * Select a single boolean field
069: */
070: public void testSelectSingleBooleanField() throws Exception {
071: boolean result = queryHome.selectSingleBooleanField(true);
072: assertEquals(true, result);
073: }
074:
075: /**
076: * Select a single char field
077: */
078: public void testSelectSingleCharField() throws Exception {
079: char result = queryHome.selectSingleCharField('2');
080: assertEquals('2', result);
081: }
082:
083: /**
084: * Select a single byte field
085: */
086: public void testSelectSingleByteField() throws Exception {
087: byte result = queryHome.selectSingleByteField((byte) 2);
088: assertEquals(2, result);
089: }
090:
091: /**
092: * Select a single short field
093: */
094: public void testSelectSingleShortField() throws Exception {
095: short result = queryHome.selectSingleShortField((short) 2);
096: assertEquals(2, result);
097: }
098:
099: /**
100: * Select a single int field
101: */
102: public void testSelectSingleIntField() throws Exception {
103: int result = queryHome.selectSingleIntField(2);
104: assertEquals(2, result);
105: }
106:
107: /**
108: * Select a single long field
109: */
110: public void testSelectSingleLongField() throws Exception {
111: long result = queryHome.selectSingleLongField(2);
112: assertEquals(2, result);
113: }
114:
115: /**
116: * Select a single float field
117: */
118: public void testSelectSingleFloatField() throws Exception {
119: float result = queryHome.selectSingleFloatField(2);
120: assertEquals((float) 2.0, result);
121: }
122:
123: /**
124: * Select a single double field
125: */
126: public void testSelectSingleDoubleField() throws Exception {
127: double result = queryHome.selectSingleDoubleField(2);
128: assertEquals(2.0, result);
129: }
130:
131: /**
132: * Select a collection string field
133: */
134: public void testSelectCollectionStringField() throws Exception {
135: Collection result = queryHome.selectCollectionStringField();
136: assertNotNull("result is null", result);
137: assertEquals("result.size()", 4, result.size());
138: assertCollection(result, "0", "1", "2", "3");
139: }
140:
141: /**
142: * Select a collection boolean field
143: */
144: public void testSelectCollectionBooleanField() throws Exception {
145: Collection result = queryHome.selectCollectionBooleanField();
146: assertNotNull("result is null", result);
147: assertEquals("result.size()", 4, result.size());
148: assertCollection(result, true, false);
149: }
150:
151: /**
152: * Select a collection char field
153: */
154: public void testSelectCollectionCharField() throws Exception {
155: Collection result = queryHome.selectCollectionCharField();
156: assertNotNull("result is null", result);
157: assertEquals("result.size()", 4, result.size());
158: assertCollection(result, '0', '1', '2', '3');
159: }
160:
161: /**
162: * Select a collection byte field
163: */
164: public void testSelectCollectionByteField() throws Exception {
165: Collection result = queryHome.selectCollectionByteField();
166: assertNotNull("result is null", result);
167: assertEquals("result.size()", 4, result.size());
168: assertCollection(result, (byte) 0, (byte) 1, (byte) 2, (byte) 3);
169: }
170:
171: /**
172: * Select a collection short field
173: */
174: public void testSelectCollectionShortField() throws Exception {
175: Collection result = queryHome.selectCollectionShortField();
176: assertNotNull("result is null", result);
177: assertEquals("result.size()", 4, result.size());
178: assertCollection(result, (short) 0, (short) 1, (short) 2,
179: (short) 3);
180: }
181:
182: /**
183: * Select a collection int field
184: */
185: public void testSelectCollectionIntField() throws Exception {
186: Collection result = queryHome.selectCollectionIntField();
187: assertNotNull("result is null", result);
188: assertEquals("result.size()", 4, result.size());
189: assertCollection(result, 0, 1, 2, 3);
190: }
191:
192: /**
193: * Select a collection long field
194: */
195: public void testSelectCollectionLongField() throws Exception {
196: Collection result = queryHome.selectCollectionLongField();
197: assertNotNull("result is null", result);
198: assertEquals("result.size()", 4, result.size());
199: assertCollection(result, (long) 0, (long) 1, (long) 2, (long) 3);
200: }
201:
202: /**
203: * Select a collection float field
204: */
205: public void testSelectCollectionFloatField() throws Exception {
206: Collection result = queryHome.selectCollectionFloatField();
207: assertNotNull("result is null", result);
208: assertEquals("result.size()", 4, result.size());
209: assertCollection(result, (float) 0, (float) 1, (float) 2,
210: (float) 3);
211: }
212:
213: /**
214: * Select a collection double field
215: */
216: public void testSelectCollectionDoubleField() throws Exception {
217: Collection result = queryHome.selectCollectionDoubleField();
218: assertNotNull("result is null", result);
219: assertEquals("result.size()", 4, result.size());
220: assertCollection(result, 0.0, 1.0, 2.0, 3.0);
221: }
222:
223: /**
224: * Select a single local ejb
225: */
226: public void testSelectSingleLocalEjb() throws Exception {
227: Object result = queryHome.selectSingleLocalEjb(2);
228: assertNotNull("result is null", result);
229: assertTrue("result should be an instance of QueryDataLocal",
230: result instanceof QueryDataLocal);
231: QueryDataLocal queryData = (QueryDataLocal) result;
232: assertEquals(2, queryData.getIntField());
233: }
234:
235: /**
236: * Select a single remote ejb
237: */
238: public void testSelectSingleRemoteEjb() throws Exception {
239: Object result = queryHome.selectSingleRemoteEjb(2);
240: assertNotNull("result is null", result);
241: assertTrue("result should be an instance of QueryDataRemote",
242: result instanceof QueryDataRemote);
243: QueryDataRemote queryData = (QueryDataRemote) result;
244: assertEquals(2, queryData.getIntField());
245: }
246:
247: /**
248: * Select a collection local ejb
249: */
250: public void testSelectCollectionLocalEjb() throws Exception {
251: Collection result = queryHome.selectCollectionLocalEjb();
252: assertNotNull("result is null", result);
253: assertEquals("result.size()", 4, result.size());
254:
255: List<Integer> values = new ArrayList<Integer>();
256: for (Object object : result) {
257: assertTrue(
258: "result item should be an instance of QueryDataLocal but is instance of "
259: + Arrays.toString(object.getClass()
260: .getInterfaces()),
261: object instanceof QueryDataLocal);
262: QueryDataLocal queryData = (QueryDataLocal) object;
263: values.add(queryData.getIntField());
264: }
265: assertCollection(values, 0, 1, 2, 3);
266: }
267:
268: /**
269: * Select a collection remote ejb
270: */
271: public void testSelectCollectionRemoteEjb() throws Exception {
272: Collection result = queryHome.selectCollectionRemoteEjb();
273: assertNotNull("result is null", result);
274: assertEquals("result.size()", 4, result.size());
275:
276: List<Integer> values = new ArrayList<Integer>();
277: for (Object object : result) {
278: assertTrue(
279: "result item should be an instance of QueryDataRemote",
280: object instanceof QueryDataRemote);
281: QueryDataRemote queryData = (QueryDataRemote) object;
282: values.add(queryData.getIntField());
283: }
284: assertCollection(values, 0, 1, 2, 3);
285: }
286:
287: @SuppressWarnings({"unchecked"})
288: private static <E> void assertCollection(Collection collection,
289: E... values) {
290: assertEquals(new TreeSet(Arrays.asList(values)), new TreeSet(
291: collection));
292: }
293: }
|