@Test @Transactional @Ignore("FIXME pending review after rename to libreplan") public void testRemove() { Order order = createValidOrder(); orderModel.setPlanningState(createPlanningStateFor(order)); orderModel.save(); assertTrue(orderDAO.exists(order.getId())); orderModel.remove(order); assertFalse(orderDAO.exists(order.getId())); }
@Test @Ignore("FIXME pending review after rename to libreplan") public void testOrderPreserved() throws ValidationException, InstanceNotFoundException { final Order order = createValidOrder(); orderModel.setPlanningState(createPlanningStateFor(order)); final OrderElement[] containers = new OrderLineGroup[10]; for (int i = 0; i < containers.length; i++) { containers[i] = adHocTransaction.runOnTransaction( new IOnTransaction<OrderLineGroup>() { @Override public OrderLineGroup execute() { return OrderLineGroup.create(); } }); containers[i].setName("bla"); containers[i].setCode("code-" + UUID.randomUUID()); order.add(containers[i]); } OrderLineGroup container = (OrderLineGroup) containers[0]; final OrderElement[] orderElements = new OrderElement[10]; for (int i = 0; i < orderElements.length; i++) { OrderLine leaf = createValidLeaf("bla"); orderElements[i] = leaf; container.add(leaf); } for (int i = 1; i < containers.length; i++) { OrderLineGroup orderLineGroup = (OrderLineGroup) containers[i]; OrderLine leaf = createValidLeaf("foo"); orderLineGroup.add(leaf); } orderModel.save(); adHocTransaction.runOnTransaction( new IOnTransaction<Void>() { @Override public Void execute() { try { Order reloaded = orderDAO.find(order.getId()); List<OrderElement> elements = reloaded.getOrderElements(); for (OrderElement orderElement : elements) { assertThat( ((OrderLineGroup) orderElement).getIndirectAdvanceAssignments().size(), equalTo(2)); } for (int i = 0; i < containers.length; i++) { assertThat(elements.get(i).getId(), equalTo(containers[i].getId())); } OrderLineGroup container = (OrderLineGroup) reloaded.getOrderElements().iterator().next(); List<OrderElement> children = container.getChildren(); for (int i = 0; i < orderElements.length; i++) { assertThat(children.get(i).getId(), equalTo(orderElements[i].getId())); } for (int i = 1; i < containers.length; i++) { OrderLineGroup orderLineGroup = (OrderLineGroup) containers[i]; assertThat(orderLineGroup.getChildren().size(), equalTo(1)); } return null; } catch (Exception e) { throw new RuntimeException(e); } } }); orderModel.remove(order); }