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.MetadataFacetFactory;
23 import org.apache.archiva.metadata.repository.AbstractMetadataRepositoryTest;
24 import org.apache.archiva.metadata.repository.cassandra.model.ProjectVersionMetadataModel;
25 import org.junit.After;
26 import org.junit.Before;
27 import org.junit.Test;
29 import javax.inject.Inject;
30 import javax.inject.Named;
31 import java.nio.file.Files;
32 import java.nio.file.Path;
33 import java.nio.file.Paths;
36 import static org.assertj.core.api.Assertions.assertThat;
39 * @author Olivier Lamy
41 public class CassandraMetadataRepositoryTest
42 extends AbstractMetadataRepositoryTest
45 @Named(value = "archivaEntityManagerFactory#cassandra")
46 CassandraArchivaManager cassandraArchivaManager;
48 CassandraMetadataRepository cmr;
57 Path directory = Paths.get( "target/test-repositories" );
58 if ( Files.exists(directory) )
60 org.apache.archiva.common.utils.FileUtils.deleteDirectory( directory );
63 Map<String, MetadataFacetFactory> factories = createTestMetadataFacetFactories();
65 this.cmr = new CassandraMetadataRepository( factories, null, cassandraArchivaManager );
66 this.repository = this.cmr;
68 clearReposAndNamespace( cassandraArchivaManager );
72 * ensure all dependant tables are cleaned up (mailinglist, license, dependencies)
77 public void clean_dependant_tables()
81 super.testUpdateProjectVersionMetadataWithAllElements();
83 String key = new ProjectVersionMetadataModel.KeyBuilder().withRepository( TEST_REPO_ID ) //
84 .withNamespace( TEST_NAMESPACE ) //
85 .withProjectId( TEST_PROJECT ) //
86 .withProjectVersion( TEST_PROJECT_VERSION ) //
87 .withId( TEST_PROJECT_VERSION ) //
90 this.cmr.removeProjectVersion( null, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
93 repository.getProjectVersion( null , TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) ).isNull();
95 assertThat( cmr.getMailingLists( key ) ).isNotNull().isEmpty();
97 assertThat( cmr.getLicenses( key ) ).isNotNull().isEmpty();
99 assertThat( cmr.getDependencies( key ) ).isNotNull().isEmpty();
104 public void shutdown()
107 clearReposAndNamespace( cassandraArchivaManager );
111 static void clearReposAndNamespace( CassandraArchivaManager cassandraArchivaManager )
114 cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
115 cassandraArchivaManager.getProjectFamilyName() );
117 cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
118 cassandraArchivaManager.getNamespaceFamilyName() );
120 cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
121 cassandraArchivaManager.getRepositoryFamilyName() );
123 cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
124 cassandraArchivaManager.getProjectVersionMetadataFamilyName() );
126 cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
127 cassandraArchivaManager.getArtifactMetadataFamilyName() );
129 cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
130 cassandraArchivaManager.getMetadataFacetFamilyName() );
132 cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
133 cassandraArchivaManager.getMailingListFamilyName() );
135 cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
136 cassandraArchivaManager.getLicenseFamilyName() );
138 cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
139 cassandraArchivaManager.getDependencyFamilyName() );