List of usage examples for java.time Instant now
public static Instant now()
From source file:no.digipost.api.useragreements.client.response.ResponseUtilsTest.java
@Test public void parsesDateFromRetryAfterHeader() { Clock clock = Clock.fixed(Instant.now().truncatedTo(SECONDS), ZoneOffset.UTC); HttpResponse tooManyRequestsErrorResponse = tooManyRequestsResponseWithRetryAfter( RFC_1123_DATE_TIME.format(ZonedDateTime.now(clock).plusSeconds(42))); Optional<Duration> parsedDuration = ResponseUtils .parseDelayDurationOfRetryAfterHeader(tooManyRequestsErrorResponse, clock); assertThat(parsedDuration, contains(Duration.ofSeconds(42))); }
From source file:org.ng200.openolympus.controller.api.ContestTimerController.java
@RequestMapping("/api/contestTimeRemaining/{contest}") public @ResponseBody Map<String, String> getTimeRemaining(@PathVariable("contest") final Contest contest, final Principal principal) { Assertions.resourceExists(contest);/*from w w w. j a v a2 s. co m*/ Instant end = contest.getStartTime().toInstant(); final boolean isInProcess = contest.getStartTime().before(java.util.Date.from(Instant.now())); if (isInProcess) { if (this.contestSecurityService.isSuperuser(principal)) { end = this.contestService.getContestEndIncludingAllTimeExtensions(contest); } else if (principal != null) { final User user = this.userRepository.findByUsername(principal.getName()); if (user != null) { end = end.plusMillis(contest.getDuration()) .plusMillis(this.contestService.getTimeExtensions(contest, user)); } } } if (principal != null) { this.contestService.getTimeExtensions(contest, this.userRepository.findByUsername(principal.getName())); } final Instant cur = Instant.now(); if (end.isBefore(cur)) { return new HashMap<String, String>() { /** * */ private static final long serialVersionUID = 5419629757758058933L; { this.put("timer", "00:00:00"); this.put("status", "ended"); } }; } final Duration duration = Duration.between(cur, end); final DecimalFormat format = new DecimalFormat("00"); final long hours = duration.toHours(); final long minutes = duration.minusHours(hours).toMinutes(); final long seconds = duration.minusHours(hours).minusMinutes(minutes).getSeconds(); return new HashMap<String, String>() { /** * */ private static final long serialVersionUID = -4698243010184691932L; { this.put("timer", format.format(hours) + ":" + format.format(minutes) + ":" + format.format(seconds)); this.put("status", isInProcess ? "inProgress" : "notStartedYet"); } }; }
From source file:org.noorganization.instalist.server.api.TagResourceTest.java
@Before public void setUp() throws Exception { super.setUp(); CommonData data = new CommonData(); mManager = DatabaseHelper.getInstance().getManager(); mManager.getTransaction().begin();/*from ww w . j a va 2 s. co m*/ Instant creation = Instant.now(); mGroup = new DeviceGroup(); mTag = new Tag().withGroup(mGroup).withName("tag1").withUUID(UUID.randomUUID()).withUpdated(creation); mDeletedTag = new DeletedObject().withGroup(mGroup).withUUID(UUID.randomUUID()) .withType(DeletedObject.Type.TAG).withUpdated(creation); mNAGroup = new DeviceGroup(); mNATag = new Tag().withGroup(mNAGroup).withName("tag2").withUUID(UUID.randomUUID()); Device authorizedDevice = new Device().withAuthorized(true).withGroup(mGroup).withName("dev1") .withSecret(data.mEncryptedSecret); mManager.persist(mGroup); mManager.persist(mTag); mManager.persist(mDeletedTag); mManager.persist(mNAGroup); mManager.persist(mNATag); mManager.persist(authorizedDevice); mManager.getTransaction().commit(); mManager.refresh(mGroup); mManager.refresh(mTag); mManager.refresh(mDeletedTag); mManager.refresh(mNAGroup); mManager.refresh(mNATag); mManager.refresh(authorizedDevice); mToken = ControllerFactory.getAuthController().getTokenByHttpAuth(mManager, authorizedDevice.getId(), data.mSecret); assertNotNull(mToken); }
From source file:dk.dbc.rawrepo.oai.ResumptionToken.java
/** * Construct a ResumptionToken from a json object * * @param obj json value/*from ww w. j ava 2 s. co m*/ * @param validHours timeout * @return Resumption token to add to an oaipmh request */ public static ResumptionTokenType toToken(ObjectNode obj, int validHours) { if (obj == null) { return null; } ResumptionTokenType token = OBJECT_FACTORY.createResumptionTokenType(); Instant timeout = Instant.now().plus(validHours, ChronoUnit.HOURS).truncatedTo(ChronoUnit.SECONDS); XMLGregorianCalendar date = OAIResource.gregorianTimestamp(timeout); token.setExpirationDate(date); token.setValue(encode(obj, validHours)); return token; }
From source file:org.ng200.openolympus.TestUtilities.java
public User createTestUser(String name, String password) throws MessagingException, EmailException { User user = this.userService.getUserByUsername(name); if (user != null) { return user; }/*from w ww . j a v a 2s . co m*/ user = new User(name, this.passwordEncoder.encode(password), "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", Date.from(Instant.now()), UUID.randomUUID().toString()); user.setRoles(new HashSet<Role>()); user = this.userService.saveUser(user); this.approveUserRegistrationController.approveUser(user); return user; }
From source file:org.ng200.openolympus.services.SecurityService.java
public boolean isContestOver(final Contest contest) { return this.contestService.getContestEndIncludingAllTimeExtensions(contest).isBefore(Instant.now()); }
From source file:com.joyent.manta.client.MantaClientSigningIT.java
@Test public final void testCanCreateSignedGETUriFromPath() throws IOException { if (config.isClientEncryptionEnabled()) { throw new SkipException("Signed URLs are not decrypted by the client"); }/* w ww . ja v a 2 s . c o m*/ final String name = UUID.randomUUID().toString(); final String path = testPathPrefix + name; mantaClient.put(path, TEST_DATA); // This will throw an error if the newly inserted object isn't present mantaClient.head(path); Instant expires = Instant.now().plus(1, ChronoUnit.HOURS); URI uri = mantaClient.getAsSignedURI(path, "GET", expires); HttpURLConnection connection = (HttpURLConnection) uri.toURL().openConnection(); try (InputStream is = connection.getInputStream()) { connection.setReadTimeout(3000); connection.connect(); if (connection.getResponseCode() != 200) { Assert.fail(IOUtils.toString(connection.getErrorStream(), Charset.defaultCharset())); } String actual = IOUtils.toString(is, Charset.defaultCharset()); Assert.assertEquals(actual, TEST_DATA); } finally { connection.disconnect(); } }
From source file:org.noorganization.instalist.server.api.RecipeResourceTest.java
@Before public void setUp() throws Exception { super.setUp(); CommonData data = new CommonData(); mManager = DatabaseHelper.getInstance().getManager(); mManager.getTransaction().begin();/* w w w. java2 s . c o m*/ Instant creation = Instant.now(); mGroup = new DeviceGroup(); mRecipe = new Recipe().withGroup(mGroup).withName("recipe1").withUUID(UUID.randomUUID()) .withUpdated(creation); mDeletedRecipe = new DeletedObject().withGroup(mGroup).withUUID(UUID.randomUUID()) .withType(DeletedObject.Type.RECIPE).withUpdated(creation); mNAGroup = new DeviceGroup(); mNARecipe = new Recipe().withGroup(mNAGroup).withName("recipe2").withUUID(UUID.randomUUID()); Device authorizedDevice = new Device().withAuthorized(true).withGroup(mGroup).withName("dev1") .withSecret(data.mEncryptedSecret); mManager.persist(mGroup); mManager.persist(mRecipe); mManager.persist(mDeletedRecipe); mManager.persist(mNAGroup); mManager.persist(mNARecipe); mManager.persist(authorizedDevice); mManager.getTransaction().commit(); mManager.refresh(mGroup); mManager.refresh(mRecipe); mManager.refresh(mDeletedRecipe); mManager.refresh(mNAGroup); mManager.refresh(mNARecipe); mManager.refresh(authorizedDevice); mToken = ControllerFactory.getAuthController().getTokenByHttpAuth(mManager, authorizedDevice.getId(), data.mSecret); assertNotNull(mToken); }
From source file:com.synopsys.integration.hub.bdio.BdioNodeFactory.java
public BdioBillOfMaterials createBillOfMaterials(final String codeLocationName, final String projectName, final String projectVersion) { final BdioBillOfMaterials billOfMaterials = new BdioBillOfMaterials(); billOfMaterials.id = String.format("uuid:%s", UUID.randomUUID()); if (StringUtils.isNotBlank(codeLocationName)) { billOfMaterials.spdxName = codeLocationName; } else {/*from ww w .j a v a 2 s . c o m*/ billOfMaterials.spdxName = String.format("%s/%s Black Duck I/O Export", projectName, projectVersion); } billOfMaterials.bdioSpecificationVersion = "1.1.0"; billOfMaterials.creationInfo = new BdioCreationInfo(); billOfMaterials.creationInfo.created = Instant.now().atOffset(ZoneOffset.UTC) .format(DateTimeFormatter.ISO_INSTANT); String version = "UnknownVersion"; try (InputStream inputStream = getClass().getClassLoader() .getResourceAsStream("com/blackducksoftware/integration/hub/bdio/version.txt")) { version = IOUtils.toString(inputStream, StandardCharsets.UTF_8); } catch (final IOException e) { } billOfMaterials.creationInfo.addSpdxCreator(SpdxCreator.createToolSpdxCreator("IntegrationBdio", version)); return billOfMaterials; }
From source file:com.orange.cepheus.broker.persistence.RegistrationsRepositoryTest.java
@Test public void saveRegistrationTest() throws URISyntaxException, RegistrationPersistenceException { RegisterContext registerContext = createRegisterContextTemperature(); registerContext.setRegistrationId("12345"); Registration registration = new Registration(Instant.now().plus(1, ChronoUnit.DAYS), registerContext); registrationsRepository.saveRegistration(registration); Map<String, Registration> registrations = registrationsRepository.getAllRegistrations(); Assert.assertEquals(1, registrations.size()); Assert.assertEquals(registration.getExpirationDate(), registrations.get("12345").getExpirationDate()); Assert.assertEquals(registerContext.getDuration(), registrations.get("12345").getRegisterContext().getDuration()); }