1 package org.apache.archiva.rss.processor;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import com.sun.syndication.feed.synd.SyndEntry;
23 import com.sun.syndication.feed.synd.SyndFeed;
24 import junit.framework.TestCase;
25 import org.apache.archiva.metadata.model.ArtifactMetadata;
26 import org.apache.archiva.metadata.repository.MetadataRepository;
27 import org.apache.archiva.rss.RssFeedGenerator;
28 import org.easymock.MockControl;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
33 import java.util.Arrays;
34 import java.util.Collections;
35 import java.util.Date;
36 import java.util.HashMap;
37 import java.util.List;
39 import org.apache.archiva.test.ArchivaBlockJUnit4ClassRunner;
41 @RunWith( ArchivaBlockJUnit4ClassRunner.class )
42 public class NewVersionsOfArtifactRssFeedProcessorTest
45 private NewVersionsOfArtifactRssFeedProcessor newVersionsProcessor;
47 private static final String TEST_REPO = "test-repo";
49 private static final String GROUP_ID = "org.apache.archiva";
51 private static final String ARTIFACT_ID = "artifact-two";
53 private MockControl metadataRepositoryControl;
55 private MetadataRepository metadataRepository;
63 newVersionsProcessor = new NewVersionsOfArtifactRssFeedProcessor();
64 newVersionsProcessor.setGenerator( new RssFeedGenerator() );
66 metadataRepositoryControl = MockControl.createControl( MetadataRepository.class );
67 metadataRepository = (MetadataRepository) metadataRepositoryControl.getMock();
70 @SuppressWarnings( "unchecked" )
72 public void testProcess()
75 Date whenGathered = new Date( 123456789 );
77 ArtifactMetadata artifact1 = createArtifact( whenGathered, "1.0.1" );
78 ArtifactMetadata artifact2 = createArtifact( whenGathered, "1.0.2" );
80 Date whenGatheredNext = new Date( 345678912 );
82 ArtifactMetadata artifact3 = createArtifact( whenGatheredNext, "1.0.3-SNAPSHOT" );
84 Map<String, String> reqParams = new HashMap<String, String>();
85 reqParams.put( RssFeedProcessor.KEY_GROUP_ID, GROUP_ID );
86 reqParams.put( RssFeedProcessor.KEY_ARTIFACT_ID, ARTIFACT_ID );
88 metadataRepositoryControl.expectAndReturn( metadataRepository.getRepositories(), Collections.singletonList(
90 metadataRepositoryControl.expectAndReturn( metadataRepository.getProjectVersions( TEST_REPO, GROUP_ID,
91 ARTIFACT_ID ), Arrays.asList(
92 "1.0.1", "1.0.2", "1.0.3-SNAPSHOT" ) );
93 metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( TEST_REPO, GROUP_ID, ARTIFACT_ID,
95 Collections.singletonList( artifact1 ) );
96 metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( TEST_REPO, GROUP_ID, ARTIFACT_ID,
98 Collections.singletonList( artifact2 ) );
99 metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( TEST_REPO, GROUP_ID, ARTIFACT_ID,
101 Collections.singletonList( artifact3 ) );
102 metadataRepositoryControl.replay();
104 SyndFeed feed = newVersionsProcessor.process( reqParams, metadataRepository );
106 assertEquals( "New Versions of Artifact 'org.apache.archiva:artifact-two'", feed.getTitle() );
107 assertEquals( "New versions of artifact 'org.apache.archiva:artifact-two' found during repository scan.",
108 feed.getDescription() );
109 assertEquals( "en-us", feed.getLanguage() );
110 assertEquals( whenGatheredNext, feed.getPublishedDate() );
112 List<SyndEntry> entries = feed.getEntries();
114 assertEquals( 2, entries.size() );
116 assertEquals( "New Versions of Artifact 'org.apache.archiva:artifact-two' as of " + whenGathered, entries.get(
118 assertEquals( whenGathered, entries.get( 0 ).getPublishedDate() );
120 assertEquals( "New Versions of Artifact 'org.apache.archiva:artifact-two' as of " + whenGatheredNext,
121 entries.get( 1 ).getTitle() );
122 assertEquals( whenGatheredNext, entries.get( 1 ).getPublishedDate() );
124 metadataRepositoryControl.verify();
127 private ArtifactMetadata createArtifact( Date whenGathered, String version )
129 ArtifactMetadata artifact = new ArtifactMetadata();
130 artifact.setNamespace( GROUP_ID );
131 artifact.setProject( ARTIFACT_ID );
132 artifact.setProjectVersion( version );
133 artifact.setVersion( version );
134 artifact.setRepositoryId( TEST_REPO );
135 artifact.setId( ARTIFACT_ID + "-" + version + ".jar" );
136 artifact.setWhenGathered( whenGathered );