You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RepositoryServletTest.java 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. package org.apache.archiva.webdav;
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. import com.gargoylesoftware.htmlunit.WebRequest;
  21. import com.gargoylesoftware.htmlunit.WebResponse;
  22. import org.apache.archiva.admin.model.beans.ManagedRepository;
  23. import org.apache.archiva.configuration.ArchivaConfiguration;
  24. import org.apache.archiva.configuration.Configuration;
  25. import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
  26. import org.junit.Before;
  27. import org.junit.Test;
  28. import java.nio.file.Files;
  29. import java.nio.file.Path;
  30. import java.nio.file.Paths;
  31. import static org.assertj.core.api.Assertions.assertThat;
  32. /**
  33. * RepositoryServletTest
  34. */
  35. public class RepositoryServletTest
  36. extends AbstractRepositoryServletTestCase
  37. {
  38. private static final String REQUEST_PATH = "http://machine.com/repository/internal/";
  39. private static final String NEW_REPOSITORY_ID = "new-id";
  40. private static final String NEW_REPOSITORY_NAME = "New Repository";
  41. @Before
  42. @Override
  43. public void setUp()
  44. throws Exception
  45. {
  46. super.setUp();
  47. startRepository();
  48. }
  49. @Test
  50. public void testGetRepository()
  51. throws Exception
  52. {
  53. RepositoryServlet servlet = RepositoryServlet.class.cast( findServlet( "repository" ) );
  54. assertNotNull( servlet );
  55. assertRepositoryValid( servlet, REPOID_INTERNAL );
  56. }
  57. @Test
  58. public void testGetRepositoryAfterDelete()
  59. throws Exception
  60. {
  61. RepositoryServlet servlet = RepositoryServlet.class.cast( findServlet( "repository" ) );
  62. assertNotNull( servlet );
  63. ArchivaConfiguration archivaConfiguration = servlet.getConfiguration();
  64. Configuration c = archivaConfiguration.getConfiguration();
  65. c.removeManagedRepository( c.findManagedRepositoryById( REPOID_INTERNAL ) );
  66. saveConfiguration( archivaConfiguration );
  67. ManagedRepository repository = servlet.getRepository( REPOID_INTERNAL );
  68. assertNull( repository );
  69. }
  70. @Test
  71. public void testGetRepositoryAfterAdd()
  72. throws Exception
  73. {
  74. RepositoryServlet servlet = RepositoryServlet.class.cast( findServlet( "repository" ) );
  75. assertNotNull( servlet );
  76. ArchivaConfiguration archivaConfiguration = servlet.getConfiguration();
  77. Configuration c = archivaConfiguration.getConfiguration();
  78. ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration();
  79. repo.setId( NEW_REPOSITORY_ID );
  80. repo.setName( NEW_REPOSITORY_NAME );
  81. Path repoRoot = Paths.get( "target/test-repository-root" );
  82. if ( !Files.exists(repoRoot) )
  83. {
  84. Files.createDirectories( repoRoot );
  85. }
  86. repo.setLocation( repoRoot.toAbsolutePath().toString() );
  87. c.addManagedRepository( repo );
  88. saveConfiguration( archivaConfiguration );
  89. ManagedRepository repository = servlet.getRepository( NEW_REPOSITORY_ID );
  90. assertNotNull( repository );
  91. assertEquals( NEW_REPOSITORY_NAME, repository.getName() );
  92. // check other is still intact
  93. assertRepositoryValid( servlet, REPOID_INTERNAL );
  94. }
  95. @Test
  96. public void testGetRepositoryInvalidPathPassthroughPresent()
  97. throws Exception
  98. {
  99. String path = REQUEST_PATH + ".index/filecontent/segments.gen";
  100. populateRepo( repoRootInternal, ".index/filecontent/segments.gen", "index file" );
  101. WebRequest request = new GetMethodWebRequest( path );
  102. WebResponse response = getServletUnitClient().getResponse( request );
  103. assertResponseOK( response );
  104. assertEquals( "index file", response.getContentAsString() );
  105. }
  106. @Test
  107. public void testGetRepositoryInvalidPathPassthroughMissing()
  108. throws Exception
  109. {
  110. String path = REQUEST_PATH + ".index/filecontent/foo.bar";
  111. WebRequest request = new GetMethodWebRequest( path );
  112. WebResponse response = getServletUnitClient().getResponse( request );
  113. assertResponseNotFound( response );
  114. assertThat( response.getContentAsString() ) //
  115. .contains( "Legacy Maven1 repository not supported anymore." );
  116. }
  117. }