1 package org.apache.archiva.metadata.repository.cassandra;
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.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 static org.assertj.core.api.Assertions.assertThat;
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;
35 import javax.inject.Inject;
36 import javax.inject.Named;
39 * @author Olivier Lamy
41 @RunWith( ArchivaSpringJUnit4ClassRunner.class )
42 @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
43 public class RepositoriesNamespaceTest
46 private Logger logger = LoggerFactory.getLogger( getClass() );
49 @Named( value = "archivaEntityManagerFactory#cassandra" )
50 CassandraArchivaManager cassandraArchivaManager;
53 CassandraMetadataRepository cmr;
59 cmr = new CassandraMetadataRepository( null, null, cassandraArchivaManager );
60 if ( !cassandraArchivaManager.started() )
62 cassandraArchivaManager.start();
64 clearReposAndNamespace();
68 public void shutdown()
71 clearReposAndNamespace();
72 cassandraArchivaManager.shutdown();
77 public void testMetadataRepo()
87 cmr.updateNamespace( "release", "org" );
89 r = cmr.getRepository( "release" );
91 assertThat( r ).isNotNull();
93 assertThat( cmr.getRepositories() ).isNotEmpty().hasSize( 1 );
94 assertThat( cmr.getNamespaces( "release" ) ).isNotEmpty().hasSize( 1 );
96 n = cmr.getNamespace( "release", "org" );
98 assertThat( n ).isNotNull();
99 assertThat( n.getRepository() ).isNotNull();
101 cmr.updateNamespace( "release", "org.apache" );
103 r = cmr.getRepository( "release" );
105 assertThat( r ).isNotNull();
106 assertThat( cmr.getNamespaces( "release" ) ).isNotEmpty().hasSize( 2 );
108 cmr.removeNamespace( "release", "org.apache" );
109 assertThat( cmr.getNamespaces( "release" ) ).isNotEmpty().hasSize( 1 );
110 assertThat( cmr.getNamespaces( "release" ) ).containsExactly( "org" );
112 ProjectMetadata projectMetadata = new ProjectMetadata();
113 projectMetadata.setId( "theproject" );
114 projectMetadata.setNamespace( "org" );
116 cmr.updateProject( "release", projectMetadata );
118 assertThat( cmr.getProjects( "release", "org" ) ).isNotEmpty().hasSize( 1 ).containsExactly(
121 cmr.removeProject( "release", "org", "theproject" );
123 assertThat( cmr.getProjects( "release", "org" ) ).isEmpty();
125 cmr.removeRepository( "release" );
127 r = cmr.getRepository( "release" );
129 assertThat( r ).isNull();
132 catch ( Exception e )
134 logger.error( e.getMessage(), e );
139 clearReposAndNamespace();
143 protected void clearReposAndNamespace()
146 cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
148 cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
150 cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),