1 package org.apache.maven.archiva.web.rss;
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 javax.servlet.http.HttpServletResponse;
23 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
24 import com.meterware.httpunit.HttpException;
25 import com.meterware.httpunit.WebResponse;
26 import com.meterware.servletunit.ServletRunner;
27 import com.meterware.servletunit.ServletUnitClient;
31 * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
34 public class RssFeedServletTest
35 extends PlexusInSpringTestCase
37 private ServletRunner sr;
39 private ServletUnitClient client;
44 sr = new ServletRunner( getTestFile( "src/test/webapp/WEB-INF/feedServletTest-web.xml" ) );
45 client = sr.newClient();
48 public void testRetrieveServlet()
51 RssFeedServlet servlet =
52 (RssFeedServlet) client.newInvocation( "http://localhost/rss/rss_feeds?repoId=test-repo" ).getServlet();
53 assertNotNull( servlet );
56 public void testRequestNewArtifactsInRepo()
59 RssFeedServlet servlet =
60 (RssFeedServlet) client.newInvocation( "http://localhost/rss/rss_feeds?repoId=test-repo" ).getServlet();
61 assertNotNull( servlet );
63 WebResponse response = client.getResponse( "http://localhost/rss/rss_feeds?repoId=test-repo" );
64 assertEquals( RssFeedServlet.MIME_TYPE, response.getHeaderField( "CONTENT-TYPE" ) );
66 assertNotNull( "Should have recieved a response", response );
67 assertEquals( "Should have been an OK response code.", HttpServletResponse.SC_OK, response.getResponseCode() );
70 public void testRequestNewVersionsOfArtifact()
73 RssFeedServlet servlet =
74 (RssFeedServlet) client.newInvocation(
75 "http://localhost/rss/rss_feeds?groupId=org.apache.archiva&artifactId=artifact-two" ).getServlet();
76 assertNotNull( servlet );
78 WebResponse response = client.getResponse( "http://localhost/rss/rss_feeds?groupId=org.apache.archiva&artifactId=artifact-two" );
79 assertEquals( RssFeedServlet.MIME_TYPE, response.getHeaderField( "CONTENT-TYPE" ) );
81 assertNotNull( "Should have recieved a response", response );
82 assertEquals( "Should have been an OK response code.", HttpServletResponse.SC_OK, response.getResponseCode() );
85 public void testInvalidRequest()
88 RssFeedServlet servlet =
89 (RssFeedServlet) client.newInvocation(
90 "http://localhost/rss/rss_feeds?invalid_param=xxx" ).getServlet();
91 assertNotNull( servlet );
95 WebResponse response = client.getResponse( "http://localhost/rss/rss_feeds?invalid_param=xxx" );
97 catch ( HttpException he )
99 assertEquals( "Should have been a bad request response code.", HttpServletResponse.SC_BAD_REQUEST, he.getResponseCode() );
103 public void testUnAuthorizedRequest()
106 RssFeedServlet servlet =
107 (RssFeedServlet) client.newInvocation(
108 "http://localhost/rss/rss_feeds" ).getServlet();
109 assertNotNull( servlet );
111 //WebResponse response = client.getResponse( "http://localhost/rss/rss_feeds" );
112 //assertNotNull( "Should have recieved a response", response );
113 //assertEquals( "Should have been a bad request response code.", HttpServletResponse.SC_BAD_REQUEST, response.getResponseCode() );
117 protected String getPlexusConfigLocation()
119 return "org/apache/maven/archiva/web/rss/RssFeedServletTest.xml";
123 protected void tearDown()
126 if ( client != null )
128 client.clearContents();