コード例 #1
0
  @Test
  public void testSetEntryNumbersForNewEntriesHalfAutomatically() {
    final OrderModel order = createNewOrder();

    modelService.save(order);
    final List<AbstractOrderEntryModel> oldEntries = order.getEntries();

    Assert.assertEquals(Integer.valueOf(0), oldEntries.get(0).getEntryNumber());
    Assert.assertEquals(Integer.valueOf(1), oldEntries.get(1).getEntryNumber());
    Assert.assertEquals(Integer.valueOf(2), oldEntries.get(2).getEntryNumber());
    Assert.assertEquals(Integer.valueOf(3), oldEntries.get(3).getEntryNumber());

    final OrderEntryModel entry1 = createTestOrderEntry(order);
    entry1.setEntryNumber(5);
    final OrderEntryModel entry2 = createTestOrderEntry(order);
    entry2.setEntryNumber(4);
    final OrderEntryModel entry3 = createTestOrderEntry(order);
    final OrderEntryModel entry4 = createTestOrderEntry(order);

    modelService.saveAll(entry1, entry2, entry3, entry4);
    Assert.assertEquals(Integer.valueOf(5), entry1.getEntryNumber());
    Assert.assertEquals(Integer.valueOf(4), entry2.getEntryNumber());
    Assert.assertEquals(Integer.valueOf(6), entry3.getEntryNumber());
    Assert.assertEquals(Integer.valueOf(7), entry4.getEntryNumber());
  }
コード例 #2
0
 private OrderEntryModel createTestOrderEntry(final OrderModel order) {
   final OrderEntryModel entry1 = modelService.create(OrderEntryModel.class);
   entry1.setOrder(order);
   entry1.setQuantity(Long.valueOf(1));
   entry1.setUnit(productService.getOrderableUnit(product1));
   entry1.setProduct(product1);
   return entry1;
 }
コード例 #3
0
  @Test
  public void testSetEntryNumbersForAdditionalEntries() {
    final OrderModel order = createNewOrder();

    modelService.save(order);
    final List<AbstractOrderEntryModel> oldEntries = order.getEntries();

    Assert.assertEquals(Integer.valueOf(0), oldEntries.get(0).getEntryNumber());
    Assert.assertEquals(Integer.valueOf(1), oldEntries.get(1).getEntryNumber());
    Assert.assertEquals(Integer.valueOf(2), oldEntries.get(2).getEntryNumber());
    Assert.assertEquals(Integer.valueOf(3), oldEntries.get(3).getEntryNumber());

    final OrderEntryModel entry1 = createTestOrderEntry(order);
    final OrderEntryModel entry2 = createTestOrderEntry(order);
    modelService.saveAll(entry1, entry2);
    Assert.assertEquals(Integer.valueOf(4), entry1.getEntryNumber());
    Assert.assertEquals(Integer.valueOf(5), entry2.getEntryNumber());
  }
コード例 #4
0
  private OrderModel createNewOrder() {
    final OrderModel order = modelService.create(OrderModel.class);

    final UserModel user = userService.getCurrentUser();

    order.setUser(user);

    order.setCurrency(commonI18NService.getBaseCurrency());
    order.setDate(new java.util.Date());
    order.setNet(Boolean.FALSE);

    final OrderEntryModel entry1 = modelService.create(OrderEntryModel.class);
    entry1.setOrder(order);
    entry1.setQuantity(Long.valueOf(1));
    entry1.setUnit(productService.getOrderableUnit(product1));
    entry1.setProduct(product1);
    entry1.setEntryNumber(Integer.valueOf(0));

    final OrderEntryModel entry2 = modelService.create(OrderEntryModel.class);
    entry2.setOrder(order);
    entry2.setQuantity(Long.valueOf(1));
    entry2.setUnit(productService.getOrderableUnit(product2));
    entry2.setProduct(product2);
    entry2.setEntryNumber(Integer.valueOf(1));

    final OrderEntryModel entry3 = modelService.create(OrderEntryModel.class);
    entry3.setOrder(order);
    entry3.setQuantity(Long.valueOf(1));
    entry3.setUnit(productService.getOrderableUnit(product3));
    entry3.setProduct(product3);
    entry3.setEntryNumber(Integer.valueOf(2));

    final OrderEntryModel entry4 = modelService.create(OrderEntryModel.class);
    entry4.setOrder(order);
    entry4.setQuantity(Long.valueOf(1));
    entry4.setUnit(productService.getOrderableUnit(product4));
    entry4.setProduct(product4);
    entry4.setEntryNumber(Integer.valueOf(3));

    order.setEntries((List) Arrays.asList(entry1, entry2, entry3, entry4));

    return order;
  }