1 package org.apache.archiva.rest.services;
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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
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;
30 import java.util.HashMap;
31 import java.util.List;
34 import static org.fest.assertions.Assertions.assertThat;
37 * @author Olivier Lamy
39 public class BrowseServiceTest
40 extends AbstractArchivaRestTest
43 Map<String, String> toMap( List<Entry> entries )
45 Map<String, String> map = new HashMap<String, String>( entries.size() );
47 for ( Entry entry : entries )
49 map.put( entry.getKey(), entry.getValue() );
56 public void metadatagetthenadd()
60 String testRepoId = "test-repo";
61 // force guest user creation if not exists
62 if ( getUserService( authorizationHeader ).getGuestUser() == null )
64 assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
67 createAndIndexRepo( testRepoId, "src/test/repo-with-osgi" );
69 BrowseService browseService = getBrowseService( authorizationHeader, false );
71 Map<String, String> metadatas =
72 toMap( browseService.getMetadatas( "commons-cli", "commons-cli", "1.0", testRepoId ) );
74 assertThat( metadatas ).isNotNull().isEmpty();
76 browseService.addMetadata( "commons-cli", "commons-cli", "1.0", "wine", "bordeaux", testRepoId );
78 metadatas = toMap( browseService.getMetadatas( "commons-cli", "commons-cli", "1.0", testRepoId ) );
80 assertThat( metadatas ).isNotNull().isNotEmpty().includes( MapAssert.entry( "wine", "bordeaux" ) );
82 deleteTestRepo( testRepoId );
88 public void metadatagetthenaddthendelete()
92 String testRepoId = "test-repo";
93 // force guest user creation if not exists
94 if ( getUserService( authorizationHeader ).getGuestUser() == null )
96 assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
99 createAndIndexRepo( testRepoId, "src/test/repo-with-osgi" );
101 BrowseService browseService = getBrowseService( authorizationHeader, false );
103 Map<String, String> metadatas =
104 toMap( browseService.getMetadatas( "commons-cli", "commons-cli", "1.0", testRepoId ) );
106 assertThat( metadatas ).isNotNull().isEmpty();
108 browseService.addMetadata( "commons-cli", "commons-cli", "1.0", "wine", "bordeaux", testRepoId );
110 metadatas = toMap( browseService.getMetadatas( "commons-cli", "commons-cli", "1.0", testRepoId ) );
112 assertThat( metadatas ).isNotNull().isNotEmpty().includes( MapAssert.entry( "wine", "bordeaux" ) );
114 browseService.deleteMetadata( "commons-cli", "commons-cli", "1.0", "wine", testRepoId );
116 metadatas = toMap( browseService.getMetadatas( "commons-cli", "commons-cli", "1.0", testRepoId ) );
118 assertThat( metadatas ).isNotNull().isEmpty();
120 deleteTestRepo( testRepoId );
125 public void browserootGroups()
129 String testRepoId = "test-repo";
130 // force guest user creation if not exists
131 if ( getUserService( authorizationHeader ).getGuestUser() == null )
133 assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
136 createAndIndexRepo( testRepoId, "src/test/repo-with-osgi", false );
138 BrowseService browseService = getBrowseService( authorizationHeader, false );
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 ) );
146 deleteTestRepo( testRepoId );
151 public void browsegroupId()
155 String testRepoId = "test-repo";
156 // force guest user creation if not exists
157 if ( getUserService( authorizationHeader ).getGuestUser() == null )
159 assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
162 createAndIndexRepo( testRepoId, "src/test/repo-with-osgi", false );
164 BrowseService browseService = getBrowseService( authorizationHeader, false );
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 ) );
172 deleteTestRepo( testRepoId );
177 public void versionsList()
181 String testRepoId = "test-repo";
182 // force guest user creation if not exists
183 if ( getUserService( authorizationHeader ).getGuestUser() == null )
185 assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
188 createAndIndexRepo( testRepoId, "src/test/repo-with-osgi", false );
190 BrowseService browseService = getBrowseService( authorizationHeader, false );
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" );
197 deleteTestRepo( testRepoId );
202 public void getProjectVersionMetadata()
205 String testRepoId = "test-repo";
206 // force guest user creation if not exists
207 if ( getUserService( authorizationHeader ).getGuestUser() == null )
209 assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
212 createAndIndexRepo( testRepoId, "src/test/repo-with-osgi", false );
214 BrowseService browseService = getBrowseService( authorizationHeader, true );
216 ProjectVersionMetadata metadata =
217 browseService.getProjectVersionMetadata( "org.apache.karaf.features", "org.apache.karaf.features.core",
220 assertThat( metadata ).isNotNull();
222 deleteTestRepo( testRepoId );