1 package org.apache.maven.archiva.webdav;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
35
36
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
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 }