public boolean isDiscontinuedRightNow() { return isDiscontinued(new Date()); }
return false; if (isDiscontinued(checkDate) || autoExpireDate == null) { return false;
/** * Convenience method to determine if the order is active as of the specified date * * @param checkDate - the date on which to check order. if null, will use current date * @return boolean indicating whether the order was active on the check date * @since 1.10.1 * @should return true if an order expired on the check date * @should return true if an order was discontinued on the check date * @should return true if an order was activated on the check date * @should return true if an order was activated on the check date but scheduled for the future * @should return false for a voided order * @should return false for a discontinued order * @should return false for an expired order * @should return false for an order activated after the check date * @should return false for a discontinuation order */ public boolean isActive(Date aCheckDate) { if (getVoided() || action == Action.DISCONTINUE) { return false; } Date checkDate = aCheckDate == null ? new Date() : aCheckDate; return isActivated(checkDate) && !isDiscontinued(checkDate) && !isExpired(checkDate); }
/** * @see Order#isDiscontinued(Date) */ @Test public void isDiscontinued_shouldNotDiscontinueGivenOrderWithoutDates() throws Exception { assertFalse("order without dates shouldn't be discontinued", o.isDiscontinued(ymd.parse("2007-10-26"))); }
/** * @see Order#isDiscontinued(Date) */ @Test public void isDiscontinued_shouldNotDiscontinueBeforeActivationDate() throws Exception { o.setDateActivated(ymd.parse("2007-01-01")); assertFalse("shouldn't be discontinued before date activated", o.isDiscontinued(ymd.parse("2006-10-26"))); }
/** * @see Order#isDiscontinued(Date) */ @Test public void isDiscontinued_shouldNotDiscontinueGivenActivatedOrderWithoutEndDate() throws Exception { o.setDateActivated(ymd.parse("2007-01-01")); assertFalse("order without no end dates shouldn't be discontinued", o.isDiscontinued(ymd.parse("2007-10-26"))); }
/** * @see Order#isDiscontinued(Date) */ @Test public void isDiscontinued_shouldNotDiscontinueActivatedOrderBeforeAutoExpireDate() throws Exception { o.setDateActivated(ymd.parse("2007-01-01")); o.setAutoExpireDate(ymd.parse("2007-12-31")); assertFalse("shouldn't be discontinued before autoExpireDate", o.isDiscontinued(ymd.parse("2007-10-26"))); }
/** * @see Order#isDiscontinued(Date) */ @Test public void isDiscontinued_shouldNotDiscontinueActivatedOrderAfterAutoExpireDate() throws Exception { o.setDateActivated(ymd.parse("2007-01-01")); o.setAutoExpireDate(ymd.parse("2007-12-31")); assertFalse("shouldn't be discontinued after autoExpireDate", o.isDiscontinued(ymd.parse("2008-10-26"))); }
/** * @see Order#isDiscontinued(Date) */ @Test public void isDiscontinued_shouldDiscontinueActivatedOrderAfterDateStopped() throws Exception { o.setDateActivated(ymd.parse("2007-01-01")); o.setAutoExpireDate(ymd.parse("2007-12-31")); OrderUtilTest.setDateStopped(o, ymd.parse("2007-11-01")); assertTrue("should be discontinued after dateStopped", o.isDiscontinued(ymd.parse("2007-11-26"))); }
/** * @see Order#isDiscontinued(Date) */ @Test public void isDiscontinued_shouldNotDiscontinueActivatedOrderBeforeDateStopped() throws Exception { o.setDateActivated(ymd.parse("2007-01-01")); o.setAutoExpireDate(ymd.parse("2007-12-31")); OrderUtilTest.setDateStopped(o, ymd.parse("2007-11-01")); assertFalse("shouldn't be discontinued before dateStopped", o.isDiscontinued(ymd.parse("2007-10-26"))); }
/** * @see Order#isDiscontinued(java.util.Date) */ @Test public void isDiscontinued_shouldReturnFalseIfDateActivatedIsAfterCheckDate() throws Exception { Order order = new Order(); order.setDateActivated(DateUtils.parseDate("2014-11-01 11:11:12", DATE_FORMAT)); OrderUtilTest.setDateStopped(order, DateUtils.parseDate("2014-11-01 11:11:13", DATE_FORMAT)); assertFalse(order.isDiscontinued(DateUtils.parseDate("2014-11-01 11:11:11", DATE_FORMAT))); }
/** * @see Order#isDiscontinued(java.util.Date) */ @Test public void isDiscontinued_shouldReturnFalseIfAutoExpireDateIsNullAndDateStoppedIsEqualToCheckDate() throws Exception { Order order = new Order(); order.setDateActivated(DateUtils.parseDate("2014-11-01 11:11:10", DATE_FORMAT)); Date checkDate = DateUtils.parseDate("2014-11-01 11:11:11", DATE_FORMAT); OrderUtilTest.setDateStopped(order, checkDate); assertNull(order.getAutoExpireDate()); assertFalse(order.isDiscontinued(checkDate)); }
/** * @see Order#isDiscontinued(java.util.Date) */ @Test public void isDiscontinued_shouldReturnTrueIfCheckDateIsAfterDateStoppedButBeforeAutoExpireDate() throws Exception { Order order = new Order(); order.setDateActivated(DateUtils.parseDate("2014-11-01 11:11:10", DATE_FORMAT)); OrderUtilTest.setDateStopped(order, DateUtils.parseDate("2014-11-01 11:11:11", DATE_FORMAT)); order.setAutoExpireDate(DateUtils.parseDate("2014-11-01 11:11:13", DATE_FORMAT)); assertTrue(order.isDiscontinued(DateUtils.parseDate("2014-11-01 11:11:12", DATE_FORMAT))); }
/** * @see Order#isDiscontinued(java.util.Date) */ @Test public void isDiscontinued_shouldReturnTrueIfCheckDateIsAfterBothDateStoppedAutoExpireDate() throws Exception { Order order = new Order(); order.setDateActivated(DateUtils.parseDate("2014-11-01 11:11:10", DATE_FORMAT)); OrderUtilTest.setDateStopped(order, DateUtils.parseDate("2014-11-01 11:11:11", DATE_FORMAT)); order.setAutoExpireDate(DateUtils.parseDate("2014-11-01 11:11:12", DATE_FORMAT)); assertTrue(order.isDiscontinued(DateUtils.parseDate("2014-11-01 11:11:13", DATE_FORMAT))); }
/** * @see Order#isDiscontinued(java.util.Date) */ @Test public void isDiscontinued_shouldReturnFalseIfDateStoppedAndAutoExpireDateAreBothNull() throws Exception { Order order = new Order(); order.setDateActivated(DateUtils.parseDate("2014-11-01 11:11:10", DATE_FORMAT)); assertNull(order.getDateStopped()); assertNull(order.getAutoExpireDate()); assertFalse(order.isDiscontinued(DateUtils.parseDate("2014-11-01 11:11:11", DATE_FORMAT))); }
/** * @see Order#isDiscontinued(java.util.Date) */ @Test public void isDiscontinued_shouldReturnFalseIfAutoExpireDateIsNullAndDateStoppedIsAfterCheckDate() throws Exception { Order order = new Order(); order.setDateActivated(DateUtils.parseDate("2014-11-01 11:11:10", DATE_FORMAT)); OrderUtilTest.setDateStopped(order, DateUtils.parseDate("2014-11-01 11:11:12", DATE_FORMAT)); assertNull(order.getAutoExpireDate()); assertFalse(order.isDiscontinued(DateUtils.parseDate("2014-11-01 11:11:11", DATE_FORMAT))); }
/** * @see Order#isDiscontinued(java.util.Date) */ @Test public void isDiscontinued_shouldReturnTrueIfAutoExpireDateIsNullAndDateStoppedIsBeforeCheckDate() throws Exception { Order order = new Order(); order.setDateActivated(DateUtils.parseDate("2014-11-01 11:11:10", DATE_FORMAT)); OrderUtilTest.setDateStopped(order, DateUtils.parseDate("2014-11-01 11:11:11", DATE_FORMAT)); assertNull(order.getAutoExpireDate()); assertTrue(order.isDiscontinued(DateUtils.parseDate("2014-11-01 11:11:12", DATE_FORMAT))); }
/** * @see Order#isDiscontinued(java.util.Date) */ @Test public void isDiscontinued_shouldReturnFalseForAVoidedOrder() throws Exception { Order order = new Order(); order.setVoided(true); order.setDateActivated(DateUtils.parseDate("2014-11-01 11:11:10", DATE_FORMAT)); OrderUtilTest.setDateStopped(order, DateUtils.parseDate("2014-11-01 11:11:11", DATE_FORMAT)); assertNull(order.getAutoExpireDate()); assertFalse(order.isDiscontinued(DateUtils.parseDate("2014-11-01 11:11:12", DATE_FORMAT))); }
/** * @see Order#isDiscontinued(Date) */ @Test public void isDiscontinued_shouldReturnTrueIfTheOrderIsScheduledForTheFutureAndActivatedOnCheckDateButTheCheckDateIsAfterDateStopped() throws Exception { // tests the case when a scheduled order is revised: // in that case its original order is stopped. // the stopped date of the original order is set to a moment before the activated date of the revised order. // the order here represents such an original order Order order = new Order(); order.setUrgency(Urgency.ON_SCHEDULED_DATE); Date today = new Date(); Date scheduledDateInFuture = DateUtils.addMonths(today, 2); order.setScheduledDate(scheduledDateInFuture); Date activationDate = DateUtils.addDays(today, -2); order.setDateActivated(activationDate); Date stopDate = new Date(); OrderUtilTest.setDateStopped(order, stopDate); assertNotNull(order.getDateActivated()); assertNotNull(order.getDateStopped()); assertNull(order.getAutoExpireDate()); assertTrue(order.isDiscontinued(DateUtils.addSeconds(stopDate, 1))); }
/** * @see Order#isDiscontinued(java.util.Date) */ @Test public void isDiscontinued_shouldFailIfDateStoppedIsAfterAutoExpireDate() throws Exception { Order order = new Order(); order.setDateActivated(DateUtils.parseDate("2014-11-01 11:11:10", DATE_FORMAT)); order.setAutoExpireDate(DateUtils.parseDate("2014-11-01 11:11:11", DATE_FORMAT)); OrderUtilTest.setDateStopped(order, DateUtils.parseDate("2014-11-01 11:11:12", DATE_FORMAT)); expectedException.expect(APIException.class); expectedException.expectMessage( Context.getMessageSourceService().getMessage("Order.error.invalidDateStoppedAndAutoExpireDate")); order.isDiscontinued(DateUtils.parseDate("2014-11-01 11:11:13", DATE_FORMAT)); }