Ejemplo n.º 1
0
 @Test
 @Transactional
 @Ignore("FIXME pending review after rename to libreplan")
 public void testCreationUsingPrepareForCreate() {
   Order order = givenOrderFromPrepareForCreate();
   orderModel.save();
   assertTrue(orderDAO.exists(order.getId()));
 }
  @Test
  @Ignore("Only working if you have a JIRA server configured")
  public void testSyncJiraTimesheet() throws ConnectorException {

    Order order = givenOrderWithValidOrderLines();
    jiraTimesheetSynchronizer.syncJiraTimesheetWithJiraIssues(issues, order);
    assertTrue(order.getWorkReportLines(false).size() > 0);
  }
Ejemplo n.º 3
0
 @Test
 @Transactional
 @Ignore("FIXME pending review after rename to libreplan")
 public void testFind() throws InstanceNotFoundException {
   Order order = createValidOrder();
   orderModel.setPlanningState(createPlanningStateFor(order));
   orderModel.save();
   assertThat(orderDAO.find(order.getId()), notNullValue());
 }
Ejemplo n.º 4
0
  @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;
          }
        });
  }
Ejemplo n.º 5
0
 @Test
 @Transactional
 @Ignore("FIXME pending review after rename to libreplan")
 public void testCreation() throws ValidationException {
   Order order = createValidOrder();
   order.setCustomer(createValidExternalCompany());
   orderModel.setPlanningState(createPlanningStateFor(order));
   orderModel.save();
   assertTrue(orderDAO.exists(order.getId()));
 }
Ejemplo n.º 6
0
 @Test(expected = ValidationException.class)
 @Transactional
 @Ignore("FIXME pending review after rename to libreplan")
 public void shouldSendValidationExceptionIfEndDateIsBeforeThanStartingDate()
     throws ValidationException {
   Order order = createValidOrder();
   order.setDeadline(year(0));
   orderModel.setPlanningState(createPlanningStateFor(order));
   orderModel.save();
 }
Ejemplo n.º 7
0
 @Ignore("Test ignored until having the possibility to have a user " + "session from tests")
 @Test
 @Transactional
 public void testListing() {
   List<Order> list = orderModel.getOrders();
   Order order = createValidOrder();
   order.setCustomer(createValidExternalCompany());
   orderModel.setPlanningState(createPlanningStateFor(order));
   orderModel.save();
   assertThat(orderModel.getOrders().size(), equalTo(list.size() + 1));
 }
Ejemplo n.º 8
0
 @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()));
 }
 private Order givenValidOrderWithValidOrderLinesAlreadyStored() {
   Order order = givenOrder();
   jiraOrderElementSynchronizer.syncOrderElementsWithJiraIssues(issues, order);
   order.dontPoseAsTransientObjectAnymore();
   orderDAO.saveWithoutValidating(order);
   orderDAO.flush();
   try {
     return orderDAO.find(order.getId());
   } catch (InstanceNotFoundException e) {
     return null;
   }
 }
Ejemplo n.º 10
0
 @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());
 }
Ejemplo n.º 11
0
  @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();
  }
Ejemplo n.º 12
0
 @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()));
 }
Ejemplo n.º 13
0
  @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;
          }
        });
  }
  public ProjectStatusReportDTO(OrderElement orderElement, Order orderToAppendName) {
    code = orderElement.getCode();

    if (orderToAppendName != null) {
      name = orderElement.getName() + " (" + orderToAppendName.getName() + ")";
    } else {
      name = Util.getPrefixSpacesDependingOnDepth(orderElement) + orderElement.getName();
    }

    Integer estimatedHours = orderElement.getWorkHours();
    this.estimatedHours = estimatedHours != null ? EffortDuration.hours(estimatedHours) : null;

    TaskSource taskSource = orderElement.getTaskSource();
    if (taskSource != null) {
      plannedHours = taskSource.getTask().getSumOfAssignedEffort();
    }

    SumChargedEffort sumChargedEffort = orderElement.getSumChargedEffort();
    if (sumChargedEffort != null) {
      imputedHours = sumChargedEffort.getTotalChargedEffort();
    }

    setBudget(orderElement.getSubstractedBudget());

    setExpensesBudget(orderElement.getBudget());
    setResourcesBudget(orderElement.getResourcesBudget());
  }
Ejemplo n.º 15
0
 private Order givenOrderFromPrepareForCreate() {
   adHocTransaction.runOnAnotherReadOnlyTransaction(
       new IOnTransaction<Void>() {
         @Override
         public Void execute() {
           orderModel.prepareForCreate(mockDesktop());
           return null;
         }
       });
   Order order = orderModel.getOrder();
   order.setName("name");
   order.setCode("code");
   order.setInitDate(new Date());
   order.setCustomer(createValidExternalCompany());
   return order;
 }
  private Order givenValidOrderAlreadyStored() {
    Order order = Order.create();
    order.setCode(UUID.randomUUID().toString());
    order.setName("Order name " + UUID.randomUUID());
    order.setInitDate(new Date());
    order.setCalendar(configurationDAO.getConfiguration().getDefaultCalendar());
    OrderVersion version = setupVersionUsing(scenarioManager, order);
    order.useSchedulingDataFor(version);

    orderDAO.save(order);
    orderDAO.flush();
    try {
      return orderDAO.find(order.getId());
    } catch (InstanceNotFoundException e) {
      return null;
    }
  }
Ejemplo n.º 17
0
  private Order createValidOrder() {
    Order order = Order.create();
    order.setDescription("description");
    order.setInitDate(year(2000));
    order.setName("name");
    order.setResponsible("responsible");
    order.setCode("code-" + UUID.randomUUID());
    BaseCalendar calendar =
        adHocTransaction.runOnReadOnlyTransaction(
            new IOnTransaction<BaseCalendar>() {

              @Override
              public BaseCalendar execute() {
                BaseCalendar result =
                    configurationDAO.getConfigurationWithReadOnlyTransaction().getDefaultCalendar();
                BaseCalendarModel.forceLoadBaseCalendar(result);
                return result;
              }
            });
    order.setCalendar(calendar);
    return order;
  }
  @Test
  @Transactional
  public void validSubcontractedTaskData() {
    int previous = orderDAO.getOrders().size();

    String orderLineCode = "order-line-code";

    OrderElementDTO orderElementDTO = givenBasicOrderLineDTO(orderLineCode);
    ExternalCompany externalCompany = getClientExternalCompanySaved("Company", "company-nif");

    SubcontractedTaskDataDTO subcontractedTaskDataDTO = new SubcontractedTaskDataDTO();
    subcontractedTaskDataDTO.orderElementDTO = orderElementDTO;
    subcontractedTaskDataDTO.externalCompanyNif = externalCompany.getNif();

    String orderName = "Work description";
    String orderCustomerReference = "client-reference-code";
    BigDecimal orderBudget = new BigDecimal(1000).setScale(2);
    subcontractedTaskDataDTO.workDescription = orderName;
    subcontractedTaskDataDTO.subcontractedCode = orderCustomerReference;
    subcontractedTaskDataDTO.subcontractPrice = orderBudget;

    List<InstanceConstraintViolationsDTO> instanceConstraintViolationsList =
        subcontractService.subcontract(subcontractedTaskDataDTO).instanceConstraintViolationsList;
    assertThat(instanceConstraintViolationsList.size(), equalTo(0));

    assertThat(orderDAO.getOrders().size(), equalTo(previous + 1));

    Order order = orderDAO.getOrders().get(previous);
    assertNotNull(order.getCode());
    assertTrue(order.isCodeAutogenerated());
    assertNotNull(order.getExternalCode());
    assertThat(order.getExternalCode(), equalTo(orderLineCode));
    assertThat(order.getState(), equalTo(OrderStatusEnum.OUTSOURCED));
    assertThat(order.getWorkHours(), equalTo(0));
    assertThat(order.getCustomer().getId(), equalTo(externalCompany.getId()));
    assertThat(order.getName(), equalTo(orderName));
    assertThat(order.getCustomerReference(), equalTo(orderCustomerReference));
    assertThat(order.getTotalManualBudget(), equalTo(orderBudget));

    List<OrderElement> children = order.getChildren();
    assertThat(children.size(), equalTo(1));
    assertNull(children.get(0).getExternalCode());
  }
Ejemplo n.º 19
0
  @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);
  }
Ejemplo n.º 20
0
 public static OrderVersion setupVersionUsing(IScenarioManager scenarioManager, Order order) {
   Scenario current = scenarioManager.getCurrent();
   OrderVersion result = OrderVersion.createInitialVersion(current);
   order.setVersionForScenario(current, result);
   return result;
 }