@CheckForNull public Date paramAsDate(String key) { String s = param(key); if (s == null) { return null; } try { return DateUtils.parseDate(s); } catch (RuntimeException notDateException) { throw new IllegalArgumentException(notDateException); } }
@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} }; }
@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} }; }
@Test public void parseDate_valid_format() { Date date = DateUtils.parseDate("2010-05-18"); assertThat(date.getDate()).isEqualTo(18); }
@Test public void should_delete_only_old_closed_issues() { Date now = DateUtils.parseDate("2013-05-18"); PurgeConfiguration conf = new PurgeConfiguration(new IdUuidPair(1L, "1"), emptyList(), 30, Optional.empty(), System2.INSTANCE, emptyList()); Date toDate = conf.maxLiveDateOfClosedIssues(now); assertThat(toDate.getYear()).isEqualTo(113);// =2013 assertThat(toDate.getMonth()).isEqualTo(3); // means April assertThat(toDate.getDate()).isEqualTo(18); }
@Test public void create_from_comment_with_created_at() { DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "user_uuid", "the comment"); comment.setCreatedAt(parseDate("2015-01-13")); IssueChangeDto dto = IssueChangeDto.of(comment); assertThat(dto.getIssueChangeCreationDate()).isEqualTo(parseDate("2015-01-13").getTime()); }
@Test public void parseDate_not_lenient() { expectedException.expect(MessageException.class); DateUtils.parseDate("2010-13-18"); }
@Test public void parseDateTime_not_valid_format() { expectedException.expect(MessageException.class); DateUtils.parseDate("2010/05/18 10:55"); }
@Test public void parseDate_fail_if_additional_characters() { expectedException.expect(MessageException.class); DateUtils.parseDate("1986-12-04foo"); }
@Test public void create_from_diff_with_created_at() { FieldDiffs diffs = new FieldDiffs(); diffs.setDiff("severity", "INFO", "BLOCKER"); diffs.setUserUuid("user_uuid"); diffs.setCreationDate(parseDate("2015-01-13")); IssueChangeDto dto = IssueChangeDto.of("ABCDE", diffs); assertThat(dto.getIssueChangeCreationDate()).isEqualTo(parseDate("2015-01-13").getTime()); }
public static PurgeableAnalysisDto createAnalysisWithDate(String analysisUuid, String date) { PurgeableAnalysisDto snapshot = new PurgeableAnalysisDto(); snapshot.setAnalysisUuid(analysisUuid); snapshot.setDate(DateUtils.parseDate(date).getTime()); return snapshot; }
@Test public void filter_by_created_before_must_be_lower_than_after() { try { underTest.search(IssueQuery.builder().createdAfter(parseDate("2014-09-20")).createdBefore(parseDate("2014-09-19")).build(), new SearchOptions()); Fail.failBecauseExceptionWasNotThrown(IllegalArgumentException.class); } catch (IllegalArgumentException exception) { assertThat(exception.getMessage()).isEqualTo("Start bound cannot be larger or equal to end bound"); } }
@Test public void toDate() { assertThat(RubyUtils.toDate(null)).isNull(); assertThat(RubyUtils.toDate("")).isNull(); assertThat(RubyUtils.toDate(" ")).isNull(); assertThat(RubyUtils.toDate("2013-01-18").getDate()).isEqualTo(18); assertThat(RubyUtils.toDate("2013-01-18T15:38:19+0200").getDate()).isEqualTo(18); assertThat(RubyUtils.toDate("2013-01-18T15:38:19+0200").getMinutes()).isEqualTo(38); assertThat(RubyUtils.toDate(DateUtils.parseDate("2013-01-18")).getDate()).isEqualTo(18); }
@Test public void shouldKeepNonDeletableSnapshots() { Filter filter = new KeepOneFilter(DateUtils.parseDate("2011-03-25"), DateUtils.parseDate("2011-08-25"), Calendar.MONTH, "month"); List<PurgeableAnalysisDto> toDelete = filter.filter(Arrays.asList( DbCleanerTestUtils.createAnalysisWithDate("u1", "2011-05-01"), // to be deleted DbCleanerTestUtils.createAnalysisWithDate("u2", "2011-05-02").setLast(true), DbCleanerTestUtils.createAnalysisWithDate("u3", "2011-05-19").setHasEvents(true).setLast(false), DbCleanerTestUtils.createAnalysisWithDate("u4", "2011-05-23") // to be deleted )); assertThat(toDelete).hasSize(2); assertThat(analysisUuids(toDelete)).contains("u1", "u4"); }
@Test public void dates_are_inclusive() { SearchRequest request = new SearchRequest() .setCreatedAfter("2013-04-16") .setCreatedBefore("2013-04-17"); IssueQuery query = underTest.create(request); assertThat(query.createdAfter().date()).isEqualTo(DateUtils.parseDate("2013-04-16")); assertThat(query.createdAfter().inclusive()).isTrue(); assertThat(query.createdBefore()).isEqualTo(DateUtils.parseDate("2013-04-18")); }
@Test public void creation_date_support_localdate() { SearchRequest request = new SearchRequest() .setCreatedAt("2013-04-16"); IssueQuery query = underTest.create(request); assertThat(query.createdAt()).isEqualTo(DateUtils.parseDate("2013-04-16")); }
@Test public void shouldDeleteAllSnapshotsPriorToDate() { Filter filter = new DeleteAllFilter(DateUtils.parseDate("2011-12-25")); List<PurgeableAnalysisDto> toDelete = filter.filter(Arrays.asList( DbCleanerTestUtils.createAnalysisWithDate("u1", "2010-01-01"), DbCleanerTestUtils.createAnalysisWithDate("u2", "2010-12-25"), DbCleanerTestUtils.createAnalysisWithDate("u3", "2012-01-01") )); assertThat(toDelete).extracting("analysisUuid").containsOnly("u1", "u2"); } }
@Test public void keep_only_analyses_with_a_version() { Filter underTest = new KeepWithVersionFilter(parseDate("2015-10-18")); List<PurgeableAnalysisDto> result = underTest.filter(Arrays.asList( DbCleanerTestUtils.createAnalysisWithDate("u1", "2015-10-17").setVersion("V1"), DbCleanerTestUtils.createAnalysisWithDate("u2", "2015-10-17").setVersion(null), DbCleanerTestUtils.createAnalysisWithDate("u3", "2015-10-19").setVersion(null))); assertThat(result).extracting(PurgeableAnalysisDto::getAnalysisUuid).containsExactlyInAnyOrder("u2"); } }
@Test public void do_not_update_created_at_on_existing_component() { Date oldDate = DateUtils.parseDate("2015-01-01"); ComponentDto project = prepareProject(p -> p.setCreatedAt(oldDate)); db.getSession().commit(); treeRootHolder.setRoot( builder(PROJECT, 1).setUuid(project.uuid()).setKey(project.getDbKey()) .build()); underTest.execute(new TestComputationStepContext()); Optional<ComponentDto> projectReloaded = dbClient.componentDao().selectByUuid(db.getSession(), project.uuid()); assertThat(projectReloaded.get().getCreatedAt()).isNotEqualTo(now); }