本文整理匯總了Java中org.joda.time.DateTimeUtils類的典型用法代碼示例。如果您正苦於以下問題:Java DateTimeUtils類的具體用法?Java DateTimeUtils怎麽用?Java DateTimeUtils使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
DateTimeUtils類屬於org.joda.time包,在下文中一共展示了DateTimeUtils類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: redeem_willThrowError_whenCodeIsExpired
import org.joda.time.DateTimeUtils; //導入依賴的package包/類
@Test
public void redeem_willThrowError_whenCodeIsExpired() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Invite code has expired. Please ask your administrator to issue you an new one.");
String code = "invalid";
String email = "[email protected]";
AppUser issuer = user("[email protected]");
Roles roles = new Roles(Roles.User);
UserInviteLink inviteLink = new UserInviteLink(code, issuer, email, roles);
DateTimeUtils.setCurrentMillisFixed(DateTime.now().plusDays(2).getMillis() + 1);
String hashedCode = UserInviteLink.hash(code);
when(userInviteLinkRepository.get(hashedCode)).thenReturn(inviteLink);
userInviteService.redeem(code, "name", "password");
}
示例2: setup
import org.joda.time.DateTimeUtils; //導入依賴的package包/類
@Before
public void setup() {
DateTimeUtils.setCurrentMillisFixed(TIMESTAMP.getMillis());
service = new AuthnResponseFromCountryService(
samlEngineProxy,
samlSoapProxyProxy,
matchingServiceConfigProxy,
policyConfiguration,
sessionRepository,
samlAuthnResponseTranslatorDtoFactory,
countriesService,
assertionRestrictionFactory);
when(sessionRepository.getStateController(SESSION_ID, CountrySelectedState.class)).thenReturn(stateController);
when(stateController.getAssertionConsumerServiceUri()).thenReturn(ASSERTION_CONSUMER_SERVICE_URI);
when(stateController.getRequestIssuerEntityId()).thenReturn(TEST_RP);
when(stateController.getMatchingServiceEntityId()).thenReturn(TEST_RP_MS);
when(stateController.getRequestId()).thenReturn(REQUEST_ID);
when(samlAuthnResponseTranslatorDtoFactory.fromSamlAuthnResponseContainerDto(SAML_AUTHN_RESPONSE_CONTAINER_DTO, TEST_RP_MS)).thenReturn(SAML_AUTHN_RESPONSE_TRANSLATOR_DTO);
when(samlEngineProxy.translateAuthnResponseFromCountry(SAML_AUTHN_RESPONSE_TRANSLATOR_DTO)).thenReturn(INBOUND_RESPONSE_FROM_COUNTRY);
when(samlEngineProxy.generateEidasAttributeQuery(EIDAS_ATTRIBUTE_QUERY_REQUEST_DTO)).thenReturn(ATTRIBUTE_QUERY_CONTAINER_DTO);
when(matchingServiceConfigProxy.getMatchingService(TEST_RP_MS)).thenReturn(MATCHING_SERVICE_CONFIG_ENTITY_DATA_DTO);
when(policyConfiguration.getMatchingServiceResponseWaitPeriod()).thenReturn(MATCHING_SERVICE_RESPONSE_WAIT_PERIOD);
when(assertionRestrictionFactory.getAssertionExpiry()).thenReturn(TIMESTAMP.plus(ASSERTION_EXPIRY));
}
示例3: testHarvestReminderNeverSentBeforeButNowTooEarly
import org.joda.time.DateTimeUtils; //導入依賴的package包/類
@Test
public void testHarvestReminderNeverSentBeforeButNowTooEarly() {
try {
createHarvest(HarvestReportRequired.REQUIRED, AuthorIsRegistered.REGISTERED);
persistInNewTransaction();
runInTransaction(() -> {
DateTime fakeNow = getTestStartTime().plus(HarvestReportReminderFeature.FIRST_REMINDER_DELAY).minusSeconds(1);
DateTimeUtils.setCurrentMillisFixed(fakeNow.getMillis());
Map<Long, Set<String>> res = harvestReportReminder.sendReminders();
assertEquals(0, res.size());
});
} finally {
DateTimeUtils.setCurrentMillisSystem();
}
}
示例4: testHarvestReminderNeverSentBeforeNowOldEnough
import org.joda.time.DateTimeUtils; //導入依賴的package包/類
@Test
public void testHarvestReminderNeverSentBeforeNowOldEnough() {
try {
final Harvest harvest = createHarvest(HarvestReportRequired.REQUIRED, AuthorIsRegistered.REGISTERED);
persistInNewTransaction();
final DateTime fakeNow = getTestStartTime().plus(HarvestReportReminderFeature.FIRST_REMINDER_DELAY).plusSeconds(1);
DateTimeUtils.setCurrentMillisFixed(fakeNow.getMillis());
runInTransaction(() -> {
final Map<Long, Set<String>> res = harvestReportReminder.sendReminders();
assertEquals(1, res.size());
assertThat(res, hasKey(harvest.getId()));
});
runInTransaction(() -> {
final DateTime reminderSentTime = harvestRepository.getOne(harvest.getId()).getEmailReminderSentTime();
assertEquals(fakeNow, reminderSentTime);
});
} finally {
DateTimeUtils.setCurrentMillisSystem();
}
}
示例5: testHarvestReminderIsSentButNowTooEarly
import org.joda.time.DateTimeUtils; //導入依賴的package包/類
@Test
public void testHarvestReminderIsSentButNowTooEarly() {
try {
final Harvest harvest = createHarvest(HarvestReportRequired.REQUIRED, AuthorIsRegistered.REGISTERED);
harvest.setEmailReminderSentTime(getTestStartTime());
persistInNewTransaction();
final DateTime fakeNow = getTestStartTime().plus(HarvestReportReminderFeature.REMINDER_INTERVAL).minusSeconds(1);
DateTimeUtils.setCurrentMillisFixed(fakeNow.getMillis());
runInTransaction(() -> {
final Map<Long, Set<String>> res = harvestReportReminder.sendReminders();
assertEquals(0, res.size());
});
} finally {
DateTimeUtils.setCurrentMillisSystem();
}
}
示例6: testUpdateOnlyThoseWhichEmailIsSent
import org.joda.time.DateTimeUtils; //導入依賴的package包/類
@Test
public void testUpdateOnlyThoseWhichEmailIsSent() {
try {
final Harvest harvest = createHarvest(HarvestReportRequired.REQUIRED, AuthorIsRegistered.REGISTERED);
final Harvest harvest2 = createHarvest(HarvestReportRequired.REQUIRED, AuthorIsRegistered.NOT_REGISTERED);
persistInNewTransaction();
final DateTime fakeNow = getTestStartTime().plus(HarvestReportReminderFeature.FIRST_REMINDER_DELAY).plusSeconds(1);
DateTimeUtils.setCurrentMillisFixed(fakeNow.getMillis());
runInTransaction(() -> {
final Map<Long, Set<String>> res = harvestReportReminder.sendReminders();
assertEquals(1, res.size());
assertThat(res, hasKey(harvest.getId()));
});
runInTransaction(() -> assertNull(harvestRepository.getOne(harvest2.getId()).getEmailReminderSentTime()));
} finally {
DateTimeUtils.setCurrentMillisSystem();
}
}
示例7: canStartBackup
import org.joda.time.DateTimeUtils; //導入依賴的package包/類
@Test
public void canStartBackup()
{
final DateTime initialTime = new DateTime(2016, 9, 26, 23, 0, 35, 0, DateTimeZone.UTC);
final InstantMillisProvider clock = new InstantMillisProvider(initialTime);
DateTimeUtils.setCurrentMillisProvider(clock);
BackupConfiguration testinfo = BackupConfiguration.builder( ).enabled(false).scheduledPeriod(Period.days(1))
.mongoDumpPath(StringUtils.EMPTY)
.restorePath(StringUtils.EMPTY)
.backupPath(StringUtils.EMPTY)
.lastbackupTime(Tools.nowUTC( )).build( );
BackupConfigurationPeriodical configuration = new BackupConfigurationPeriodical(null, null);
assertThat(configuration.canStartBackup(testinfo)).isFalse( );
DateTime lastBackup = new DateTime(2016, 9, 26, 22, 56, 0, 0);
testinfo = BackupConfiguration.builder( ).enabled(true).scheduledPeriod(Period.minutes(1)).mongoDumpPath("").restorePath("").backupPath("").lastbackupTime(lastBackup).build( );
assertThat(configuration.canStartBackup(testinfo)).isTrue( );
lastBackup = new DateTime(2016, 9, 26, 23, 2, 0, 0, DateTimeZone.UTC);
testinfo = BackupConfiguration.builder( ).enabled(true).scheduledPeriod(Period.minutes(1)).mongoDumpPath("").restorePath("").backupPath("").lastbackupTime(lastBackup).build( );
assertThat(configuration.canStartBackup(testinfo)).isFalse( );
}
開發者ID:fbalicchia,項目名稱:graylog-plugin-backup-configuration,代碼行數:27,代碼來源:BackConfigurationPeriodicalTest.java
示例8: setUp
import org.joda.time.DateTimeUtils; //導入依賴的package包/類
@Override
@Before
public void setUp() throws Exception {
super.setUp();
final MockTrackingClient testTrackingClient = new MockTrackingClient();
this.koalaTest = new TestSubscriber<>();
testTrackingClient.eventNames.subscribe(this.koalaTest);
DateTimeUtils.setCurrentMillisFixed(new DateTime().getMillis());
this.environment = application().component().environment().toBuilder()
.apiClient(new MockApiClient())
.currentConfig(new MockCurrentConfig())
.webClient(new MockWebClient())
.koala(new Koala(testTrackingClient))
.build();
}
示例9: create
import org.joda.time.DateTimeUtils; //導入依賴的package包/類
@Override
public String create(PipelineOptions options) {
String appName = options.as(ApplicationNameOptions.class).getAppName();
String normalizedAppName = appName == null || appName.length() == 0 ? "BeamApp"
: appName.toLowerCase()
.replaceAll("[^a-z0-9]", "0")
.replaceAll("^[^a-z]", "a");
String userName = MoreObjects.firstNonNull(System.getProperty("user.name"), "");
String normalizedUserName = userName.toLowerCase()
.replaceAll("[^a-z0-9]", "0");
String datePart = FORMATTER.print(DateTimeUtils.currentTimeMillis());
String randomPart = Integer.toHexString(ThreadLocalRandom.current().nextInt());
return String.format("%s-%s-%s-%s",
normalizedAppName, normalizedUserName, datePart, randomPart);
}
示例10: RemoteDisco
import org.joda.time.DateTimeUtils; //導入依賴的package包/類
/**
* Construct a new RemoteDisco - purely for testing - with an already
* determined result. Either jid or error must be passed.
*
* @param remoteDomain the name of the remote domain (not JID)
* @param jid the domain's remote JID
* @param error the error from disco
*/
@VisibleForTesting
RemoteDisco(String remoteDomain, String jid, FederationError error) {
Preconditions.checkArgument((jid != null)^(error != null));
manager = null;
status = new AtomicReference<Status>(Status.COMPLETE);
pending = null;
this.remoteDomain = remoteDomain;
this.remoteJid = jid;
this.error = error;
// defaults for testing
this.creationTimeMillis = DateTimeUtils.currentTimeMillis();
this.failExpirySecs = 2 * 60;
this.successExpirySecs = 2 * 60 * 60;
}
示例11: ttlExceeded
import org.joda.time.DateTimeUtils; //導入依賴的package包/類
/**
* Returns true if this RemoteDisco's time to live is exceeded.
*
* We can't use MapMaker's expiration code as it won't let us have different expiry for
* successful and failed cases.
*
* @return whether this object should be deleted and recreated
*/
public boolean ttlExceeded() {
if (status.get() == Status.COMPLETE) {
if (remoteJid == null) {
// Failed disco case
if (DateTimeUtils.currentTimeMillis() >
(creationTimeMillis + (1000 * failExpirySecs))) {
return true;
}
} else {
// Successful disco case
if (DateTimeUtils.currentTimeMillis() >
(creationTimeMillis + (1000 * successExpirySecs))) {
return true;
}
}
}
return false;
}
示例12: testNewYear
import org.joda.time.DateTimeUtils; //導入依賴的package包/類
@Test
public void testNewYear() {
DateTimeUtils.setCurrentMillisFixed(1450911600000L); // 24.12.2015
ParserUtils.init();
assertEquals(2016, ParserUtils.parseDate("1.1. Freitag").getYear());
assertEquals(2015, ParserUtils.parseDate("31.12. Donnerstag").getYear());
assertEquals(2016, ParserUtils.parseDateTime("1.1. Freitag 12:00").getYear());
assertEquals(2015, ParserUtils.parseDateTime("31.12. Donnerstag 12:00").getYear());
DateTimeUtils.setCurrentMillisFixed(1452034800000L); // 06.01.2016
ParserUtils.init();
assertEquals(2016, ParserUtils.parseDate("1.1. Freitag").getYear());
assertEquals(2015, ParserUtils.parseDate("31.12. Donnerstag").getYear());
assertEquals(2016, ParserUtils.parseDateTime("1.1. Freitag 12:00").getYear());
assertEquals(2015, ParserUtils.parseDateTime("31.12. Donnerstag 12:00").getYear());
}
示例13: testTriggerAlreadyRunningRun
import org.joda.time.DateTimeUtils; //導入依賴的package包/類
@Test
public void testTriggerAlreadyRunningRun() throws InterruptedException, ReaperException {
DateTimeUtils.setCurrentMillisFixed(TIME_CREATE);
context.repairManager
.initializeThreadPool(THREAD_CNT, REPAIR_TIMEOUT_S, TimeUnit.SECONDS, RETRY_DELAY_S, TimeUnit.SECONDS);
RepairRunResource resource = new RepairRunResource(context);
Response response = addDefaultRepairRun(resource);
assertTrue(response.getEntity().toString(), response.getEntity() instanceof RepairRunStatus);
RepairRunStatus repairRunStatus = (RepairRunStatus) response.getEntity();
UUID runId = repairRunStatus.getId();
DateTimeUtils.setCurrentMillisFixed(TIME_START);
Optional<String> newState = Optional.of(RepairRun.RunState.RUNNING.toString());
resource.modifyRunState(uriInfo, runId, newState);
Thread.sleep(1000);
response = resource.modifyRunState(uriInfo, runId, newState);
assertEquals(Response.Status.NOT_MODIFIED.getStatusCode(), response.getStatus());
}
示例14: testPauseNotRunningRun
import org.joda.time.DateTimeUtils; //導入依賴的package包/類
@Test
public void testPauseNotRunningRun() throws InterruptedException, ReaperException {
DateTimeUtils.setCurrentMillisFixed(TIME_CREATE);
context.repairManager.initializeThreadPool(THREAD_CNT, REPAIR_TIMEOUT_S, TimeUnit.SECONDS,
RETRY_DELAY_S, TimeUnit.SECONDS);
RepairRunResource resource = new RepairRunResource(context);
Response response = addDefaultRepairRun(resource);
assertTrue(response.getEntity().toString(), response.getEntity() instanceof RepairRunStatus);
RepairRunStatus repairRunStatus = (RepairRunStatus) response.getEntity();
UUID runId = repairRunStatus.getId();
response = resource.modifyRunState(uriInfo, runId,
Optional.of(RepairRun.RunState.PAUSED.toString()));
Thread.sleep(200);
assertEquals(405, response.getStatus());
RepairRun repairRun = context.storage.getRepairRun(runId).get();
// the run should be paused
assertEquals(RepairRun.RunState.NOT_STARTED, repairRun.getRunState());
// but the running segment should be untouched
assertEquals(0,
context.storage.getSegmentAmountForRepairRunWithState(runId,
RepairSegment.State.RUNNING));
}
示例15: testModifyIntensity
import org.joda.time.DateTimeUtils; //導入依賴的package包/類
@Test
public void testModifyIntensity() throws ReaperException {
DateTimeUtils.setCurrentMillisFixed(TIME_CREATE);
context.repairManager
.initializeThreadPool(THREAD_CNT, REPAIR_TIMEOUT_S, TimeUnit.SECONDS, RETRY_DELAY_S, TimeUnit.SECONDS);
RepairRunResource resource = new RepairRunResource(context);
Response response = addDefaultRepairRun(resource);
assertTrue(response.getEntity().toString(), response.getEntity() instanceof RepairRunStatus);
RepairRunStatus repairRunStatus = (RepairRunStatus) response.getEntity();
UUID runId = repairRunStatus.getId();
response = resource.modifyRunState(uriInfo, runId, Optional.of(RepairRun.RunState.RUNNING.toString()));
assertEquals(200, response.getStatus());
response = resource.modifyRunState(uriInfo, runId, Optional.of(RepairRun.RunState.PAUSED.toString()));
assertEquals(200, response.getStatus());
response = resource.modifyRunIntensity(uriInfo, runId, Optional.of("0.1"));
assertTrue(response.getEntity() instanceof RepairRunStatus);
repairRunStatus = (RepairRunStatus) response.getEntity();
assertEquals(0.1, repairRunStatus.getIntensity(), 0.09);
}