@Test(expected = RuntimeException.class) public void insertOrderStatus_shouldThrowRuntimeExceptionForNonExistingOrder() { Order nonExistingOrder = createOrderWithAllFields(); DBObject orderObj = collection.findOne(new BasicDBObject("_id", nonExistingOrder.getOrderId())); assertThat(orderObj, nullValue()); orderDao.insertOrderStatus(nonExistingOrder); }
public void insertOrderStatus(@Nonnull final Order order) { checkNotNull(order, "Argument[order] must not be null"); DBObject query = new BasicDBObject("_id", order.getOrderId()); DBObject update = new BasicDBObject( "$set", new BasicDBObject("status", order.getStatus())); WriteResult result = collection.update(query, update); if (result.getN() == 0) { throw new RuntimeException("Cannot update non-existing document[" + query + "]"); } logger.info("Updated status[{}] for order with id[{}]", order.getStatus(), order.getOrderId()); }
OrderDao extends AbstractBaseDao<Order, Integer> implements OrderMapper, LineItemMapper { public void insertOrderStatus(@Nonnull final Order order) { checkNotNull(order, "Argument[order] must not be null"); DBObject query = new BasicDBObject("_id", order.getOrderId()); DBObject update = new BasicDBObject( "$set", new BasicDBObject("status", order.getStatus())); WriteResult result = collection.update(query, update); if (result.getN() == 0) { throw new RuntimeException("Cannot update non-existing document[" + query + "]"); } logger.info("Updated status[{}] for order with id[{}]", order.getStatus(), order.getOrderId()); } }
OrderDao extends AbstractBaseDao<Order, Integer> implements OrderMapper, LineItemMapper { public void insertOrderStatus(@Nonnull final Order order) { checkNotNull(order, "Argument[order] must not be null"); DBObject query = new BasicDBObject("_id", order.getOrderId()); DBObject update = new BasicDBObject( "$set", new BasicDBObject("status", order.getStatus())); WriteResult result = collection.update(query, update); if (result.getN() == 0) { throw new RuntimeException("Cannot update non-existing document[" + query + "]"); } logger.info("Updated status[{}] for order with id[{}]", order.getStatus(), order.getOrderId()); } OrderDao(@Nonnull final String collectionName); }
OrderDao extends AbstractBaseDao<Order, Integer> implements OrderMapper, LineItemMapper { public void insertOrderStatus(@Nonnull final Order order) { checkNotNull(order, "Argument[order] must not be null"); DBObject query = new BasicDBObject("_id", order.getOrderId()); DBObject update = new BasicDBObject( "$set", new BasicDBObject("status", order.getStatus())); WriteResult result = collection.update(query, update); if (result.getN() == 0) { throw new RuntimeException("Cannot update non-existing document[" + query + "]"); } logger.info("Updated status[{}] for order with id[{}]", order.getStatus(), order.getOrderId()); } OrderDao(@Nonnull final String collectionName); List<LineItem> getLineItemsByOrderId(final int orderId); void insertLineItem(@Nonnull final LineItem lineItem); List<Order> getOrdersByUsername(@Nonnull final String username); Order getOrder(final int orderId); void insertOrder(@Nonnull final Order order); void insertOrderStatus(@Nonnull final Order order); }
OrderDao extends AbstractBaseDao<Order, Integer> implements OrderMapper, LineItemMapper { public void insertOrderStatus(@Nonnull final Order order) { checkNotNull(order, "Argument[order] must not be null"); DBObject query = new BasicDBObject("_id", order.getOrderId()); DBObject update = new BasicDBObject( "$set", new BasicDBObject("status", order.getStatus())); WriteResult result = collection.update(query, update); if (result.getN() == 0) { throw new RuntimeException("Cannot update non-existing document[" + query + "]"); } logger.info("Updated status[{}] for order with id[{}]", order.getStatus(), order.getOrderId()); } OrderDao(@Nonnull final String collectionName); List<LineItem> getLineItemsByOrderId(final int orderId); void insertLineItem(@Nonnull final LineItem lineItem); List<Order> getOrdersByUsername(@Nonnull final String username); Order getOrder(final int orderId); void insertOrder(@Nonnull final Order order); void insertOrderStatus(@Nonnull final Order order);  }