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 );
82 repositoryRegistry.removeRepository( REPOID_INTERNAL );
84 org.apache.archiva.repository.ManagedRepository repository = servlet.getRepository( REPOID_INTERNAL );
85 assertNull( repository );
89 public void testGetRepositoryAfterAdd()
92 RepositoryServlet servlet = RepositoryServlet.class.cast( findServlet( "repository" ) );
93 assertNotNull( servlet );
95 ArchivaConfiguration archivaConfiguration = servlet.getConfiguration();
96 Configuration c = archivaConfiguration.getConfiguration();
97 ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration();
98 repo.setId( NEW_REPOSITORY_ID );
99 repo.setName( NEW_REPOSITORY_NAME );
100 Path repoRoot = Paths.get( "target/test-repository-root" );
101 if ( !Files.exists(repoRoot) )
103 Files.createDirectories( repoRoot );
105 repo.setLocation( repoRoot.toAbsolutePath().toString() );
106 c.addManagedRepository( repo );
107 saveConfiguration( archivaConfiguration );
109 ManagedRepository repository = servlet.getRepository( NEW_REPOSITORY_ID );
110 assertNotNull( repository );
111 assertEquals( NEW_REPOSITORY_NAME, repository.getName() );
113 // check other is still intact
114 assertRepositoryValid( servlet, REPOID_INTERNAL );
118 public void testGetRepositoryInvalidPathPassthroughPresent()
121 String path = REQUEST_PATH + ".indexer/filecontent/segments.gen";
123 populateRepo( repoRootInternal, ".indexer/filecontent/segments.gen", "index file" );
125 WebRequest request = new GetMethodWebRequest( path );
126 WebResponse response = getServletUnitClient().getResponse( request );
127 assertResponseOK( response );
128 assertEquals( "index file", response.getContentAsString() );
132 public void testGetRepositoryInvalidPathPassthroughMissing()
135 String path = REQUEST_PATH + ".indexer/filecontent/foo.bar";
137 WebRequest request = new GetMethodWebRequest( path );
138 WebResponse response = getServletUnitClient().getResponse( request );
139 assertResponseNotFound( response );
140 assertThat( response.getContentAsString() ) //
141 .contains( "Resource does not exist" );