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