1 package org.apache.archiva.rest.services;
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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
21 import junit.framework.TestCase;
22 import org.apache.archiva.rest.api.model.ArtifactContentEntry;
23 import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
29 import java.nio.file.Path;
30 import java.nio.file.Paths;
31 import java.util.List;
33 import static org.assertj.core.api.Assertions.assertThat;
36 * @author Olivier Lamy
38 @RunWith( ArchivaBlockJUnit4ClassRunner.class )
39 public class ArtifactContentEntriesTests
43 protected Logger log = LoggerFactory.getLogger( getClass() );
46 DefaultBrowseService browseService = new DefaultBrowseService();
49 public String getBasedir()
51 return System.getProperty( "basedir" );
55 public void readArtifactContentEntriesRootPathNull()
59 Path file = Paths.get( getBasedir(),
60 "src/test/repo-with-osgi/commons-logging/commons-logging/1.1/commons-logging-1.1.jar" );
62 List<ArtifactContentEntry> artifactContentEntries = browseService.readFileEntries( file, null, "foo" );
64 log.info( "artifactContentEntries: {}", artifactContentEntries );
66 assertThat( artifactContentEntries ).isNotNull().isNotEmpty().hasSize( 2 ).contains(
67 new ArtifactContentEntry( "org", false, 0, "foo" ),
68 new ArtifactContentEntry( "META-INF", false, 0, "foo" ) );
73 public void readArtifactContentEntriesRootPathEmpty()
77 Path file = Paths.get( getBasedir(),
78 "src/test/repo-with-osgi/commons-logging/commons-logging/1.1/commons-logging-1.1.jar" );
80 List<ArtifactContentEntry> artifactContentEntries = browseService.readFileEntries( file, "", "foo" );
82 log.info( "artifactContentEntries: {}", artifactContentEntries );
84 assertThat( artifactContentEntries ).isNotNull().isNotEmpty().hasSize( 2 ).contains(
85 new ArtifactContentEntry( "org", false, 0, "foo" ),
86 new ArtifactContentEntry( "META-INF", false, 0, "foo" ) );
91 public void readArtifactContentEntriesRootSlash()
95 Path file = Paths.get( getBasedir(),
96 "src/test/repo-with-osgi/commons-logging/commons-logging/1.1/commons-logging-1.1.jar" );
98 List<ArtifactContentEntry> artifactContentEntries = browseService.readFileEntries( file, "/", "foo" );
100 log.info( "artifactContentEntries: {}", artifactContentEntries );
102 assertThat( artifactContentEntries ).isNotNull().isNotEmpty().hasSize( 2 ).contains(
103 new ArtifactContentEntry( "org", false, 0, "foo" ),
104 new ArtifactContentEntry( "META-INF", false, 0, "foo" ) );
109 public void readArtifactContentEntriesSecondDepthOnlyOneDirectory()
113 Path file = Paths.get( getBasedir(),
114 "src/test/repo-with-osgi/commons-logging/commons-logging/1.1/commons-logging-1.1.jar" );
116 List<ArtifactContentEntry> artifactContentEntries = browseService.readFileEntries( file, "org", "foo" );
118 log.info( "artifactContentEntries: {}", artifactContentEntries );
120 assertThat( artifactContentEntries ).isNotNull().isNotEmpty().hasSize( 1 ).contains(
121 new ArtifactContentEntry( "org/apache", false, 1, "foo" ) );
126 public void readArtifactContentEntriesOnlyFiles()
130 Path file = Paths.get( getBasedir(),
131 "src/test/repo-with-osgi/commons-logging/commons-logging/1.1/commons-logging-1.1.jar" );
133 List<ArtifactContentEntry> artifactContentEntries =
134 browseService.readFileEntries( file, "org/apache/commons/logging/impl/", "foo" );
136 log.info( "artifactContentEntries: {}", artifactContentEntries );
138 assertThat( artifactContentEntries ).isNotNull().isNotEmpty().hasSize( 16 ).contains(
139 new ArtifactContentEntry( "org/apache/commons/logging/impl/AvalonLogger.class", true, 5, "foo" ) );
144 public void readArtifactContentEntriesDirectoryAndFiles()
148 Path file = Paths.get( getBasedir(),
149 "src/test/repo-with-osgi/commons-logging/commons-logging/1.1/commons-logging-1.1.jar" );
151 List<ArtifactContentEntry> artifactContentEntries =
152 browseService.readFileEntries( file, "org/apache/commons/logging/", "foo" );
154 log.info( "artifactContentEntries: {}", artifactContentEntries );
156 assertThat( artifactContentEntries ).isNotNull().isNotEmpty().hasSize( 10 ).contains(
157 new ArtifactContentEntry( "org/apache/commons/logging/impl", false, 4, "foo" ),
158 new ArtifactContentEntry( "org/apache/commons/logging/LogSource.class", true, 4, "foo" ) );