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 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;
34 import javax.inject.Inject;
35 import javax.inject.Named;
37 import static org.assertj.core.api.Assertions.assertThat;
40 * @author Olivier Lamy
42 @RunWith( ArchivaSpringJUnit4ClassRunner.class )
43 @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
44 public class RepositoriesNamespaceTest
47 private Logger logger = LoggerFactory.getLogger( getClass() );
50 @Named( value = "archivaEntityManagerFactory#cassandra" )
51 CassandraArchivaManager cassandraArchivaManager;
54 CassandraMetadataRepository cmr;
60 cmr = new CassandraMetadataRepository( null, null, cassandraArchivaManager );
61 if ( !cassandraArchivaManager.started() )
63 cassandraArchivaManager.start();
65 CassandraMetadataRepositoryTest.clearReposAndNamespace( cassandraArchivaManager );
69 public void shutdown()
72 CassandraMetadataRepositoryTest.clearReposAndNamespace( cassandraArchivaManager );
73 cassandraArchivaManager.shutdown();
78 public void testMetadataRepo()
88 cmr.updateNamespace( null , "release", "org" );
90 r = cmr.getRepository( "release" );
92 assertThat( r ).isNotNull();
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( null, "release", "org.apache" );
103 r = cmr.getRepository( "release" );
105 assertThat( r ).isNotNull();
106 assertThat( cmr.getNamespaces( "release" ) ).isNotEmpty().hasSize( 2 );
108 cmr.removeNamespace(null , "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(null , "release", projectMetadata );
118 assertThat( cmr.getProjects(null , "release", "org" ) ).isNotEmpty().hasSize( 1 ).containsExactly(
121 cmr.removeProject(null , "release", "org", "theproject" );
123 assertThat( cmr.getProjects(null , "release", "org" ) ).isEmpty();
125 cmr.removeRepository(null , "release" );
127 r = cmr.getRepository( "release" );
129 assertThat( r ).isNull();
132 catch ( Exception e )
134 logger.error( e.getMessage(), e );
139 CassandraMetadataRepositoryTest.clearReposAndNamespace( cassandraArchivaManager );