Search in sources :

Example 1 with House

use of org.apache.deltaspike.data.test.ee7.domain.House in project deltaspike by apache.

the class HouseRepositoryTest method should_run_modifying_in_transaction.

@Test
@InSequence(1)
public void should_run_modifying_in_transaction() throws Exception {
    House house = repository.findByName("Bellevue");
    assertNotNull(house);
    assertNotNull(house.getId());
    assertEquals("Bellevue", house.getName());
    assertTrue(puu.isLoaded(house, "flats"));
    assertFalse(puu.isLoaded(house, "garages"));
}
Also used : House(org.apache.deltaspike.data.test.ee7.domain.House) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Example 2 with House

use of org.apache.deltaspike.data.test.ee7.domain.House in project deltaspike by apache.

the class HouseRepositoryTest method shouldNotLoadLazyAssociationsWithoutGraph.

@Test
@InSequence(2)
public void shouldNotLoadLazyAssociationsWithoutGraph() throws Exception {
    House house = repository.findOptionalByName("Bellevue");
    assertNotNull(house);
    PersistenceUnitUtil puu = entityManager.getEntityManagerFactory().getPersistenceUnitUtil();
    assertFalse(puu.isLoaded(house, "flats"));
    assertFalse(puu.isLoaded(house, "garages"));
}
Also used : PersistenceUnitUtil(javax.persistence.PersistenceUnitUtil) House(org.apache.deltaspike.data.test.ee7.domain.House) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Example 3 with House

use of org.apache.deltaspike.data.test.ee7.domain.House in project deltaspike by apache.

the class HouseRepositoryTest method should_build_dynamic_graph_from_paths.

@Test
@InSequence(5)
public void should_build_dynamic_graph_from_paths() throws Exception {
    House house = repository.fetchByNameWithDynamicGraph("Bellevue");
    assertNotNull(house);
    assertTrue(puu.isLoaded(house, "flats"));
    assertTrue(puu.isLoaded(house, "garages"));
    assertEquals(2, house.getFlats().size());
    assertEquals(2, house.getGarages().size());
    Flat flat = house.getFlats().get(0);
    assertFalse(puu.isLoaded(flat, "tenants"));
}
Also used : Flat(org.apache.deltaspike.data.test.ee7.domain.Flat) House(org.apache.deltaspike.data.test.ee7.domain.House) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Example 4 with House

use of org.apache.deltaspike.data.test.ee7.domain.House in project deltaspike by apache.

the class HouseRepositoryTest method init.

@Before
public void init() throws Exception {
    puu = entityManager.getEntityManagerFactory().getPersistenceUnitUtil();
    // TODO this causes a tx rollback on GlassFish 4 when run in a UserTransaction
    if (repository.count() == 0) {
        tx.begin();
        House house = new House();
        Flat flat1 = new Flat();
        flat1.setName("Flat 1");
        flat1.setHouse(house);
        Tenant alice = new Tenant();
        alice.setName("Alice");
        alice.setFlat(flat1);
        Tenant bob = new Tenant();
        bob.setName("Bob");
        bob.setFlat(flat1);
        Tenant charlie = new Tenant();
        charlie.setName("Charlie");
        charlie.setFlat(flat1);
        flat1.setTenants(Arrays.asList(alice, bob, charlie));
        Flat flat2 = new Flat();
        flat2.setName("Flat 2");
        flat2.setHouse(house);
        Garage garageA = new Garage();
        garageA.setName("Garage A");
        garageA.setHouse(house);
        Garage garageB = new Garage();
        garageB.setName("Garage B");
        garageB.setHouse(house);
        house.setName("Bellevue");
        house.setFlats(Arrays.asList(flat1, flat2));
        house.setGarages(Arrays.asList(garageA, garageB));
        entityManager.persist(house);
        tx.commit();
    }
}
Also used : Tenant(org.apache.deltaspike.data.test.ee7.domain.Tenant) Garage(org.apache.deltaspike.data.test.ee7.domain.Garage) Flat(org.apache.deltaspike.data.test.ee7.domain.Flat) House(org.apache.deltaspike.data.test.ee7.domain.House) Before(org.junit.Before)

Example 5 with House

use of org.apache.deltaspike.data.test.ee7.domain.House in project deltaspike by apache.

the class HouseRepositoryTest method should_build_dynamic_graph_from_composite_paths.

@Test
@InSequence(6)
public void should_build_dynamic_graph_from_composite_paths() throws Exception {
    House house = repository.fetchByNameWithFlatTenants("Bellevue");
    assertNotNull(house);
    assertTrue(puu.isLoaded(house, "flats"));
    assertTrue(puu.isLoaded(house, "garages"));
    assertEquals(2, house.getFlats().size());
    assertEquals(2, house.getGarages().size());
    Flat flat = house.getFlats().get(0);
    assertTrue(puu.isLoaded(flat, "tenants"));
    assertEquals(3, flat.getTenants().size());
}
Also used : Flat(org.apache.deltaspike.data.test.ee7.domain.Flat) House(org.apache.deltaspike.data.test.ee7.domain.House) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Aggregations

House (org.apache.deltaspike.data.test.ee7.domain.House)6 InSequence (org.jboss.arquillian.junit.InSequence)5 Test (org.junit.Test)5 Flat (org.apache.deltaspike.data.test.ee7.domain.Flat)3 PersistenceUnitUtil (javax.persistence.PersistenceUnitUtil)1 Garage (org.apache.deltaspike.data.test.ee7.domain.Garage)1 Tenant (org.apache.deltaspike.data.test.ee7.domain.Tenant)1 Before (org.junit.Before)1