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