use of eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit in project dwoss by gg-net.
the class AssignmentController method dragAndDropHandling.
private void dragAndDropHandling() {
/**
* Start of the Drag an Drop from the unassigned units List.
*/
unassignedUnitsList.setOnDragDetected(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
ArrayList<UniqueUnit> selected = new ArrayList<>();
selected.addAll(unassignedUnitsList.getSelectionModel().getSelectedItems());
if (selected.isEmpty() || unitCollectionList.getSelectionModel().getSelectedItem() == null)
return;
Dragboard db = unassignedUnitsList.startDragAndDrop(TransferMode.ANY);
ClipboardContent content = new ClipboardContent();
content.put(df, selected);
db.setContent(content);
L.info("DnD of {} Units started", selected.size());
event.consume();
}
});
/**
* Handling the DragOver for only UniqueUnits with the right dataformat.
*/
unassignedUnitsList.setOnDragOver(new EventHandler<DragEvent>() {
@Override
public void handle(DragEvent event) {
if (event.getGestureSource() != unassignedUnitsList && event.getDragboard().hasContent(df)) {
event.acceptTransferModes(TransferMode.ANY);
}
event.consume();
}
});
/**
* Handling the Dropped UniqueUnit and saving it.
*/
unassignedUnitsList.setOnDragDropped(new EventHandler<DragEvent>() {
@Override
public void handle(final DragEvent event) {
Dragboard db = event.getDragboard();
if (db.hasContent(df)) {
List<UniqueUnit> dragged = (List<UniqueUnit>) db.getContent(df);
for (UniqueUnit draggedUnit : dragged) {
Optional.of(Dl.remote().lookup(UniqueUnitAgent.class).unsetUnitCollection(new PicoUnit(draggedUnit.getId(), "RefurbishedId=" + draggedUnit.getRefurbishId()))).filter(r -> {
if (!r.hasSucceded())
event.setDropCompleted(false);
return Ui.failure().handle(r);
}).ifPresent(c -> {
unassignedUnitsList.getItems().add(draggedUnit);
assignedUnitsList.getItems().remove(draggedUnit);
});
}
event.setDropCompleted(true);
} else {
event.setDropCompleted(false);
}
event.consume();
}
});
/**
* Start of the Drag an Drop from the assigned units List.
*/
assignedUnitsList.setOnDragDetected(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
List<UniqueUnit> selected = new ArrayList<>();
selected.addAll(assignedUnitsList.getSelectionModel().getSelectedItems());
if (selected.isEmpty())
return;
Dragboard db = assignedUnitsList.startDragAndDrop(TransferMode.ANY);
ClipboardContent content = new ClipboardContent();
content.put(df, selected);
db.setContent(content);
L.info("DnD of {} Units started", selected.size());
event.consume();
}
});
/**
* Handling the DragOver for only UniqueUnits with the right dataformat.
*/
assignedUnitsList.setOnDragOver(new EventHandler<DragEvent>() {
@Override
public void handle(DragEvent event) {
if (event.getGestureSource() != assignedUnitsList && event.getDragboard().hasContent(df)) {
event.acceptTransferModes(TransferMode.ANY);
}
event.consume();
}
});
/**
* Handling the Dropped UniqueUnit and saving it.
*/
assignedUnitsList.setOnDragDropped(new EventHandler<DragEvent>() {
@Override
public void handle(DragEvent event) {
Dragboard db = event.getDragboard();
if (db.hasContent(df)) {
List<UniqueUnit> dragged = (List<UniqueUnit>) db.getContent(df);
for (UniqueUnit draggedUnit : dragged) {
UnitCollection selectedCollection = unitCollectionList.getSelectionModel().getSelectedItem();
Optional.of(Dl.remote().lookup(UniqueUnitAgent.class).addToUnitCollection(new PicoUnit(draggedUnit.getId(), "RefurbishedId=" + draggedUnit.getRefurbishId()), selectedCollection.getId())).filter(r -> {
if (!r.hasSucceded())
event.setDropCompleted(false);
return Ui.failure().handle(r);
}).ifPresent(c -> {
assignedUnitsList.getItems().add(draggedUnit);
unassignedUnitsList.getItems().remove(draggedUnit);
event.setDropCompleted(true);
});
}
event.setDropCompleted(true);
} else {
event.setDropCompleted(false);
}
event.consume();
}
});
/**
* Handling the DragOver for only PicoProducts with the right dataformat.
*/
productList.setOnDragOver(new EventHandler<DragEvent>() {
@Override
public void handle(DragEvent event) {
if (event.getGestureSource() != productList && event.getDragboard().hasContent(ProductListController.PICO_PRODUCT_DATA_FORMAT)) {
event.acceptTransferModes(TransferMode.ANY);
}
event.consume();
}
});
/**
* Handling the Dropped PicoProduct
*/
productList.setOnDragDropped(new EventHandler<DragEvent>() {
@Override
public void handle(DragEvent event) {
Dragboard db = event.getDragboard();
boolean success = false;
if (db.hasContent(ProductListController.PICO_PRODUCT_DATA_FORMAT)) {
ArrayList<PicoProduct> products = (ArrayList<PicoProduct>) db.getContent(ProductListController.PICO_PRODUCT_DATA_FORMAT);
productList.getItems().addAll(products.stream().filter(p -> !productList.getItems().contains(p)).collect(Collectors.toList()));
success = true;
}
event.setDropCompleted(success);
event.consume();
}
});
}
use of eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit in project dwoss by gg-net.
the class RedTapeOperationAnnulationInvoiceIT method testCreditMemo.
@Test
public void testCreditMemo() throws UserInfoException {
// We need two stocks at least.
List<Stock> allStocks = stockGenerator.makeStocksAndLocations(2);
long customerId = customerGenerator.makeCustomer();
List<UniqueUnit> uus = receiptGenerator.makeUniqueUnits(4, true, true);
UniqueUnit uu1 = uus.get(0);
UniqueUnit uu2 = uus.get(1);
UniqueUnit uu3 = uus.get(2);
UniqueUnit uu4 = uus.get(3);
Product uuProduct1 = uu1.getProduct();
int stockIdOfUU1 = stockAgent.findStockUnitByUniqueUnitIdEager(uu1.getId()).getStock().getId();
int alternateStockId = allStocks.stream().map(Stock::getId).filter(id -> id != stockIdOfUU1).findFirst().orElseThrow(() -> new RuntimeException("No alternate StockId found, impossible"));
Dossier dos = redTapeWorker.create(customerId, true, "Me");
Document doc = dos.getActiveDocuments(DocumentType.ORDER).get(0);
assertThat(doc).overridingErrorMessage("Expected active document Order, got null. Dossier: " + dos.toMultiLine()).isNotNull();
Position batch = batch(uuProduct1);
Position shipping = shippingcost();
doc.append(unit(uu1));
doc.append(unit(uu2));
doc.append(unit(uu3));
doc.append(comment());
doc.append(service());
doc.append(batch);
doc.append(shipping);
// add units to LogicTransaction
unitOverseer.lockStockUnit(dos.getId(), uu1.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
unitOverseer.lockStockUnit(dos.getId(), uu2.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
unitOverseer.lockStockUnit(dos.getId(), uu3.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
unitOverseer.lockStockUnit(dos.getId(), uu4.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
doc = redTapeWorker.update(doc, null, "JUnit");
doc.add(Document.Condition.PAID);
doc.add(Document.Condition.PICKED_UP);
doc.setType(DocumentType.INVOICE);
doc = redTapeWorker.update(doc, null, "JUnit");
LogicTransaction lt = support.findByDossierId(doc.getDossier().getId());
assertNotNull("A LogicTrasaction must exists", lt);
assertEquals("The Size of the LogicTransaction", 3, lt.getUnits().size());
// A CreditMemo for Unit1, negate prices on Annulation Invoice.
for (Position pos : new ArrayList<>(doc.getPositions().values())) {
if (pos.getUniqueUnitId() == uu1.getId()) {
pos.setPrice(pos.getPrice() * -1);
} else {
doc.remove(pos);
}
}
assertEquals("Document should have exactly one possition", 1, doc.getPositions().size());
assertEquals("Position is exactly the same UniqueUnitId", uu1.getId(), doc.getPositions().get(1).getUniqueUnitId());
doc.setType(DocumentType.ANNULATION_INVOICE);
// Setting the Stock by force, cause we want to see if on update, the unit is moved to the original stock.
support.changeStock(uu1.getId(), alternateStockId);
doc = redTapeWorker.update(doc, stockIdOfUU1, "JUnit Test");
// Asserting Everything
assertEquals("The Identifier of CreditMemo", "SR" + YY + "_00001", doc.getIdentifier());
lt = support.findByDossierId(doc.getDossier().getId());
assertNotNull("A LogicTrasaction must still exists", lt);
assertEquals("The Size of the LogicTransaction", 2, lt.getUnits().size());
for (StockUnit stockUnit : lt.getUnits()) {
if (stockUnit.getUniqueUnitId() == uu1.getId()) {
fail("The StockUnit of the CreditMemo should not be on the LogicTransaction of the Dossier");
}
}
List<StockTransaction> sto = stockAgent.findStockTransactionEager(StockTransactionType.EXTERNAL_TRANSFER, StockTransactionStatusType.COMPLETED);
assertEquals("One External Transfer Transaction", 1, sto.size());
assertEquals("Only One Position on the Transaction should exist", 1, sto.get(0).getPositions().size());
assertEquals("The One Position should reference to the UniqueUnit of the CreditMemo", uu1.getId(), sto.get(0).getPositions().get(0).getUniqueUnitId().intValue());
assertEquals("The Transaction should contain exactlly one shadow of the UniqueUnit", 1, sto.size());
StockUnit stockUnit1 = stockAgent.findStockUnitByUniqueUnitIdEager(uu1.getId());
assertEquals("The Stock of the StockUnit", stockIdOfUU1, stockUnit1.getStock().getId());
assertNotNull("StockUnit should be on a LogicTransaction", stockUnit1.getLogicTransaction());
Dossier dossier = redTapeAgent.findByIdEager(Dossier.class, stockUnit1.getLogicTransaction().getDossierId());
assertNotNull("A Dossier on the SystemCustomer must exist", dossier);
assertFalse(dossier.getActiveDocuments().isEmpty());
assertFalse(dossier.getActiveDocuments().get(0).getPositions().isEmpty());
assertEquals(2, dossier.getActiveDocuments().get(0).getPositions().size());
boolean unit1Found = false;
boolean commentFound = false;
for (Position pos : dossier.getActiveDocuments().get(0).getPositions().values()) {
if (pos.getType() == PositionType.UNIT) {
assertEquals(uu1.getId(), pos.getUniqueUnitId());
unit1Found = true;
} else if (pos.getType() == PositionType.COMMENT) {
commentFound = true;
}
}
assertTrue(unit1Found);
assertTrue(commentFound);
Document invoice = doc.getDossier().getActiveDocuments(DocumentType.INVOICE).get(0);
// A CreditMemo for a Unit, which is Rolled Out before.
for (Position pos : new ArrayList<>(invoice.getPositions().values())) {
if (pos.getType() != PositionType.UNIT)
invoice.remove(pos);
else if (pos.getUniqueUnitId() != uu2.getId())
invoice.remove(pos);
else {
pos.setPrice(pos.getPrice() * -1);
}
}
assertEquals("Document should have exactly one possition", 1, invoice.getPositions().size());
assertEquals("Position is exactly the same UniqueUnitId", uu2.getId(), invoice.getPositions().get(1).getUniqueUnitId());
invoice.setType(DocumentType.ANNULATION_INVOICE);
// Lets roll Out the Unit
support.rollOut(uu2.getId());
// Verify it is not in stock
StockUnit stockUnit2 = stockAgent.findStockUnitByUniqueUnitIdEager(uu2.getId());
assertNull("StockUnit should not exist: " + stockUnit2, stockUnit2);
// Do the second credit Memo and check if the Unit is back in the stock.
doc = redTapeWorker.update(invoice, stockIdOfUU1, "JUnit");
// Assert Everything
// TODO: this is Mandatorspecific, pickup there.
assertEquals("The Identifier of CreditMemo", "SR" + YY + "_00002", doc.getIdentifier());
stockUnit2 = stockAgent.findStockUnitByUniqueUnitIdEager(uu2.getId());
assertNotNull("StockUnit exists", stockUnit2);
assertNotNull("StockUnit should have LogicTransaction", stockUnit2.getLogicTransaction());
assertEquals("StockUnit is not the correct one", uu2.getId(), stockUnit2.getUniqueUnitId().intValue());
dossier = redTapeAgent.findByIdEager(Dossier.class, stockUnit2.getLogicTransaction().getDossierId());
assertNotNull("A Dossier on the SystemCustomer must exist", dossier);
assertFalse(dossier.getActiveDocuments().isEmpty());
assertFalse(dossier.getActiveDocuments().get(0).getPositions().isEmpty());
assertEquals(2, dossier.getActiveDocuments().get(0).getPositions().size());
unit1Found = false;
commentFound = false;
for (Position pos : dossier.getActiveDocuments().get(0).getPositions().values()) {
if (pos.getType() == PositionType.UNIT) {
assertEquals(uu2.getId(), pos.getUniqueUnitId());
unit1Found = true;
} else if (pos.getType() == PositionType.COMMENT) {
commentFound = true;
}
}
assertTrue(unit1Found);
assertTrue(commentFound);
Date now = new Date();
Date start = DateUtils.addDays(now, -1);
Date end = DateUtils.addDays(now, 1);
FileJacket fj = sageExporter.toXml(start, end);
String result = Strings.fromByteArray(fj.getContent());
assertThat(result).as("SageXml spot Test").isNotBlank().contains(dos.getIdentifier()).contains(Double.toString(TwoDigits.round(batch.getPrice() * batch.getAmount())).replace(".", ",")).contains(Double.toString(TwoDigits.round(shipping.getPrice() * shipping.getAmount())).replace(".", ","));
System.out.println(result);
}
use of eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit in project dwoss by gg-net.
the class RedTapeOperationCapitalAssetUpdateIT method testUpdate.
@Test
public void testUpdate() throws UserInfoException {
UniqueUnit uu = receiptGenerator.makeUniqueUnit();
uu.setPrice(CUSTOMER, 50., "JunitTestPrice");
// Generate Dossier
Dossier dos = redTapeWorker.create(capitalAssestCustomer, false, "Me");
assertThat(dos.getActiveDocuments()).isNotEmpty();
assertThat(dos.getActiveDocuments(CAPITAL_ASSET)).overridingErrorMessage("Expected a capital Asset Document but has " + dos.getActiveDocuments()).isNotEmpty();
Document doc = dos.getActiveDocuments(DocumentType.CAPITAL_ASSET).get(0);
assertTrue(doc.equalsContent(dos.getActiveDocuments(DocumentType.CAPITAL_ASSET).get(0)));
// Commit explicit date to document for assertion
doc = supportBean.changeActual(doc, new GregorianCalendar(2012, 3, 15).getTime());
Position pos = NaivBuilderUtil.unit(uu);
// Create Positions
doc.append(pos);
doc.append(NaivBuilderUtil.comment("Comment", "A nice comment"));
// add units to LogicTransaction
unitOverseer.lockStockUnit(dos.getId(), uu.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
// update document
Date date = doc.getActual();
doc = redTapeWorker.update(doc, null, "Me");
assertEquals("Same actual dates expected", date, doc.getActual());
assertEquals("Only one Active Document expected", 1, doc.getDossier().getActiveDocuments().size());
assertTrue(stockAgent.findAllEager(LogicTransaction.class).get(0).getUnits().size() == 1);
assertEquals("Ammount of Documents", 2, redTapeAgent.findAll(Document.class).size());
}
use of eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit in project dwoss by gg-net.
the class RedTapeOperationComplaintIT method testCreditMemo.
@Test
public void testCreditMemo() throws UserInfoException {
long customerId = customerGenerator.makeCustomer();
List<UniqueUnit> units = receiptGenerator.makeUniqueUnits(2, true, true);
UniqueUnit uu1 = units.get(0);
UniqueUnit uu2 = units.get(1);
Dossier dos = redTapeOperation.create(customerId, true, "Me");
Document doc = dos.getActiveDocuments(DocumentType.ORDER).get(0);
assertThat(doc).overridingErrorMessage("Expected active document Order, got null. Dossier: " + dos.toMultiLine()).isNotNull();
// Create Positions
Position p1 = NaivBuilderUtil.unit(uu1);
Position p2 = NaivBuilderUtil.unit(uu2);
doc.append(p1);
doc.append(p2);
// add units to LogicTransaction
unitOverseer.lockStockUnit(dos.getId(), uu1.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
unitOverseer.lockStockUnit(dos.getId(), uu2.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
doc = redTapeOperation.update(doc, null, "JUnit");
doc.add(Document.Condition.PAID);
doc.add(Document.Condition.PICKED_UP);
doc.setType(DocumentType.INVOICE);
doc = redTapeOperation.update(doc, null, "JUnit");
LogicTransaction lt = supportBean.findByDossierId(doc.getDossier().getId());
assertNotNull("A LogicTrasaction must exists", lt);
assertEquals("The Size of the LogicTransaction", 2, lt.getUnits().size());
assertEquals("Document should have exactly two possitions", 2, doc.getPositions().size());
doc.setType(DocumentType.COMPLAINT);
doc.setDirective(Document.Directive.WAIT_FOR_COMPLAINT_COMPLETION);
doc.removeAt(p2.getId());
assertEquals("Document should have exactly one possitions", 1, doc.getPositions().size());
doc = redTapeOperation.update(doc, null, "JUnit Test");
lt = supportBean.findByDossierId(doc.getDossier().getId());
assertNotNull("A LogicTrasaction must still exists", lt);
assertEquals("The Size of the LogicTransaction", 2, lt.getUnits().size());
Arrays.asList(uu1.getId(), uu2.getId());
assertTrue("Should contain the same UniqueUnitIds", lt.getUnits().stream().map(su -> su.getUniqueUnitId()).collect(Collectors.toSet()).containsAll(Arrays.asList(uu1.getId(), uu2.getId())));
doc.add(Document.Condition.REJECTED);
redTapeOperation.update(doc, null, "JUnit Test");
}
use of eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit in project dwoss by gg-net.
the class RedTapeOperationCreditMemoIT method testCreditMemo.
@Test
public void testCreditMemo() throws UserInfoException {
// We need two stocks at least.
List<Stock> allStocks = stockGenerator.makeStocksAndLocations(2);
long customerId = customerGenerator.makeCustomer();
List<UniqueUnit> uus = receiptGenerator.makeUniqueUnits(4, true, true);
UniqueUnit uu1 = uus.get(0);
UniqueUnit uu2 = uus.get(1);
UniqueUnit uu3 = uus.get(2);
UniqueUnit uu4 = uus.get(3);
Product uuProduct1 = uu1.getProduct();
int stockIdOfUU1 = stockAgent.findStockUnitByUniqueUnitIdEager(uu1.getId()).getStock().getId();
int alternateStockId = allStocks.stream().map(Stock::getId).filter(id -> id != stockIdOfUU1).findFirst().orElseThrow(() -> new RuntimeException("No alternate StockId found, impossible"));
Dossier dos = redTapeWorker.create(customerId, true, "Me");
Document doc = dos.getActiveDocuments(DocumentType.ORDER).get(0);
assertThat(doc).overridingErrorMessage("Expected active document Order, got null. Dossier: " + dos.toMultiLine()).isNotNull();
// Create Positions
doc.append(unit(uu1));
doc.append(unit(uu2));
doc.append(unit(uu3));
doc.append(comment());
doc.append(service());
doc.append(batch(uuProduct1));
doc.append(shippingcost());
// add units to LogicTransaction
unitOverseer.lockStockUnit(dos.getId(), uu1.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
unitOverseer.lockStockUnit(dos.getId(), uu2.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
unitOverseer.lockStockUnit(dos.getId(), uu3.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
unitOverseer.lockStockUnit(dos.getId(), uu4.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
doc = redTapeWorker.update(doc, null, "JUnit");
doc.add(Document.Condition.PAID);
doc.add(Document.Condition.PICKED_UP);
doc.setType(DocumentType.INVOICE);
doc = redTapeWorker.update(doc, null, "JUnit");
LogicTransaction lt = supportBean.findByDossierId(doc.getDossier().getId());
assertNotNull("A LogicTrasaction must exists", lt);
assertEquals("The Size of the LogicTransaction", 3, lt.getUnits().size());
// A CreditMemo for a Unit, which is on the wrong Stock
for (Position pos : new ArrayList<>(doc.getPositions().values())) {
if (pos.getType() != PositionType.UNIT)
doc.remove(pos);
else if (pos.getUniqueUnitId() != uu1.getId())
doc.remove(pos);
}
assertEquals("Document should have exactly one possition", 1, doc.getPositions().size());
assertEquals("Position is exactly the same UniqueUnitId", uu1.getId(), doc.getPositions().get(1).getUniqueUnitId());
doc.setType(DocumentType.CREDIT_MEMO);
// Setting the Stock by force.
supportBean.changeStock(uu1.getId(), alternateStockId);
doc = redTapeWorker.update(doc, stockIdOfUU1, "JUnit Test");
// Asserting Everything
assertEquals("The Identifier of CreditMemo", "GS" + YY + "_00001", doc.getIdentifier());
lt = supportBean.findByDossierId(doc.getDossier().getId());
assertNotNull("A LogicTrasaction must still exists", lt);
assertEquals("The Size of the LogicTransaction", 2, lt.getUnits().size());
for (StockUnit stockUnit : lt.getUnits()) {
if (stockUnit.getUniqueUnitId() == uu1.getId()) {
fail("The StockUnit of the CreditMemo should not be on the LogicTransaction of the Dossier");
}
}
List<StockTransaction> sto = stockAgent.findStockTransactionEager(StockTransactionType.EXTERNAL_TRANSFER, StockTransactionStatusType.COMPLETED);
assertEquals("One External Transfer Transaction", 1, sto.size());
assertEquals("Only One Position on the Transaction should exist", 1, sto.get(0).getPositions().size());
assertThat(uu1.getId()).as("The One Position should reference to the UniqueUnit of the CreditMemo").isEqualTo(sto.get(0).getPositions().get(0).getUniqueUnitId());
assertEquals("The Transaction should contain exactlly one shadow of the UniqueUnit", 1, sto.size());
StockUnit stockUnit1 = stockAgent.findStockUnitByUniqueUnitIdEager(uu1.getId());
assertEquals("The Stock of the StockUnit", stockIdOfUU1, stockUnit1.getStock().getId());
assertNotNull("StockUnit should be on a LogicTransaction", stockUnit1.getLogicTransaction());
Dossier dossier = redTapeAgent.findByIdEager(Dossier.class, stockUnit1.getLogicTransaction().getDossierId());
assertNotNull("A Dossier on the SystemCustomer must exist", dossier);
assertFalse(dossier.getActiveDocuments().isEmpty());
assertFalse(dossier.getActiveDocuments().get(0).getPositions().isEmpty());
assertEquals(2, dossier.getActiveDocuments().get(0).getPositions().size());
boolean unit1Found = false;
boolean commentFound = false;
for (Position pos : dossier.getActiveDocuments().get(0).getPositions().values()) {
if (pos.getType() == PositionType.UNIT) {
assertEquals(uu1.getId(), pos.getUniqueUnitId());
unit1Found = true;
} else if (pos.getType() == PositionType.COMMENT) {
commentFound = true;
}
}
assertTrue(unit1Found);
assertTrue(commentFound);
Document invoice = doc.getDossier().getActiveDocuments(DocumentType.INVOICE).get(0);
// A CreditMemo for a Unit, which is Rolled Out before.
for (Position pos : new ArrayList<>(invoice.getPositions().values())) {
if (pos.getType() != PositionType.UNIT)
invoice.remove(pos);
else if (pos.getUniqueUnitId() != uu2.getId())
invoice.remove(pos);
}
assertEquals("Document should have exactly one possition", 1, invoice.getPositions().size());
assertEquals("Position is exactly the same UniqueUnitId", uu2.getId(), invoice.getPositions().get(1).getUniqueUnitId());
invoice.setType(DocumentType.CREDIT_MEMO);
// Lets roll Out the Unit
supportBean.rollOut(uu2.getId());
// Do the second credit Memo and check if the Unit is back in the stock.
StockUnit stockUnit2 = stockAgent.findStockUnitByUniqueUnitIdEager(uu2.getId());
assertNull("StockUnit should not exist: " + stockUnit2, stockUnit2);
doc = redTapeWorker.update(invoice, stockIdOfUU1, "JUnit");
// Assert Everything
assertEquals("The Identifier of CreditMemo", "GS" + YY + "_00002", doc.getIdentifier());
stockUnit2 = stockAgent.findStockUnitByUniqueUnitIdEager(uu2.getId());
assertNotNull("StockUnit exists", stockUnit2);
assertNotNull("StockUnit should have LogicTransaction", stockUnit2.getLogicTransaction());
assertThat(uu2.getId()).as("StockUnit is not the correct one").isEqualTo(stockUnit2.getUniqueUnitId());
dossier = redTapeAgent.findByIdEager(Dossier.class, stockUnit2.getLogicTransaction().getDossierId());
assertNotNull("A Dossier on the SystemCustomer must exist", dossier);
assertFalse(dossier.getActiveDocuments().isEmpty());
assertFalse(dossier.getActiveDocuments().get(0).getPositions().isEmpty());
assertEquals(2, dossier.getActiveDocuments().get(0).getPositions().size());
unit1Found = false;
commentFound = false;
for (Position pos : dossier.getActiveDocuments().get(0).getPositions().values()) {
if (pos.getType() == PositionType.UNIT) {
assertEquals(uu2.getId(), pos.getUniqueUnitId());
unit1Found = true;
} else if (pos.getType() == PositionType.COMMENT) {
commentFound = true;
}
}
assertTrue(unit1Found);
assertTrue(commentFound);
}
Aggregations