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.VersionsList;
25 import org.apache.archiva.rest.api.services.BrowseService;
26 import org.fest.assertions.MapAssert;
27 import org.junit.Test;
31 import static org.fest.assertions.Assertions.assertThat;
34 * @author Olivier Lamy
36 public class BrowseServiceTest
37 extends AbstractArchivaRestTest
40 public void metadatagetthenadd()
44 String testRepoId = "test-repo";
45 // force guest user creation if not exists
46 if ( getUserService( authorizationHeader ).getGuestUser() == null )
48 assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
51 createAndIndexRepo( testRepoId, "src/test/repo-with-osgi" );
53 BrowseService browseService = getBrowseService( authorizationHeader, false );
55 Map<String, String> metadatas = browseService.getMetadatas( "commons-cli", "commons-cli", "1.0", testRepoId );
57 assertThat( metadatas ).isNotNull().isEmpty();
59 browseService.addMetadata( "commons-cli", "commons-cli", "1.0", "wine", "bordeaux", testRepoId );
61 metadatas = browseService.getMetadatas( "commons-cli", "commons-cli", "1.0", testRepoId );
63 assertThat( metadatas ).isNotNull().isNotEmpty().includes( MapAssert.entry( "wine", "bordeaux" ) );
65 deleteTestRepo( testRepoId );
71 public void metadatagetthenaddthendelete()
75 String testRepoId = "test-repo";
76 // force guest user creation if not exists
77 if ( getUserService( authorizationHeader ).getGuestUser() == null )
79 assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
82 createAndIndexRepo( testRepoId, "src/test/repo-with-osgi" );
84 BrowseService browseService = getBrowseService( authorizationHeader, false );
86 Map<String, String> metadatas = browseService.getMetadatas( "commons-cli", "commons-cli", "1.0", testRepoId );
88 assertThat( metadatas ).isNotNull().isEmpty();
90 browseService.addMetadata( "commons-cli", "commons-cli", "1.0", "wine", "bordeaux", testRepoId );
92 metadatas = browseService.getMetadatas( "commons-cli", "commons-cli", "1.0", testRepoId );
94 assertThat( metadatas ).isNotNull().isNotEmpty().includes( MapAssert.entry( "wine", "bordeaux" ) );
96 browseService.deleteMetadata( "commons-cli", "commons-cli", "1.0", "wine", testRepoId );
98 metadatas = browseService.getMetadatas( "commons-cli", "commons-cli", "1.0", testRepoId );
100 assertThat( metadatas ).isNotNull().isEmpty();
102 deleteTestRepo( testRepoId );
107 public void browserootGroups()
111 String testRepoId = "test-repo";
112 // force guest user creation if not exists
113 if ( getUserService( authorizationHeader ).getGuestUser() == null )
115 assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
118 createAndIndexRepo( testRepoId, "src/test/repo-with-osgi", false );
120 BrowseService browseService = getBrowseService( authorizationHeader, false );
122 BrowseResult browseResult = browseService.getRootGroups( testRepoId );
123 assertThat( browseResult ).isNotNull();
124 assertThat( browseResult.getBrowseResultEntries() ).isNotNull().isNotEmpty().hasSize( 3 ).contains(
125 new BrowseResultEntry( "commons-cli", false ), new BrowseResultEntry( "commons-logging", false ),
126 new BrowseResultEntry( "org.apache", false ) );
128 deleteTestRepo( testRepoId );
133 public void browsegroupId()
137 String testRepoId = "test-repo";
138 // force guest user creation if not exists
139 if ( getUserService( authorizationHeader ).getGuestUser() == null )
141 assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
144 createAndIndexRepo( testRepoId, "src/test/repo-with-osgi", false );
146 BrowseService browseService = getBrowseService( authorizationHeader, false );
148 BrowseResult browseResult = browseService.browseGroupId( "org.apache", testRepoId );
149 assertThat( browseResult ).isNotNull();
150 assertThat( browseResult.getBrowseResultEntries() ).isNotNull().isNotEmpty().hasSize( 2 ).contains(
151 new BrowseResultEntry( "org.apache.felix", false ),
152 new BrowseResultEntry( "org.apache.karaf.features", false ) );
154 deleteTestRepo( testRepoId );
159 public void versionsList()
163 String testRepoId = "test-repo";
164 // force guest user creation if not exists
165 if ( getUserService( authorizationHeader ).getGuestUser() == null )
167 assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
170 createAndIndexRepo( testRepoId, "src/test/repo-with-osgi", false );
172 BrowseService browseService = getBrowseService( authorizationHeader, false );
174 VersionsList versions =
175 browseService.getVersionsList( "org.apache.karaf.features", "org.apache.karaf.features.core", testRepoId );
176 assertThat( versions ).isNotNull();
177 assertThat( versions.getVersions() ).isNotNull().isNotEmpty().hasSize( 2 ).contains( "2.2.1", "2.2.2" );
179 deleteTestRepo( testRepoId );
184 public void getProjectVersionMetadata()
187 String testRepoId = "test-repo";
188 // force guest user creation if not exists
189 if ( getUserService( authorizationHeader ).getGuestUser() == null )
191 assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
194 createAndIndexRepo( testRepoId, "src/test/repo-with-osgi", false );
196 BrowseService browseService = getBrowseService( authorizationHeader, true );
198 ProjectVersionMetadata metadata =
199 browseService.getProjectVersionMetadata( "org.apache.karaf.features", "org.apache.karaf.features.core",
202 assertThat( metadata ).isNotNull();
204 deleteTestRepo( testRepoId );