Search in sources :

Example 91 with ZoneId

use of java.time.ZoneId in project spring-integration by spring-projects.

the class HttpProxyScenarioTests method testHttpProxyScenario.

@Test
public void testHttpProxyScenario() throws Exception {
    DateTimeFormatter dateTimeFormatter = DateTimeFormatter.RFC_1123_DATE_TIME;
    ZoneId GMT = ZoneId.of("GMT");
    Calendar c = Calendar.getInstance();
    c.set(Calendar.MILLISECOND, 0);
    final long ifModifiedSince = c.getTimeInMillis();
    Instant instant = Instant.ofEpochMilli(ifModifiedSince);
    ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(instant, GMT);
    String ifModifiedSinceValue = dateTimeFormatter.format(zonedDateTime);
    c.add(Calendar.DATE, -1);
    long ifUnmodifiedSince = c.getTimeInMillis();
    instant = Instant.ofEpochMilli(ifUnmodifiedSince);
    zonedDateTime = ZonedDateTime.ofInstant(instant, GMT);
    final String ifUnmodifiedSinceValue = dateTimeFormatter.format(zonedDateTime);
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/test");
    request.setQueryString("foo=bar&FOO=BAR");
    request.addHeader("If-Modified-Since", ifModifiedSinceValue);
    request.addHeader("If-Unmodified-Since", ifUnmodifiedSinceValue);
    request.addHeader("Connection", "Keep-Alive");
    request.setContentType("text/plain");
    Object handler = this.handlerMapping.getHandler(request).getHandler();
    assertNotNull(handler);
    MockHttpServletResponse response = new MockHttpServletResponse();
    RestTemplate template = Mockito.spy(new RestTemplate());
    final String contentDispositionValue = "attachment; filename=\"test.txt\"";
    Mockito.doAnswer(invocation -> {
        URI uri = invocation.getArgument(0);
        assertEquals(new URI("http://testServer/test?foo=bar&FOO=BAR"), uri);
        HttpEntity<?> httpEntity = (HttpEntity<?>) invocation.getArguments()[2];
        HttpHeaders httpHeaders = httpEntity.getHeaders();
        assertEquals(ifModifiedSince, httpHeaders.getIfModifiedSince());
        assertEquals(ifUnmodifiedSinceValue, httpHeaders.getFirst("If-Unmodified-Since"));
        assertEquals("Keep-Alive", httpHeaders.getFirst("Connection"));
        MultiValueMap<String, String> responseHeaders = new LinkedMultiValueMap<String, String>(httpHeaders);
        responseHeaders.set("Connection", "close");
        responseHeaders.set("Content-Disposition", contentDispositionValue);
        return new ResponseEntity<>(responseHeaders, HttpStatus.OK);
    }).when(template).exchange(Mockito.any(URI.class), Mockito.any(HttpMethod.class), Mockito.any(HttpEntity.class), (Class<?>) isNull());
    PropertyAccessor dfa = new DirectFieldAccessor(this.handler);
    dfa.setPropertyValue("restTemplate", template);
    RequestAttributes attributes = new ServletRequestAttributes(request);
    RequestContextHolder.setRequestAttributes(attributes);
    this.handlerAdapter.handle(request, response, handler);
    assertEquals(ifModifiedSinceValue, response.getHeaderValue("If-Modified-Since"));
    assertEquals(ifUnmodifiedSinceValue, response.getHeaderValue("If-Unmodified-Since"));
    assertEquals("close", response.getHeaderValue("Connection"));
    assertEquals(contentDispositionValue, response.getHeader("Content-Disposition"));
    assertEquals("text/plain", response.getContentType());
    Message<?> message = this.checkHeadersChannel.receive(2000);
    MessageHeaders headers = message.getHeaders();
    assertEquals(ifModifiedSince, headers.get("If-Modified-Since"));
    assertEquals(ifUnmodifiedSince, headers.get("If-Unmodified-Since"));
    RequestContextHolder.resetRequestAttributes();
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) URI(java.net.URI) ZonedDateTime(java.time.ZonedDateTime) MessageHeaders(org.springframework.messaging.MessageHeaders) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) PropertyAccessor(org.springframework.beans.PropertyAccessor) ZoneId(java.time.ZoneId) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Calendar(java.util.Calendar) Instant(java.time.Instant) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) RequestAttributes(org.springframework.web.context.request.RequestAttributes) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) ResponseEntity(org.springframework.http.ResponseEntity) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) RestTemplate(org.springframework.web.client.RestTemplate) DateTimeFormatter(java.time.format.DateTimeFormatter) HttpMethod(org.springframework.http.HttpMethod) Test(org.junit.Test)

Example 92 with ZoneId

use of java.time.ZoneId in project teammates by TEAMMATES.

the class FeedbackSessionAttributesTest method classSetup.

@BeforeClass
public void classSetup() {
    ZoneId timeZone = ZoneId.of("Asia/Singapore");
    startTime = TimeHelper.convertLocalDateTimeToInstant(TimeHelper.combineDateTime("Mon, 09 May, 2016", "1000"), timeZone);
    endTime = TimeHelper.convertLocalDateTimeToInstant(TimeHelper.combineDateTime("Tue, 09 May, 2017", "1000"), timeZone);
    fsa = FeedbackSessionAttributes.builder("", "", "").withStartTime(startTime).withEndTime(endTime).withTimeZone(timeZone).withGracePeriodMinutes(15).withFeedbackSessionType(FeedbackSessionType.STANDARD).withOpeningEmailEnabled(false).withClosingEmailEnabled(false).withPublishedEmailEnabled(false).build();
}
Also used : ZoneId(java.time.ZoneId) BeforeClass(org.testng.annotations.BeforeClass)

Example 93 with ZoneId

use of java.time.ZoneId in project iep by Netflix.

the class ConfigurationTests method zonePacific.

@Test
public void zonePacific() {
    TestConfig config = mkConfig();
    ZoneId v = config.getZonePacific();
    assertEquals("zonePacific", v, ZoneId.of("US/Pacific"));
}
Also used : ZoneId(java.time.ZoneId) Test(org.junit.Test)

Example 94 with ZoneId

use of java.time.ZoneId in project teammates by TEAMMATES.

the class InstructorFeedbackAbstractAction method validateTimeData.

protected void validateTimeData(FeedbackSessionAttributes attributes) throws InvalidParametersException {
    FieldValidator validator = new FieldValidator();
    // Stop if invalid or fixed offset time zone is detected
    String paramTimeZone = getRequestParamValue(Const.ParamsNames.FEEDBACK_SESSION_TIMEZONE);
    String timeZoneErrorMessage = validator.getInvalidityInfoForTimeZone(paramTimeZone);
    if (!timeZoneErrorMessage.isEmpty()) {
        // Collect other errors before throwing an exception
        List<String> errors = new ArrayList<>(attributes.getInvalidityInfo());
        errors.add(timeZoneErrorMessage);
        throw new InvalidParametersException(errors);
    }
    // The time zone is valid at this point and can be used for future calculations
    ZoneId timeZone = attributes.getTimeZone();
    // Warn if ambiguity of time fields (brought about by DST) is detected
    validateLocalDateTimeUnambiguity(inputStartTimeLocal, attributes.getStartTime(), timeZone, FieldValidator.SESSION_START_TIME_FIELD_NAME);
    validateLocalDateTimeUnambiguity(inputEndTimeLocal, attributes.getEndTime(), timeZone, FieldValidator.SESSION_END_TIME_FIELD_NAME);
    validateLocalDateTimeUnambiguity(inputVisibleTimeLocal, attributes.getSessionVisibleFromTime(), timeZone, FieldValidator.SESSION_VISIBLE_TIME_FIELD_NAME);
    validateLocalDateTimeUnambiguity(inputPublishTimeLocal, attributes.getResultsVisibleFromTime(), timeZone, FieldValidator.RESULTS_VISIBLE_TIME_FIELD_NAME);
}
Also used : ZoneId(java.time.ZoneId) FieldValidator(teammates.common.util.FieldValidator) ArrayList(java.util.ArrayList) InvalidParametersException(teammates.common.exception.InvalidParametersException)

Example 95 with ZoneId

use of java.time.ZoneId in project teammates by TEAMMATES.

the class AdminActivityLogPageAction method generateStatusMessage.

private void generateStatusMessage(List<String> versionToQuery, AdminActivityLogPageData data, List<ActivityLogEntry> logs, String courseId) {
    StringBuilder status = new StringBuilder(500);
    status.append("Total Logs gone through in last search: " + totalLogsSearched + "<br>Total Relevant Logs found in last search: " + String.format("%s<br>", logs.size()));
    long earliestSearchTime = data.getFromDate();
    ActivityLogEntry earliestLogChecked = null;
    if (!logs.isEmpty()) {
        earliestLogChecked = logs.get(logs.size() - 1);
    }
    // if the search space is limited to a certain log
    if (logs.size() >= RELEVANT_LOGS_PER_PAGE && earliestLogChecked != null) {
        earliestSearchTime = earliestLogChecked.getLogTime();
    }
    ZoneId targetTimeZone = null;
    if (data.isPersonSpecified()) {
        String targetUserGoogleId = data.getPersonSpecified();
        targetTimeZone = getLocalTimeZoneForRequest(targetUserGoogleId, "");
        if (targetTimeZone == null && courseId != null && !courseId.isEmpty()) {
            // if the user is unregistered, try finding the timezone by course id passed from Search page
            targetTimeZone = getLocalTimeZoneForUnregisteredUserRequest(courseId);
        }
    } else {
        targetTimeZone = Const.SystemParams.ADMIN_TIME_ZONE_ID;
    }
    String timeInAdminTimeZone = TimeHelper.formatActivityLogTime(Instant.ofEpochMilli(earliestSearchTime), Const.SystemParams.ADMIN_TIME_ZONE_ID);
    String timeInUserTimeZone = TimeHelper.formatActivityLogTime(Instant.ofEpochMilli(earliestSearchTime), targetTimeZone);
    status.append("The earliest log entry checked on <b>" + timeInAdminTimeZone + "</b> in Admin Time Zone (" + Const.SystemParams.ADMIN_TIME_ZONE_ID.getId() + ") and ");
    if (targetTimeZone == null) {
        status.append(timeInUserTimeZone).append(".<br>");
    } else {
        status.append("on <b>" + timeInUserTimeZone + "</b> in Local Time Zone (" + targetTimeZone + ").<br>");
    }
    status.append("Logs are from following version(s): ");
    for (int i = 0; i < versionToQuery.size(); i++) {
        String version = versionToQuery.get(i).replace('-', '.');
        if (i < versionToQuery.size() - 1) {
            status.append(version).append(", ");
        } else {
            status.append(version).append("<br>");
        }
    }
    status.append("All available version(s): ");
    GaeVersionApi versionApi = new GaeVersionApi();
    List<Version> versionList = versionApi.getAvailableVersions();
    for (int i = 0; i < versionList.size(); i++) {
        String version = versionList.get(i).toString();
        if (i < versionList.size() - 1) {
            status.append(version).append(", ");
        } else {
            status.append(version).append("<br>");
        }
    }
    // the "Search More" button to continue searching from the previous fromDate
    status.append("<button class=\"btn-link\" id=\"button_older\" data-next-end-time-to-search=\"" + nextEndTimeToSearch + "\">Search More</button><input id=\"ifShowAll\" type=\"hidden\" value=\"" + data.getShouldShowAllLogs() + "\"/><input id=\"ifShowTestData\" type=\"hidden\" value=\"" + data.getShouldShowTestData() + "\"/>");
    String statusString = status.toString();
    data.setStatusForAjax(statusString);
    statusToUser.add(new StatusMessage(statusString, StatusMessageColor.INFO));
}
Also used : ActivityLogEntry(teammates.common.util.ActivityLogEntry) ZoneId(java.time.ZoneId) Version(teammates.common.util.Version) GaeVersionApi(teammates.common.util.GaeVersionApi) StatusMessage(teammates.common.util.StatusMessage)

Aggregations

ZoneId (java.time.ZoneId)420 Test (org.junit.Test)137 ZonedDateTime (java.time.ZonedDateTime)108 LocalDateTime (java.time.LocalDateTime)69 LocalDate (java.time.LocalDate)55 Instant (java.time.Instant)49 Test (org.testng.annotations.Test)41 ZoneOffset (java.time.ZoneOffset)37 DateTimeFormatter (java.time.format.DateTimeFormatter)32 Date (java.util.Date)29 ArrayList (java.util.ArrayList)23 LocalTime (java.time.LocalTime)21 TemporalAccessor (java.time.temporal.TemporalAccessor)15 List (java.util.List)15 HashMap (java.util.HashMap)14 Clock (java.time.Clock)13 Collectors (java.util.stream.Collectors)13 DateTimeException (java.time.DateTimeException)12 Duration (java.time.Duration)12 OffsetDateTime (java.time.OffsetDateTime)11