@Test public void doSaveOrderNullOrderFee() { Order returnOrder = ServiceTestConfiguration.order(); returnOrder.setOrderId(1); double amount = returnOrder.getQuantity()*returnOrder.getPrice().doubleValue()+returnOrder.getOrderFee().doubleValue(); ResponseEntity<String> response = new ResponseEntity<String>("SUCCESS", HttpStatus.OK); when(restTemplate.postForEntity(eq(service.downstreamProtocol + ": when(repo.save(isA(Order.class))).thenReturn(returnOrder); Order requestOrder = ServiceTestConfiguration.order(); requestOrder.setOrderFee(null); Order order = service.addOrder(requestOrder); assertEquals(order.getOrderFee(), ServiceTestConfiguration.order().getOrderFee()); }
@Transactional public Order addOrder(Order order) { logger.debug("Adding order: " + order); if (order.getOrderFee() == null) { order.setOrderFee(Order.DEFAULT_ORDER_FEE); logger.debug("Adding Fee to order: " + order); } Transaction transaction = new Transaction(); if (order.getOrderType().equals(OrderType.BUY)) { double amount = order.getQuantity() * order.getPrice().doubleValue() + order.getOrderFee().doubleValue(); transaction.setAccountId(order.getAccountId()); transaction.setAmount(BigDecimal.valueOf(amount)); transaction.setCurrency(order.getCurrency()); transaction.setDate(order.getCompletionDate()); transaction.setDescription(order.toString()); transaction.setType(TransactionType.DEBIT); } else if (order.getOrderType().equals(OrderType.SELL)){ double amount = order.getQuantity() * order.getPrice().doubleValue() - order.getOrderFee().doubleValue(); transaction.setAccountId(order.getAccountId()); transaction.setAmount(BigDecimal.valueOf(amount)); transaction.setCurrency(order.getCurrency()); transaction.setDate(order.getCompletionDate()); transaction.setDescription(order.toString()); transaction.setType(TransactionType.CREDIT); } ResponseEntity<String> result = restTemplate.postForEntity(downstreamProtocol + ": + accountsService + "/accounts/transaction", transaction, String.class); if (result.getStatusCode() == HttpStatus.OK) { logger.info(String .format("Account funds updated successfully for account: %s and new funds are: %s", order.getAccountId(), result.getBody())); return repository.save(order); } else { logger.warn("PortfolioService:addOrder - decreasing balance HTTP not ok: "); return null; } }
PortfolioService { @Transactional public Order addOrder(Order order) { logger.debug("Adding order: " + order); if (order.getOrderFee() == null) { order.setOrderFee(Order.DEFAULT_ORDER_FEE); logger.debug("Adding Fee to order: " + order); } Transaction transaction = new Transaction(); if (order.getOrderType().equals(OrderType.BUY)) { double amount = order.getQuantity() * order.getPrice().doubleValue() + order.getOrderFee().doubleValue(); transaction.setAccountId(order.getAccountId()); transaction.setAmount(BigDecimal.valueOf(amount)); transaction.setCurrency(order.getCurrency()); transaction.setDate(order.getCompletionDate()); transaction.setDescription(order.toString()); transaction.setType(TransactionType.DEBIT); } else if (order.getOrderType().equals(OrderType.SELL)){ double amount = order.getQuantity() * order.getPrice().doubleValue() - order.getOrderFee().doubleValue(); transaction.setAccountId(order.getAccountId()); transaction.setAmount(BigDecimal.valueOf(amount)); transaction.setCurrency(order.getCurrency()); transaction.setDate(order.getCompletionDate()); transaction.setDescription(order.toString()); transaction.setType(TransactionType.CREDIT); } ResponseEntity<String> result = restTemplate.postForEntity(downstreamProtocol + ": + accountsService + "/accounts/transaction", transaction, String.class); if (result.getStatusCode() == HttpStatus.OK) { logger.info(String .format("Account funds updated successfully for account: %s and new funds are: %s", order.getAccountId(), result.getBody())); return repository.save(order); } else { logger.warn("PortfolioService:addOrder - decreasing balance HTTP not ok: "); return null; } } }
PortfolioService { @Transactional public Order addOrder(Order order) { logger.debug("Adding order: " + order); if (order.getOrderFee() == null) { order.setOrderFee(Order.DEFAULT_ORDER_FEE); logger.debug("Adding Fee to order: " + order); } Transaction transaction = new Transaction(); if (order.getOrderType().equals(OrderType.BUY)) { double amount = order.getQuantity() * order.getPrice().doubleValue() + order.getOrderFee().doubleValue(); transaction.setAccountId(order.getAccountId()); transaction.setAmount(BigDecimal.valueOf(amount)); transaction.setCurrency(order.getCurrency()); transaction.setDate(order.getCompletionDate()); transaction.setDescription(order.toString()); transaction.setType(TransactionType.DEBIT); } else if (order.getOrderType().equals(OrderType.SELL)){ double amount = order.getQuantity() * order.getPrice().doubleValue() - order.getOrderFee().doubleValue(); transaction.setAccountId(order.getAccountId()); transaction.setAmount(BigDecimal.valueOf(amount)); transaction.setCurrency(order.getCurrency()); transaction.setDate(order.getCompletionDate()); transaction.setDescription(order.toString()); transaction.setType(TransactionType.CREDIT); } ResponseEntity<String> result = restTemplate.postForEntity(downstreamProtocol + ": + accountsService + "/accounts/transaction", transaction, String.class); if (result.getStatusCode() == HttpStatus.OK) { logger.info(String .format("Account funds updated successfully for account: %s and new funds are: %s", order.getAccountId(), result.getBody())); return repository.save(order); } else { logger.warn("PortfolioService:addOrder - decreasing balance HTTP not ok: "); return null; } }  }
PortfolioService { @Transactional public Order addOrder(Order order) { logger.debug("Adding order: " + order); if (order.getOrderFee() == null) { order.setOrderFee(Order.DEFAULT_ORDER_FEE); logger.debug("Adding Fee to order: " + order); } Transaction transaction = new Transaction(); if (order.getOrderType().equals(OrderType.BUY)) { double amount = order.getQuantity() * order.getPrice().doubleValue() + order.getOrderFee().doubleValue(); transaction.setAccountId(order.getAccountId()); transaction.setAmount(BigDecimal.valueOf(amount)); transaction.setCurrency(order.getCurrency()); transaction.setDate(order.getCompletionDate()); transaction.setDescription(order.toString()); transaction.setType(TransactionType.DEBIT); } else if (order.getOrderType().equals(OrderType.SELL)){ double amount = order.getQuantity() * order.getPrice().doubleValue() - order.getOrderFee().doubleValue(); transaction.setAccountId(order.getAccountId()); transaction.setAmount(BigDecimal.valueOf(amount)); transaction.setCurrency(order.getCurrency()); transaction.setDate(order.getCompletionDate()); transaction.setDescription(order.toString()); transaction.setType(TransactionType.CREDIT); } ResponseEntity<String> result = restTemplate.postForEntity(downstreamProtocol + ": + accountsService + "/accounts/transaction", transaction, String.class); if (result.getStatusCode() == HttpStatus.OK) { logger.info(String .format("Account funds updated successfully for account: %s and new funds are: %s", order.getAccountId(), result.getBody())); return repository.save(order); } else { logger.warn("PortfolioService:addOrder - decreasing balance HTTP not ok: "); return null; } }  Portfolio getPortfolio(String userId); @Transactional Order addOrder(Order order); }
PortfolioService { @Transactional public Order addOrder(Order order) { logger.debug("Adding order: " + order); if (order.getOrderFee() == null) { order.setOrderFee(Order.DEFAULT_ORDER_FEE); logger.debug("Adding Fee to order: " + order); } Transaction transaction = new Transaction(); if (order.getOrderType().equals(OrderType.BUY)) { double amount = order.getQuantity() * order.getPrice().doubleValue() + order.getOrderFee().doubleValue(); transaction.setAccountId(order.getAccountId()); transaction.setAmount(BigDecimal.valueOf(amount)); transaction.setCurrency(order.getCurrency()); transaction.setDate(order.getCompletionDate()); transaction.setDescription(order.toString()); transaction.setType(TransactionType.DEBIT); } else if (order.getOrderType().equals(OrderType.SELL)){ double amount = order.getQuantity() * order.getPrice().doubleValue() - order.getOrderFee().doubleValue(); transaction.setAccountId(order.getAccountId()); transaction.setAmount(BigDecimal.valueOf(amount)); transaction.setCurrency(order.getCurrency()); transaction.setDate(order.getCompletionDate()); transaction.setDescription(order.toString()); transaction.setType(TransactionType.CREDIT); } ResponseEntity<String> result = restTemplate.postForEntity(downstreamProtocol + ": + accountsService + "/accounts/transaction", transaction, String.class); if (result.getStatusCode() == HttpStatus.OK) { logger.info(String .format("Account funds updated successfully for account: %s and new funds are: %s", order.getAccountId(), result.getBody())); return repository.save(order); } else { logger.warn("PortfolioService:addOrder - decreasing balance HTTP not ok: "); return null; } }  Portfolio getPortfolio(String userId); @Transactional Order addOrder(Order order);  }