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