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 java.util.ArrayList;
23 import java.util.Calendar;
24 import java.util.Date;
25 import java.util.HashMap;
26 import java.util.List;
28 import java.util.TimeZone;
30 import com.sun.syndication.feed.synd.SyndEntry;
31 import com.sun.syndication.feed.synd.SyndFeed;
32 import org.apache.archiva.metadata.model.ArtifactMetadata;
33 import org.apache.archiva.metadata.repository.MetadataRepository;
34 import org.apache.archiva.rss.RssFeedGenerator;
35 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
36 import org.easymock.MockControl;
38 public class NewArtifactsRssFeedProcessorTest
39 extends PlexusInSpringTestCase
41 private static final String TEST_REPO = "test-repo";
43 private NewArtifactsRssFeedProcessor newArtifactsProcessor;
45 private MetadataRepository metadataRepository;
47 private MockControl metadataRepositoryControl;
55 newArtifactsProcessor = new NewArtifactsRssFeedProcessor();
56 newArtifactsProcessor.setGenerator( new RssFeedGenerator() );
58 metadataRepositoryControl = MockControl.createControl( MetadataRepository.class );
59 metadataRepository = (MetadataRepository) metadataRepositoryControl.getMock();
60 newArtifactsProcessor.setMetadataRepository( metadataRepository );
63 @SuppressWarnings("unchecked")
64 public void testProcess()
67 List<ArtifactMetadata> newArtifacts = new ArrayList<ArtifactMetadata>();
68 Date whenGathered = Calendar.getInstance().getTime();
70 newArtifacts.add( createArtifact( "artifact-one", "1.0", whenGathered ) );
71 newArtifacts.add( createArtifact( "artifact-one", "1.1", whenGathered ) );
72 newArtifacts.add( createArtifact( "artifact-one", "2.0", whenGathered ) );
73 newArtifacts.add( createArtifact( "artifact-two", "1.0.1", whenGathered ) );
74 newArtifacts.add( createArtifact( "artifact-two", "1.0.2", whenGathered ) );
75 newArtifacts.add( createArtifact( "artifact-two", "1.0.3-SNAPSHOT", whenGathered ) );
76 newArtifacts.add( createArtifact( "artifact-three", "2.0-SNAPSHOT", whenGathered ) );
77 newArtifacts.add( createArtifact( "artifact-four", "1.1-beta-2", whenGathered ) );
79 Calendar cal = Calendar.getInstance( TimeZone.getTimeZone( "GMT" ) );
80 cal.add( Calendar.DATE, -30 );
81 cal.clear( Calendar.MILLISECOND );
82 metadataRepositoryControl.expectAndReturn(
83 metadataRepository.getArtifactsByDateRange( TEST_REPO, cal.getTime(), null ), newArtifacts );
84 metadataRepositoryControl.replay();
86 Map<String, String> reqParams = new HashMap<String, String>();
87 reqParams.put( RssFeedProcessor.KEY_REPO_ID, TEST_REPO );
89 SyndFeed feed = newArtifactsProcessor.process( reqParams );
91 assertTrue( feed.getTitle().equals( "New Artifacts in Repository 'test-repo'" ) );
93 feed.getDescription().equals( "New artifacts found in repository 'test-repo' during repository scan." ) );
94 assertTrue( feed.getLanguage().equals( "en-us" ) );
95 assertTrue( feed.getPublishedDate().equals( whenGathered ) );
97 List<SyndEntry> entries = feed.getEntries();
98 assertEquals( entries.size(), 1 );
100 entries.get( 0 ).getTitle().equals( "New Artifacts in Repository 'test-repo' as of " + whenGathered ) );
101 assertTrue( entries.get( 0 ).getPublishedDate().equals( whenGathered ) );
103 metadataRepositoryControl.verify();
106 private ArtifactMetadata createArtifact( String artifactId, String version, Date whenGathered )
108 ArtifactMetadata artifact = new ArtifactMetadata();
109 artifact.setNamespace( "org.apache.archiva" );
110 artifact.setId( artifactId + "-" + version + ".jar" );
111 artifact.setRepositoryId( TEST_REPO );
112 artifact.setWhenGathered( whenGathered );
113 artifact.setProject( artifactId );
114 artifact.setVersion( version );