]> source.dussan.org Git - archiva.git/blob
edb711538d89f8b8db71262d12f3cfa383ea01da
[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.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;
28
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;
34 import java.util.Map;
35
36 import static org.assertj.core.api.Assertions.assertThat;
37
38 /**
39  * @author Olivier Lamy
40  */
41 public class CassandraMetadataRepositoryTest
42     extends AbstractMetadataRepositoryTest
43 {
44     @Inject
45     @Named(value = "archivaEntityManagerFactory#cassandra")
46     CassandraArchivaManager cassandraArchivaManager;
47
48     CassandraMetadataRepository cmr;
49
50     @Before
51     @Override
52     public void setUp()
53         throws Exception
54     {
55         super.setUp();
56
57         Path directory = Paths.get( "target/test-repositories" );
58         if ( Files.exists(directory) )
59         {
60             org.apache.archiva.common.utils.FileUtils.deleteDirectory( directory );
61         }
62
63         Map<String, MetadataFacetFactory> factories = createTestMetadataFacetFactories();
64
65         this.cmr = new CassandraMetadataRepository( factories, null, cassandraArchivaManager );
66         this.repository = this.cmr;
67
68         clearReposAndNamespace( cassandraArchivaManager );
69     }
70
71     /**
72      * ensure all dependant tables are cleaned up (mailinglist, license, dependencies)
73      *
74      * @throws Exception
75      */
76     @Test
77     public void clean_dependant_tables()
78         throws Exception
79     {
80
81         super.testUpdateProjectVersionMetadataWithAllElements();
82
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 ) //
88             .build();
89
90         this.cmr.removeProjectVersion( null, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
91
92         assertThat(
93             repository.getProjectVersion( null , TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) ).isNull();
94
95         assertThat( cmr.getMailingLists( key ) ).isNotNull().isEmpty();
96
97         assertThat( cmr.getLicenses( key ) ).isNotNull().isEmpty();
98
99         assertThat( cmr.getDependencies( key ) ).isNotNull().isEmpty();
100     }
101
102
103     @After
104     public void shutdown()
105         throws Exception
106     {
107         clearReposAndNamespace( cassandraArchivaManager );
108         super.tearDown();
109     }
110
111     static void clearReposAndNamespace( CassandraArchivaManager cassandraArchivaManager )
112         throws Exception
113     {
114         cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
115                                                        cassandraArchivaManager.getProjectFamilyName() );
116
117         cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
118                                                        cassandraArchivaManager.getNamespaceFamilyName() );
119
120         cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
121                                                        cassandraArchivaManager.getRepositoryFamilyName() );
122
123         cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
124                                                        cassandraArchivaManager.getProjectVersionMetadataFamilyName() );
125
126         cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
127                                                        cassandraArchivaManager.getArtifactMetadataFamilyName() );
128
129         cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
130                                                        cassandraArchivaManager.getMetadataFacetFamilyName() );
131
132         cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
133                                                        cassandraArchivaManager.getMailingListFamilyName() );
134
135         cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
136                                                        cassandraArchivaManager.getLicenseFamilyName() );
137
138         cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
139                                                        cassandraArchivaManager.getDependencyFamilyName() );
140
141     }
142
143 }