-added the servlet that would handle the rss feed requests -created tests for the servlet -removed thrown exception in getSpringConfigLocation() that is being overridden in PlexusInStringTestCase -updated jsps to the new rss feed urls git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@652230 13f79535-47bb-0310-9956-ffa450edef68tags/archiva-r676265
* @see org.codehaus.plexus.spring.PlexusInSpringTestCase#getSpringConfigLocation() | * @see org.codehaus.plexus.spring.PlexusInSpringTestCase#getSpringConfigLocation() | ||||
*/ | */ | ||||
protected String getSpringConfigLocation() | protected String getSpringConfigLocation() | ||||
throws Exception | |||||
{ | { | ||||
return "org/apache/maven/archiva/configuration/spring-context.xml"; | return "org/apache/maven/archiva/configuration/spring-context.xml"; | ||||
} | } |
* @see org.codehaus.plexus.spring.PlexusInSpringTestCase#getSpringConfigLocation() | * @see org.codehaus.plexus.spring.PlexusInSpringTestCase#getSpringConfigLocation() | ||||
*/ | */ | ||||
protected String getSpringConfigLocation() | protected String getSpringConfigLocation() | ||||
throws Exception | |||||
{ | { | ||||
return "org/apache/maven/archiva/configuration/spring-context.xml"; | return "org/apache/maven/archiva/configuration/spring-context.xml"; | ||||
} | } |
*/ | */ | ||||
@Override | @Override | ||||
protected String getSpringConfigLocation() | protected String getSpringConfigLocation() | ||||
throws Exception | |||||
{ | { | ||||
return "org/apache/maven/archiva/proxy/spring-context.xml"; | return "org/apache/maven/archiva/proxy/spring-context.xml"; | ||||
} | } |
*/ | */ | ||||
@Override | @Override | ||||
protected String getSpringConfigLocation() | protected String getSpringConfigLocation() | ||||
throws Exception | |||||
{ | { | ||||
return "org/apache/maven/archiva/repository/spring-context.xml"; | return "org/apache/maven/archiva/repository/spring-context.xml"; | ||||
} | } |
extends AbstractDeclarativeConstraint | extends AbstractDeclarativeConstraint | ||||
implements Constraint | implements Constraint | ||||
{ | { | ||||
private String whereClause; | |||||
private String whereClause = ""; | |||||
private String sortColumn = "repositoryId"; | private String sortColumn = "repositoryId"; | ||||
public ArtifactVersionsConstraint( String repoId, String groupId, String artifactId ) | public ArtifactVersionsConstraint( String repoId, String groupId, String artifactId ) | ||||
{ | { | ||||
whereClause = "repositoryId == repoId && groupId == groupId && artifactId == artifactId"; | |||||
if( repoId != null ) | |||||
{ | |||||
whereClause = "repositoryId == repoId && "; | |||||
} | |||||
whereClause = whereClause + "groupId == groupId && artifactId == artifactId"; | |||||
declParams = new String[] { "String repoId", "String groupId", "String artifactId" }; | declParams = new String[] { "String repoId", "String groupId", "String artifactId" }; | ||||
params = new Object[] { repoId, groupId, artifactId }; | params = new Object[] { repoId, groupId, artifactId }; | ||||
} | } | ||||
this( repoId, groupId, artifactId ); | this( repoId, groupId, artifactId ); | ||||
this.sortColumn = sortColumn; | this.sortColumn = sortColumn; | ||||
} | } | ||||
public String getSortColumn() | public String getSortColumn() | ||||
{ | { | ||||
return sortColumn; | return sortColumn; |
private String DEFAULT_LINK = "http://localhost:8080/archiva/rss/"; | private String DEFAULT_LINK = "http://localhost:8080/archiva/rss/"; | ||||
public SyndFeed generateFeed( String title, String description, List<RssFeedEntry> dataEntries, | public SyndFeed generateFeed( String title, String description, List<RssFeedEntry> dataEntries, | ||||
String outputFilename ) | |||||
String queryString ) | |||||
{ | { | ||||
SyndFeed feed = null; | |||||
List<SyndEntry> existingEntries = null; | |||||
feed = new SyndFeedImpl(); | |||||
SyndFeed feed = new SyndFeedImpl(); | |||||
feed.setTitle( title ); | feed.setTitle( title ); | ||||
feed.setLink( DEFAULT_LINK + outputFilename ); | |||||
feed.setLink( DEFAULT_LINK + queryString ); | |||||
feed.setDescription( description ); | feed.setDescription( description ); | ||||
feed.setLanguage( DEFAULT_LANGUAGE ); | feed.setLanguage( DEFAULT_LANGUAGE ); | ||||
feed.setPublishedDate( Calendar.getInstance().getTime() ); | feed.setPublishedDate( Calendar.getInstance().getTime() ); | ||||
feed.setFeedType( DEFAULT_FEEDTYPE ); | feed.setFeedType( DEFAULT_FEEDTYPE ); | ||||
feed.setEntries( getEntries( dataEntries, existingEntries ) ); | |||||
feed.setEntries( getEntries( dataEntries ) ); | |||||
log.debug( "Finished generating the feed \'" + title + "\'." ); | log.debug( "Finished generating the feed \'" + title + "\'." ); | ||||
return feed; | return feed; | ||||
} | } | ||||
private List<SyndEntry> getEntries( List<RssFeedEntry> dataEntries, List<SyndEntry> existingEntries ) | |||||
private List<SyndEntry> getEntries( List<RssFeedEntry> dataEntries ) | |||||
{ | { | ||||
List<SyndEntry> entries = existingEntries; | |||||
if ( entries == null ) | |||||
{ | |||||
entries = new ArrayList<SyndEntry>(); | |||||
} | |||||
List<SyndEntry> entries = new ArrayList<SyndEntry>(); | |||||
SyndEntry entry; | SyndEntry entry; | ||||
SyndContent description; | SyndContent description; |
entry.setDescription( description ); | entry.setDescription( description ); | ||||
entries.add( entry ); | entries.add( entry ); | ||||
} | } | ||||
String repoId = artifact.getModel().getRepositoryId(); | |||||
if ( !isRepoLevel ) | if ( !isRepoLevel ) | ||||
{ | { | ||||
entry = | entry = | ||||
new RssFeedEntry( getTitle() + "\'" + artifact.getGroupId() + ":" + artifact.getArtifactId() + | new RssFeedEntry( getTitle() + "\'" + artifact.getGroupId() + ":" + artifact.getArtifactId() + | ||||
"\'" + " as of " + new Date( whenGathered ) ); | "\'" + " as of " + new Date( whenGathered ) ); | ||||
description = getDescription() + "\'" + repoId + "\'" + ": \n" + artifact.toString() + " | "; | |||||
description = getDescription() + "\'" + artifact.getGroupId() + ":" + artifact.getArtifactId() + | |||||
"\'" + ": \n" + artifact.toString() + " | "; | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
String repoId = artifact.getModel().getRepositoryId(); | |||||
entry = new RssFeedEntry( getTitle() + "\'" + repoId + "\'" + " as of " + new Date( whenGathered ) ); | entry = new RssFeedEntry( getTitle() + "\'" + repoId + "\'" + " as of " + new Date( whenGathered ) ); | ||||
description = getDescription() + "\'" + repoId + "\'" + ": \n" + artifact.toString() + " | "; | description = getDescription() + "\'" + repoId + "\'" + ": \n" + artifact.toString() + " | "; | ||||
} | } |
{ | { | ||||
private String title = "New Artifacts in Repository "; | private String title = "New Artifacts in Repository "; | ||||
private String desc = "New Versions of Artifact "; | |||||
private String desc = "These are the new artifacts found in the repository "; | |||||
/** | /** | ||||
* @plexus.requirement | * @plexus.requirement | ||||
List<RssFeedEntry> entries = processData( artifacts, true ); | List<RssFeedEntry> entries = processData( artifacts, true ); | ||||
return generator.generateFeed( getTitle() + "\'" + repoId + "\'", "New artifacts found in repository " + | return generator.generateFeed( getTitle() + "\'" + repoId + "\'", "New artifacts found in repository " + | ||||
"\'" + repoId + "\'" + " during repository scan.", entries, "new_artifacts_" + repoId + ".xml" ); | |||||
"\'" + repoId + "\'" + " during repository scan.", entries, "rss_feeds?repoId=" + repoId ); | |||||
} | } | ||||
catch ( ArchivaDatabaseException ae ) | catch ( ArchivaDatabaseException ae ) | ||||
{ | { |
{ | { | ||||
private String title = "New Versions of Artifact "; | private String title = "New Versions of Artifact "; | ||||
private String desc = "These are the new artifacts found in the repository "; | |||||
private String desc = "These are the new versions of artifact "; | |||||
/** | /** | ||||
* @plexus.requirement | * @plexus.requirement | ||||
String repoId = reqParams.get( RssFeedProcessor.KEY_REPO_ID ); | String repoId = reqParams.get( RssFeedProcessor.KEY_REPO_ID ); | ||||
String groupId = reqParams.get( RssFeedProcessor.KEY_GROUP_ID ); | String groupId = reqParams.get( RssFeedProcessor.KEY_GROUP_ID ); | ||||
String artifactId = reqParams.get( RssFeedProcessor.KEY_ARTIFACT_ID ); | String artifactId = reqParams.get( RssFeedProcessor.KEY_ARTIFACT_ID ); | ||||
if ( repoId != null && groupId != null && artifactId != null ) | |||||
if ( groupId != null && artifactId != null ) | |||||
{ | { | ||||
return processNewVersionsOfArtifact( repoId, groupId, artifactId ); | return processNewVersionsOfArtifact( repoId, groupId, artifactId ); | ||||
} | } | ||||
Constraint artifactVersions = new ArtifactVersionsConstraint( repoId, groupId, artifactId, "whenGathered" ); | Constraint artifactVersions = new ArtifactVersionsConstraint( repoId, groupId, artifactId, "whenGathered" ); | ||||
List<ArchivaArtifact> artifacts = artifactDAO.queryArtifacts( artifactVersions ); | List<ArchivaArtifact> artifacts = artifactDAO.queryArtifacts( artifactVersions ); | ||||
log.info( "Queried artifacts size :: " + artifacts.size() ); | |||||
List<RssFeedEntry> entries = processData( artifacts, false ); | List<RssFeedEntry> entries = processData( artifacts, false ); | ||||
String key = groupId + ":" + artifactId; | String key = groupId + ":" + artifactId; | ||||
return generator.generateFeed( getTitle() + "\'" + key + "\'", "New versions of artifact " + "\'" + key + | return generator.generateFeed( getTitle() + "\'" + key + "\'", "New versions of artifact " + "\'" + key + | ||||
"\' found in repository " + "\'" + repoId + "\'" + " during repository scan.", entries, | "\' found in repository " + "\'" + repoId + "\'" + " during repository scan.", entries, | ||||
"new_versions_" + key + ".xml" ); | |||||
"rss_feeds?groupId=" + groupId + "&artifactId=" + artifactId ); | |||||
} | } | ||||
catch ( ObjectNotFoundException oe ) | catch ( ObjectNotFoundException oe ) |
SyndFeed feed = newArtifactsProcessor.process( reqParams ); | SyndFeed feed = newArtifactsProcessor.process( reqParams ); | ||||
assertTrue( feed.getTitle().equals( "New Artifacts in Repository 'test-repo'" ) ); | assertTrue( feed.getTitle().equals( "New Artifacts in Repository 'test-repo'" ) ); | ||||
assertTrue( feed.getLink().equals( "http://localhost:8080/archiva/rss/new_artifacts_test-repo.xml" ) ); | |||||
assertTrue( feed.getLink().equals( "http://localhost:8080/archiva/rss/rss_feeds?repoId=test-repo" ) ); | |||||
assertTrue( feed.getDescription().equals( | assertTrue( feed.getDescription().equals( | ||||
"New artifacts found in repository 'test-repo' during repository scan." ) ); | "New artifacts found in repository 'test-repo' during repository scan." ) ); | ||||
assertTrue( feed.getLanguage().equals( "en-us" ) ); | assertTrue( feed.getLanguage().equals( "en-us" ) ); |
SyndFeed feed = newVersionsProcessor.process( reqParams ); | SyndFeed feed = newVersionsProcessor.process( reqParams ); | ||||
assertEquals( "New Versions of Artifact 'org.apache.archiva:artifact-two'", feed.getTitle() ); | assertEquals( "New Versions of Artifact 'org.apache.archiva:artifact-two'", feed.getTitle() ); | ||||
assertEquals( "http://localhost:8080/archiva/rss/new_versions_org.apache.archiva:artifact-two.xml", | |||||
assertEquals( "http://localhost:8080/archiva/rss/rss_feeds?groupId=org.apache.archiva&artifactId=artifact-two", | |||||
feed.getLink() ); | feed.getLink() ); | ||||
assertEquals( | assertEquals( | ||||
"New versions of artifact 'org.apache.archiva:artifact-two' found in repository 'test-repo' during repository scan.", | "New versions of artifact 'org.apache.archiva:artifact-two' found in repository 'test-repo' during repository scan.", |
<!-- TODO: actually, just exclude from WAR plugin --> | <!-- TODO: actually, just exclude from WAR plugin --> | ||||
<scope>provided</scope> | <scope>provided</scope> | ||||
</dependency> | </dependency> | ||||
<dependency> | |||||
<groupId>org.apache.archiva</groupId> | |||||
<artifactId>archiva-rss</artifactId> | |||||
</dependency> | |||||
<dependency> | <dependency> | ||||
<groupId>javax.servlet</groupId> | <groupId>javax.servlet</groupId> | ||||
<artifactId>servlet-api</artifactId> | <artifactId>servlet-api</artifactId> |
package org.apache.maven.archiva.web.rss; | |||||
/* | |||||
* Licensed to the Apache Software Foundation (ASF) under one | |||||
* or more contributor license agreements. See the NOTICE file | |||||
* distributed with this work for additional information | |||||
* regarding copyright ownership. The ASF licenses this file | |||||
* to you under the Apache License, Version 2.0 (the | |||||
* "License"); you may not use this file except in compliance | |||||
* with the License. You may obtain a copy of the License at | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, | |||||
* software distributed under the License is distributed on an | |||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |||||
* KIND, either express or implied. See the License for the | |||||
* specific language governing permissions and limitations | |||||
* under the License. | |||||
*/ | |||||
import java.io.IOException; | |||||
import java.util.HashMap; | |||||
import java.util.Map; | |||||
import javax.servlet.ServletException; | |||||
import javax.servlet.http.HttpServlet; | |||||
import javax.servlet.http.HttpServletRequest; | |||||
import javax.servlet.http.HttpServletResponse; | |||||
import org.apache.archiva.rss.RssFeedGenerator; | |||||
import org.apache.archiva.rss.processor.RssFeedProcessor; | |||||
import org.codehaus.plexus.spring.PlexusToSpringUtils; | |||||
import org.slf4j.Logger; | |||||
import org.slf4j.LoggerFactory; | |||||
import org.springframework.web.context.WebApplicationContext; | |||||
import org.springframework.web.context.support.WebApplicationContextUtils; | |||||
import com.sun.syndication.feed.synd.SyndFeed; | |||||
import com.sun.syndication.io.FeedException; | |||||
import com.sun.syndication.io.SyndFeedOutput; | |||||
/** | |||||
* Servlet for handling rss feed requests. | |||||
* | |||||
* @author <a href="mailto:oching@apache.org">Maria Odea Ching</a> | |||||
* @version | |||||
*/ | |||||
public class RssFeedServlet | |||||
extends HttpServlet | |||||
{ | |||||
public static final String MIME_TYPE = "application/xml; charset=UTF-8"; | |||||
private static final String COULD_NOT_GENERATE_FEED_ERROR = "Could not generate feed"; | |||||
private Logger log = LoggerFactory.getLogger( RssFeedGenerator.class ); | |||||
private RssFeedProcessor processor; | |||||
private WebApplicationContext wac; | |||||
public void init( javax.servlet.ServletConfig servletConfig ) | |||||
throws ServletException | |||||
{ | |||||
super.init( servletConfig ); | |||||
wac = WebApplicationContextUtils.getRequiredWebApplicationContext( servletConfig.getServletContext() ); | |||||
} | |||||
public void doGet( HttpServletRequest req, HttpServletResponse res ) | |||||
throws ServletException, IOException | |||||
{ | |||||
log.info( "Request URL: " + req.getRequestURL() ); | |||||
try | |||||
{ | |||||
Map<String, String> map = new HashMap<String, String>(); | |||||
SyndFeed feed = null; | |||||
if ( req.getParameter( "repoId" ) != null ) | |||||
{ | |||||
if ( isAuthorized() ) | |||||
{ | |||||
// new artifacts in repo feed request | |||||
processor = | |||||
(RssFeedProcessor) wac.getBean( PlexusToSpringUtils.buildSpringId( | |||||
RssFeedProcessor.class.getName(), | |||||
"new-artifacts" ) ); | |||||
map.put( RssFeedProcessor.KEY_REPO_ID, req.getParameter( "repoId" ) ); | |||||
} | |||||
else | |||||
{ | |||||
res.sendError( HttpServletResponse.SC_UNAUTHORIZED, "Request is not authorized." ); | |||||
return; | |||||
} | |||||
} | |||||
else if ( ( req.getParameter( "groupId" ) != null ) && ( req.getParameter( "artifactId" ) != null ) ) | |||||
{ | |||||
if ( isAuthorized() ) | |||||
{ | |||||
// new versions of artifact feed request | |||||
processor = | |||||
(RssFeedProcessor) wac.getBean( PlexusToSpringUtils.buildSpringId( | |||||
RssFeedProcessor.class.getName(), | |||||
"new-versions" ) ); | |||||
map.put( RssFeedProcessor.KEY_GROUP_ID, req.getParameter( "groupId" ) ); | |||||
map.put( RssFeedProcessor.KEY_ARTIFACT_ID, req.getParameter( "artifactId" ) ); | |||||
} | |||||
else | |||||
{ | |||||
res.sendError( HttpServletResponse.SC_UNAUTHORIZED, "Request is not authorized." ); | |||||
return; | |||||
} | |||||
} | |||||
else | |||||
{ | |||||
res.sendError( HttpServletResponse.SC_BAD_REQUEST, "Required fields not found in request." ); | |||||
return; | |||||
} | |||||
feed = processor.process( map ); | |||||
res.setContentType( MIME_TYPE ); | |||||
SyndFeedOutput output = new SyndFeedOutput(); | |||||
output.output( feed, res.getWriter() ); | |||||
} | |||||
catch ( FeedException ex ) | |||||
{ | |||||
String msg = COULD_NOT_GENERATE_FEED_ERROR; | |||||
log.error( msg, ex ); | |||||
res.sendError( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg ); | |||||
} | |||||
} | |||||
private boolean isAuthorized() | |||||
{ | |||||
return true; | |||||
} | |||||
} |
</ww:a> | </ww:a> | ||||
</redback:ifAnyAuthorized> | </redback:ifAnyAuthorized> | ||||
<c:url var="rssFeedIconUrl" value="/images/icons/rss-feed.png"/> | <c:url var="rssFeedIconUrl" value="/images/icons/rss-feed.png"/> | ||||
<a href="/archiva/rss/new_artifacts_${repository.id}.xml"> | |||||
<a href="/archiva/rss/rss_feeds?repoId=${repository.id}"> | |||||
<img src="${rssFeedIconUrl}" /> | <img src="${rssFeedIconUrl}" /> | ||||
</a> | </a> | ||||
</div> | </div> |
</c:set> | </c:set> | ||||
<li> | <li> | ||||
<a href="${url}">${artifactId}/</a> | <a href="${url}">${artifactId}/</a> | ||||
<a href="/archiva/rss/new_versions_${groupId}:${artifactId}.xml"> | |||||
<a href="/archiva/rss/rss_feeds?groupId=${groupId}&artifactId=${artifactId}"> | |||||
<img src="${rssFeedIconUrl}" /> | <img src="${rssFeedIconUrl}" /> | ||||
</a> | </a> | ||||
</li> | </li> |
<!-- Loading this on startup so as to take advantage of configuration listeners --> | <!-- Loading this on startup so as to take advantage of configuration listeners --> | ||||
<load-on-startup>1</load-on-startup> | <load-on-startup>1</load-on-startup> | ||||
</servlet> | </servlet> | ||||
<servlet> | |||||
<servlet-name>RssFeedServlet</servlet-name> | |||||
<servlet-class>org.apache.maven.archiva.web.rss.RssFeedServlet</servlet-class> | |||||
</servlet> | |||||
<servlet-mapping> | |||||
<servlet-name>RssFeedServlet</servlet-name> | |||||
<url-pattern>/rss/*</url-pattern> | |||||
</servlet-mapping> | |||||
<servlet-mapping> | <servlet-mapping> | ||||
<servlet-name>RepositoryServlet</servlet-name> | <servlet-name>RepositoryServlet</servlet-name> | ||||
<url-pattern>/repository/*</url-pattern> | <url-pattern>/repository/*</url-pattern> |
@Override | @Override | ||||
protected String getPlexusConfigLocation() | protected String getPlexusConfigLocation() | ||||
throws Exception | |||||
{ | { | ||||
return "org/apache/maven/archiva/web/repository/RepositoryServletTest.xml"; | return "org/apache/maven/archiva/web/repository/RepositoryServletTest.xml"; | ||||
} | } |
package org.apache.maven.archiva.web.rss; | |||||
/* | |||||
* Licensed to the Apache Software Foundation (ASF) under one | |||||
* or more contributor license agreements. See the NOTICE file | |||||
* distributed with this work for additional information | |||||
* regarding copyright ownership. The ASF licenses this file | |||||
* to you under the Apache License, Version 2.0 (the | |||||
* "License"); you may not use this file except in compliance | |||||
* with the License. You may obtain a copy of the License at | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, | |||||
* software distributed under the License is distributed on an | |||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |||||
* KIND, either express or implied. See the License for the | |||||
* specific language governing permissions and limitations | |||||
* under the License. | |||||
*/ | |||||
import java.util.ArrayList; | |||||
import java.util.Calendar; | |||||
import java.util.Date; | |||||
import java.util.List; | |||||
import org.apache.maven.archiva.database.ArchivaDatabaseException; | |||||
import org.apache.maven.archiva.database.ArtifactDAO; | |||||
import org.apache.maven.archiva.database.Constraint; | |||||
import org.apache.maven.archiva.database.ObjectNotFoundException; | |||||
import org.apache.maven.archiva.model.ArchivaArtifact; | |||||
/** | |||||
* Stub used for RssFeedServlet unit test. | |||||
* | |||||
* @author <a href="mailto:oching@apache.org">Maria Odea Ching</a> | |||||
* @version | |||||
*/ | |||||
public class ArtifactDAOStub | |||||
implements ArtifactDAO | |||||
{ | |||||
public ArchivaArtifact createArtifact( String groupId, String artifactId, String version, String classifier, | |||||
String type ) | |||||
{ | |||||
// TODO Auto-generated method stub | |||||
return null; | |||||
} | |||||
public void deleteArtifact( ArchivaArtifact artifact ) | |||||
throws ArchivaDatabaseException | |||||
{ | |||||
// TODO Auto-generated method stub | |||||
} | |||||
public ArchivaArtifact getArtifact( String groupId, String artifactId, String version, String classifier, | |||||
String type ) | |||||
throws ObjectNotFoundException, ArchivaDatabaseException | |||||
{ | |||||
// TODO Auto-generated method stub | |||||
return null; | |||||
} | |||||
public List queryArtifacts( Constraint constraint ) | |||||
throws ObjectNotFoundException, ArchivaDatabaseException | |||||
{ | |||||
List<ArchivaArtifact> artifacts = new ArrayList<ArchivaArtifact>(); | |||||
Date whenGathered = Calendar.getInstance().getTime(); | |||||
whenGathered.setTime( 123456789 ); | |||||
ArchivaArtifact artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-one", "1.0", "", "jar" ); | |||||
artifact.getModel().setRepositoryId( "test-repo" ); | |||||
artifact.getModel().setWhenGathered( whenGathered ); | |||||
artifacts.add( artifact ); | |||||
artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-one", "1.1", "", "jar" ); | |||||
artifact.getModel().setRepositoryId( "test-repo" ); | |||||
artifact.getModel().setWhenGathered( whenGathered ); | |||||
artifacts.add( artifact ); | |||||
artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-one", "2.0", "", "jar" ); | |||||
artifact.getModel().setRepositoryId( "test-repo" ); | |||||
artifact.getModel().setWhenGathered( whenGathered ); | |||||
artifacts.add( artifact ); | |||||
artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-two", "1.0.1", "", "jar" ); | |||||
artifact.getModel().setRepositoryId( "test-repo" ); | |||||
artifact.getModel().setWhenGathered( whenGathered ); | |||||
artifacts.add( artifact ); | |||||
artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-two", "1.0.2", "", "jar" ); | |||||
artifact.getModel().setRepositoryId( "test-repo" ); | |||||
artifact.getModel().setWhenGathered( whenGathered ); | |||||
artifacts.add( artifact ); | |||||
artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-two", "1.0.3-SNAPSHOT", "", "jar" ); | |||||
artifact.getModel().setRepositoryId( "test-repo" ); | |||||
artifact.getModel().setWhenGathered( whenGathered ); | |||||
artifacts.add( artifact ); | |||||
artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-three", "2.0-SNAPSHOT", "", "jar" ); | |||||
artifact.getModel().setRepositoryId( "test-repo" ); | |||||
artifact.getModel().setWhenGathered( whenGathered ); | |||||
artifacts.add( artifact ); | |||||
artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-four", "1.1-beta-2", "", "jar" ); | |||||
artifact.getModel().setRepositoryId( "test-repo" ); | |||||
artifact.getModel().setWhenGathered( whenGathered ); | |||||
artifacts.add( artifact ); | |||||
return artifacts; | |||||
} | |||||
public ArchivaArtifact saveArtifact( ArchivaArtifact artifact ) | |||||
throws ArchivaDatabaseException | |||||
{ | |||||
// TODO Auto-generated method stub | |||||
return null; | |||||
} | |||||
} |
package org.apache.maven.archiva.web.rss; | |||||
/* | |||||
* Licensed to the Apache Software Foundation (ASF) under one | |||||
* or more contributor license agreements. See the NOTICE file | |||||
* distributed with this work for additional information | |||||
* regarding copyright ownership. The ASF licenses this file | |||||
* to you under the Apache License, Version 2.0 (the | |||||
* "License"); you may not use this file except in compliance | |||||
* with the License. You may obtain a copy of the License at | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, | |||||
* software distributed under the License is distributed on an | |||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |||||
* KIND, either express or implied. See the License for the | |||||
* specific language governing permissions and limitations | |||||
* under the License. | |||||
*/ | |||||
import javax.servlet.http.HttpServletResponse; | |||||
import org.codehaus.plexus.spring.PlexusInSpringTestCase; | |||||
import com.meterware.httpunit.HttpException; | |||||
import com.meterware.httpunit.WebResponse; | |||||
import com.meterware.servletunit.ServletRunner; | |||||
import com.meterware.servletunit.ServletUnitClient; | |||||
/** | |||||
* | |||||
* @author <a href="mailto:oching@apache.org">Maria Odea Ching</a> | |||||
* @version | |||||
*/ | |||||
public class RssFeedServletTest | |||||
extends PlexusInSpringTestCase | |||||
{ | |||||
private ServletRunner sr; | |||||
private ServletUnitClient client; | |||||
public void setUp() | |||||
throws Exception | |||||
{ | |||||
sr = new ServletRunner( getTestFile( "src/test/webapp/WEB-INF/feedServletTest-web.xml" ) ); | |||||
client = sr.newClient(); | |||||
} | |||||
public void testRetrieveServlet() | |||||
throws Exception | |||||
{ | |||||
RssFeedServlet servlet = | |||||
(RssFeedServlet) client.newInvocation( "http://localhost/rss/rss_feeds?repoId=test-repo" ).getServlet(); | |||||
assertNotNull( servlet ); | |||||
} | |||||
public void testRequestNewArtifactsInRepo() | |||||
throws Exception | |||||
{ | |||||
RssFeedServlet servlet = | |||||
(RssFeedServlet) client.newInvocation( "http://localhost/rss/rss_feeds?repoId=test-repo" ).getServlet(); | |||||
assertNotNull( servlet ); | |||||
WebResponse response = client.getResponse( "http://localhost/rss/rss_feeds?repoId=test-repo" ); | |||||
assertEquals( RssFeedServlet.MIME_TYPE, response.getHeaderField( "CONTENT-TYPE" ) ); | |||||
assertNotNull( "Should have recieved a response", response ); | |||||
assertEquals( "Should have been an OK response code.", HttpServletResponse.SC_OK, response.getResponseCode() ); | |||||
} | |||||
public void testRequestNewVersionsOfArtifact() | |||||
throws Exception | |||||
{ | |||||
RssFeedServlet servlet = | |||||
(RssFeedServlet) client.newInvocation( | |||||
"http://localhost/rss/rss_feeds?groupId=org.apache.archiva&artifactId=artifact-two" ).getServlet(); | |||||
assertNotNull( servlet ); | |||||
WebResponse response = client.getResponse( "http://localhost/rss/rss_feeds?groupId=org.apache.archiva&artifactId=artifact-two" ); | |||||
assertEquals( RssFeedServlet.MIME_TYPE, response.getHeaderField( "CONTENT-TYPE" ) ); | |||||
assertNotNull( "Should have recieved a response", response ); | |||||
assertEquals( "Should have been an OK response code.", HttpServletResponse.SC_OK, response.getResponseCode() ); | |||||
} | |||||
public void testInvalidRequest() | |||||
throws Exception | |||||
{ | |||||
RssFeedServlet servlet = | |||||
(RssFeedServlet) client.newInvocation( | |||||
"http://localhost/rss/rss_feeds?invalid_param=xxx" ).getServlet(); | |||||
assertNotNull( servlet ); | |||||
try | |||||
{ | |||||
WebResponse response = client.getResponse( "http://localhost/rss/rss_feeds?invalid_param=xxx" ); | |||||
} | |||||
catch ( HttpException he ) | |||||
{ | |||||
assertEquals( "Should have been a bad request response code.", HttpServletResponse.SC_BAD_REQUEST, he.getResponseCode() ); | |||||
} | |||||
} | |||||
public void testUnAuthorizedRequest() | |||||
throws Exception | |||||
{ | |||||
RssFeedServlet servlet = | |||||
(RssFeedServlet) client.newInvocation( | |||||
"http://localhost/rss/rss_feeds" ).getServlet(); | |||||
assertNotNull( servlet ); | |||||
//WebResponse response = client.getResponse( "http://localhost/rss/rss_feeds" ); | |||||
//assertNotNull( "Should have recieved a response", response ); | |||||
//assertEquals( "Should have been a bad request response code.", HttpServletResponse.SC_BAD_REQUEST, response.getResponseCode() ); | |||||
} | |||||
@Override | |||||
protected String getPlexusConfigLocation() | |||||
{ | |||||
return "org/apache/maven/archiva/web/rss/RssFeedServletTest.xml"; | |||||
} | |||||
@Override | |||||
protected void tearDown() | |||||
throws Exception | |||||
{ | |||||
if ( client != null ) | |||||
{ | |||||
client.clearContents(); | |||||
} | |||||
if ( sr != null ) | |||||
{ | |||||
sr.shutDown(); | |||||
} | |||||
super.tearDown(); | |||||
} | |||||
} |
<?xml version="1.0" encoding="ISO-8859-1"?> | |||||
<!-- | |||||
~ Licensed to the Apache Software Foundation (ASF) under one | |||||
~ or more contributor license agreements. See the NOTICE file | |||||
~ distributed with this work for additional information | |||||
~ regarding copyright ownership. The ASF licenses this file | |||||
~ to you under the Apache License, Version 2.0 (the | |||||
~ "License"); you may not use this file except in compliance | |||||
~ with the License. You may obtain a copy of the License at | |||||
~ | |||||
~ http://www.apache.org/licenses/LICENSE-2.0 | |||||
~ | |||||
~ Unless required by applicable law or agreed to in writing, | |||||
~ software distributed under the License is distributed on an | |||||
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |||||
~ KIND, either express or implied. See the License for the | |||||
~ specific language governing permissions and limitations | |||||
~ under the License. | |||||
--> | |||||
<plexus> | |||||
<components> | |||||
<!-- | |||||
| Logger manager | |||||
--> | |||||
<component> | |||||
<role>org.codehaus.plexus.logging.LoggerManager</role> | |||||
<implementation>org.codehaus.plexus.logging.slf4j.Slf4jLoggerManager</implementation> | |||||
<lifecycle-handler>basic</lifecycle-handler> | |||||
</component> | |||||
<component> | |||||
<role>org.apache.maven.archiva.database.ArtifactDAO</role> | |||||
<role-hint>jdo</role-hint> | |||||
<implementation>org.apache.maven.archiva.web.rss.ArtifactDAOStub</implementation> | |||||
</component> | |||||
</components> | |||||
</plexus> |
<?xml version="1.0" encoding="ISO-8859-1"?> | |||||
<!-- | |||||
~ Licensed to the Apache Software Foundation (ASF) under one | |||||
~ or more contributor license agreements. See the NOTICE file | |||||
~ distributed with this work for additional information | |||||
~ regarding copyright ownership. The ASF licenses this file | |||||
~ to you under the Apache License, Version 2.0 (the | |||||
~ "License"); you may not use this file except in compliance | |||||
~ with the License. You may obtain a copy of the License at | |||||
~ | |||||
~ http://www.apache.org/licenses/LICENSE-2.0 | |||||
~ | |||||
~ Unless required by applicable law or agreed to in writing, | |||||
~ software distributed under the License is distributed on an | |||||
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |||||
~ KIND, either express or implied. See the License for the | |||||
~ specific language governing permissions and limitations | |||||
~ under the License. | |||||
--> | |||||
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" version="2.4" | |||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |||||
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> | |||||
<display-name>Apache Archiva</display-name> | |||||
<listener> | |||||
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> | |||||
</listener> | |||||
<servlet> | |||||
<servlet-name>RssFeedServlet</servlet-name> | |||||
<servlet-class>org.apache.maven.archiva.web.rss.RssFeedServlet</servlet-class> | |||||
</servlet> | |||||
<servlet-mapping> | |||||
<servlet-name>RssFeedServlet</servlet-name> | |||||
<url-pattern>/rss/*</url-pattern> | |||||
</servlet-mapping> | |||||
<context-param> | |||||
<param-name>contextClass</param-name> | |||||
<param-value>org.codehaus.plexus.spring.PlexusWebApplicationContext</param-value> | |||||
</context-param> | |||||
<context-param> | |||||
<param-name>contextConfigLocation</param-name> | |||||
<param-value> | |||||
classpath*:/META-INF/plexus/components.xml | |||||
classpath*:/META-INF/spring-context.xml | |||||
target/test-classes/org/apache/maven/archiva/web/rss/RssFeedServletTest.xml | |||||
</param-value> | |||||
</context-param> | |||||
</web-app> |