Browse Source

[MRM-773]

-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-ffa450edef68
tags/archiva-r676265
Maria Odea B. Ching 16 years ago
parent
commit
a8bc40dbd4
21 changed files with 537 additions and 35 deletions
  1. 0
    1
      archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.java
  2. 0
    1
      archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/MavenProxyPropertyLoaderTest.java
  3. 0
    1
      archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/AbstractProxyTestCase.java
  4. 0
    1
      archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/AbstractRepositoryLayerTestCase.java
  5. 8
    3
      archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArtifactVersionsConstraint.java
  6. 6
    13
      archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/RssFeedGenerator.java
  7. 4
    3
      archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/AbstractArtifactsRssFeedProcessor.java
  8. 2
    2
      archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessor.java
  9. 6
    4
      archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessor.java
  10. 1
    1
      archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessorTest.java
  11. 1
    1
      archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessorTest.java
  12. 4
    0
      archiva-modules/archiva-web/archiva-webapp/pom.xml
  13. 137
    0
      archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/rss/RssFeedServlet.java
  14. 1
    1
      archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/repositories.jsp
  15. 1
    1
      archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/browse.jsp
  16. 11
    1
      archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/web.xml
  17. 0
    1
      archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/AbstractRepositoryServletTestCase.java
  18. 123
    0
      archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/rss/ArtifactDAOStub.java
  19. 139
    0
      archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/rss/RssFeedServletTest.java
  20. 38
    0
      archiva-modules/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/rss/RssFeedServletTest.xml
  21. 55
    0
      archiva-modules/archiva-web/archiva-webapp/src/test/webapp/WEB-INF/feedServletTest-web.xml

+ 0
- 1
archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.java View File

@@ -42,7 +42,6 @@ public class ArchivaConfigurationTest
* @see org.codehaus.plexus.spring.PlexusInSpringTestCase#getSpringConfigLocation()
*/
protected String getSpringConfigLocation()
throws Exception
{
return "org/apache/maven/archiva/configuration/spring-context.xml";
}

+ 0
- 1
archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/MavenProxyPropertyLoaderTest.java View File

@@ -40,7 +40,6 @@ public class MavenProxyPropertyLoaderTest
* @see org.codehaus.plexus.spring.PlexusInSpringTestCase#getSpringConfigLocation()
*/
protected String getSpringConfigLocation()
throws Exception
{
return "org/apache/maven/archiva/configuration/spring-context.xml";
}

+ 0
- 1
archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/AbstractProxyTestCase.java View File

@@ -400,7 +400,6 @@ public abstract class AbstractProxyTestCase
*/
@Override
protected String getSpringConfigLocation()
throws Exception
{
return "org/apache/maven/archiva/proxy/spring-context.xml";
}

+ 0
- 1
archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/AbstractRepositoryLayerTestCase.java View File

@@ -40,7 +40,6 @@ public abstract class AbstractRepositoryLayerTestCase
*/
@Override
protected String getSpringConfigLocation()
throws Exception
{
return "org/apache/maven/archiva/repository/spring-context.xml";
}

+ 8
- 3
archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArtifactVersionsConstraint.java View File

@@ -31,13 +31,18 @@ public class ArtifactVersionsConstraint
extends AbstractDeclarativeConstraint
implements Constraint
{
private String whereClause;
private String whereClause = "";
private String sortColumn = "repositoryId";
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" };
params = new Object[] { repoId, groupId, artifactId };
}
@@ -47,7 +52,7 @@ public class ArtifactVersionsConstraint
this( repoId, groupId, artifactId );
this.sortColumn = sortColumn;
}
public String getSortColumn()
{
return sortColumn;

+ 6
- 13
archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/RssFeedGenerator.java View File

@@ -54,33 +54,26 @@ public class RssFeedGenerator
private String DEFAULT_LINK = "http://localhost:8080/archiva/rss/";

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.setLink( DEFAULT_LINK + outputFilename );
feed.setLink( DEFAULT_LINK + queryString );
feed.setDescription( description );
feed.setLanguage( DEFAULT_LANGUAGE );
feed.setPublishedDate( Calendar.getInstance().getTime() );
feed.setFeedType( DEFAULT_FEEDTYPE );
feed.setEntries( getEntries( dataEntries, existingEntries ) );
feed.setEntries( getEntries( dataEntries ) );

log.debug( "Finished generating the feed \'" + title + "\'." );
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;
SyndContent description;

+ 4
- 3
archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/AbstractArtifactsRssFeedProcessor.java View File

@@ -56,17 +56,18 @@ public abstract class AbstractArtifactsRssFeedProcessor
entry.setDescription( description );
entries.add( entry );
}

String repoId = artifact.getModel().getRepositoryId();
if ( !isRepoLevel )
{
entry =
new RssFeedEntry( getTitle() + "\'" + artifact.getGroupId() + ":" + artifact.getArtifactId() +
"\'" + " as of " + new Date( whenGathered ) );
description = getDescription() + "\'" + repoId + "\'" + ": \n" + artifact.toString() + " | ";
description = getDescription() + "\'" + artifact.getGroupId() + ":" + artifact.getArtifactId() +
"\'" + ": \n" + artifact.toString() + " | ";
}
else
{
String repoId = artifact.getModel().getRepositoryId();
entry = new RssFeedEntry( getTitle() + "\'" + repoId + "\'" + " as of " + new Date( whenGathered ) );
description = getDescription() + "\'" + repoId + "\'" + ": \n" + artifact.toString() + " | ";
}

+ 2
- 2
archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessor.java View File

@@ -48,7 +48,7 @@ public class NewArtifactsRssFeedProcessor
{
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
@@ -89,7 +89,7 @@ public class NewArtifactsRssFeedProcessor
List<RssFeedEntry> entries = processData( artifacts, true );

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 )
{

+ 6
- 4
archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessor.java View File

@@ -49,7 +49,7 @@ public class NewVersionsOfArtifactRssFeedProcessor
{
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
@@ -71,8 +71,8 @@ public class NewVersionsOfArtifactRssFeedProcessor
String repoId = reqParams.get( RssFeedProcessor.KEY_REPO_ID );
String groupId = reqParams.get( RssFeedProcessor.KEY_GROUP_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 );
}
@@ -87,12 +87,14 @@ public class NewVersionsOfArtifactRssFeedProcessor
Constraint artifactVersions = new ArtifactVersionsConstraint( repoId, groupId, artifactId, "whenGathered" );
List<ArchivaArtifact> artifacts = artifactDAO.queryArtifacts( artifactVersions );

log.info( "Queried artifacts size :: " + artifacts.size() );
List<RssFeedEntry> entries = processData( artifacts, false );

String key = groupId + ":" + artifactId;
return generator.generateFeed( getTitle() + "\'" + key + "\'", "New versions of artifact " + "\'" + key +
"\' found in repository " + "\'" + repoId + "\'" + " during repository scan.", entries,
"new_versions_" + key + ".xml" );
"rss_feeds?groupId=" + groupId + "&artifactId=" + artifactId );

}
catch ( ObjectNotFoundException oe )

+ 1
- 1
archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessorTest.java View File

@@ -116,7 +116,7 @@ public class NewArtifactsRssFeedProcessorTest
SyndFeed feed = newArtifactsProcessor.process( reqParams );

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(
"New artifacts found in repository 'test-repo' during repository scan." ) );
assertTrue( feed.getLanguage().equals( "en-us" ) );

+ 1
- 1
archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessorTest.java View File

@@ -93,7 +93,7 @@ public class NewVersionsOfArtifactRssFeedProcessorTest
SyndFeed feed = newVersionsProcessor.process( reqParams );

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() );
assertEquals(
"New versions of artifact 'org.apache.archiva:artifact-two' found in repository 'test-repo' during repository scan.",

+ 4
- 0
archiva-modules/archiva-web/archiva-webapp/pom.xml View File

@@ -80,6 +80,10 @@
<!-- TODO: actually, just exclude from WAR plugin -->
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-rss</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>

+ 137
- 0
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/rss/RssFeedServlet.java View File

@@ -0,0 +1,137 @@
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;
}
}

+ 1
- 1
archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/repositories.jsp View File

@@ -88,7 +88,7 @@
</ww:a>
</redback:ifAnyAuthorized>
<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}" />
</a>
</div>

+ 1
- 1
archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/browse.jsp View File

@@ -72,7 +72,7 @@
</c:set>
<li>
<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}" />
</a>
</li>

+ 11
- 1
archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/web.xml View File

@@ -85,7 +85,17 @@
<!-- Loading this on startup so as to take advantage of configuration listeners -->
<load-on-startup>1</load-on-startup>
</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-name>RepositoryServlet</servlet-name>
<url-pattern>/repository/*</url-pattern>

+ 0
- 1
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/AbstractRepositoryServletTestCase.java View File

@@ -172,7 +172,6 @@ public abstract class AbstractRepositoryServletTestCase

@Override
protected String getPlexusConfigLocation()
throws Exception
{
return "org/apache/maven/archiva/web/repository/RepositoryServletTest.xml";
}

+ 123
- 0
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/rss/ArtifactDAOStub.java View File

@@ -0,0 +1,123 @@
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;
}

}

+ 139
- 0
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/rss/RssFeedServletTest.java View File

@@ -0,0 +1,139 @@
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();
}

}

+ 38
- 0
archiva-modules/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/rss/RssFeedServletTest.xml View File

@@ -0,0 +1,38 @@
<?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>

+ 55
- 0
archiva-modules/archiva-web/archiva-webapp/src/test/webapp/WEB-INF/feedServletTest-web.xml View File

@@ -0,0 +1,55 @@
<?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>

Loading…
Cancel
Save