Package org.objectweb.speedo.runtime.basic

Source Code of org.objectweb.speedo.runtime.basic.TestMultitable

/**
* Copyright (C) 2001-2006 France Telecom R&D
*/
package org.objectweb.speedo.runtime.basic;

import org.objectweb.speedo.SpeedoTestHelper;
import org.objectweb.speedo.pobjects.multitable.Address;

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

import javax.jdo.PersistenceManager;
import javax.jdo.Query;

public class TestMultitable extends SpeedoTestHelper {

    public TestMultitable(String s) {
        super(s);
    }
    protected String getLoggerName() {
        return LOG_NAME + ".rt.basic.TestMultitable";
    }

    public void testAddress() {
        final int size = 5;
        List as = getData(size);
        PersistenceManager pm = pmf.getPersistenceManager();
        pm.currentTransaction().begin();
        pm.makePersistentAll(as);
        pm.currentTransaction().commit();
       
        as = null;
        pm.evictAll();
       
        pm.currentTransaction().begin();
        Query q = pm.newQuery(Address.class);
        Collection c = (Collection) q.execute();
        assertSameCollection("Bad collection of address from the query", getData(size), c);
        as = new ArrayList(c);
        q.closeAll();
        pm.currentTransaction().commit();
       
        pm.currentTransaction().begin();
        pm.deletePersistentAll(as);
        pm.currentTransaction().commit();
        pm.close();
       
    }
   
    private List getData(final int size) {
        List as = new ArrayList(size);
        for (int i = 0; i < size; i++) {
            Address a = new Address();
            a.setCity("city_"+ i);
            a.setDeliveryInstructions("deliv_"+ i);
            byte[] map = new byte[20 * (i+1)];
            for (int j = 0; j < map.length; j++) {
                map[j] = (byte) i;
            }
            a.setMapJPG(map);
            a.setSignatureRequired(i % 2 == 1);
            a.setState("state_" + i);
            a.setStreet("street_" + i);
            a.setZip("zip_" + i);
            as.add(a);
        }
        return as;
    }
}
TOP

Related Classes of org.objectweb.speedo.runtime.basic.TestMultitable

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.