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