1 package org.apache.archiva.rest.services;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.apache.archiva.rest.api.model.ManagedRepository;
23 import org.apache.archiva.rest.api.services.ManagedRepositoriesService;
24 import org.apache.cxf.jaxrs.client.WebClient;
25 import org.apache.maven.archiva.common.utils.FileUtil;
26 import org.junit.Test;
31 * @author Olivier Lamy
33 public class ManagedRepositoriesServiceTest
34 extends AbstractArchivaRestTest
39 public void addManagedRepo()
42 ManagedRepositoriesService service = getManagedRepositoriesService();
43 WebClient.client( service ).header( "Authorization", authorizationHeader );
44 WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 300000 );
45 ManagedRepository repo = getTestManagedRepository();
46 if ( service.getManagedRepository( repo.getId() ) != null )
48 service.deleteManagedRepository( repo.getId(), true );
49 assertNull( service.getManagedRepository( repo.getId() ) );
51 service.addManagedRepository( repo );
52 assertNotNull( service.getManagedRepository( repo.getId() ) );
54 service.deleteManagedRepository( repo.getId(), true );
55 assertNull( service.getManagedRepository( repo.getId() ) );
59 public void updateManagedRepo()
62 ManagedRepositoriesService service = getManagedRepositoriesService();
63 WebClient.client( service ).header( "Authorization", authorizationHeader );
64 WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 300000 );
65 ManagedRepository repo = getTestManagedRepository();
66 if ( service.getManagedRepository( repo.getId() ) != null )
68 service.deleteManagedRepository( repo.getId(), true );
69 assertNull( service.getManagedRepository( repo.getId() ) );
71 service.addManagedRepository( repo );
72 repo = service.getManagedRepository( repo.getId() );
73 assertNotNull( repo );
74 assertEquals( "test", repo.getName() );
75 // toto is foo in French :-)
76 repo.setName( "toto" );
78 service.updateManagedRepository( repo );
80 repo = service.getManagedRepository( repo.getId() );
81 assertNotNull( repo );
82 assertEquals( "toto", repo.getName() );
85 service.deleteManagedRepository( repo.getId(), true );
86 assertNull( service.getManagedRepository( repo.getId() ) );
91 private ManagedRepository getTestManagedRepository()
93 String location = new File( FileUtil.getBasedir(), "target/test-repo" ).getAbsolutePath();
94 return new ManagedRepository( "TEST", "test", location, "default", true, true, false, false, "2 * * * * ?" );