Package org.apache.cayenne.jpa

Examples of org.apache.cayenne.jpa.JpaUnit


public class JpaUnitTest extends TestCase {

    public void testTransactionType() {

        JpaUnit info = new JpaUnit() {

            @Override
            public void addTransformer(ClassTransformer transformer) {
            }
        };
        info.addProperties(Collections.singletonMap(
                Provider.TRANSACTION_TYPE_PROPERTY,
                PersistenceUnitTransactionType.JTA.name()));
        assertSame(PersistenceUnitTransactionType.JTA, info.getTransactionType());

        info.addProperties(Collections.singletonMap(
                Provider.TRANSACTION_TYPE_PROPERTY,
                PersistenceUnitTransactionType.RESOURCE_LOCAL.name()));
        assertSame(PersistenceUnitTransactionType.RESOURCE_LOCAL, info
                .getTransactionType());
    }
View Full Code Here


        assertSame(PersistenceUnitTransactionType.RESOURCE_LOCAL, info
                .getTransactionType());
    }

    public void testClassLoader() {
        JpaUnit info = new JpaUnit() {

            @Override
            public void addTransformer(ClassTransformer transformer) {
            }
        };

        ClassLoader topLoader = new URLClassLoader(new URL[0], Thread
                .currentThread()
                .getContextClassLoader());
        info.setClassLoader(topLoader);
        assertSame(topLoader, info.getClassLoader());
    }
View Full Code Here

        info.setClassLoader(topLoader);
        assertSame(topLoader, info.getClassLoader());
    }

    public void testGetNewTempClassLoader() {
        JpaUnit info = new JpaUnit() {

            @Override
            public void addTransformer(ClassTransformer transformer) {
            }
        };

        ClassLoader topLoader = new URLClassLoader(new URL[0], Thread
                .currentThread()
                .getContextClassLoader());
        info.setClassLoader(topLoader);

        ClassLoader tmp1 = info.getNewTempClassLoader();
        ClassLoader tmp2 = info.getNewTempClassLoader();
        assertNotSame(topLoader, tmp1);
        assertNotSame(topLoader, tmp2);
        assertNotSame(tmp1, tmp2);
    }
View Full Code Here

                .getResourceAsStream("xml-samples/persistence1.xml");
        Collection<JpaUnit> units = parser.getPersistenceUnits(new InputSource(in), root);

        assertEquals(1, units.size());

        JpaUnit info = (JpaUnit) units.iterator().next();

        assertEquals("OrderManagement", info.getPersistenceUnitName());

        // JTA is the default when type is ommitted
        assertEquals(PersistenceUnitTransactionType.JTA, info.getTransactionType());
        assertEquals(root, info.getPersistenceUnitRootUrl());
        assertTrue(info.getDescription().startsWith("This unit manages orders"));
        assertEquals("jdbc/MyOrderDB", info.getProperties().getProperty(
                Provider.JTA_DATA_SOURCE_PROPERTY));

        assertEquals(1, info.getMappingFileNames().size());
        assertTrue(info.getMappingFileNames().contains("ormap.xml"));

        assertEquals(2, info.getManagedClassNames().size());
        assertTrue(info.getManagedClassNames().contains("com.widgets.Order"));
        assertTrue(info.getManagedClassNames().contains("com.widgets.Customer"));
    }
View Full Code Here

                .getResourceAsStream("xml-samples/persistence-schema-headers.xml");
        Collection<JpaUnit> units = parser.getPersistenceUnits(new InputSource(in), root);

        assertEquals(1, units.size());

        JpaUnit info = (JpaUnit) units.iterator().next();

        assertEquals("OrderManagement", info.getPersistenceUnitName());

        // JTA is the default when type is ommitted
        assertEquals(PersistenceUnitTransactionType.JTA, info.getTransactionType());
        assertEquals(root, info.getPersistenceUnitRootUrl());
        assertTrue(info.getDescription().startsWith("This unit manages orders"));
        assertEquals("jdbc/MyOrderDB", info.getProperties().getProperty(
                Provider.JTA_DATA_SOURCE_PROPERTY));

        assertEquals(1, info.getMappingFileNames().size());
        assertTrue(info.getMappingFileNames().contains("ormap.xml"));

        assertEquals(2, info.getManagedClassNames().size());
        assertTrue(info.getManagedClassNames().contains("com.widgets.Order"));
        assertTrue(info.getManagedClassNames().contains("com.widgets.Customer"));
    }
View Full Code Here

        assertEquals(3, units.size());

        Iterator<JpaUnit> it = units.iterator();
        for (int i = 1; i <= 3; i++) {
            JpaUnit info = it.next();

            assertEquals("Unit" + i, info.getPersistenceUnitName());
            assertEquals(root, info.getPersistenceUnitRootUrl());
            assertNull(info.getDescription());
            assertTrue(info.getProperties().isEmpty());

            assertEquals(0, info.getMappingFileNames().size());
            assertEquals(0, info.getManagedClassNames().size());
        }
    }
View Full Code Here

                .getResourceAsStream("xml-samples/persistence3.xml");
        Collection<JpaUnit> units = parser.getPersistenceUnits(new InputSource(in), root);

        assertEquals(1, units.size());

        JpaUnit info = units.iterator().next();

        assertEquals("OrderManagement4", info.getPersistenceUnitName());
        assertEquals(PersistenceUnitTransactionType.RESOURCE_LOCAL, info
                .getTransactionType());
        assertEquals(root, info.getPersistenceUnitRootUrl());
        assertEquals("jdbc/MyDB", info.getProperties().getProperty(
                Provider.NON_JTA_DATA_SOURCE_PROPERTY));

        assertEquals(1, info.getMappingFileNames().size());
        assertTrue(info.getMappingFileNames().contains("order-mappings.xml"));

        assertEquals(3, info.getManagedClassNames().size());
        assertTrue(info.getManagedClassNames().contains("com.acme.Order"));
        assertTrue(info.getManagedClassNames().contains("com.acme.Customer"));
        assertTrue(info.getManagedClassNames().contains("com.acme.Item"));

        assertTrue(info.excludeUnlistedClasses());
    }
View Full Code Here

                .getResourceAsStream("xml-samples/persistence-schema-headers.xml");
        Collection<JpaUnit> units = parser.getPersistenceUnits(new InputSource(in), root);

        assertEquals(1, units.size());

        JpaUnit info = units.iterator().next();

        assertEquals("OrderManagement", info.getPersistenceUnitName());

        // JTA is the default when type is omitted
        assertEquals(PersistenceUnitTransactionType.JTA, info.getTransactionType());
        assertEquals(root, info.getPersistenceUnitRootUrl());
        assertTrue(info.getDescription().startsWith("This unit manages orders"));
        assertEquals("jdbc/MyOrderDB", info.getProperties().getProperty(
                Provider.JTA_DATA_SOURCE_PROPERTY));

        assertEquals(1, info.getMappingFileNames().size());
        assertTrue(info.getMappingFileNames().contains("ormap.xml"));

        assertEquals(2, info.getManagedClassNames().size());
        assertTrue(info.getManagedClassNames().contains("com.widgets.Order"));
        assertTrue(info.getManagedClassNames().contains("com.widgets.Customer"));
    }
View Full Code Here

TOP

Related Classes of org.apache.cayenne.jpa.JpaUnit

Copyright © 2018 www.massapicom. 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.