@Test
  @Ignore("FIXME pending review after rename to libreplan")
  public void testAddingOrderElement() {
    final Order order = createValidOrder();
    orderModel.setPlanningState(createPlanningStateFor(order));
    OrderLineGroup container =
        adHocTransaction.runOnTransaction(
            new IOnTransaction<OrderLineGroup>() {
              @Override
              public OrderLineGroup execute() {
                return OrderLineGroup.create();
              }
            });
    order.add(container);
    container.setName("bla");
    container.setCode("code-" + UUID.randomUUID());
    OrderLine leaf = OrderLine.create();
    leaf.setName("leaf");
    leaf.setCode("code-" + UUID.randomUUID());
    container.add(leaf);
    HoursGroup hoursGroup = HoursGroup.create(leaf);
    hoursGroup.setCode("hoursGroupName");
    hoursGroup.setWorkingHours(3);
    leaf.addHoursGroup(hoursGroup);
    orderModel.save();
    adHocTransaction.runOnTransaction(
        new IOnTransaction<Void>() {

          @Override
          public Void execute() {
            try {
              Order reloaded = orderDAO.find(order.getId());
              assertFalse(order == reloaded);
              assertThat(reloaded.getOrderElements().size(), equalTo(1));
              OrderLineGroup containerReloaded =
                  (OrderLineGroup) reloaded.getOrderElements().get(0);
              assertThat(containerReloaded.getHoursGroups().size(), equalTo(1));
              assertThat(containerReloaded.getChildren().size(), equalTo(1));
              OrderElement leaf = containerReloaded.getChildren().get(0);
              assertThat(leaf.getHoursGroups().size(), equalTo(1));
              orderModel.remove(order);
            } catch (InstanceNotFoundException e) {
              throw new RuntimeException(e);
            }
            return null;
          }
        });
  }
  @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);
  }