diff options
author | Martin Stockhammer <martin_s@apache.org> | 2019-08-20 20:08:49 +0200 |
---|---|---|
committer | Martin Stockhammer <martin_s@apache.org> | 2019-08-20 20:08:49 +0200 |
commit | 379a72c3b7ea9d6474f71c3d1cbffa98765af8d9 (patch) | |
tree | 459029d69e82ab5a558fa45d92f3e880a8263273 /archiva-modules/archiva-web/archiva-rss | |
parent | 7a5bc65de4877f79b7c8ff30fc4f77976cce46cb (diff) | |
download | archiva-379a72c3b7ea9d6474f71c3d1cbffa98765af8d9.tar.gz archiva-379a72c3b7ea9d6474f71c3d1cbffa98765af8d9.zip |
Changing time parameter
Diffstat (limited to 'archiva-modules/archiva-web/archiva-rss')
4 files changed, 29 insertions, 23 deletions
diff --git a/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessor.java b/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessor.java index 99260c52b..2e93e62ac 100644 --- a/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessor.java +++ b/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessor.java @@ -97,7 +97,7 @@ public class NewArtifactsRssFeedProcessor throws FeedException { - ZonedDateTime greaterThanThisDate = ZonedDateTime.of(LocalDateTime.now(), GMT_TIME_ZONE.toZoneId()).minusDays( + ZonedDateTime greaterThanThisDate = ZonedDateTime.now(GMT_TIME_ZONE.toZoneId()).minusDays( getNumberOfDaysBeforeNow() ).truncatedTo(ChronoUnit.SECONDS); List<ArtifactMetadata> artifacts; @@ -118,7 +118,7 @@ public class NewArtifactsRssFeedProcessor int idx = 0; for ( ArtifactMetadata artifact : artifacts ) { - long whenGathered = artifact.getWhenGathered().getTime(); + long whenGathered = artifact.getWhenGathered().toInstant().toEpochMilli(); String id = artifact.getNamespace() + "/" + artifact.getProject() + "/" + artifact.getId(); if ( tmp != whenGathered ) @@ -133,7 +133,7 @@ public class NewArtifactsRssFeedProcessor String repoId1 = artifact.getRepositoryId(); entry = new RssFeedEntry( this.getTitle() + "\'" + repoId1 + "\'" + " as of " + new Date( whenGathered ) ); - entry.setPublishedDate( artifact.getWhenGathered() ); + entry.setPublishedDate( Date.from(artifact.getWhenGathered().toInstant()) ); description = this.getDescription() + "\'" + repoId1 + "\'" + ": \n" + id + " | "; } else diff --git a/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessor.java b/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessor.java index aae625c64..bb58befd6 100644 --- a/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessor.java +++ b/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessor.java @@ -32,6 +32,7 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import javax.inject.Inject; +import java.time.ZoneId; import java.util.ArrayList; import java.util.Collection; import java.util.Date; @@ -116,7 +117,7 @@ public class NewVersionsOfArtifactRssFeedProcessor int idx = 0; for ( ArtifactMetadata artifact : artifacts ) { - long whenGathered = artifact.getWhenGathered().getTime(); + long whenGathered = artifact.getWhenGathered().toInstant().toEpochMilli(); if ( tmp != whenGathered ) { @@ -129,7 +130,7 @@ public class NewVersionsOfArtifactRssFeedProcessor entry = new RssFeedEntry( this.getTitle() + "\'" + groupId + ":" + artifactId + "\'" + " as of " + new Date( whenGathered ) ); - entry.setPublishedDate( artifact.getWhenGathered() ); + entry.setPublishedDate( Date.from(artifact.getWhenGathered().toInstant()) ); description = this.getDescription() + "\'" + groupId + ":" + artifactId + "\'" + ": \n" + artifact.getId() + " | "; diff --git a/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessorTest.java b/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessorTest.java index f6e33101a..89ddd63ce 100644 --- a/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessorTest.java +++ b/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessorTest.java @@ -34,6 +34,8 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import java.time.LocalDateTime; +import java.time.ZoneId; import java.time.ZonedDateTime; import java.time.temporal.ChronoUnit; import java.util.ArrayList; @@ -95,7 +97,7 @@ public class NewArtifactsRssFeedProcessorTest throws Exception { List<ArtifactMetadata> newArtifacts = new ArrayList<>(); - Date whenGathered = Calendar.getInstance().getTime(); + ZonedDateTime whenGathered = ZonedDateTime.of(LocalDateTime.now(), ZoneId.systemDefault()); newArtifacts.add( createArtifact( "artifact-one", "1.0", whenGathered ) ); newArtifacts.add( createArtifact( "artifact-one", "1.1", whenGathered ) ); @@ -115,9 +117,8 @@ public class NewArtifactsRssFeedProcessorTest SyndFeed feed = newArtifactsProcessor.process( reqParams ); // check that the date used in the call is close to the one passed (5 seconds difference at most) - Calendar cal = Calendar.getInstance( TimeZone.getTimeZone( "GMT" ) ); - cal.add( Calendar.DATE, -30 ); - assertTrue( metadataRepository.getFrom().minus(cal.getTimeInMillis(), ChronoUnit.MILLIS).toInstant().toEpochMilli() < 1000 * 5 ); + ZonedDateTime cal = ZonedDateTime.of(LocalDateTime.now(), ZoneId.systemDefault()).minusDays(30); + assertTrue(ChronoUnit.SECONDS.between(cal.toInstant(), metadataRepository.getFrom().toInstant())<5); assertEquals( null, metadataRepository.getTo() ); assertEquals( TEST_REPO, metadataRepository.getRepoId() ); @@ -125,16 +126,16 @@ public class NewArtifactsRssFeedProcessorTest assertTrue( feed.getDescription().equals( "New artifacts found in repository 'test-repo' during repository scan." ) ); assertTrue( feed.getLanguage().equals( "en-us" ) ); - assertTrue( feed.getPublishedDate().equals( whenGathered ) ); + assertTrue( feed.getPublishedDate().toInstant().equals( whenGathered.toInstant() ) ); List<SyndEntry> entries = feed.getEntries(); assertEquals( entries.size(), 1 ); assertTrue( - entries.get( 0 ).getTitle().equals( "New Artifacts in Repository 'test-repo' as of " + whenGathered ) ); - assertTrue( entries.get( 0 ).getPublishedDate().equals( whenGathered ) ); + entries.get( 0 ).getTitle().contains( "New Artifacts in Repository 'test-repo' as of " )); + assertTrue( entries.get( 0 ).getPublishedDate().toInstant().equals( whenGathered.toInstant() ) ); } - private ArtifactMetadata createArtifact( String artifactId, String version, Date whenGathered ) + private ArtifactMetadata createArtifact( String artifactId, String version, ZonedDateTime whenGathered ) { ArtifactMetadata artifact = new ArtifactMetadata(); artifact.setNamespace( "org.apache.archiva" ); diff --git a/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessorTest.java b/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessorTest.java index eef6a96ad..017b2c854 100644 --- a/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessorTest.java +++ b/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessorTest.java @@ -40,6 +40,9 @@ import org.junit.Test; import org.junit.runner.RunWith; import java.nio.file.Paths; +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.time.temporal.TemporalAccessor; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -119,12 +122,14 @@ public class NewVersionsOfArtifactRssFeedProcessorTest public void testProcess() throws Exception { - Date whenGathered = new Date( 123456789 ); + Date whenGatheredDate = new Date( 123456789 ); + ZonedDateTime whenGathered = ZonedDateTime.ofInstant(whenGatheredDate.toInstant(), ZoneId.systemDefault()); ArtifactMetadata artifact1 = createArtifact( whenGathered, "1.0.1" ); ArtifactMetadata artifact2 = createArtifact( whenGathered, "1.0.2" ); - Date whenGatheredNext = new Date( 345678912 ); + Date whenGatheredNextDate = new Date( 345678912 ); + ZonedDateTime whenGatheredNext = ZonedDateTime.ofInstant(whenGatheredNextDate.toInstant(), ZoneId.systemDefault()); ArtifactMetadata artifact3 = createArtifact( whenGatheredNext, "1.0.3-SNAPSHOT" ); @@ -148,24 +153,23 @@ public class NewVersionsOfArtifactRssFeedProcessorTest assertEquals( "New versions of artifact 'org.apache.archiva:artifact-two' found during repository scan.", feed.getDescription() ); assertEquals( "en-us", feed.getLanguage() ); - assertEquals( whenGatheredNext, feed.getPublishedDate() ); + assertEquals( whenGatheredNext.toInstant(), ZonedDateTime.ofInstant(feed.getPublishedDate().toInstant(), ZoneId.systemDefault()).toInstant() ); List<SyndEntry> entries = feed.getEntries(); assertEquals( 2, entries.size() ); - assertEquals( "New Versions of Artifact 'org.apache.archiva:artifact-two' as of " + whenGathered, - entries.get( 0 ).getTitle() ); - assertEquals( whenGathered, entries.get( 0 ).getPublishedDate() ); + assertTrue( entries.get(0).getTitle().contains("New Versions of Artifact 'org.apache.archiva:artifact-two' as of ")); + assertEquals( whenGathered.toInstant(), entries.get( 0 ).getPublishedDate().toInstant() ); - assertEquals( "New Versions of Artifact 'org.apache.archiva:artifact-two' as of " + whenGatheredNext, - entries.get( 1 ).getTitle() ); - assertEquals( whenGatheredNext, entries.get( 1 ).getPublishedDate() ); + assertTrue(entries.get(1).getTitle().contains("New Versions of Artifact 'org.apache.archiva:artifact-two' as of ")); + + assertEquals( whenGatheredNext.toInstant(), entries.get( 1 ).getPublishedDate().toInstant() ); metadataRepositoryControl.verify(); } - private ArtifactMetadata createArtifact( Date whenGathered, String version ) + private ArtifactMetadata createArtifact(ZonedDateTime whenGathered, String version ) { ArtifactMetadata artifact = new ArtifactMetadata(); artifact.setNamespace( GROUP_ID ); |