List of usage examples for java.time Clock fixed
public static Clock fixed(Instant fixedInstant, ZoneId zone)
From source file:Main.java
public static void main(String[] args) { Instant instant = Instant.now(); Clock newClock = Clock.fixed(instant, ZoneId.systemDefault()); System.out.println(newClock.instant()); }
From source file:org.ligoj.app.plugin.prov.aws.auth.AWS4SignerForAuthorizationHeaderTest.java
/** * Test method for//from ww w . ja v a 2s . c o m * {@link org.ligoj.app.plugin.prov.aws.auth.AWS4SignerForAuthorizationHeader#computeSignature(org.ligoj.app.plugin.prov.aws.auth.AWS4SignatureQuery)}. */ @Test public void testComputeSignature() { ReflectionTestUtils.setField(signer, "clock", Clock.fixed( LocalDateTime.of(2017, 5, 29, 22, 15).toInstant(ZoneOffset.UTC), ZoneOffset.UTC.normalized())); final AWS4SignatureQuery signatureQuery = AWS4SignatureQuery.builder().accessKey("awsAccessKey") .secretKey("awsSecretKey").region("eu-west-1").method("GET").service("s3").path("path").build(); Assertions.assertEquals( "AWS4-HMAC-SHA256 Credential=awsAccessKey/20170529/eu-west-1/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature=6a48aa41b25ea6d1b0e636c78ea971de060256ea2a2b2e6b103d6fbf14c7d21a", signer.computeSignature(signatureQuery)); }
From source file:cz.muni.fi.pv168.project.hotelmanager.TestReservationManagerImpl.java
private static Clock prepareClockMock(ZonedDateTime now) { return Clock.fixed(now.toInstant(), now.getZone()); }
From source file:org.ligoj.app.plugin.prov.aws.auth.AWS4SignerForAuthorizationHeaderTest.java
/** * Test method for//from w ww. ja v a2 s . c om * {@link org.ligoj.app.plugin.prov.aws.auth.AWS4SignerForAuthorizationHeader#computeSignature(org.ligoj.app.plugin.prov.aws.auth.AWS4SignatureQuery)}. */ @Test public void testComputeSignatureWithBody() { ReflectionTestUtils.setField(signer, "clock", Clock.fixed( LocalDateTime.of(2017, 5, 29, 22, 15).toInstant(ZoneOffset.UTC), ZoneOffset.UTC.normalized())); final AWS4SignatureQuery signatureQuery = AWS4SignatureQuery.builder().accessKey("awsAccessKey") .secretKey("awsSecretKey").region("eu-west-1").method("GET").service("s3").path("path").body("body") .build(); Assertions.assertEquals( "AWS4-HMAC-SHA256 Credential=awsAccessKey/20170529/eu-west-1/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature=704a07b30cf11a27123ea3b430680a37ffe311a858496440ab519d0cc5adaa8f", signer.computeSignature(signatureQuery)); }
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:com.gigglinggnus.controllers.AdminClockController.java
/** * * @param request servlet request/*from w w w. ja va 2 s . c om*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { EntityManager em = (EntityManager) request.getSession().getAttribute("em"); String strTime = request.getParameter("systemTime"); LocalDateTime ldTime = LocalDateTime.parse(strTime); Instant instant = ldTime.atZone(ZoneId.systemDefault()).toInstant(); Clock clk = Clock.fixed(instant, ZoneId.systemDefault()); request.getSession().setAttribute("clock", clk); RequestDispatcher rd = request.getRequestDispatcher("/home.jsp"); rd.forward(request, response); }
From source file:org.codice.ddf.security.session.management.impl.SessionManagementServiceImplTest.java
@Test public void testGetExpiry() { sessionManagementServiceImpl.setClock(Clock.fixed(Instant.EPOCH, ZoneId.of("UTC"))); String expiryString = sessionManagementServiceImpl.getExpiry(request); assertThat(expiryString, is("4522435794788")); }
From source file:org.codice.ddf.security.servlet.expiry.SessionManagementServiceTest.java
@Test public void testGetExpiry() throws IOException { sessionManagementService.setClock(Clock.fixed(Instant.EPOCH, ZoneId.of("UTC"))); Response expiry = sessionManagementService.getExpiry(request); assertThat(expiry.getStatus(), is(200)); assertThat(IOUtils.toString(new InputStreamReader((ByteArrayInputStream) expiry.getEntity())), is("4522435794788")); }
From source file:org.codice.ddf.security.session.management.impl.SessionManagementServiceImplTest.java
@Test public void testGetExpirySoonest() throws IOException, ParserConfigurationException, SAXException { sessionManagementServiceImpl.setClock(Clock.fixed(Instant.EPOCH, ZoneId.of("UTC"))); SecurityToken soonerToken = mock(SecurityToken.class); String saml = IOUtils//from w w w. j a v a 2 s .c o m .toString(new InputStreamReader(getClass().getClassLoader().getResourceAsStream("saml.xml"))); saml = saml.replace("2113", "2103"); when(soonerToken.getToken()).thenReturn(readXml(IOUtils.toInputStream(saml, "UTF-8")).getDocumentElement()); SecurityToken laterToken = mock(SecurityToken.class); saml = IOUtils.toString(new InputStreamReader(getClass().getClassLoader().getResourceAsStream("saml.xml"))); saml = saml.replace("2113", "2213"); when(laterToken.getToken()).thenReturn(readXml(IOUtils.toInputStream(saml, "UTF-8")).getDocumentElement()); when(tokenHolder.getSecurityToken()).thenReturn(soonerToken); String expiryString = sessionManagementServiceImpl.getExpiry(request); assertThat(expiryString, is("4206816594788")); }
From source file:org.codice.ddf.security.servlet.expiry.SessionManagementServiceTest.java
@Test public void testGetExpirySoonest() throws IOException, ParserConfigurationException, SAXException { sessionManagementService.setClock(Clock.fixed(Instant.EPOCH, ZoneId.of("UTC"))); SecurityToken soonerToken = mock(SecurityToken.class); String saml = IOUtils// ww w. ja v a 2 s . co m .toString(new InputStreamReader(getClass().getClassLoader().getResourceAsStream("saml.xml"))); saml = saml.replace("2113", "2103"); when(soonerToken.getToken()).thenReturn(readXml(IOUtils.toInputStream(saml, "UTF-8")).getDocumentElement()); SecurityToken laterToken = mock(SecurityToken.class); saml = IOUtils.toString(new InputStreamReader(getClass().getClassLoader().getResourceAsStream("saml.xml"))); saml = saml.replace("2113", "2213"); when(laterToken.getToken()).thenReturn(readXml(IOUtils.toInputStream(saml, "UTF-8")).getDocumentElement()); HashMap<String, SecurityToken> tokenMap = new HashMap<>(); tokenMap.put("jaas", laterToken); tokenMap.put("idp", token); tokenMap.put("karaf", soonerToken); when(tokenHolder.getRealmTokenMap()).thenReturn(tokenMap); Response expiry = sessionManagementService.getExpiry(request); assertThat(expiry.getStatus(), is(200)); assertThat(IOUtils.toString(new InputStreamReader((ByteArrayInputStream) expiry.getEntity())), is("4206816594788")); }