]> source.dussan.org Git - archiva.git/blob
8e692012b7c35d09a49f13a450d4b33bc346657b
[archiva.git] /
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
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.junit.runners.JUnit4;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 import java.io.File;
31 import java.nio.file.Path;
32 import java.nio.file.Paths;
33 import java.util.List;
34
35 import static org.assertj.core.api.Assertions.assertThat;
36
37 /**
38  * @author Olivier Lamy
39  */
40 @RunWith( ArchivaBlockJUnit4ClassRunner.class )
41 public class ArtifactContentEntriesTests
42     extends TestCase
43 {
44
45     protected Logger log = LoggerFactory.getLogger( getClass() );
46
47
48     DefaultBrowseService browseService = new DefaultBrowseService();
49
50
51     public String getBasedir()
52     {
53         return System.getProperty( "basedir" );
54     }
55
56     @Test
57     public void readArtifactContentEntriesRootPathNull()
58         throws Exception
59     {
60
61         Path file = Paths.get( getBasedir(),
62                               "src/test/repo-with-osgi/commons-logging/commons-logging/1.1/commons-logging-1.1.jar" );
63
64         List<ArtifactContentEntry> artifactContentEntries = browseService.readFileEntries( file, null, "foo" );
65
66         log.info( "artifactContentEntries: {}", artifactContentEntries );
67
68         assertThat( artifactContentEntries ).isNotNull().isNotEmpty().hasSize( 2 ).contains(
69             new ArtifactContentEntry( "org", false, 0, "foo" ),
70             new ArtifactContentEntry( "META-INF", false, 0, "foo" ) );
71
72     }
73
74     @Test
75     public void readArtifactContentEntriesRootPathEmpty()
76         throws Exception
77     {
78
79         Path file = Paths.get( getBasedir(),
80                               "src/test/repo-with-osgi/commons-logging/commons-logging/1.1/commons-logging-1.1.jar" );
81
82         List<ArtifactContentEntry> artifactContentEntries = browseService.readFileEntries( file, "", "foo" );
83
84         log.info( "artifactContentEntries: {}", artifactContentEntries );
85
86         assertThat( artifactContentEntries ).isNotNull().isNotEmpty().hasSize( 2 ).contains(
87             new ArtifactContentEntry( "org", false, 0, "foo" ),
88             new ArtifactContentEntry( "META-INF", false, 0, "foo" ) );
89
90     }
91
92     @Test
93     public void readArtifactContentEntriesRootSlash()
94         throws Exception
95     {
96
97         Path file = Paths.get( getBasedir(),
98                               "src/test/repo-with-osgi/commons-logging/commons-logging/1.1/commons-logging-1.1.jar" );
99
100         List<ArtifactContentEntry> artifactContentEntries = browseService.readFileEntries( file, "/", "foo" );
101
102         log.info( "artifactContentEntries: {}", artifactContentEntries );
103
104         assertThat( artifactContentEntries ).isNotNull().isNotEmpty().hasSize( 2 ).contains(
105             new ArtifactContentEntry( "org", false, 0, "foo" ),
106             new ArtifactContentEntry( "META-INF", false, 0, "foo" ) );
107
108     }
109
110     @Test
111     public void readArtifactContentEntriesSecondDepthOnlyOneDirectory()
112         throws Exception
113     {
114
115         Path file = Paths.get( getBasedir(),
116                               "src/test/repo-with-osgi/commons-logging/commons-logging/1.1/commons-logging-1.1.jar" );
117
118         List<ArtifactContentEntry> artifactContentEntries = browseService.readFileEntries( file, "org", "foo" );
119
120         log.info( "artifactContentEntries: {}", artifactContentEntries );
121
122         assertThat( artifactContentEntries ).isNotNull().isNotEmpty().hasSize( 1 ).contains(
123             new ArtifactContentEntry( "org/apache", false, 1, "foo" ) );
124
125     }
126
127     @Test
128     public void readArtifactContentEntriesOnlyFiles()
129         throws Exception
130     {
131
132         Path file = Paths.get( getBasedir(),
133                               "src/test/repo-with-osgi/commons-logging/commons-logging/1.1/commons-logging-1.1.jar" );
134
135         List<ArtifactContentEntry> artifactContentEntries =
136             browseService.readFileEntries( file, "org/apache/commons/logging/impl/", "foo" );
137
138         log.info( "artifactContentEntries: {}", artifactContentEntries );
139
140         assertThat( artifactContentEntries ).isNotNull().isNotEmpty().hasSize( 16 ).contains(
141             new ArtifactContentEntry( "org/apache/commons/logging/impl/AvalonLogger.class", true, 5, "foo" ) );
142
143     }
144
145     @Test
146     public void readArtifactContentEntriesDirectoryAndFiles()
147         throws Exception
148     {
149
150         Path file = Paths.get( getBasedir(),
151                               "src/test/repo-with-osgi/commons-logging/commons-logging/1.1/commons-logging-1.1.jar" );
152
153         List<ArtifactContentEntry> artifactContentEntries =
154             browseService.readFileEntries( file, "org/apache/commons/logging/", "foo" );
155
156         log.info( "artifactContentEntries: {}", artifactContentEntries );
157
158         assertThat( artifactContentEntries ).isNotNull().isNotEmpty().hasSize( 10 ).contains(
159             new ArtifactContentEntry( "org/apache/commons/logging/impl", false, 4, "foo" ),
160             new ArtifactContentEntry( "org/apache/commons/logging/LogSource.class", true, 4, "foo" ) );
161
162     }
163
164
165 }