OPENJPA-51 removing testcases

git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@536706 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Dick 2007-05-09 23:05:16 +00:00
parent a92785fea6
commit 59bd5b0d3f
3 changed files with 0 additions and 261 deletions

View File

@ -1,87 +0,0 @@
/*
* 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.openjpa.persistence.query;
import javax.persistence.*;
import java.util.Collection;
import java.util.ArrayList;
@Entity(name="Customer")
@Table(name="CUSTOMERTB")
public class CustomerEntity {
public enum CreditRating { POOR, GOOD, EXCELLENT };
@Id
@GeneratedValue
long cid;
@Column(length=30)
String name;
@Enumerated
CreditRating creditRating;
@Version
long version;
@OneToMany(fetch=FetchType.LAZY, mappedBy="customer")
private Collection<OrderEntity> orders = new ArrayList<OrderEntity>();
public CustomerEntity() {}
public CustomerEntity(String name, CreditRating rating){
this.name=name;
this.creditRating=rating;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public CreditRating getRating() {
return creditRating;
}
public void setRating(CreditRating rating) {
this.creditRating = rating;
}
public Collection<OrderEntity> getOrders() {
return orders;
}
public void setOrders(Collection<OrderEntity> orders) {
this.orders = orders;
}
public String toString() {
return "Customer:"+cid+" name:"+name;
}
public long getCid() {
return cid;
}
public void setCid(long cid) {
this.cid = cid;
}
}

View File

@ -1,80 +0,0 @@
/*
* 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.openjpa.persistence.query;
import javax.persistence.*;
@Entity(name="Order")
@Table(name="ORDERTB")
public class OrderEntity {
@Id
@GeneratedValue
int oid;
double amount;
boolean delivered;
@ManyToOne
CustomerEntity customer;
@Version
long version;
public OrderEntity(){}
public OrderEntity( double amt, boolean delivered, CustomerEntity c){
amount=amt;
this.delivered=delivered;
customer=c;
if (c!=null) c.getOrders().add(this);
}
public double getAmount() {
return amount;
}
public void setAmount(double amount) {
this.amount = amount;
}
public CustomerEntity getCustomer() {
return customer;
}
public void setCustomer(CustomerEntity customer) {
this.customer = customer;
}
public boolean isDelivered() {
return delivered;
}
public void setDelivered(boolean delivered) {
this.delivered = delivered;
}
public int getOid() {
return oid;
}
public String toString(){
return "Order:"+oid+" amount:"+amount+" delivered:"+delivered+" customer:"+
( customer!=null ? customer.getCid() : -1 );
}
}

View File

@ -1,94 +0,0 @@
/*
* 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.openjpa.persistence.query;
import java.util.List;
import javax.persistence.EntityManager;
import junit.textui.TestRunner;
import org.apache.openjpa.persistence.test.SingleEMFTestCase;
/**
* Test queries with subselects
*
* @author Catalina Wei
*/
public class TestSubQuery
extends SingleEMFTestCase {
public void setUp() {
setUp(CustomerEntity.class, CustomerEntity.class,
OrderEntity.class, OrderEntity.class);
}
public void testQuery() {
EntityManager em = emf.createEntityManager();
String[] query = new String[] {
"select o from Customer c, in(c.orders) o where o.amount > "
+ "(select avg(o.amount) from Order o)",
"select c from Customer c, in(c.orders) o where o.amount > "
+ "(select avg(o.amount) from in(c.orders) o)",
"select c from Customer c where "
+ "((select sum(o.amount) from Order o where o.customer = c) "
+ "between 100 and 200) order by c.name",
"select o from Order o where o.amount < "
+ "(select max(o2.amount) from Order o2 where "
+ "o2.amount = o.amount)",
"select o from Order o where o.amount > "
+ "(select avg(o.amount) from Customer c, in(c.orders) o)",
"select o.oid from Order o where o.amount > 10 "
+ "and o.amount < (select min(o2.amount) from Order o2 where "
+ "o2.amount > 0)",
"select o from Order o where o.amount > any "
+ "(select o.amount from Customer c, in (c.orders) o where "
+ "c.cid = 1)",
"select o from Order o where o.amount between "
+ "(select min(o.amount) from Customer c, in(c.orders) o) and "
+ "(select avg(o.amount) from Customer c, in(c.orders) o)"
};
int failures = 0;
for (int i=0; i<query.length; i++) {
try {
List res = em.createQuery(query[i])
.getResultList();
} catch (Exception e) {
failures++;
}
}
em.getTransaction().begin();
try {
String update = "update Order o set o.amount = o.amount + 1 where "
+ "o.oid not in (select o2.oid from Customer c, "
+ "in(c.orders) o2)";
em.createQuery(update).executeUpdate();
}
catch (Exception e) {
failures++;
}
em.getTransaction().commit();
assertEquals(0, failures);
em.close();
}
public static void main(String[] args) {
TestRunner.run(TestSubQuery.class);
}
}