@Override public Date getStartedAt() { String dateString = settings.get(CoreProperties.SERVER_STARTTIME).orElseThrow(() -> new IllegalStateException("Mandatory")); return DateUtils.parseDateTime(dateString); }
/** * Load from database */ private static StartupMetadata load(DbClient dbClient) { try (DbSession dbSession = dbClient.openSession(false)) { String startedAt = selectProperty(dbClient, dbSession, SERVER_STARTTIME); return new StartupMetadata(DateUtils.parseDateTime(startedAt).getTime()); } }
@Test public void format_date() { TimeZone initialTz = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("GMT+1")); assertThat(underTest.formatDate(Locale.ENGLISH, DateUtils.parseDateTime("2014-01-22T19:10:03+0100"))).isEqualTo("Jan 22, 2014"); TimeZone.setDefault(initialTz); }
public QualityProfiles(Collection<QualityProfile> profiles) { Map<String, QProfile> map = new HashMap<>(profiles.size()); for (QualityProfile qProfile : profiles) { map.put(qProfile.getLanguage(), new QProfile.Builder() .setKey(qProfile.getKey()) .setName(qProfile.getName()) .setLanguage(qProfile.getLanguage()) .setRulesUpdatedAt(DateUtils.parseDateTime(qProfile.getRulesUpdatedAt())).build()); } byLanguage = Collections.unmodifiableMap(map); }
@Test public void format_date_time() { TimeZone initialTz = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("GMT+1")); assertThat(underTest.formatDateTime(Locale.ENGLISH, DateUtils.parseDateTime("2014-01-22T19:10:03+0100"))).startsWith("Jan 22, 2014"); TimeZone.setDefault(initialTz); }
@Before public void wireMocksTogether() { when(updateCenterFactory.getUpdateCenter(anyBoolean())).thenReturn(Optional.of(updateCenter)); when(updateCenter.getDate()).thenReturn(DateUtils.parseDateTime("2015-04-24T16:08:36+0200")); } }
@Before public void wireMocks() { when(updateCenterFactory.getUpdateCenter(anyBoolean())).thenReturn(Optional.of(updateCenter)); when(updateCenter.getDate()).thenReturn(DateUtils.parseDateTime("2015-04-24T16:08:36+0200")); }
@Test public void parseDateTime_fail_if_additional_characters() { expectedException.expect(MessageException.class); DateUtils.parseDateTime("1986-12-04T01:02:03+0300foo"); }
@DataProvider public static Object[][] date_times() { return new Object[][] { {"2014-05-27", parseDate("2014-05-27")}, {"2014-05-27T15:50:45+0100", parseDateTime("2014-05-27T15:50:45+0100")}, {null, null} }; }
@DataProvider public static Object[][] ending_date_times() { return new Object[][] { {"2014-05-27", parseDate("2014-05-28")}, {"2014-05-27T15:50:45+0100", parseDateTime("2014-05-27T15:50:45+0100")}, {null, null} }; }
public static PurgeableAnalysisDto createAnalysisWithDateTime(String analysisUuid, String datetime) { PurgeableAnalysisDto snapshot = new PurgeableAnalysisDto(); snapshot.setAnalysisUuid(analysisUuid); snapshot.setDate(DateUtils.parseDateTime(datetime).getTime()); return snapshot; }
@Test public void verify_example() throws Exception { when(dialect.supportsMigration()).thenReturn(true); when(migrationState.getStatus()).thenReturn(RUNNING); when(migrationState.getStartedAt()).thenReturn(DateUtils.parseDateTime("2015-02-23T18:54:23+0100")); underTest.handle(request, response); assertJson(response.outputAsString()).isSimilarTo(getClass().getResource("example-migrate_db.json")); }
@Test public void verify_example() throws Exception { when(dialect.supportsMigration()).thenReturn(true); when(migrationState.getStatus()).thenReturn(RUNNING); when(migrationState.getStartedAt()).thenReturn(DateUtils.parseDateTime("2015-02-23T18:54:23+0100")); underTest.handle(request, response); assertJson(response.outputAsString()).isSimilarTo(getClass().getResource("example-migrate_db.json")); }
@Test public void set_created_after_from_created_since() { Date now = DateUtils.parseDateTime("2013-07-25T07:35:00+0100"); when(clock.instant()).thenReturn(now.toInstant()); when(clock.getZone()).thenReturn(ZoneOffset.UTC); SearchRequest request = new SearchRequest() .setCreatedInLast("1y2m3w4d"); assertThat(underTest.create(request).createdAfter().date()).isEqualTo(DateUtils.parseDateTime("2012-04-30T07:35:00+0100")); assertThat(underTest.create(request).createdAfter().inclusive()).isTrue(); }
@Test public void setProperty_date() { Settings settings = new MapSettings(); Date date = DateUtils.parseDateTime("2010-05-18T15:50:45+0100"); settings.setProperty("aDate", date); settings.setProperty("aDateTime", date, true); assertThat(settings.getString("aDate")).isEqualTo("2010-05-18"); assertThat(settings.getString("aDateTime")).startsWith("2010-05-18T"); }
@Test public void creation_date_support_zoneddatetime() { SearchRequest request = new SearchRequest() .setCreatedAt("2013-04-16T09:08:24+0200"); IssueQuery query = underTest.create(request); assertThat(query.createdAt()).isEqualTo(DateUtils.parseDateTime("2013-04-16T09:08:24+0200")); }
@Test public void facet_on_created_at_with_one_day() { SearchOptions options = fixtureForCreatedAtFacet(); SearchResponse result = underTest.search(IssueQuery.builder() .createdAfter(parseDateTime("2014-09-01T00:00:00-0100")) .createdBefore(parseDateTime("2014-09-02T00:00:00-0100")).build(), options); Map<String, Long> createdAt = new Facets(result, system2.getDefaultTimeZone()).get("createdAt"); assertThat(createdAt).containsOnly( entry("2014-09-01", 2L)); }
@Test public void return_component_info_when_snapshot() { ComponentDto project = insertOrganizationAndProject(); db.components().insertSnapshot(project, snapshot -> snapshot .setCreatedAt(parseDateTime("2015-04-22T11:44:00+0200").getTime()) .setVersion("3.14")); userSession.addProjectPermission(UserRole.USER, project); init(); executeAndVerify(project.getDbKey(), "return_component_info_when_snapshot.json"); }
@Test public void facet_on_created_at() { SearchOptions searchOptions = fixtureForCreatedAtFacet(); Builder query = newQueryBuilder().createdBefore(parseDateTime("2016-01-01T00:00:00+0100")); Map<String, Long> createdAt = new Facets(underTest.search(query.build(), searchOptions), system2.getDefaultTimeZone()).get("createdAt"); assertThat(createdAt).containsOnly( entry("2011-01-01", 10L), entry("2012-01-01", 0L), entry("2013-01-01", 0L), entry("2014-01-01", 50L), entry("2015-01-01", 10L)); }
@Test public void show_scm() throws Exception { userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project, file); dbTester.getDbClient().fileSourceDao().insert(dbSession, new FileSourceDto() .setProjectUuid(PROJECT_UUID) .setFileUuid(FILE_UUID) .setSourceData(DbFileSources.Data.newBuilder().addLines( newSourceLine("julien", "123-456-789", DateUtils.parseDateTime("2015-03-30T12:34:56+0000"), 1)).build())); dbSession.commit(); WsTester.TestRequest request = tester.newGetRequest("api/sources", "scm").setParam("key", FILE_KEY); request.execute().assertJson(getClass(), "show_scm.json"); }