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.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
29 import org.easymock.IMocksControl;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
34 import java.util.Arrays;
35 import java.util.Collections;
36 import java.util.Date;
37 import java.util.HashMap;
38 import java.util.List;
41 import static org.easymock.EasyMock.createControl;
42 import static org.easymock.EasyMock.expect;
44 @RunWith(ArchivaBlockJUnit4ClassRunner.class)
45 public class NewVersionsOfArtifactRssFeedProcessorTest
48 private NewVersionsOfArtifactRssFeedProcessor newVersionsProcessor;
50 private static final String TEST_REPO = "test-repo";
52 private static final String GROUP_ID = "org.apache.archiva";
54 private static final String ARTIFACT_ID = "artifact-two";
56 private IMocksControl metadataRepositoryControl;
58 private MetadataRepository metadataRepository;
66 newVersionsProcessor = new NewVersionsOfArtifactRssFeedProcessor();
67 newVersionsProcessor.setGenerator( new RssFeedGenerator() );
69 metadataRepositoryControl = createControl();
70 metadataRepository = metadataRepositoryControl.createMock( MetadataRepository.class );
73 @SuppressWarnings("unchecked")
75 public void testProcess()
78 Date whenGathered = new Date( 123456789 );
80 ArtifactMetadata artifact1 = createArtifact( whenGathered, "1.0.1" );
81 ArtifactMetadata artifact2 = createArtifact( whenGathered, "1.0.2" );
83 Date whenGatheredNext = new Date( 345678912 );
85 ArtifactMetadata artifact3 = createArtifact( whenGatheredNext, "1.0.3-SNAPSHOT" );
87 Map<String, String> reqParams = new HashMap<String, String>();
88 reqParams.put( RssFeedProcessor.KEY_GROUP_ID, GROUP_ID );
89 reqParams.put( RssFeedProcessor.KEY_ARTIFACT_ID, ARTIFACT_ID );
91 //metadataRepositoryControl.expectAndReturn( metadataRepository.getRepositories(), Collections.singletonList(
93 expect( metadataRepository.getRepositories() ).andReturn( Collections.singletonList( TEST_REPO ) );
94 //metadataRepositoryControl.expectAndReturn( metadataRepository.getProjectVersions( TEST_REPO, GROUP_ID,
95 // ARTIFACT_ID ), Arrays.asList(
96 // "1.0.1", "1.0.2", "1.0.3-SNAPSHOT" ) );
97 expect( metadataRepository.getProjectVersions( TEST_REPO, GROUP_ID, ARTIFACT_ID ) ).andReturn(
98 Arrays.asList( "1.0.1", "1.0.2", "1.0.3-SNAPSHOT" ) );
99 //metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( TEST_REPO, GROUP_ID, ARTIFACT_ID,
101 // Collections.singletonList( artifact1 ) );
102 expect( metadataRepository.getArtifacts( TEST_REPO, GROUP_ID, ARTIFACT_ID, "1.0.1" ) ).andReturn(
103 Collections.singletonList( artifact1 ) );
104 //metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( TEST_REPO, GROUP_ID, ARTIFACT_ID,
106 // Collections.singletonList( artifact2 ) );
107 expect( metadataRepository.getArtifacts( TEST_REPO, GROUP_ID, ARTIFACT_ID, "1.0.2" ) ).andReturn(
108 Collections.singletonList( artifact2 ) );
109 //metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( TEST_REPO, GROUP_ID, ARTIFACT_ID,
110 // "1.0.3-SNAPSHOT" ),
111 // Collections.singletonList( artifact3 ) );
112 expect( metadataRepository.getArtifacts( TEST_REPO, GROUP_ID, ARTIFACT_ID, "1.0.3-SNAPSHOT" ) ).andReturn(
113 Collections.singletonList( artifact3 ) );
114 metadataRepositoryControl.replay();
116 SyndFeed feed = newVersionsProcessor.process( reqParams, metadataRepository );
118 assertEquals( "New Versions of Artifact 'org.apache.archiva:artifact-two'", feed.getTitle() );
119 assertEquals( "New versions of artifact 'org.apache.archiva:artifact-two' found during repository scan.",
120 feed.getDescription() );
121 assertEquals( "en-us", feed.getLanguage() );
122 assertEquals( whenGatheredNext, feed.getPublishedDate() );
124 List<SyndEntry> entries = feed.getEntries();
126 assertEquals( 2, entries.size() );
128 assertEquals( "New Versions of Artifact 'org.apache.archiva:artifact-two' as of " + whenGathered,
129 entries.get( 0 ).getTitle() );
130 assertEquals( whenGathered, entries.get( 0 ).getPublishedDate() );
132 assertEquals( "New Versions of Artifact 'org.apache.archiva:artifact-two' as of " + whenGatheredNext,
133 entries.get( 1 ).getTitle() );
134 assertEquals( whenGatheredNext, entries.get( 1 ).getPublishedDate() );
136 metadataRepositoryControl.verify();
139 private ArtifactMetadata createArtifact( Date whenGathered, String version )
141 ArtifactMetadata artifact = new ArtifactMetadata();
142 artifact.setNamespace( GROUP_ID );
143 artifact.setProject( ARTIFACT_ID );
144 artifact.setProjectVersion( version );
145 artifact.setVersion( version );
146 artifact.setRepositoryId( TEST_REPO );
147 artifact.setId( ARTIFACT_ID + "-" + version + ".jar" );
148 artifact.setWhenGathered( whenGathered );