View Javadoc

1   package org.apache.maven.archiva.webdav;
2   
3   /*
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
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
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
19   * under the License.
20   */
21  
22  import com.meterware.httpunit.GetMethodWebRequest;
23  import com.meterware.httpunit.WebLink;
24  import com.meterware.httpunit.WebRequest;
25  import com.meterware.httpunit.WebResponse;
26  
27  import java.io.File;
28  
29  import javax.servlet.http.HttpServletResponse;
30  
31  /**
32   * RepositoryServletBrowseTest 
33   *
34   * @version $Id: RepositoryServletBrowseTest.java 718864 2008-11-19 06:33:35Z brett $
35   */
36  public class RepositoryServletBrowseTest
37      extends AbstractRepositoryServletTestCase
38  {
39      @Override
40      protected void setUp()
41          throws Exception 
42      {
43          super.setUp();
44          
45          new File( repoRootInternal, "org/apache/archiva" ).mkdirs();
46          new File( repoRootInternal, "org/codehaus/mojo/" ).mkdirs();
47          new File( repoRootInternal, "net/sourceforge" ).mkdirs();
48          new File( repoRootInternal, "commons-lang" ).mkdirs();
49      }
50      
51      public void testBrowse()
52          throws Exception
53      {
54          WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" );
55          WebResponse response = sc.getResponse( request );
56          assertEquals( "Response", HttpServletResponse.SC_OK, response.getResponseCode() );
57  
58          // dumpResponse( response );
59  
60          String expectedLinks[] = new String[] { "commons-lang/", "net/", "org/" };
61          assertLinks(expectedLinks, response.getLinks());
62      }
63      
64      public void testBrowseSubdirectory()
65          throws Exception
66      {
67          WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/org" );
68          WebResponse response = sc.getResponse( request );
69          assertEquals( "Response", HttpServletResponse.SC_OK, response.getResponseCode() );
70          
71          String expectedLinks[] = new String[] { "../", "apache/", "codehaus/" };
72          assertLinks(expectedLinks, response.getLinks());
73      }
74  
75      public void testGetDirectoryWhichHasMatchingFile() //MRM-893
76          throws Exception
77      {
78          new File( repoRootInternal, "org/apache/archiva/artifactId/1.0" ).mkdirs();
79          new File( repoRootInternal, "org/apache/archiva/artifactId/1.0/artifactId-1.0.jar" ).createNewFile();
80  
81          WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/org/apache/archiva/artifactId" );
82          WebResponse response = sc.getResponse( request );
83          assertEquals( "Response", HttpServletResponse.SC_OK, response.getResponseCode() );
84  
85          request = new GetMethodWebRequest( "http://machine.com/repository/internal/org/apache/archiva/artifactId/" );
86          response = sc.getResponse( request );
87          assertEquals( "Response", HttpServletResponse.SC_OK, response.getResponseCode() );
88          
89          request = new GetMethodWebRequest( "http://machine.com/repository/internal/org/apache/archiva/artifactId/1.0/artifactId-1.0.jar" );
90          response = sc.getResponse( request );
91          assertEquals( "Response", HttpServletResponse.SC_OK, response.getResponseCode() );
92          
93          request = new GetMethodWebRequest( "http://machine.com/repository/internal/org/apache/archiva/artifactId/1.0/artifactId-1.0.jar/" );
94          response = sc.getResponse( request );
95          assertEquals( "Response", HttpServletResponse.SC_NOT_FOUND, response.getResponseCode() );
96      }
97      
98      
99      private void assertLinks(String expectedLinks[], WebLink actualLinks[])
100     {
101         assertEquals( "Links.length", expectedLinks.length, actualLinks.length );
102         for ( int i = 0; i < actualLinks.length; i++ )
103         {
104             assertEquals( "Link[" + i + "]", expectedLinks[i], actualLinks[i].getURLString() );
105         }        
106     }
107 }