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