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 org.apache.maven.archiva.configuration.ArchivaConfiguration;
23  import org.apache.maven.archiva.configuration.Configuration;
24  import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
25  import org.apache.maven.archiva.webdav.RepositoryServlet;
26  
27  import com.meterware.httpunit.GetMethodWebRequest;
28  import com.meterware.httpunit.WebRequest;
29  import com.meterware.httpunit.WebResponse;
30  
31  import java.io.File;
32  
33  /**
34   * RepositoryServletTest 
35   *
36   * @version $Id$
37   */
38  public class RepositoryServletTest
39      extends AbstractRepositoryServletTestCase
40  {
41      private static final String REQUEST_PATH = "http://machine.com/repository/internal/";
42  
43      private static final String NEW_REPOSITORY_ID = "new-id";
44  
45      private static final String NEW_REPOSITORY_NAME = "New Repository";
46  
47      public void testGetRepository()
48          throws Exception
49      {
50          RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
51          assertNotNull( servlet );
52  
53          assertRepositoryValid( servlet, REPOID_INTERNAL );
54      }
55  
56      public void testGetRepositoryAfterDelete()
57          throws Exception
58      {
59          RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
60          assertNotNull( servlet );
61  
62          ArchivaConfiguration archivaConfiguration = servlet.getConfiguration();
63          Configuration c = archivaConfiguration.getConfiguration();
64          c.removeManagedRepository( c.findManagedRepositoryById( REPOID_INTERNAL ) );
65          saveConfiguration( archivaConfiguration );
66  
67          ManagedRepositoryConfiguration repository = servlet.getRepository( REPOID_INTERNAL );
68          assertNull( repository );
69      }
70  
71      public void testGetRepositoryAfterAdd()
72          throws Exception
73      {
74          RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
75          assertNotNull( servlet );
76  
77          ArchivaConfiguration archivaConfiguration = servlet.getConfiguration();
78          Configuration c = archivaConfiguration.getConfiguration();
79          ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration();
80          repo.setId( NEW_REPOSITORY_ID );
81          repo.setName( NEW_REPOSITORY_NAME );
82          File repoRoot = new File( getBasedir(), "target/test-repository-root" );
83          if ( !repoRoot.exists() )
84          {
85              repoRoot.mkdirs();
86          }
87          repo.setLocation( repoRoot.getAbsolutePath() );
88          c.addManagedRepository( repo );
89          saveConfiguration( archivaConfiguration );
90  
91          ManagedRepositoryConfiguration repository = servlet.getRepository( NEW_REPOSITORY_ID );
92          assertNotNull( repository );
93          assertEquals( NEW_REPOSITORY_NAME, repository.getName() );
94  
95          // check other is still intact
96          assertRepositoryValid( servlet, REPOID_INTERNAL );
97      }
98  
99      public void testGetRepositoryInvalidPathPassthroughPresent()
100         throws Exception
101     {
102         String path = REQUEST_PATH + ".index/filecontent/segments.gen";
103 
104         populateRepo( repoRootInternal, ".index/filecontent/segments.gen", "index file" );
105         
106         WebRequest request = new GetMethodWebRequest( path );
107         WebResponse response = sc.getResponse( request );
108         assertResponseOK( response );
109         assertEquals( "index file", response.getText() );        
110     }
111 
112     public void testGetRepositoryInvalidPathPassthroughMissing()
113         throws Exception
114     {
115         String path = REQUEST_PATH + ".index/filecontent/foo.bar";
116 
117         WebRequest request = new GetMethodWebRequest( path );
118         WebResponse response = sc.getResponse( request );
119         assertResponseNotFound( response );
120         assertEquals( "Invalid path to Artifact: legacy paths should have an expected type ending in [s] in the second part of the path.", response.getResponseMessage() );
121     }
122 }