Search in sources :

Example 1 with Company

use of org.jboss.as.test.integration.jpa.hibernate.entity.Company in project wildfly by wildfly.

the class EntityTestCase method testManyToOne.

@Test
@InSequence(2)
public void testManyToOne() throws Exception {
    EntityTest test = lookup("EntityTest", EntityTest.class);
    Flight f = test.manyToOneCreate();
    Flight f2 = test.findFlightById(f.getId());
    assertEquals(f.getId(), new Long(1));
    assertEquals(f.getName(), f2.getName());
    assertEquals(f.getCompany().getName(), f2.getCompany().getName());
    Company c = test.findCompanyById(f.getCompany().getId());
    assertNotNull("Company has one flight.", c.getFlights());
    assertEquals(f.getCompany().getFlights().size(), c.getFlights().size());
}
Also used : Company(org.jboss.as.test.integration.jpa.hibernate.entity.Company) Flight(org.jboss.as.test.integration.jpa.hibernate.entity.Flight) EntityTest(org.jboss.as.test.integration.jpa.hibernate.EntityTest) EntityTest(org.jboss.as.test.integration.jpa.hibernate.EntityTest) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Example 2 with Company

use of org.jboss.as.test.integration.jpa.hibernate.entity.Company in project wildfly by wildfly.

the class EntityTest method manyToOneCreate.

public Flight manyToOneCreate() throws Exception {
    Flight f = new Flight();
    f.setName("Flight number one");
    f.setId(new Long(1));
    Company comp = new Company();
    comp.setName("Airline 1");
    f.setCompany(comp);
    session.save(f);
    return f;
}
Also used : Company(org.jboss.as.test.integration.jpa.hibernate.entity.Company) Flight(org.jboss.as.test.integration.jpa.hibernate.entity.Flight)

Example 3 with Company

use of org.jboss.as.test.integration.jpa.hibernate.entity.Company in project wildfly by wildfly.

the class EntityTest method manyToManyCreate.

public void manyToManyCreate() throws Exception {
    Flight f1 = findFlightById(new Long(1));
    Flight f2 = new Flight();
    f2.setId(new Long(2));
    f2.setName("Flight two");
    Company us = new Company();
    us.setName("Airline 2");
    f2.setCompany(us);
    Set<Customer> customers1 = new HashSet<Customer>();
    Set<Customer> customers2 = new HashSet<Customer>();
    Customer c1 = new Customer();
    c1.setName("John");
    customers1.add(c1);
    Customer c2 = new Customer();
    c2.setName("Tom");
    customers2.add(c2);
    Customer c3 = new Customer();
    c3.setName("Pete");
    customers2.add(c3);
    f1.setCustomers(customers1);
    f2.setCustomers(customers2);
    session.save(c1);
    session.save(c2);
    session.save(c3);
    session.save(f2);
}
Also used : Company(org.jboss.as.test.integration.jpa.hibernate.entity.Company) Customer(org.jboss.as.test.integration.jpa.hibernate.entity.Customer) Flight(org.jboss.as.test.integration.jpa.hibernate.entity.Flight) HashSet(java.util.HashSet)

Aggregations

Company (org.jboss.as.test.integration.jpa.hibernate.entity.Company)3 Flight (org.jboss.as.test.integration.jpa.hibernate.entity.Flight)3 HashSet (java.util.HashSet)1 InSequence (org.jboss.arquillian.junit.InSequence)1 EntityTest (org.jboss.as.test.integration.jpa.hibernate.EntityTest)1 Customer (org.jboss.as.test.integration.jpa.hibernate.entity.Customer)1 Test (org.junit.Test)1