subsidiaryEntity = subsidiaryRepository.findByName("ARS Grodno");
Subsidiary subsidiary = DozerHelper.map(subsidiaryEntity,
Subsidiary.class);
log.info("Creating new order and setting NEW status for it.");
Order order = new Order("Do something", car, customer, subsidiary);
try {
order.changeStatus(EOrderStatus.NEW);
} catch (InvalidOrderStatusSequenceException e) {
e.printStackTrace();
} catch (UnknownOrderStatusException e) {
e.printStackTrace();
} catch (NoneActivitiesException e) {
e.printStackTrace();
} catch (NonePaymentException e) {
e.printStackTrace();
} catch (PaymentNotCompletedException e) {
e.printStackTrace();
}
log.info("Selecting mechanic for order.");
log.info("Mapping to order entity and mergin it to database.");
OrderEntity orderEntity = DozerHelper.map(order, OrderEntity.class);
orderEntity = orderRepository.merge(orderEntity);
orderEntity
.setOrderRegNo(order.generateOrderRegNo(orderEntity.getId()));
// Check
List<OrderEntity> result = orderRepository.findByCustomer(
customerEntity, null, null, null);
Assert.assertEquals(1, result.size());
log.info("Result: " + result.iterator().next());
log.info("Changing status to IN_PROGRESS.");
order = DozerHelper.map(orderEntity, Order.class);
try {
order.changeStatus(EOrderStatus.IN_PROGRESS);
} catch (InvalidOrderStatusSequenceException e) {
e.printStackTrace();
} catch (UnknownOrderStatusException e) {
e.printStackTrace();
} catch (NoneActivitiesException e) {
e.printStackTrace();
} catch (NonePaymentException e) {
e.printStackTrace();
} catch (PaymentNotCompletedException e) {
e.printStackTrace();
}
log.info("Adding activities to the order.");
Service testService = new Service("Test service.");
testService.setElapsedTime((short) 2);
testService.setNote("Test note");
testService.setTotal(50);
try {
order.addActivity(testService);
} catch (ActivityAlreadyExistsException e1) {
e1.printStackTrace();
} catch (OrderNotInProgressException e) {
e.printStackTrace();
}
orderEntity = DozerHelper.map(order, OrderEntity.class);
orderEntity = orderRepository.merge(orderEntity);
// Check
result = orderRepository.findByCustomer(customerEntity, null, null,
null);
Assert.assertEquals(1, result.size());
Assert.assertEquals(EOrderStatus.IN_PROGRESS, result.iterator().next()
.getStatus());
log.info("Result: " + result);
log.info("Changing status to AWAITING_PAYMENT.");
order = DozerHelper.map(orderEntity, Order.class);
try {
order.changeStatus(EOrderStatus.AWAITING_PAYMENT);
} catch (InvalidOrderStatusSequenceException e) {
e.printStackTrace();
} catch (UnknownOrderStatusException e) {
e.printStackTrace();
} catch (NoneActivitiesException e) {
e.printStackTrace();
} catch (NonePaymentException e) {
e.printStackTrace();
} catch (PaymentNotCompletedException e) {
e.printStackTrace();
}
orderEntity = DozerHelper.map(order, OrderEntity.class);
orderEntity = orderRepository.merge(orderEntity);
// Check
result = orderRepository.findByCustomer(customerEntity, null, null,
null);
Assert.assertEquals(1, result.size());
Assert.assertEquals(EOrderStatus.AWAITING_PAYMENT, result.iterator()
.next().getStatus());
log.info("Result: " + result);
log.info("Changing status to COMPLETED.");
order = DozerHelper.map(orderEntity, Order.class);
order.getPayment().makePayment(new TestPaymentSystem());
try {
order.changeStatus(EOrderStatus.COMPLETED);
} catch (InvalidOrderStatusSequenceException e) {
e.printStackTrace();
} catch (UnknownOrderStatusException e) {
e.printStackTrace();
} catch (NoneActivitiesException e) {