]> source.dussan.org Git - archiva.git/blob
82f496e9f28109e03b8a08eef9488c0cd5f71e87
[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
22 import org.apache.archiva.admin.model.beans.ManagedRepository;
23 import org.apache.archiva.rest.api.services.ArchivaAdministrationService;
24 import org.apache.archiva.rest.api.services.ManagedRepositoriesService;
25 import org.apache.archiva.rest.api.services.NetworkProxyService;
26 import org.apache.archiva.rest.api.services.PingService;
27 import org.apache.archiva.rest.api.services.ProxyConnectorService;
28 import org.apache.archiva.rest.api.services.RemoteRepositoriesService;
29 import org.apache.archiva.rest.api.services.RepositoriesService;
30 import org.apache.archiva.rest.api.services.RepositoryGroupService;
31 import org.apache.archiva.rest.api.services.SearchService;
32 import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
33 import org.apache.cxf.jaxrs.client.WebClient;
34 import org.apache.archiva.common.utils.FileUtil;
35 import org.codehaus.redback.rest.services.AbstractRestServicesTest;
36
37 import java.io.File;
38
39 /**
40  * @author Olivier Lamy
41  */
42 public abstract class AbstractArchivaRestTest
43     extends AbstractRestServicesTest
44 {
45
46     // START SNIPPET: authz-header
47     public String guestAuthzHeader =
48         "Basic " + org.apache.cxf.common.util.Base64Utility.encode( ( "guest" + ":" ).getBytes() );
49     // END SNIPPET: authz-header
50
51     @Override
52     protected String getSpringConfigLocation()
53     {
54         return "classpath*:META-INF/spring-context.xml,classpath:META-INF/spring-context-test.xml";
55     }
56
57     protected String getRestServicesPath()
58     {
59         return "restServices";
60     }
61
62     protected RepositoriesService getRepositoriesService()
63     {
64         return getRepositoriesService( null );
65     }
66
67
68     protected RepositoriesService getRepositoriesService( String authzHeader )
69     {
70         RepositoriesService service =
71             JAXRSClientFactory.create( "http://localhost:" + port + "/" + getRestServicesPath() + "/archivaServices/",
72                                        RepositoriesService.class );
73
74         if ( authzHeader != null )
75         {
76             WebClient.client( service ).header( "Authorization", authzHeader );
77         }
78         WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 100000000 );
79         return service;
80
81     }
82
83     protected ManagedRepositoriesService getManagedRepositoriesService( String authzHeader )
84     {
85         ManagedRepositoriesService service =
86             JAXRSClientFactory.create( "http://localhost:" + port + "/" + getRestServicesPath() + "/archivaServices/",
87                                        ManagedRepositoriesService.class );
88
89         if ( authzHeader != null )
90         {
91             WebClient.client( service ).header( "Authorization", authzHeader );
92         }
93         WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 100000000 );
94         return service;
95
96     }
97
98     protected PingService getPingService()
99     {
100         return JAXRSClientFactory.create(
101             "http://localhost:" + port + "/" + getRestServicesPath() + "/archivaServices/", PingService.class );
102     }
103
104     protected RemoteRepositoriesService getRemoteRepositoriesService()
105     {
106         return JAXRSClientFactory.create(
107             "http://localhost:" + port + "/" + getRestServicesPath() + "/archivaServices/",
108             RemoteRepositoriesService.class );
109
110
111     }
112
113     protected RepositoryGroupService getRepositoryGroupService()
114     {
115         return JAXRSClientFactory.create(
116             "http://localhost:" + port + "/" + getRestServicesPath() + "/archivaServices/",
117             RepositoryGroupService.class );
118     }
119
120     protected ProxyConnectorService getProxyConnectorService()
121     {
122         ProxyConnectorService service =
123             JAXRSClientFactory.create( "http://localhost:" + port + "/" + getRestServicesPath() + "/archivaServices/",
124                                        ProxyConnectorService.class );
125
126         WebClient.client( service ).header( "Authorization", authorizationHeader );
127         WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 300000 );
128         return service;
129     }
130
131     protected NetworkProxyService getNetworkProxyService()
132     {
133         NetworkProxyService service =
134             JAXRSClientFactory.create( "http://localhost:" + port + "/" + getRestServicesPath() + "/archivaServices/",
135                                        NetworkProxyService.class );
136
137         WebClient.client( service ).header( "Authorization", authorizationHeader );
138         WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 300000 );
139         return service;
140     }
141
142     protected ArchivaAdministrationService getArchivaAdministrationService()
143     {
144         ArchivaAdministrationService service =
145             JAXRSClientFactory.create( "http://localhost:" + port + "/" + getRestServicesPath() + "/archivaServices/",
146                                        ArchivaAdministrationService.class );
147
148         WebClient.client( service ).header( "Authorization", authorizationHeader );
149         WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 300000 );
150         return service;
151     }
152
153     protected SearchService getSearchService( String authzHeader )
154     {
155         // START SNIPPET: cxf-searchservice-creation
156         SearchService service =
157             JAXRSClientFactory.create( "http://localhost:" + port + "/" + getRestServicesPath() + "/archivaServices/",
158                                        SearchService.class );
159
160         if ( authzHeader != null )
161         {
162             WebClient.client( service ).header( "Authorization", authzHeader );
163         }
164         WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 100000000 );
165         return service;
166         // END SNIPPET: cxf-searchservice-creation
167
168     }
169
170     protected ManagedRepository getTestManagedRepository()
171     {
172         String location = new File( FileUtil.getBasedir(), "target/test-repo" ).getAbsolutePath();
173         return new ManagedRepository( "TEST", "test", location, "default", true, true, false, "2 * * * * ?", null,
174                                       false, 2, 3, true, false );
175
176     }
177 }