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