]> source.dussan.org Git - archiva.git/blob
09e7fcd5deace97969c08b3225a76b561905b484
[archiva.git] /
1 package org.apache.archiva.metadata.repository.cassandra;
2
3 /*
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
11  *
12  *  http://www.apache.org/licenses/LICENSE-2.0
13  *
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
19  * under the License.
20  */
21
22 import org.apache.archiva.metadata.model.ProjectMetadata;
23 import org.apache.archiva.metadata.repository.cassandra.model.Namespace;
24 import org.apache.archiva.metadata.repository.cassandra.model.Repository;
25 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
26 import org.junit.After;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.springframework.test.context.ContextConfiguration;
33
34 import javax.inject.Inject;
35 import javax.inject.Named;
36
37 import static org.assertj.core.api.Assertions.assertThat;
38
39 /**
40  * @author Olivier Lamy
41  */
42 @RunWith( ArchivaSpringJUnit4ClassRunner.class )
43 @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
44 public class RepositoriesNamespaceTest
45 {
46
47     private Logger logger = LoggerFactory.getLogger( getClass() );
48
49     @Inject
50     @Named( value = "archivaEntityManagerFactory#cassandra" )
51     CassandraArchivaManager cassandraArchivaManager;
52
53
54     CassandraMetadataRepository cmr;
55
56     @Before
57     public void setup()
58         throws Exception
59     {
60         cmr = new CassandraMetadataRepository( null, null, cassandraArchivaManager );
61         if ( !cassandraArchivaManager.started() )
62         {
63             cassandraArchivaManager.start();
64         }
65         CassandraMetadataRepositoryTest.clearReposAndNamespace( cassandraArchivaManager );
66     }
67
68     @After
69     public void shutdown()
70         throws Exception
71     {
72         CassandraMetadataRepositoryTest.clearReposAndNamespace( cassandraArchivaManager );
73         cassandraArchivaManager.shutdown();
74     }
75
76
77     @Test
78     public void testMetadataRepo()
79         throws Exception
80     {
81
82         Repository r = null;
83         Namespace n = null;
84
85         try
86         {
87
88             cmr.updateNamespace( null , "release", "org" );
89
90             r = cmr.getRepository( "release" );
91
92             assertThat( r ).isNotNull();
93
94             assertThat( cmr.getNamespaces( "release" ) ).isNotEmpty().hasSize( 1 );
95
96             n = cmr.getNamespace( "release", "org" );
97
98             assertThat( n ).isNotNull();
99             assertThat( n.getRepository() ).isNotNull();
100
101             cmr.updateNamespace( null, "release", "org.apache" );
102
103             r = cmr.getRepository( "release" );
104
105             assertThat( r ).isNotNull();
106             assertThat( cmr.getNamespaces( "release" ) ).isNotEmpty().hasSize( 2 );
107
108             cmr.removeNamespace(null , "release", "org.apache" );
109             assertThat( cmr.getNamespaces( "release" ) ).isNotEmpty().hasSize( 1 );
110             assertThat( cmr.getNamespaces( "release" ) ).containsExactly( "org" );
111
112             ProjectMetadata projectMetadata = new ProjectMetadata();
113             projectMetadata.setId( "theproject" );
114             projectMetadata.setNamespace( "org" );
115
116             cmr.updateProject(null , "release", projectMetadata );
117
118             assertThat( cmr.getProjects(null , "release", "org" ) ).isNotEmpty().hasSize( 1 ).containsExactly(
119                 "theproject" );
120
121             cmr.removeProject(null , "release", "org", "theproject" );
122
123             assertThat( cmr.getProjects(null , "release", "org" ) ).isEmpty();
124
125             cmr.removeRepository(null , "release" );
126
127             r = cmr.getRepository( "release" );
128
129             assertThat( r ).isNull();
130
131         }
132         catch ( Exception e )
133         {
134             logger.error( e.getMessage(), e );
135             throw e;
136         }
137         finally
138         {
139             CassandraMetadataRepositoryTest.clearReposAndNamespace( cassandraArchivaManager );
140         }
141     }
142 }