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.

ArtifactContentEntriesTests.java 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. package org.apache.archiva.rest.services;
  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 junit.framework.TestCase;
  21. import org.apache.archiva.common.filelock.DefaultFileLockManager;
  22. import org.apache.archiva.repository.storage.FilesystemAsset;
  23. import org.apache.archiva.repository.storage.FilesystemStorage;
  24. import org.apache.archiva.rest.api.model.ArtifactContentEntry;
  25. import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
  26. import org.junit.Test;
  27. import org.junit.runner.RunWith;
  28. import org.slf4j.Logger;
  29. import org.slf4j.LoggerFactory;
  30. import java.nio.file.Path;
  31. import java.nio.file.Paths;
  32. import java.util.List;
  33. import static org.assertj.core.api.Assertions.assertThat;
  34. /**
  35. * @author Olivier Lamy
  36. */
  37. @RunWith( ArchivaBlockJUnit4ClassRunner.class )
  38. public class ArtifactContentEntriesTests
  39. extends TestCase
  40. {
  41. protected Logger log = LoggerFactory.getLogger( getClass() );
  42. DefaultBrowseService browseService = new DefaultBrowseService();
  43. public String getBasedir()
  44. {
  45. return System.getProperty( "basedir" );
  46. }
  47. @Test
  48. public void readArtifactContentEntriesRootPathNull()
  49. throws Exception
  50. {
  51. FilesystemStorage filesystemStorage = new FilesystemStorage(Paths.get(getBasedir()), new DefaultFileLockManager());
  52. Path file = Paths.get( getBasedir(),
  53. "src/test/repo-with-osgi/commons-logging/commons-logging/1.1/commons-logging-1.1.jar" );
  54. List<ArtifactContentEntry> artifactContentEntries = browseService.readFileEntries( new FilesystemAsset(filesystemStorage, file.toString(), file), null, "foo" );
  55. log.info( "artifactContentEntries: {}", artifactContentEntries );
  56. assertThat( artifactContentEntries ).isNotNull().isNotEmpty().hasSize( 2 ).contains(
  57. new ArtifactContentEntry( "org", false, 0, "foo" ),
  58. new ArtifactContentEntry( "META-INF", false, 0, "foo" ) );
  59. }
  60. @Test
  61. public void readArtifactContentEntriesRootPathEmpty()
  62. throws Exception
  63. {
  64. FilesystemStorage filesystemStorage = new FilesystemStorage(Paths.get(getBasedir()), new DefaultFileLockManager());
  65. Path file = Paths.get( getBasedir(),
  66. "src/test/repo-with-osgi/commons-logging/commons-logging/1.1/commons-logging-1.1.jar" );
  67. List<ArtifactContentEntry> artifactContentEntries = browseService.readFileEntries(
  68. new FilesystemAsset(filesystemStorage, file.toString(), file), "", "foo" );
  69. log.info( "artifactContentEntries: {}", artifactContentEntries );
  70. assertThat( artifactContentEntries ).isNotNull().isNotEmpty().hasSize( 2 ).contains(
  71. new ArtifactContentEntry( "org", false, 0, "foo" ),
  72. new ArtifactContentEntry( "META-INF", false, 0, "foo" ) );
  73. }
  74. @Test
  75. public void readArtifactContentEntriesRootSlash()
  76. throws Exception
  77. {
  78. FilesystemStorage filesystemStorage = new FilesystemStorage(Paths.get(getBasedir()), new DefaultFileLockManager());
  79. Path file = Paths.get( getBasedir(),
  80. "src/test/repo-with-osgi/commons-logging/commons-logging/1.1/commons-logging-1.1.jar" );
  81. List<ArtifactContentEntry> artifactContentEntries = browseService.readFileEntries( new FilesystemAsset(filesystemStorage, file.toString(),file), "/", "foo" );
  82. log.info( "artifactContentEntries: {}", artifactContentEntries );
  83. assertThat( artifactContentEntries ).isNotNull().isNotEmpty().hasSize( 2 ).contains(
  84. new ArtifactContentEntry( "org", false, 0, "foo" ),
  85. new ArtifactContentEntry( "META-INF", false, 0, "foo" ) );
  86. }
  87. @Test
  88. public void readArtifactContentEntriesSecondDepthOnlyOneDirectory()
  89. throws Exception
  90. {
  91. FilesystemStorage filesystemStorage = new FilesystemStorage(Paths.get(getBasedir()), new DefaultFileLockManager());
  92. Path file = Paths.get( getBasedir(),
  93. "src/test/repo-with-osgi/commons-logging/commons-logging/1.1/commons-logging-1.1.jar" );
  94. List<ArtifactContentEntry> artifactContentEntries = browseService.readFileEntries( new FilesystemAsset(filesystemStorage, file.toString(), file), "org", "foo" );
  95. log.info( "artifactContentEntries: {}", artifactContentEntries );
  96. assertThat( artifactContentEntries ).isNotNull().isNotEmpty().hasSize( 1 ).contains(
  97. new ArtifactContentEntry( "org/apache", false, 1, "foo" ) );
  98. }
  99. @Test
  100. public void readArtifactContentEntriesOnlyFiles()
  101. throws Exception
  102. {
  103. FilesystemStorage filesystemStorage = new FilesystemStorage(Paths.get(getBasedir()), new DefaultFileLockManager());
  104. Path file = Paths.get( getBasedir(),
  105. "src/test/repo-with-osgi/commons-logging/commons-logging/1.1/commons-logging-1.1.jar" );
  106. List<ArtifactContentEntry> artifactContentEntries =
  107. browseService.readFileEntries( new FilesystemAsset(filesystemStorage, file.toString(), file), "org/apache/commons/logging/impl/", "foo" );
  108. log.info( "artifactContentEntries: {}", artifactContentEntries );
  109. assertThat( artifactContentEntries ).isNotNull().isNotEmpty().hasSize( 16 ).contains(
  110. new ArtifactContentEntry( "org/apache/commons/logging/impl/AvalonLogger.class", true, 5, "foo" ) );
  111. }
  112. @Test
  113. public void readArtifactContentEntriesDirectoryAndFiles()
  114. throws Exception
  115. {
  116. FilesystemStorage filesystemStorage = new FilesystemStorage(Paths.get(getBasedir()), new DefaultFileLockManager());
  117. Path file = Paths.get( getBasedir(),
  118. "src/test/repo-with-osgi/commons-logging/commons-logging/1.1/commons-logging-1.1.jar" );
  119. List<ArtifactContentEntry> artifactContentEntries =
  120. browseService.readFileEntries( new FilesystemAsset(filesystemStorage, file.toString(), file), "org/apache/commons/logging/", "foo" );
  121. log.info( "artifactContentEntries: {}", artifactContentEntries );
  122. assertThat( artifactContentEntries ).isNotNull().isNotEmpty().hasSize( 10 ).contains(
  123. new ArtifactContentEntry( "org/apache/commons/logging/impl", false, 4, "foo" ),
  124. new ArtifactContentEntry( "org/apache/commons/logging/LogSource.class", true, 4, "foo" ) );
  125. }
  126. }