1 package org.apache.archiva.webdav;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import com.gargoylesoftware.htmlunit.WebRequest;
23 import com.gargoylesoftware.htmlunit.WebResponse;
24 import org.apache.archiva.configuration.ArchivaConfiguration;
25 import org.apache.archiva.configuration.Configuration;
26 import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
27 import org.apache.archiva.repository.ManagedRepository;
28 import org.junit.Before;
29 import org.junit.Test;
31 import java.nio.file.Files;
32 import java.nio.file.Path;
33 import java.nio.file.Paths;
35 import static org.assertj.core.api.Assertions.assertThat;
38 * RepositoryServletTest
40 public class RepositoryServletTest
41 extends AbstractRepositoryServletTestCase
43 private static final String REQUEST_PATH = "http://machine.com/repository/internal/";
45 private static final String NEW_REPOSITORY_ID = "new-id";
47 private static final String NEW_REPOSITORY_NAME = "New Repository";
59 public void testGetRepository()
63 RepositoryServlet servlet = RepositoryServlet.class.cast( findServlet( "repository" ) );
64 assertNotNull( servlet );
66 assertRepositoryValid( servlet, REPOID_INTERNAL );
71 public void testGetRepositoryAfterDelete()
74 RepositoryServlet servlet = RepositoryServlet.class.cast( findServlet( "repository" ) );
76 assertNotNull( servlet );
78 ArchivaConfiguration archivaConfiguration = servlet.getConfiguration();
79 Configuration c = archivaConfiguration.getConfiguration();
80 c.removeManagedRepository( c.findManagedRepositoryById( REPOID_INTERNAL ) );
81 saveConfiguration( archivaConfiguration );
83 org.apache.archiva.repository.ManagedRepository repository = servlet.getRepository( REPOID_INTERNAL );
84 assertNull( repository );
88 public void testGetRepositoryAfterAdd()
91 RepositoryServlet servlet = RepositoryServlet.class.cast( findServlet( "repository" ) );
92 assertNotNull( servlet );
94 ArchivaConfiguration archivaConfiguration = servlet.getConfiguration();
95 Configuration c = archivaConfiguration.getConfiguration();
96 ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration();
97 repo.setId( NEW_REPOSITORY_ID );
98 repo.setName( NEW_REPOSITORY_NAME );
99 Path repoRoot = Paths.get( "target/test-repository-root" );
100 if ( !Files.exists(repoRoot) )
102 Files.createDirectories( repoRoot );
104 repo.setLocation( repoRoot.toAbsolutePath().toString() );
105 c.addManagedRepository( repo );
106 saveConfiguration( archivaConfiguration );
108 ManagedRepository repository = servlet.getRepository( NEW_REPOSITORY_ID );
109 assertNotNull( repository );
110 assertEquals( NEW_REPOSITORY_NAME, repository.getName() );
112 // check other is still intact
113 assertRepositoryValid( servlet, REPOID_INTERNAL );
117 public void testGetRepositoryInvalidPathPassthroughPresent()
120 String path = REQUEST_PATH + ".index/filecontent/segments.gen";
122 populateRepo( repoRootInternal, ".index/filecontent/segments.gen", "index file" );
124 WebRequest request = new GetMethodWebRequest( path );
125 WebResponse response = getServletUnitClient().getResponse( request );
126 assertResponseOK( response );
127 assertEquals( "index file", response.getContentAsString() );
131 public void testGetRepositoryInvalidPathPassthroughMissing()
134 String path = REQUEST_PATH + ".index/filecontent/foo.bar";
136 WebRequest request = new GetMethodWebRequest( path );
137 WebResponse response = getServletUnitClient().getResponse( request );
138 assertResponseNotFound( response );
139 assertThat( response.getContentAsString() ) //
140 .contains( "Resource does not exist" );