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.MailingList;
23 import org.apache.archiva.metadata.model.MetadataFacetFactory;
24 import org.apache.archiva.metadata.repository.AbstractMetadataRepositoryTest;
25 import org.apache.archiva.metadata.repository.cassandra.model.ProjectVersionMetadataModel;
26 import org.apache.commons.io.FileUtils;
27 import org.junit.After;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
33 import javax.inject.Inject;
34 import javax.inject.Named;
36 import java.util.List;
39 import static org.assertj.core.api.Assertions.assertThat;
42 * @author Olivier Lamy
44 public class CassandraMetadataRepositoryTest
45 extends AbstractMetadataRepositoryTest
47 private Logger logger = LoggerFactory.getLogger( getClass() );
50 @Named(value = "archivaEntityManagerFactory#cassandra")
51 CassandraArchivaManager cassandraArchivaManager;
53 CassandraMetadataRepository cmr;
62 File directory = new File( "target/test-repositories" );
63 if ( directory.exists() )
65 FileUtils.deleteDirectory( directory );
68 Map<String, MetadataFacetFactory> factories = createTestMetadataFacetFactories();
70 this.cmr = new CassandraMetadataRepository( factories, null, cassandraArchivaManager );
71 this.repository = this.cmr;
73 clearReposAndNamespace( cassandraArchivaManager );
77 * ensure all dependant tables are cleaned up (mailinglist, license, dependencies)
82 public void clean_dependant_tables()
86 super.testUpdateProjectVersionMetadataWithAllElements();
88 String key = new ProjectVersionMetadataModel.KeyBuilder().withRepository( TEST_REPO_ID ) //
89 .withNamespace( TEST_NAMESPACE ) //
90 .withProjectId( TEST_PROJECT ) //
91 .withProjectVersion( TEST_PROJECT_VERSION ) //
92 .withId( TEST_PROJECT_VERSION ) //
95 this.cmr.removeProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
98 repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) ).isNull();
100 assertThat( cmr.getMailingLists( key ) ).isNotNull().isEmpty();
102 assertThat( cmr.getLicenses( key ) ).isNotNull().isEmpty();
104 assertThat( cmr.getDependencies( key ) ).isNotNull().isEmpty();
109 public void shutdown()
112 clearReposAndNamespace( cassandraArchivaManager );
116 static void clearReposAndNamespace( CassandraArchivaManager cassandraArchivaManager )
119 cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
120 cassandraArchivaManager.getProjectFamilyName() );
122 cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
123 cassandraArchivaManager.getNamespaceFamilyName() );
125 cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
126 cassandraArchivaManager.getRepositoryFamilyName() );
128 cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
129 cassandraArchivaManager.getProjectVersionMetadataFamilyName() );
131 cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
132 cassandraArchivaManager.getArtifactMetadataFamilyName() );
134 cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
135 cassandraArchivaManager.getMetadataFacetFamilyName() );
137 cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
138 cassandraArchivaManager.getMailingListFamilyName() );
140 cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
141 cassandraArchivaManager.getLicenseFamilyName() );
143 cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
144 cassandraArchivaManager.getDependencyFamilyName() );