Package cz.muni.fi.pa165.stis.entity

Examples of cz.muni.fi.pa165.stis.entity.Order


    /**
     * Test of get method, of class OrderDAO.
     */
    @Test
    public void testGet() {
        Order o = newOrder(customer, null, null, null, extraServices, tyres, BigDecimal.valueOf(124.66));
        dao.create(o);
        //
        Long id = null;
        try {
            dao.get(id);
            fail("Id null and didn't throw exception");
        } catch (DataAccessException ex) {
            //ok
        } catch (Exception ex) {
            fail("Id null and didn't throw appropriate exception");
        }
        Order o2 = dao.get(o.getId());
        assertNotNull("Order is null", o2);
        assertEquals("Orders are not the same", o2, o);
        assertDeepEquals(o2, o);
        //
        Order o3 = dao.get(o.getId() + 1); // shouldn't exist
        assertNull("Order is not null", o3);
    }
View Full Code Here


     * Test of update method, of class OrderDAO.
     */
    @Test
    public void testUpdate() {
        Long oId;
        Order o = newOrder(customer, null, null, null, extraServices, tyres, BigDecimal.valueOf(2690.9));
        dao.create(o);
        oId = o.getId();
        o.setId(null);
        //
        try {
            dao.update(null);
            fail("Order null and didn't throw exception");
        } catch (DataAccessException ex) {
            //ok
        } catch (Exception ex) {
            fail("Order null and didn't throw appropriate exception");
        }
        try {
            dao.update(o);
            fail("Order ID null and didn't throw exception");
        } catch (DataAccessException ex) {
            //ok
        } catch (Exception ex) {
            fail("Order ID null and didn't throw appropriate exception");
        }
        //
        o.setId(oId);
        Date d = newDate("22.1.2010 22:15:00");
        o.setOrderNewDate(d);
        dao.update(o);
        //
        Order o2 = dao.get(o.getId());
        assertEquals("Orders are not the same", o2, o);
        assertDeepEquals(o2, o);
        //
        // test tyre remove and add
        o.getTyres().remove(TyrePosition.FRONT_LEFT);
        Tyre t = newTyre(12D, "AJ22", "BRPL", "Matador", BigDecimal.valueOf(77.7));
        tyreDAO.create(t);
        o.getTyres().put(TyrePosition.REAR_RIGHT, t);
        dao.update(o);
        //
        Order o3 = dao.get(o.getId());
        assertEquals("Orders are not the same", o3, o);
        assertDeepEquals(o3, o);
        //
        // test extra services remove and add
        o.getExtraServices().remove(o.getExtraServices().iterator().next());
        ExtraService es = newExtraService("Baking pastery", "You wouldn't drive hungry!", BigDecimal.ZERO);
        extraServiceDAO.create(es);
        o.getExtraServices().add(es);
        dao.update(o);
        //
        Order o4 = dao.get(o.getId());
        assertEquals("Orders are not the same", o4, o);
        assertDeepEquals(o4, o);
    }
View Full Code Here

    /**
     * Test of remove method, of class OrderDAO.
     */
    @Test
    public void testRemove() {
        Order o = newOrder(customer, null, null, null, extraServices, tyres, BigDecimal.valueOf(21.4));
        dao.create(o);
        //
        try {
            dao.remove(null);
            fail("Order null and didn't throw exception");
        } catch (DataAccessException ex) {
            //ok
        } catch (Exception ex) {
            fail("Order null and didn't throw appropriate exception");
        }
        try {
            dao.remove(new Order());
            fail("Order ID null and didn't throw exception");
        } catch (DataAccessException ex) {
            // ok
        } catch (Exception ex) {
            fail("Order ID null and didn't throw appropriate exception");
        }
        try {
            Order ord = new Order();
            ord.setId(-1L);
            dao.remove(ord);
            fail("Shouldn't remove non-existent entity");
        } catch (DataAccessException ex) {
            //ok
        } catch (Exception ex) {
            fail("Non existent order - should throw appropriate exception");
        }
        //
        dao.remove(o);
        Order o2 = dao.get(o.getId());
        assertNull("Found order that shouldn't be there", o2);
    }
View Full Code Here

    /**
     * Test of findByCustomer method, of class OrderDAO.
     */
    @Test
    public void testFindByCustomer() {
        Order o1 = newOrder(customer, null, null, null, extraServices, tyres, BigDecimal.valueOf(223));
        Order o2 = newOrder(customer, null, null, null, new HashSet<ExtraService>(), tyres, BigDecimal.valueOf(221.5));
        List<Order> os = Arrays.asList(new Order[]{o1, o2});
        for (Order o : os) {
            dao.create(o);
        }
        //
View Full Code Here

        return c;
    }
   
    private static Order newOrder(Customer c, Date orderNewDate, Date orderServicedDate,
            Date orderPaidDate, Set<ExtraService> extraServices, Map<TyrePosition, Tyre> tyres, BigDecimal totalPrice) {
        Order o = new Order();
        o.setCustomer(c);
        o.setOrderNewDate(orderNewDate);
        o.setOrderServicedDate(orderServicedDate);
        o.setOrderPaidDate(orderPaidDate);
        o.setTyres(tyres);
        o.setExtraServices(extraServices);
        o.setTotalPrice(totalPrice);
       
        return o;
    }
View Full Code Here

        }
        if (order.getId() == null) {
            throw new IllegalArgumentException("order.id is null");
        }

        Order toRemove = entityManager.find(Order.class, order.getId());
        if (toRemove == null) {
            throw new IllegalArgumentException("given extraService doesn't exist");
        }
        entityManager.remove(toRemove);
    }
View Full Code Here

            throw new IllegalArgumentException("order is null");
        }
        if (order.getId() != null) {
            throw new IllegalArgumentException("order.id is not null");
        }
        Order ord = mapper.map(order, Order.class);
        orderDAO.create(ord);
        order.setId(ord.getId());
    }
View Full Code Here

    @Override
    public OrderTO get(Long id) {
        if (id == null) {
            throw new IllegalArgumentException("id is null");
        }
        Order o = orderDAO.get(id);
        if (o == null) {
            return null;
        }
        return mapper.map(o, OrderTO.class);
    }
View Full Code Here

            throw new IllegalArgumentException("order is null");
        }
        if (order.getId() == null) {
            throw new IllegalArgumentException("order.id is null");
        }
        Order ord = mapper.map(order, Order.class);
        orderDAO.update(ord);
    }
View Full Code Here

            throw new IllegalArgumentException("order is null");
        }
        if (order.getId() == null) {
            throw new IllegalArgumentException("order.id is null");
        }
        Order ord = mapper.map(order, Order.class);
        orderDAO.remove(ord);
    }
View Full Code Here

TOP

Related Classes of cz.muni.fi.pa165.stis.entity.Order

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.