@Test @Ignore("FIXME pending review after rename to libreplan") public void testManyToManyHoursGroupCriterionMapping() { givenCriterion(); final Order order = createValidOrder(); orderModel.setPlanningState(createPlanningStateFor(order)); OrderLine orderLine = OrderLine.create(); orderLine.setName("Order element"); orderLine.setCode("000000000"); order.add(orderLine); HoursGroup hoursGroup = HoursGroup.create(orderLine); hoursGroup.setCode("hoursGroupName"); hoursGroup.setWorkingHours(10); HoursGroup hoursGroup2 = HoursGroup.create(orderLine); hoursGroup2.setCode("hoursGroupName2"); hoursGroup2.setWorkingHours(5); orderLine.addHoursGroup(hoursGroup); // orderLine.addHoursGroup(hoursGroup2); CriterionRequirement criterionRequirement = DirectCriterionRequirement.create(criterion); hoursGroup.addCriterionRequirement(criterionRequirement); // hoursGroup2.addCriterionRequirement(criterionRequirement); orderModel.save(); adHocTransaction.runOnTransaction( new IOnTransaction<Void>() { @Override public Void execute() { try { sessionFactory.getCurrentSession().flush(); Order reloaded = orderDAO.find(order.getId()); List<OrderElement> orderElements = reloaded.getOrderElements(); assertThat(orderElements.size(), equalTo(1)); List<HoursGroup> hoursGroups = orderElements.get(0).getHoursGroups(); assertThat(hoursGroups.size(), equalTo(1)); Set<CriterionRequirement> criterionRequirements = hoursGroups.get(0).getCriterionRequirements(); assertThat(criterionRequirements.size(), equalTo(1)); Set<Criterion> criterions = hoursGroups.get(0).getValidCriterions(); assertThat(criterions.size(), equalTo(1)); } catch (InstanceNotFoundException e) { throw new RuntimeException(e); } return null; } }); }
private OrderLine createValidLeaf(String parameter) { OrderLine result = OrderLine.create(); result.setName(parameter); result.setCode("code-" + UUID.randomUUID()); HoursGroup hoursGroup = HoursGroup.create(result); hoursGroup.setCode("hoursGroupCode-" + UUID.randomUUID()); hoursGroup.setWorkingHours(0); result.addHoursGroup(hoursGroup); return result; }
@Test(expected = ValidationException.class) @Transactional @Ignore("FIXME pending review after rename to libreplan") public void testAtLeastOneHoursGroup() { Order order = createValidOrder(); orderModel.setPlanningState(createPlanningStateFor(order)); OrderLine orderLine = OrderLine.create(); orderLine.setName(randomize("foo" + new Random().nextInt())); orderLine.setCode(randomize("000000000")); order.add(orderLine); orderModel.save(); }
@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 @Transactional public void ifAnOrderLineIsScheduledItsTypeChanges() { Order order = givenOrderFromPrepareForCreate(); OrderElement line = OrderLine.createOrderLineWithUnfixedPercentage(20); line.useSchedulingDataFor(order.getCurrentOrderVersion()); line.getSchedulingState().unschedule(); order.add(line); assertFalse(order.getSchedulingState().isSomewhatScheduled()); line.getSchedulingState().schedule(); assertTrue(order.getSchedulingState().isSomewhatScheduled()); }
@Test @Transactional @Ignore("FIXME pending review after rename to libreplan") public void createOrderWithScheduledOrderLine() { Order order = givenOrderFromPrepareForCreate(); OrderElement line = OrderLine.createOrderLineWithUnfixedPercentage(20); order.add(line); line.setName(UUID.randomUUID().toString()); line.setCode(UUID.randomUUID().toString()); assert line.getSchedulingState().isSomewhatScheduled(); orderModel.save(); assertTrue(orderDAO.exists(order.getId())); TaskSource lineTaskSource = line.getTaskSource(); assertTrue(taskSourceDAO.exists(lineTaskSource.getId())); }