您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ArtifactContentEntriesTests.java 5.7KB

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