use of eu.ggnet.dwoss.stock.ee.entity.StockTransactionPosition in project dwoss by gg-net.
the class ValidationTest method testStockUnit.
@Test
public void testStockUnit() {
StockUnit su = new StockUnit("Bla", 0);
Set<? extends ConstraintViolation> violations = validator.validate(su);
if (violations.isEmpty())
fail("No violation, but StockUnit has neither Stock nor Position");
Stock s = new Stock(1, "Teststock");
su.setStock(s);
violations = validator.validate(su);
if (!violations.isEmpty())
fail("Violation, but StockUnit has Stock. msg: " + buildMessage(violations));
su.setStock(null);
violations = validator.validate(su);
if (violations.isEmpty())
fail("No violation, but StockUnit has neither Stock nor Position");
StockTransactionPosition stp = new StockTransactionPosition(su);
if (validator.validate(su).isEmpty())
fail("No violation, but StockUnit has invalid Position");
StockTransaction t = new StockTransaction();
t.addPosition(stp);
if (validator.validate(su).isEmpty())
fail("No violation, but StockTransaction is still invalid (no status, no type)");
t.addStatus(new StockTransactionStatus(StockTransactionStatusType.PREPARED, new Date()));
if (validator.validate(su).isEmpty())
fail("No violation, but StockTransaction is still invalid (no type)");
t.setType(StockTransactionType.TRANSFER);
violations = validator.validate(su);
if (!violations.isEmpty())
fail("Violation, but StockUnit has valid Position and Transaction. msg: " + buildMessage(violations));
su.setStock(s);
violations = validator.validate(su);
if (!violations.isEmpty())
fail("Violation, Special Case: StockUnit has Stock and Transaction(Prepared) which is ok. msg: " + buildMessage(violations));
t.addStatus(new StockTransactionStatus(StockTransactionStatusType.COMMISSIONED, new Date()));
if (validator.validate(su).isEmpty())
fail("No violation, but now StockUnit has Stock and StockTransaction( not prepared), which is not ok.");
}
Aggregations