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();
}
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();
}
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"));
}
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);
}
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));
}
Aggregations