Package org.jboss.as.test.integration.jpa.hibernate.entity

Examples of org.jboss.as.test.integration.jpa.hibernate.entity.Flight


    @Test
    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());
View Full Code Here


    public void testManyToMany() throws Exception {

        EntityTest test = lookup("EntityTest", EntityTest.class);
        test.manyToManyCreate();

        Flight f1 = test.findFlightById(new Long(1));
        assertTrue("Name read from Hibernate is Airline 1", f1.getCompany().getName().equals("Airline 1"));

        Flight f2 = test.findFlightById(new Long(2));
        assertTrue("Name read from Hibernate is Airline 1", f2.getCompany().getName().equals("Airline 2"));

        assertEquals(1, f1.getCustomers().size());
        assertEquals(2, f2.getCustomers().size());

    }
View Full Code Here

    @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());
View Full Code Here

    public void testManyToMany() throws Exception {

        EntityTest test = lookup("EntityTest", EntityTest.class);
        test.manyToManyCreate();

        Flight f1 = test.findFlightById(new Long(1));
        assertTrue("Name read from Hibernate is Airline 1", f1.getCompany().getName().equals("Airline 1"));

        Flight f2 = test.findFlightById(new Long(2));
        assertTrue("Name read from Hibernate is Airline 1", f2.getCompany().getName().equals("Airline 2"));

        assertEquals(1, f1.getCustomers().size());
        assertEquals(2, f2.getCustomers().size());

    }
View Full Code Here

        return c;
    }

    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;
    }
View Full Code Here

        return f;
    }

    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);
View Full Code Here

            try {
                String mode = req.getParameter("mode");

                if (mode.equals("write")) {
                    Flight f = new Flight();
                    f.setId(new Long(1));
                    f.setName("Flight number one");
                    em.merge(f);

                } else if (mode.equals("read")) {

                    Flight f = (Flight) em.find(Flight.class, new Long(1));
                    resp.setContentType("text/plain");
                    PrintWriter out = resp.getWriter();
                    out.print(f.getName());
                    out.close();
                }

            } catch (Exception e) {
                e.printStackTrace();
View Full Code Here

TOP

Related Classes of org.jboss.as.test.integration.jpa.hibernate.entity.Flight

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.