]> source.dussan.org Git - archiva.git/blob
a573ba6ce1085b305f4cb6cd95e8dd97d5ffcb5b
[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.VersionsList;
25 import org.apache.archiva.rest.api.services.BrowseService;
26 import org.fest.assertions.MapAssert;
27 import org.junit.Test;
28
29 import java.util.Map;
30
31 import static org.fest.assertions.Assertions.assertThat;
32
33 /**
34  * @author Olivier Lamy
35  */
36 public class BrowseServiceTest
37     extends AbstractArchivaRestTest
38 {
39     @Test
40     public void metadatagetthenadd()
41         throws Exception
42     {
43
44         String testRepoId = "test-repo";
45         // force guest user creation if not exists
46         if ( getUserService( authorizationHeader ).getGuestUser() == null )
47         {
48             assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
49         }
50
51         createAndIndexRepo( testRepoId, "src/test/repo-with-osgi" );
52
53         BrowseService browseService = getBrowseService( authorizationHeader, false );
54
55         Map<String, String> metadatas = browseService.getMetadatas( "commons-cli", "commons-cli", "1.0", testRepoId );
56
57         assertThat( metadatas ).isNotNull().isEmpty();
58
59         browseService.addMetadata( "commons-cli", "commons-cli", "1.0", "wine", "bordeaux", testRepoId );
60
61         metadatas = browseService.getMetadatas( "commons-cli", "commons-cli", "1.0", testRepoId );
62
63         assertThat( metadatas ).isNotNull().isNotEmpty().includes( MapAssert.entry( "wine", "bordeaux" ) );
64
65         deleteTestRepo( testRepoId );
66
67     }
68
69
70     @Test
71     public void metadatagetthenaddthendelete()
72         throws Exception
73     {
74
75         String testRepoId = "test-repo";
76         // force guest user creation if not exists
77         if ( getUserService( authorizationHeader ).getGuestUser() == null )
78         {
79             assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
80         }
81
82         createAndIndexRepo( testRepoId, "src/test/repo-with-osgi" );
83
84         BrowseService browseService = getBrowseService( authorizationHeader, false );
85
86         Map<String, String> metadatas = browseService.getMetadatas( "commons-cli", "commons-cli", "1.0", testRepoId );
87
88         assertThat( metadatas ).isNotNull().isEmpty();
89
90         browseService.addMetadata( "commons-cli", "commons-cli", "1.0", "wine", "bordeaux", testRepoId );
91
92         metadatas = browseService.getMetadatas( "commons-cli", "commons-cli", "1.0", testRepoId );
93
94         assertThat( metadatas ).isNotNull().isNotEmpty().includes( MapAssert.entry( "wine", "bordeaux" ) );
95
96         browseService.deleteMetadata( "commons-cli", "commons-cli", "1.0", "wine", testRepoId );
97
98         metadatas = browseService.getMetadatas( "commons-cli", "commons-cli", "1.0", testRepoId );
99
100         assertThat( metadatas ).isNotNull().isEmpty();
101
102         deleteTestRepo( testRepoId );
103
104     }
105
106     @Test
107     public void browserootGroups()
108         throws Exception
109     {
110
111         String testRepoId = "test-repo";
112         // force guest user creation if not exists
113         if ( getUserService( authorizationHeader ).getGuestUser() == null )
114         {
115             assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
116         }
117
118         createAndIndexRepo( testRepoId, "src/test/repo-with-osgi", false );
119
120         BrowseService browseService = getBrowseService( authorizationHeader, false );
121
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 ) );
127
128         deleteTestRepo( testRepoId );
129
130     }
131
132     @Test
133     public void browsegroupId()
134         throws Exception
135     {
136
137         String testRepoId = "test-repo";
138         // force guest user creation if not exists
139         if ( getUserService( authorizationHeader ).getGuestUser() == null )
140         {
141             assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
142         }
143
144         createAndIndexRepo( testRepoId, "src/test/repo-with-osgi", false );
145
146         BrowseService browseService = getBrowseService( authorizationHeader, false );
147
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 ) );
153
154         deleteTestRepo( testRepoId );
155
156     }
157
158     @Test
159     public void versionsList()
160         throws Exception
161     {
162
163         String testRepoId = "test-repo";
164         // force guest user creation if not exists
165         if ( getUserService( authorizationHeader ).getGuestUser() == null )
166         {
167             assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
168         }
169
170         createAndIndexRepo( testRepoId, "src/test/repo-with-osgi", false );
171
172         BrowseService browseService = getBrowseService( authorizationHeader, false );
173
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" );
178
179         deleteTestRepo( testRepoId );
180
181     }
182
183     @Test
184     public void getProjectVersionMetadata()
185         throws Exception
186     {
187         String testRepoId = "test-repo";
188         // force guest user creation if not exists
189         if ( getUserService( authorizationHeader ).getGuestUser() == null )
190         {
191             assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
192         }
193
194         createAndIndexRepo( testRepoId, "src/test/repo-with-osgi", false );
195
196         BrowseService browseService = getBrowseService( authorizationHeader, true );
197
198         ProjectVersionMetadata metadata =
199             browseService.getProjectVersionMetadata( "org.apache.karaf.features", "org.apache.karaf.features.core",
200                                                      testRepoId );
201
202         assertThat( metadata ).isNotNull();
203
204         deleteTestRepo( testRepoId );
205     }
206 }