/**
 * Copyright 2012 Impetus Infotech.
 *
 * Licensed 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 com.impetus.client.oraclenosql.batch;

import java.util.ArrayList;
import java.util.List;

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

import junit.framework.Assert;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * Test case for more than one entities persisted in the same batch
 * 
 * @author amresh.singh
 */
public class OracleNosqlBatchProcessorMixedTest
{
    private static final String PERSISTENCE_UNIT = "oracleNosqlBatchTestSizeTwenty";

    /** The emf. */
    private static EntityManagerFactory emf;

    /** The em. */
    private static EntityManager em;

    @Before
    public void setUp() throws Exception
    {
        emf = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT);
        em = emf.createEntityManager();
    }

    @Test
    public void onBatch()
    {
        List<PersonBatchOracleNosql> persons = preparePersonData(10);
        List<AddressBatchOracleNosql> addresses = prepareAddressData(10);

        // Insert Persons
        for (PersonBatchOracleNosql person : persons)
        {
            em.persist(person);
        }

        // Insert Addresses
        for (AddressBatchOracleNosql address : addresses)
        {
            em.persist(address);
        }

        // flush all on close.
        // explicit flush on close
        em.clear();
        em.close();

        em = emf.createEntityManager();

        // Query on Persons
        String personsQueryStr = " Select p from PersonBatchOracleNosql p";
        Query personsQuery = em.createQuery(personsQueryStr);
        List<PersonBatchOracleNosql> allPersons = personsQuery.getResultList();
        Assert.assertNotNull(allPersons);
        Assert.assertEquals(10, allPersons.size());

        // Query on Addresses
        String addressQueryStr = " Select a from AddressBatchOracleNosql a";
        Query addressQuery = em.createQuery(addressQueryStr);
        List<AddressBatchOracleNosql> allAddresses = addressQuery.getResultList();
        Assert.assertNotNull(allAddresses);
        Assert.assertEquals(10, allAddresses.size());

    }

    /**
     * @throws java.lang.Exception
     */
    @After
    public void tearDown() throws Exception
    {
        emf.close();
    }

    private List<PersonBatchOracleNosql> preparePersonData(Integer noOfRecords)
    {
        List<PersonBatchOracleNosql> persons = new ArrayList<PersonBatchOracleNosql>();
        for (int i = 1; i <= noOfRecords; i++)
        {
            PersonBatchOracleNosql o = new PersonBatchOracleNosql();
            o.setPersonId(i + "");
            o.setPersonName("Name " + i);
            o.setAge(10);
            persons.add(o);
        }
        return persons;
    }

    private List<AddressBatchOracleNosql> prepareAddressData(Integer noOfRecords)
    {
        List<AddressBatchOracleNosql> addresses = new ArrayList<AddressBatchOracleNosql>();
        for (int i = 1; i <= noOfRecords; i++)
        {
            AddressBatchOracleNosql o = new AddressBatchOracleNosql();
            o.setAddressId(i + "");
            o.setStreet("My Street " + i);
            addresses.add(o);
        }
        return addresses;
    }

}

@@ -1321,16 +1321,127 @@
 er em;%0A%0A
+    private List%3CPersonBatchOracleNosql%3E allPersons;%0A%0A    private List%3CAddressBatchOracleNosql%3E allAddresses;%0A%0A
     @Bef
@@ -2395,37 +2395,8 @@
     
- List%3CPersonBatchOracleNosql%3E
  all
@@ -2427,32 +2427,32 @@
 etResultList();%0A
+
         Assert.a
@@ -2710,38 +2710,8 @@
     
- List%3CAddressBatchOracleNosql%3E
  all
@@ -2956,38 +2956,277 @@
 hrows Exception%0A
-
     %7B%0A
+        for (PersonBatchOracleNosql entity : allPersons)%0A        %7B%0A            em.remove(entity);%0A        %7D%0A        for (AddressBatchOracleNosql entity : allAddresses)%0A        %7B%0A            em.remove(entity);%0A        %7D%0A        em.close();%0A
         emf.clos

Add truncate code in batch test