]> source.dussan.org Git - archiva.git/blob
66dd6541ab119257c7cc8ee22dd3e3a0b3650919
[archiva.git] /
1 package org.apache.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 import org.junit.Before;
27 import org.junit.Test;
28
29 import javax.servlet.http.HttpServletResponse;
30 import java.io.File;
31
32 /**
33  * RepositoryServletBrowseTest
34  *
35  * @version $Id$
36  */
37 public class RepositoryServletBrowseTest
38     extends AbstractRepositoryServletTestCase
39 {
40     @Override
41     @Before
42     public void setUp()
43         throws Exception
44     {
45         super.setUp();
46
47         new File( repoRootInternal, "org/apache/archiva" ).mkdirs();
48         new File( repoRootInternal, "org/codehaus/mojo/" ).mkdirs();
49         new File( repoRootInternal, "net/sourceforge" ).mkdirs();
50         new File( repoRootInternal, "commons-lang" ).mkdirs();
51     }
52
53     @Test
54     public void testBrowse()
55         throws Exception
56     {
57         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" );
58         WebResponse response = getServletUnitClient().getResponse( request );
59         assertEquals( "Response", HttpServletResponse.SC_OK, response.getResponseCode() );
60
61         // dumpResponse( response );
62
63         String expectedLinks[] = new String[]{ ".indexer", "commons-lang/", "net/", "org/" };
64         assertLinks( expectedLinks, response.getLinks() );
65     }
66
67     @Test
68     public void testBrowseSubdirectory()
69         throws Exception
70     {
71         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/org" );
72         WebResponse response = getServletUnitClient().getResponse( request );
73         assertEquals( "Response", HttpServletResponse.SC_OK, response.getResponseCode() );
74
75         String expectedLinks[] = new String[]{ "../", "apache/", "codehaus/" };
76         assertLinks( expectedLinks, response.getLinks() );
77     }
78
79     @Test
80     public void testGetDirectoryWhichHasMatchingFile() //MRM-893
81         throws Exception
82     {
83         new File( repoRootInternal, "org/apache/archiva/artifactId/1.0" ).mkdirs();
84         new File( repoRootInternal, "org/apache/archiva/artifactId/1.0/artifactId-1.0.jar" ).createNewFile();
85
86         WebRequest request =
87             new GetMethodWebRequest( "http://machine.com/repository/internal/org/apache/archiva/artifactId" );
88         WebResponse response = getServletUnitClient().getResponse( request );
89         assertEquals( "1st Response", HttpServletResponse.SC_OK, response.getResponseCode() );
90
91         request = new GetMethodWebRequest( "http://machine.com/repository/internal/org/apache/archiva/artifactId/" );
92         response = getServletUnitClient().getResponse( request );
93         assertEquals( "2nd Response", HttpServletResponse.SC_OK, response.getResponseCode() );
94
95         request = new GetMethodWebRequest(
96             "http://machine.com/repository/internal/org/apache/archiva/artifactId/1.0/artifactId-1.0.jar" );
97         response = getServletUnitClient().getResponse( request );
98         assertEquals( "3rd Response", HttpServletResponse.SC_OK, response.getResponseCode() );
99
100         request = new GetMethodWebRequest(
101             "http://machine.com/repository/internal/org/apache/archiva/artifactId/1.0/artifactId-1.0.jar/" );
102         response = getServletUnitClient().getResponse( request );
103         assertEquals( "4th Response", HttpServletResponse.SC_NOT_FOUND, response.getResponseCode() );
104     }
105
106
107     private void assertLinks( String expectedLinks[], WebLink actualLinks[] )
108     {
109         assertEquals( "Links.length", expectedLinks.length, actualLinks.length );
110         for ( int i = 0; i < actualLinks.length; i++ )
111         {
112             assertEquals( "Link[" + i + "]", expectedLinks[i], actualLinks[i].getURLString() );
113         }
114     }
115 }