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

    // take out entries
    final List<AbstractOrderEntryModel> entries = newOne.getEntries();
    newOne.setEntries(null);

    modelService.save(newOne);

    Assert.assertFalse(modelService.isNew(newOne));
    Assert.assertEquals(Collections.EMPTY_LIST, newOne.getEntries());

    Assert.assertTrue(modelService.isNew(entries.get(0)));
    Assert.assertTrue(modelService.isNew(entries.get(1)));
    Assert.assertTrue(modelService.isNew(entries.get(2)));
    Assert.assertTrue(modelService.isNew(entries.get(3)));

    // now save in reverse order
    AbstractOrderEntryModel entry = entries.get(3);
    modelService.save(entry);
    Assert.assertEquals(Integer.valueOf(3), entry.getEntryNumber());

    entry = entries.get(2);
    modelService.save(entry);
    Assert.assertEquals(Integer.valueOf(2), entry.getEntryNumber());

    entry = entries.get(1);
    modelService.save(entry);
    Assert.assertEquals(Integer.valueOf(1), entry.getEntryNumber());

    entry = entries.get(0);
    modelService.save(entry);
    Assert.assertEquals(Integer.valueOf(0), entry.getEntryNumber());

    modelService.refresh(newOne);

    Assert.assertFalse(modelService.isNew(newOne));
    Assert.assertFalse(modelService.isNew(entries.get(0)));
    Assert.assertFalse(modelService.isNew(entries.get(1)));
    Assert.assertFalse(modelService.isNew(entries.get(2)));
    Assert.assertFalse(modelService.isNew(entries.get(3)));

    assertEntriesOrder(newOne);
  }
コード例 #2
0
 private void displayEntries(final OrderModel order, final String prefix) {
   System.out.println(prefix + "Order@" + System.identityHashCode(order));
   final List<AbstractOrderEntryModel> entries = order.getEntries();
   if (entries != null && !entries.isEmpty()) {
     for (final AbstractOrderEntryModel entry : entries) {
       System.out.println(
           prefix
               + "Entry@"
               + System.identityHashCode(entry)
               + ", Entry.PK="
               + entry.getPk()
               + ", Entry.EntryNumber="
               + entry.getEntryNumber()
               + ", Entry.Product.PK="
               + entry.getProduct().getPk()
               + ", Entry.Product.Code="
               + entry.getProduct().getCode());
     }
   }
 }