Index: tck/src/java/org/apache/jdo/tck/query/api/SetResultDefault.java =================================================================== --- tck/src/java/org/apache/jdo/tck/query/api/SetResultDefault.java (nonexistent) +++ tck/src/java/org/apache/jdo/tck/query/api/SetResultDefault.java (working copy) @@ -0,0 +1,109 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.query.api; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.pc.company.CompanyModelReader; +import org.apache.jdo.tck.pc.company.Person; +import org.apache.jdo.tck.query.QueryTest; +import org.apache.jdo.tck.util.BatchTestRunner; +import org.apache.jdo.tck.util.EqualityHelper; + +import javax.jdo.JDOUserException; +import javax.jdo.Query; +import javax.jdo.Transaction; +import java.util.Arrays; +import java.util.List; + +/** + *Title: Set Result Default. + *
+ *Keywords: query + *
+ *Assertion ID: A14.6-X. + *
+ *Assertion Description: + * If not specified, the result defaults to “distinct this as C” + * where C is the unqualified name of the candidate class. + */ +public class SetResultDefault extends QueryTest { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A14.6-X (SetResultDefault) failed: "; + + /** + * The main is called when the class + * is directly executed from the command line. + * @param args The arguments passed to the program. + */ + public static void main(String[] args) { + BatchTestRunner.run(SetResult.class); + } + + /** */ + public void testPositive() { + Transaction tx = pm.currentTransaction(); + try { + tx.begin(); + Query query = pm.newQuery(Person.class, "lastname == 'emp1Last'"); + query.setResult("distinct this as Person"); + query.setResultClass(PersonWrapper.class); + Object results = query.execute(); + + PersonWrapper wrapper = new PersonWrapper((Person)getTransientCompanyModelInstance("emp1")); + List expected = Arrays.asList(wrapper); + checkQueryResultWithoutOrder(ASSERTION_FAILED, results, expected); + tx.commit(); + } finally { + if (tx.isActive()) { + tx.rollback(); + } + } + } + + public static class PersonWrapper { + private Person person; + public PersonWrapper() { } + public PersonWrapper(Person person) { this.person = person;} + public boolean equals(Object obj) { + if (!(obj instanceof PersonWrapper)) { + return false; + } + PersonWrapper other = (PersonWrapper)obj; + if (!EqualityHelper.equals(person, other.person)) { + return false; + } + return true; + } + public int hashCode () { + int hashCode = 0; + hashCode += person == null ? 0 : person.hashCode(); + return hashCode; + } + } + + /** + * @see JDO_Test#localSetUp() + */ + protected void localSetUp() { + addTearDownClass(CompanyModelReader.getTearDownClasses()); + loadAndPersistCompanyModel(getPM()); + } + +}