List of usage examples for java.time OffsetDateTime now
public static OffsetDateTime now()
From source file:org.jimsey.project.turbine.spring.domain.StrategyJsonTest.java
@Ignore @Test/* ww w . jav a2 s . com*/ public void testSerializable() throws IOException { strategy = new StrategyJson(1401174943825l, TurbineTestConstants.SYMBOL, TurbineTestConstants.MARKET, 100.0d, "enter", "myname", 1, 6, 11.0d, 14.0d, OffsetDateTime.now().toString()); byte[] bytes = SerializationUtils.serialize(strategy); TickJson strategy2 = (TickJson) SerializationUtils.deserialize(bytes); logger.info(strategy.toString()); logger.info(strategy2.toString()); }
From source file:org.jimsey.project.turbine.spring.domain.IndicatorJsonTest.java
@Ignore @Test/* w w w .j av a 2s.c o m*/ public void testSerializable() throws IOException { indicator = new IndicatorJson(OffsetDateTime.now(), 100.0d, indicators, TurbineTestConstants.SYMBOL, TurbineTestConstants.MARKET, name, OffsetDateTime.now().toString()); byte[] bytes = SerializationUtils.serialize(indicator); TickJson stock2 = (TickJson) SerializationUtils.deserialize(bytes); logger.info(indicator.toString()); logger.info(stock2.toString()); }
From source file:org.jimsey.projects.turbine.fuel.domain.RandomDomainObjectGenerator.java
@Override public StrategyJson newStrategy(OffsetDateTime date, String name) { final double variation = 3.0d; double close = tick.getClose(); String action = "none"; Integer amount = 0;// w w w . j a va2 s .c o m Integer position = 0; Double cash = 250d; Double value = 0d; strategy = new StrategyJson(date, this.market, this.symbol, close, name, action, amount, position, cash, value, OffsetDateTime.now().toString()); return strategy; }
From source file:org.jimsey.projects.turbine.fuel.domain.RandomDomainObjectGenerator.java
@Override public TickJson newTick() { tick = newTick(OffsetDateTime.now()); return tick; }
From source file:org.jimsey.projects.turbine.fuel.domain.RandomDomainObjectGenerator.java
@Override public IndicatorJson newIndicator(String name) { return newIndicator(OffsetDateTime.now(), name); }
From source file:org.jimsey.projects.turbine.fuel.domain.RandomDomainObjectGenerator.java
@Override public StrategyJson newStrategy(String name) { return newStrategy(OffsetDateTime.now(), name); }
From source file:org.springframework.session.web.http.DefaultCookieSerializer.java
@Override public void writeCookieValue(CookieValue cookieValue) { HttpServletRequest request = cookieValue.getRequest(); HttpServletResponse response = cookieValue.getResponse(); StringBuilder sb = new StringBuilder(); sb.append(this.cookieName).append('='); String value = getValue(cookieValue); if (value != null && value.length() > 0) { validateValue(value);//from w w w . j av a2s .c o m sb.append(value); } int maxAge = getMaxAge(cookieValue); if (maxAge > -1) { sb.append("; Max-Age=").append(cookieValue.getCookieMaxAge()); OffsetDateTime expires = (maxAge != 0) ? OffsetDateTime.now().plusSeconds(maxAge) : Instant.EPOCH.atOffset(ZoneOffset.UTC); sb.append("; Expires=").append(expires.format(DateTimeFormatter.RFC_1123_DATE_TIME)); } String domain = getDomainName(request); if (domain != null && domain.length() > 0) { validateDomain(domain); sb.append("; Domain=").append(domain); } String path = getCookiePath(request); if (path != null && path.length() > 0) { validatePath(path); sb.append("; Path=").append(path); } if (isSecureCookie(request)) { sb.append("; Secure"); } if (this.useHttpOnlyCookie) { sb.append("; HttpOnly"); } if (this.sameSite != null) { sb.append("; SameSite=").append(this.sameSite); } response.addHeader("Set-Cookie", sb.toString()); }
From source file:com.nike.cerberus.service.AuthenticationServiceTest.java
@Test public void test_that_getKeyId_only_validates_kms_policy_one_time_within_interval() { String principalArn = "principal arn"; String region = "region"; String iamRoleId = "iam role id"; String kmsKeyId = "kms id"; String cmkId = "key id"; // ensure that validate interval is passed OffsetDateTime dateTime = OffsetDateTime.of(2016, 1, 1, 1, 1, 1, 1, ZoneOffset.UTC); OffsetDateTime now = OffsetDateTime.now(); IamPrincipalCredentials iamPrincipalCredentials = new IamPrincipalCredentials(); iamPrincipalCredentials.setIamPrincipalArn(principalArn); iamPrincipalCredentials.setRegion(region); AwsIamRoleRecord awsIamRoleRecord = new AwsIamRoleRecord().setAwsIamRoleArn(principalArn); awsIamRoleRecord.setAwsIamRoleArn(principalArn); awsIamRoleRecord.setId(iamRoleId);/*w w w .j av a 2s . c o m*/ when(awsIamRoleDao.getIamRole(principalArn)).thenReturn(Optional.of(awsIamRoleRecord)); AwsIamRoleKmsKeyRecord awsIamRoleKmsKeyRecord = new AwsIamRoleKmsKeyRecord(); awsIamRoleKmsKeyRecord.setId(kmsKeyId); awsIamRoleKmsKeyRecord.setAwsKmsKeyId(cmkId); awsIamRoleKmsKeyRecord.setLastValidatedTs(dateTime); when(awsIamRoleDao.getKmsKey(iamRoleId, region)).thenReturn(Optional.of(awsIamRoleKmsKeyRecord)); when(dateTimeSupplier.get()).thenReturn(now); String result = authenticationService.getKeyId(iamPrincipalCredentials); // verify validate is called once interval has passed assertEquals(cmkId, result); verify(kmsService, times(1)).validatePolicy(awsIamRoleKmsKeyRecord, principalArn); }
From source file:com.nike.cerberus.service.MetadataServiceTest.java
@Test public void test_that_get_sdb_metadata_list_returns_valid_list() { String sdbId = "123"; String categoryName = "foo"; String categoryId = "321"; String name = "test-name"; String path = "app/test-name"; String desc = "blah blah blah"; String by = "justin.field@nike.com"; String careBearsGroup = "care-bears"; String careBearsId = "000-abc"; String grumpyBearsGroup = "grumpy-bears"; String grumpyBearsId = "111-def"; String ownerId = "000"; String readId = "111"; String arn = "arn:aws:iam::12345:role/foo-role"; OffsetDateTime offsetDateTime = OffsetDateTime.now(); Map<String, String> catMap = new HashMap<>(); catMap.put(categoryId, categoryName); Map<String, String> roleIdToStringMap = new HashMap<>(); roleIdToStringMap.put(ownerId, RoleRecord.ROLE_OWNER); roleIdToStringMap.put(readId, RoleRecord.ROLE_READ); when(roleService.getRoleIdToStringMap()).thenReturn(roleIdToStringMap); when(categoryService.getCategoryIdToCategoryNameMap()).thenReturn(catMap); SafeDepositBoxV2 box = new SafeDepositBoxV2(); box.setId(sdbId);/*from w w w . j av a 2 s. c om*/ box.setName(name); box.setPath(path); box.setDescription(desc); box.setCategoryId(categoryId); box.setCreatedBy(by); box.setLastUpdatedBy(by); box.setCreatedTs(offsetDateTime); box.setLastUpdatedTs(offsetDateTime); box.setOwner(careBearsGroup); Set<UserGroupPermission> userPerms = new HashSet<>(); userPerms.add(new UserGroupPermission().withName(grumpyBearsGroup).withRoleId(readId)); box.setUserGroupPermissions(userPerms); Set<IamPrincipalPermission> iamPerms = new HashSet<>(); iamPerms.add(new IamPrincipalPermission().withIamPrincipalArn(arn).withRoleId(readId)); box.setIamPrincipalPermissions(iamPerms); when(safeDepositBoxService.getSafeDepositBoxes(1, 0)).thenReturn(Arrays.asList(box)); List<SDBMetadata> actual = metadataService.getSDBMetadataList(1, 0); assertEquals("List should have 1 entry", 1, actual.size()); SDBMetadata data = actual.get(0); assertEquals("Name should match record", name, data.getName()); assertEquals("path should match record", path, data.getPath()); assertEquals("", categoryName, data.getCategory()); assertEquals("desc should match record", desc, data.getDescription()); assertEquals("created by should match record", by, data.getCreatedBy()); assertEquals("last updated by should match record", by, data.getLastUpdatedBy()); assertEquals("created ts should match record", offsetDateTime, data.getCreatedTs()); assertEquals("updated ts should match record", offsetDateTime, data.getLastUpdatedTs()); Map<String, String> expectedIamPermMap = new HashMap<>(); expectedIamPermMap.put(arn, RoleRecord.ROLE_READ); assertEquals("iam role perm map should match what is returned by getIamPrincipalPermissionMap", expectedIamPermMap, data.getIamRolePermissions()); Map<String, String> expectedGroupPermMap = new HashMap<>(); expectedGroupPermMap.put(grumpyBearsGroup, RoleRecord.ROLE_READ); assertEquals("Owner group should be care-bears", careBearsGroup, data.getOwner()); assertEquals("The user group perms should match the expected map", expectedGroupPermMap, data.getUserGroupPermissions()); }
From source file:org.openmhealth.shim.jawbone.JawboneShim.java
protected ResponseEntity<ShimDataResponse> getData(OAuth2RestOperations restTemplate, ShimDataRequest shimDataRequest) throws ShimException { final JawboneDataTypes jawboneDataType; try {//from w w w .j a v a 2 s . co m jawboneDataType = JawboneDataTypes.valueOf(shimDataRequest.getDataTypeKey().trim().toUpperCase()); } catch (NullPointerException | IllegalArgumentException e) { throw new ShimException("Null or Invalid data type parameter: " + shimDataRequest.getDataTypeKey() + " in shimDataRequest, cannot retrieve data."); } /* Jawbone defaults to returning a maximum of 10 entries per request (limit = 10 by default), so we override the default by specifying an arbitrarily large number as the limit. */ long numToReturn = 100_000; OffsetDateTime today = OffsetDateTime.now(); OffsetDateTime startDateTime = shimDataRequest.getStartDateTime() == null ? today.minusDays(1) : shimDataRequest.getStartDateTime(); long startTimeInEpochSecond = startDateTime.toEpochSecond(); // We are inclusive of the last day, so we need to add an extra day since we are dealing with start of day, // and would miss the activities that occurred during the last day within going to midnight of that day OffsetDateTime endDateTime = shimDataRequest.getEndDateTime() == null ? today.plusDays(1) : shimDataRequest.getEndDateTime().plusDays(1); long endTimeInEpochSecond = endDateTime.toEpochSecond(); UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString(DATA_URL) .path(jawboneDataType.getEndPoint()).queryParam("start_time", startTimeInEpochSecond) .queryParam("end_time", endTimeInEpochSecond).queryParam("limit", numToReturn); ResponseEntity<JsonNode> responseEntity; try { responseEntity = restTemplate.getForEntity(uriComponentsBuilder.build().encode().toUri(), JsonNode.class); } catch (HttpClientErrorException | HttpServerErrorException e) { // FIXME figure out how to handle this logger.error("A request for Jawbone data failed.", e); throw e; } if (shimDataRequest.getNormalize()) { JawboneDataPointMapper mapper; switch (jawboneDataType) { case WEIGHT: mapper = new JawboneBodyWeightDataPointMapper(); break; case STEPS: mapper = new JawboneStepCountDataPointMapper(); break; case BODY_MASS_INDEX: mapper = new JawboneBodyMassIndexDataPointMapper(); break; case ACTIVITY: mapper = new JawbonePhysicalActivityDataPointMapper(); break; case SLEEP: mapper = new JawboneSleepDurationDataPointMapper(); break; case HEART_RATE: mapper = new JawboneHeartRateDataPointMapper(); break; default: throw new UnsupportedOperationException(); } return ResponseEntity.ok().body(ShimDataResponse.result(JawboneShim.SHIM_KEY, mapper.asDataPoints(singletonList(responseEntity.getBody())))); } else { return ResponseEntity.ok() .body(ShimDataResponse.result(JawboneShim.SHIM_KEY, responseEntity.getBody())); } }