1 package org.apache.archiva.webdav;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import com.gargoylesoftware.htmlunit.WebRequest;
23 import com.gargoylesoftware.htmlunit.WebResponse;
24 import org.apache.archiva.admin.model.beans.ManagedRepository;
25 import org.apache.archiva.configuration.ArchivaConfiguration;
26 import org.apache.archiva.configuration.Configuration;
27 import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
28 import org.junit.Before;
29 import org.junit.Test;
30
31 import java.io.File;
32
33 import static org.assertj.core.api.Assertions.assertThat;
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 @Before
48 @Override
49 public void setUp()
50 throws Exception
51 {
52 super.setUp();
53 startRepository();
54 }
55
56 @Test
57 public void testGetRepository()
58 throws Exception
59 {
60
61 RepositoryServlet servlet = RepositoryServlet.class.cast( findServlet( "repository" ) );
62 assertNotNull( servlet );
63
64 assertRepositoryValid( servlet, REPOID_INTERNAL );
65 }
66
67
68 @Test
69 public void testGetRepositoryAfterDelete()
70 throws Exception
71 {
72 RepositoryServlet servlet = RepositoryServlet.class.cast( findServlet( "repository" ) );
73
74 assertNotNull( servlet );
75
76 ArchivaConfiguration archivaConfiguration = servlet.getConfiguration();
77 Configuration c = archivaConfiguration.getConfiguration();
78 c.removeManagedRepository( c.findManagedRepositoryById( REPOID_INTERNAL ) );
79 saveConfiguration( archivaConfiguration );
80
81 ManagedRepository repository = servlet.getRepository( REPOID_INTERNAL );
82 assertNull( repository );
83 }
84
85 @Test
86 public void testGetRepositoryAfterAdd()
87 throws Exception
88 {
89 RepositoryServlet servlet = RepositoryServlet.class.cast( findServlet( "repository" ) );
90 assertNotNull( servlet );
91
92 ArchivaConfiguration archivaConfiguration = servlet.getConfiguration();
93 Configuration c = archivaConfiguration.getConfiguration();
94 ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration();
95 repo.setId( NEW_REPOSITORY_ID );
96 repo.setName( NEW_REPOSITORY_NAME );
97 File repoRoot = new File( "target/test-repository-root" );
98 if ( !repoRoot.exists() )
99 {
100 repoRoot.mkdirs();
101 }
102 repo.setLocation( repoRoot.getAbsolutePath() );
103 c.addManagedRepository( repo );
104 saveConfiguration( archivaConfiguration );
105
106 ManagedRepository repository = servlet.getRepository( NEW_REPOSITORY_ID );
107 assertNotNull( repository );
108 assertEquals( NEW_REPOSITORY_NAME, repository.getName() );
109
110
111 assertRepositoryValid( servlet, REPOID_INTERNAL );
112 }
113
114 @Test
115 public void testGetRepositoryInvalidPathPassthroughPresent()
116 throws Exception
117 {
118 String path = REQUEST_PATH + ".index/filecontent/segments.gen";
119
120 populateRepo( repoRootInternal, ".index/filecontent/segments.gen", "index file" );
121
122 WebRequest request = new GetMethodWebRequest( path );
123 WebResponse response = getServletUnitClient().getResponse( request );
124 assertResponseOK( response );
125 assertEquals( "index file", response.getContentAsString() );
126 }
127
128 @Test
129 public void testGetRepositoryInvalidPathPassthroughMissing()
130 throws Exception
131 {
132 String path = REQUEST_PATH + ".index/filecontent/foo.bar";
133
134 WebRequest request = new GetMethodWebRequest( path );
135 WebResponse response = getServletUnitClient().getResponse( request );
136 assertResponseNotFound( response );
137 assertThat( response.getContentAsString() )
138 .contains( "Legacy Maven1 repository not supported anymore." );
139 }
140 }