]> source.dussan.org Git - archiva.git/blob
cc1bedefea6644709b37cca9258ef6f53a815e1a
[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 org.apache.archiva.metadata.model.ProjectVersionMetadata;
22 import org.apache.archiva.rest.api.model.BrowseResult;
23 import org.apache.archiva.rest.api.model.BrowseResultEntry;
24 import org.apache.archiva.rest.api.model.Entry;
25 import org.apache.archiva.rest.api.model.VersionsList;
26 import org.apache.archiva.rest.api.services.BrowseService;
27 import org.fest.assertions.MapAssert;
28 import org.junit.Test;
29
30 import java.io.File;
31 import java.util.HashMap;
32 import java.util.List;
33 import java.util.Map;
34
35 import static org.fest.assertions.Assertions.assertThat;
36
37 /**
38  * @author Olivier Lamy
39  */
40 public class BrowseServiceTest
41     extends AbstractArchivaRestTest
42 {
43
44     Map<String, String> toMap( List<Entry> entries )
45     {
46         Map<String, String> map = new HashMap<String, String>( entries.size() );
47
48         for ( Entry entry : entries )
49         {
50             map.put( entry.getKey(), entry.getValue() );
51         }
52
53         return map;
54     }
55
56     @Test
57     public void metadatagetthenadd()
58         throws Exception
59     {
60
61         String testRepoId = "test-repo";
62         // force guest user creation if not exists
63         if ( getUserService( authorizationHeader ).getGuestUser() == null )
64         {
65             assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
66         }
67
68         createAndIndexRepo( testRepoId, new File( getBasedir(), "src/test/repo-with-osgi" ).getAbsolutePath() );
69
70         BrowseService browseService = getBrowseService( authorizationHeader, false );
71
72         Map<String, String> metadatas =
73             toMap( browseService.getMetadatas( "commons-cli", "commons-cli", "1.0", testRepoId ) );
74
75         assertThat( metadatas ).isNotNull().isEmpty();
76
77         browseService.addMetadata( "commons-cli", "commons-cli", "1.0", "wine", "bordeaux", testRepoId );
78
79         metadatas = toMap( browseService.getMetadatas( "commons-cli", "commons-cli", "1.0", testRepoId ) );
80
81         assertThat( metadatas ).isNotNull().isNotEmpty().includes( MapAssert.entry( "wine", "bordeaux" ) );
82
83         deleteTestRepo( testRepoId );
84
85     }
86
87
88     @Test
89     public void metadatagetthenaddthendelete()
90         throws Exception
91     {
92
93         String testRepoId = "test-repo";
94         // force guest user creation if not exists
95         if ( getUserService( authorizationHeader ).getGuestUser() == null )
96         {
97             assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
98         }
99
100         createAndIndexRepo( testRepoId, new File( getBasedir(), "src/test/repo-with-osgi" ).getAbsolutePath() );
101
102         BrowseService browseService = getBrowseService( authorizationHeader, false );
103
104         Map<String, String> metadatas =
105             toMap( browseService.getMetadatas( "commons-cli", "commons-cli", "1.0", testRepoId ) );
106
107         assertThat( metadatas ).isNotNull().isEmpty();
108
109         browseService.addMetadata( "commons-cli", "commons-cli", "1.0", "wine", "bordeaux", testRepoId );
110
111         metadatas = toMap( browseService.getMetadatas( "commons-cli", "commons-cli", "1.0", testRepoId ) );
112
113         assertThat( metadatas ).isNotNull().isNotEmpty().includes( MapAssert.entry( "wine", "bordeaux" ) );
114
115         browseService.deleteMetadata( "commons-cli", "commons-cli", "1.0", "wine", testRepoId );
116
117         metadatas = toMap( browseService.getMetadatas( "commons-cli", "commons-cli", "1.0", testRepoId ) );
118
119         assertThat( metadatas ).isNotNull().isEmpty();
120
121         deleteTestRepo( testRepoId );
122
123     }
124
125     @Test
126     public void browserootGroups()
127         throws Exception
128     {
129
130         String testRepoId = "test-repo";
131         // force guest user creation if not exists
132         if ( getUserService( authorizationHeader ).getGuestUser() == null )
133         {
134             assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
135         }
136
137         createAndIndexRepo( testRepoId, new File( getBasedir(), "src/test/repo-with-osgi" ).getAbsolutePath(), false );
138
139         BrowseService browseService = getBrowseService( authorizationHeader, false );
140
141         BrowseResult browseResult = browseService.getRootGroups( testRepoId );
142         assertThat( browseResult ).isNotNull();
143         assertThat( browseResult.getBrowseResultEntries() ).isNotNull().isNotEmpty().hasSize( 3 ).contains(
144             new BrowseResultEntry( "commons-cli", false ), new BrowseResultEntry( "commons-logging", false ),
145             new BrowseResultEntry( "org.apache", false ) );
146
147         deleteTestRepo( testRepoId );
148
149     }
150
151     @Test
152     public void browsegroupId()
153         throws Exception
154     {
155
156         String testRepoId = "test-repo";
157         // force guest user creation if not exists
158         if ( getUserService( authorizationHeader ).getGuestUser() == null )
159         {
160             assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
161         }
162
163         createAndIndexRepo( testRepoId, new File( getBasedir(), "src/test/repo-with-osgi" ).getAbsolutePath(), false );
164
165         BrowseService browseService = getBrowseService( authorizationHeader, false );
166
167         BrowseResult browseResult = browseService.browseGroupId( "org.apache", testRepoId );
168         assertThat( browseResult ).isNotNull();
169         assertThat( browseResult.getBrowseResultEntries() ).isNotNull().isNotEmpty().hasSize( 2 ).contains(
170             new BrowseResultEntry( "org.apache.felix", false ),
171             new BrowseResultEntry( "org.apache.karaf.features", false ) );
172
173         deleteTestRepo( testRepoId );
174
175     }
176
177     @Test
178     public void versionsList()
179         throws Exception
180     {
181
182         String testRepoId = "test-repo";
183         // force guest user creation if not exists
184         if ( getUserService( authorizationHeader ).getGuestUser() == null )
185         {
186             assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
187         }
188
189         createAndIndexRepo( testRepoId, new File( getBasedir(), "src/test/repo-with-osgi" ).getAbsolutePath(), false );
190
191         BrowseService browseService = getBrowseService( authorizationHeader, false );
192
193         VersionsList versions =
194             browseService.getVersionsList( "org.apache.karaf.features", "org.apache.karaf.features.core", testRepoId );
195         assertThat( versions ).isNotNull();
196         assertThat( versions.getVersions() ).isNotNull().isNotEmpty().hasSize( 2 ).contains( "2.2.1", "2.2.2" );
197
198         deleteTestRepo( testRepoId );
199
200     }
201
202     @Test
203     public void getProjectVersionMetadata()
204         throws Exception
205     {
206         String testRepoId = "test-repo";
207         // force guest user creation if not exists
208         if ( getUserService( authorizationHeader ).getGuestUser() == null )
209         {
210             assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
211         }
212
213         createAndIndexRepo( testRepoId, new File( getBasedir(), "src/test/repo-with-osgi" ).getAbsolutePath(), false );
214
215         BrowseService browseService = getBrowseService( authorizationHeader, true );
216
217         ProjectVersionMetadata metadata =
218             browseService.getProjectVersionMetadata( "org.apache.karaf.features", "org.apache.karaf.features.core",
219                                                      testRepoId );
220
221         assertThat( metadata ).isNotNull();
222
223         deleteTestRepo( testRepoId );
224     }
225 }