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;
31 import java.util.HashMap;
32 import java.util.List;
35 import static org.fest.assertions.Assertions.assertThat;
38 * @author Olivier Lamy
40 public class BrowseServiceTest
41 extends AbstractArchivaRestTest
44 Map<String, String> toMap( List<Entry> entries )
46 Map<String, String> map = new HashMap<String, String>( entries.size() );
48 for ( Entry entry : entries )
50 map.put( entry.getKey(), entry.getValue() );
57 public void metadatagetthenadd()
61 String testRepoId = "test-repo";
62 // force guest user creation if not exists
63 if ( getUserService( authorizationHeader ).getGuestUser() == null )
65 assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
68 createAndIndexRepo( testRepoId, new File( getBasedir(), "src/test/repo-with-osgi" ).getAbsolutePath() );
70 BrowseService browseService = getBrowseService( authorizationHeader, false );
72 Map<String, String> metadatas =
73 toMap( browseService.getMetadatas( "commons-cli", "commons-cli", "1.0", testRepoId ) );
75 assertThat( metadatas ).isNotNull().isEmpty();
77 browseService.addMetadata( "commons-cli", "commons-cli", "1.0", "wine", "bordeaux", testRepoId );
79 metadatas = toMap( browseService.getMetadatas( "commons-cli", "commons-cli", "1.0", testRepoId ) );
81 assertThat( metadatas ).isNotNull().isNotEmpty().includes( MapAssert.entry( "wine", "bordeaux" ) );
83 deleteTestRepo( testRepoId );
89 public void metadatagetthenaddthendelete()
93 String testRepoId = "test-repo";
94 // force guest user creation if not exists
95 if ( getUserService( authorizationHeader ).getGuestUser() == null )
97 assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
100 createAndIndexRepo( testRepoId, new File( getBasedir(), "src/test/repo-with-osgi" ).getAbsolutePath() );
102 BrowseService browseService = getBrowseService( authorizationHeader, false );
104 Map<String, String> metadatas =
105 toMap( browseService.getMetadatas( "commons-cli", "commons-cli", "1.0", testRepoId ) );
107 assertThat( metadatas ).isNotNull().isEmpty();
109 browseService.addMetadata( "commons-cli", "commons-cli", "1.0", "wine", "bordeaux", testRepoId );
111 metadatas = toMap( browseService.getMetadatas( "commons-cli", "commons-cli", "1.0", testRepoId ) );
113 assertThat( metadatas ).isNotNull().isNotEmpty().includes( MapAssert.entry( "wine", "bordeaux" ) );
115 browseService.deleteMetadata( "commons-cli", "commons-cli", "1.0", "wine", testRepoId );
117 metadatas = toMap( browseService.getMetadatas( "commons-cli", "commons-cli", "1.0", testRepoId ) );
119 assertThat( metadatas ).isNotNull().isEmpty();
121 deleteTestRepo( testRepoId );
126 public void browserootGroups()
130 String testRepoId = "test-repo";
131 // force guest user creation if not exists
132 if ( getUserService( authorizationHeader ).getGuestUser() == null )
134 assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
137 createAndIndexRepo( testRepoId, new File( getBasedir(), "src/test/repo-with-osgi" ).getAbsolutePath(), false );
139 BrowseService browseService = getBrowseService( authorizationHeader, false );
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 ) );
147 deleteTestRepo( testRepoId );
152 public void browsegroupId()
156 String testRepoId = "test-repo";
157 // force guest user creation if not exists
158 if ( getUserService( authorizationHeader ).getGuestUser() == null )
160 assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
163 createAndIndexRepo( testRepoId, new File( getBasedir(), "src/test/repo-with-osgi" ).getAbsolutePath(), false );
165 BrowseService browseService = getBrowseService( authorizationHeader, false );
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 ) );
173 deleteTestRepo( testRepoId );
178 public void versionsList()
182 String testRepoId = "test-repo";
183 // force guest user creation if not exists
184 if ( getUserService( authorizationHeader ).getGuestUser() == null )
186 assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
189 createAndIndexRepo( testRepoId, new File( getBasedir(), "src/test/repo-with-osgi" ).getAbsolutePath(), false );
191 BrowseService browseService = getBrowseService( authorizationHeader, false );
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" );
198 deleteTestRepo( testRepoId );
203 public void getProjectVersionMetadata()
206 String testRepoId = "test-repo";
207 // force guest user creation if not exists
208 if ( getUserService( authorizationHeader ).getGuestUser() == null )
210 assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
213 createAndIndexRepo( testRepoId, new File( getBasedir(), "src/test/repo-with-osgi" ).getAbsolutePath(), false );
215 BrowseService browseService = getBrowseService( authorizationHeader, true );
217 ProjectVersionMetadata metadata =
218 browseService.getProjectVersionMetadata( "org.apache.karaf.features", "org.apache.karaf.features.core",
221 assertThat( metadata ).isNotNull();
223 deleteTestRepo( testRepoId );