]> source.dussan.org Git - archiva.git/blob
e0d77b31a65cb8e241a7acf244235405904fba21
[archiva.git] /
1 package org.apache.maven.archiva.database.constraints;
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.maven.archiva.database.AbstractArchivaDatabaseTestCase;
23 import org.apache.maven.archiva.database.ArchivaDAO;
24 import org.apache.maven.archiva.database.Constraint;
25 import org.apache.maven.archiva.database.RepositoryProblemDAO;
26 import org.apache.maven.archiva.model.RepositoryProblem;
27
28 import java.util.List;
29
30 /**
31  * RepositoryProblemConstraintTest
32  */
33 public class RepositoryProblemConstraintTest
34     extends AbstractArchivaDatabaseTestCase
35 {
36     private static final String GROUP_ID_1 = "org.apache.maven.archiva.test.1";
37
38     private static final String GROUP_ID_2 = "org.apache.maven.archiva.test.2";
39
40     private static final String GROUP_ID_3 = "org.apache.maven.archiva.test.3";
41
42     private static final String GROUP_ID_4 = "org.apache.maven.archiva.test.4";
43
44     private static final String REPO_ID_1 = "test-repo-1";
45
46     private static final String REPO_ID_2 = "test-repo-2";
47
48     private static final String REPO_ID_3 = "test-repo-3";
49
50     private static final String REPO_ID_4 = "test-repo-4";
51
52     private RepositoryProblemDAO repoProblemDao;
53
54     protected void setUp()
55         throws Exception
56     {
57         super.setUp();
58
59         ArchivaDAO dao = (ArchivaDAO) lookup( ArchivaDAO.ROLE, "jdo" );
60         repoProblemDao = dao.getRepositoryProblemDAO();
61     }
62
63     public RepositoryProblem createRepoProblem( String groupId, String repoId )
64     {
65         RepositoryProblem repoProblem = new RepositoryProblem();
66
67         repoProblem.setGroupId( groupId );
68         repoProblem.setArtifactId( "artifactId" );
69         repoProblem.setMessage( "message" );
70         repoProblem.setOrigin( "origin" );
71         repoProblem.setPath( "path" );
72         repoProblem.setRepositoryId( repoId );
73         repoProblem.setType( "type" );
74         repoProblem.setVersion( "version" );
75
76         return repoProblem;
77     }
78
79     public void testGroupIdConstraint()
80         throws Exception
81     {
82         repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_1, REPO_ID_1 ) );
83
84         repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_2, REPO_ID_1 ) );
85         repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_2, REPO_ID_1 ) );
86
87         repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_3, REPO_ID_1 ) );
88         repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_3, REPO_ID_1 ) );
89         repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_3, REPO_ID_1 ) );
90
91         assertConstraint( 1, new RepositoryProblemConstraint( GROUP_ID_1, REPO_ID_1 ) );
92         assertConstraint( 2, new RepositoryProblemConstraint( GROUP_ID_2, REPO_ID_1 ) );
93         assertConstraint( 3, new RepositoryProblemConstraint( GROUP_ID_3, REPO_ID_1 ) );
94         assertConstraint( 0, new RepositoryProblemConstraint( GROUP_ID_4, REPO_ID_1 ) );
95     }
96
97     public void testRepoIdConstraint()
98         throws Exception
99     {
100         repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_1, REPO_ID_1 ) );
101
102         repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_1, REPO_ID_2 ) );
103         repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_1, REPO_ID_2 ) );
104
105         repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_1, REPO_ID_3 ) );
106         repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_1, REPO_ID_3 ) );
107         repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_1, REPO_ID_3 ) );
108
109         assertConstraint( 1, new RepositoryProblemConstraint( GROUP_ID_1, REPO_ID_1 ) );
110         assertConstraint( 2, new RepositoryProblemConstraint( GROUP_ID_1, REPO_ID_2 ) );
111         assertConstraint( 3, new RepositoryProblemConstraint( GROUP_ID_1, REPO_ID_3 ) );
112         assertConstraint( 0, new RepositoryProblemConstraint( GROUP_ID_1, REPO_ID_4 ) );
113     }
114
115     private void assertConstraint( int expectedHits, Constraint constraint )
116         throws Exception
117     {
118         List results = repoProblemDao.queryRepositoryProblems( constraint );
119         assertNotNull( "Repository Problems: Not Null", results );
120         assertEquals( "Repository Problems: Results.size", expectedHits, results.size() );
121     }
122 }