]> source.dussan.org Git - archiva.git/blob
b4f0cdb82e495eb1de92adb8069524f80c84dc88
[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.apache.commons.io.FileUtils;
26 import org.junit.After;
27 import org.junit.Before;
28 import org.junit.Test;
29
30 import javax.inject.Inject;
31 import javax.inject.Named;
32
33 import java.io.File;
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         File directory = new File( "target/test-repositories" );
58         if ( directory.exists() )
59         {
60             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( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
91
92         assertThat(
93             repository.getProjectVersion( 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 }