package org.apache.ode.dao.jpa.test;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;

import org.apache.ode.bpel.dao.BpelDAOConnection;
import org.apache.ode.dao.jpa.ojpa.BPELDAOConnectionFactoryImpl;

import junit.framework.TestCase;

public class SelectObjectTest extends TestCase {
	
	private EntityManager em;

	@Override
	protected void setUp() throws Exception {
		
		try {
			EntityManagerFactory emf = Persistence.createEntityManagerFactory("ode-unit-test");
			em = emf.createEntityManager();
		
		} catch ( Exception e ) {
			e.printStackTrace();
			fail();
		}
		
		
	}
	
	public void testGetObject() throws Exception {
		
		BPELDAOConnectionFactoryImpl factory = new BPELDAOConnectionFactoryImpl(em);
		BpelDAOConnection conn1 = factory.getConnection();
		Long connId1 = factory.getConnectionId(conn1);
		BpelDAOConnection conn2 = factory.getConnection(connId1 + 5);
		Long connId2 = factory.getConnectionId(conn2);
		
		if ( conn1 != null && conn2 != null	 ) {
			System.out.println("got conn1:" + connId1);
			System.out.println("got conn2:" + connId2);
		}
	}

	@Override
	protected void tearDown() throws Exception {
		em.close();
	}
	
}

@@ -29,24 +29,56 @@
 pa.test;%0D%0A%0D%0A
+import java.util.Collection;%0D%0A%0D%0A
 import javax
@@ -230,244 +230,630 @@
 y;%0D%0A
-%0D%0Aimport org.apache.ode.bpel.dao.BpelDAOConnection;%0D%0Aimport org.apache.ode.dao.jpa.ojpa.BPELDAOConnectionFactoryImpl;%0D%0A%0D%0Aimport junit.framework.TestCase;%0D%0A%0D%0Apublic class SelectObjectTest extends TestCase %7B%0D%0A%09%0D%0A%09private EntityManager em;
+import javax.xml.namespace.QName;%0D%0A%0D%0Aimport org.apache.ode.bpel.common.CorrelationKey;%0D%0Aimport org.apache.ode.bpel.dao.BpelDAOConnection;%0D%0Aimport org.apache.ode.bpel.dao.ProcessDAO;%0D%0Aimport org.apache.ode.bpel.dao.ProcessInstanceDAO;%0D%0Aimport org.apache.ode.dao.jpa.ojpa.BPELDAOConnectionFactoryImpl;%0D%0A%0D%0Aimport junit.framework.TestCase;%0D%0A%0D%0Apublic class SelectObjectTest extends TestCase %7B%0D%0A%09%0D%0A%09private EntityManager em;%0D%0A%09private static final String TEST_NS = %22http://org.apache.ode.jpa.test%22;%0D%0A%09private String%5B%5D correlationKeys = %7B %22key1%22, %22key2%22 %7D;%0D%0A%09private CorrelationKey key1 = new CorrelationKey(1,correlationKeys);%0D%0A
 %0D%0A%0D%0A
@@ -1292,17 +1292,16 @@
 ion conn
-1
  = facto
@@ -1327,318 +1327,307 @@
 %0D%0A%09%09
-Long connId1 = factory.getConnectionId(conn1);%0D%0A%09%09BpelDAOConnection conn2 = factory.getConnection(connId1 + 5);%0D%0A%09%09Long connId2 = factory.getConnectionId(conn2);%0D%0A%09%09%0D%0A%09%09if ( conn1 != null && conn2 != null%09 ) %7B%0D%0A%09%09%09System.out.println(%22got conn1:%22 + connId1
+%0D%0A%09%09ProcessDAO p = conn.getProcess(new QName(TEST_NS,%22testPID1%22));%0D%0A%09%09Collection%3CProcessInstanceDAO%3E insts = p.findInstance(key1);%0D%0A%09%09%0D%0A%09%09for ( ProcessInstanceDAO inst : insts ) %7B%0D%0A%09%09%09Long id = inst.getInstanceId(
 );%0D%0A%09%09
-%09System.out.println(%22got conn2:%22 + connId2
+%7D%0D%0A%09%09%0D%0A%09%09int instCount = p.getNumInstances();%0D%0A%09%09%0D%0A%09%09%0D%0A%09%09%0D%0A%09%09conn.close(
 );%0D%0A%09%09
-%7D
+%0D%0A
 %0D%0A%09%7D

Enhance unit test