Search in sources :

Example 1 with Customer

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

the class EntityTest method testCustomerByIdQuery.

public Customer testCustomerByIdQuery() {
    Customer c = new Customer();
    c.setName("Peter");
    session.save(c);
    session.flush();
    return (Customer) session.getNamedQuery("customerById").setParameter("id", c.getId()).uniqueResult();
}
Also used : Customer(org.jboss.as.test.integration.jpa.hibernate.entity.Customer)

Example 2 with Customer

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

the class EntityTest method changeCustomer.

public void changeCustomer(Long id, String name) {
    Customer c = session.load(Customer.class, id);
    c.setName(name);
}
Also used : Customer(org.jboss.as.test.integration.jpa.hibernate.entity.Customer)

Example 3 with Customer

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

the class EntityTest method oneToManyCreate.

public Customer oneToManyCreate() throws Exception {
    Ticket t = new Ticket();
    t.setNumber("111");
    Customer c = new Customer();
    Set<Ticket> tickets = new HashSet<Ticket>();
    tickets.add(t);
    t.setCustomer(c);
    c.setTickets(tickets);
    session.save(c);
    return c;
}
Also used : Ticket(org.jboss.as.test.integration.jpa.hibernate.entity.Ticket) Customer(org.jboss.as.test.integration.jpa.hibernate.entity.Customer) HashSet(java.util.HashSet)

Example 4 with Customer

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

the class EntityTestCase method testNamedQueries.

@Test
@InSequence(4)
public void testNamedQueries() throws Exception {
    EntityTest test = lookup("EntityTest", EntityTest.class);
    int count = test.testAllCustomersQuery();
    assertEquals("Number returned for allCustomers query", 4, count);
    Customer c = test.testCustomerByIdQuery();
    assertNotNull("One object should be returned by customerById query", c);
}
Also used : Customer(org.jboss.as.test.integration.jpa.hibernate.entity.Customer) 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 5 with Customer

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

the class EntityTestCase method testFlush.

@Test
@InSequence(5)
public void testFlush() throws Exception {
    EntityTest test = lookup("EntityTest", EntityTest.class);
    Customer c = test.createCustomer("Thomas");
    test.changeCustomer(c.getId(), "George");
    Customer c2 = test.findCustomerById(c.getId());
    assertEquals("George", c2.getName());
}
Also used : Customer(org.jboss.as.test.integration.jpa.hibernate.entity.Customer) 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)

Aggregations

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