diff options
Diffstat (limited to 'sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/test/java/org/apache/tuscany/sca/implementation/openjpa/CompanyTestCase.java')
-rw-r--r-- | sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/test/java/org/apache/tuscany/sca/implementation/openjpa/CompanyTestCase.java | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/test/java/org/apache/tuscany/sca/implementation/openjpa/CompanyTestCase.java b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/test/java/org/apache/tuscany/sca/implementation/openjpa/CompanyTestCase.java new file mode 100644 index 0000000000..1c4d6fb254 --- /dev/null +++ b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/test/java/org/apache/tuscany/sca/implementation/openjpa/CompanyTestCase.java @@ -0,0 +1,80 @@ +/* + * 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.tuscany.sca.implementation.openjpa; + +import junit.framework.*; +import org.apache.tuscany.sca.host.embedded.*; +import org.apache.commons.logging.*; + +import company.*; + +import javax.persistence.*; +import java.util.*; + +public class CompanyTestCase extends TestCase { + private EntityManager em; + private Log log = LogFactory.getLog(this.getClass()); + private SCADomain domain; + + public void setUp() { + domain = SCADomain.newInstance("openjpa.composite"); + em = domain.getService(EntityManager.class, "CompanyServiceComponent"); + + } + + public void testAccess() { + Company company = new Company(); + int id = new Random().nextInt(); + + company.setId(id); + company.setName("Company " + id); + + em.persist(company); + log.info(em.find(Company.class, id)); + + Query q = em.createQuery("select company from Company company"); + q.setMaxResults(5); + log.info("There are " + q.getResultList().size() + " Company in the database now"); + } + + public void testRollback() { + try { + Company company1 = new Company(); + Company company2 = new Company(); + + int id = new Random().nextInt(); + + company1.setId(id); + company1.setName("Company " + id); + em.persist(company1); + + company2.setId(id); + company2.setName("Company " + id); + em.persist(company2); + + } catch (RuntimeException ex) { + log.info("An expected exception occured, Tuscany is rolling back..."); + } + } + + public void tearDown() { + em.close(); + domain.close(); + } +} |