]> source.dussan.org Git - archiva.git/blob
cc8b3f42b3067c86617bbf49f72dd90d9d664d22
[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  * RepositoryProblemByGroupIdConstraintTest
32  */
33 public class RepositoryProblemByGroupIdConstraintTest
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_PARTIAL = "org.apache.maven.archiva";
43
44     private RepositoryProblemDAO repoProblemDao;
45
46     protected void setUp()
47         throws Exception
48     {
49         super.setUp();
50
51         ArchivaDAO dao = (ArchivaDAO) lookup( ArchivaDAO.ROLE, "jdo" );
52         repoProblemDao = dao.getRepositoryProblemDAO();
53     }
54
55     public RepositoryProblem createRepoProblem( String groupId )
56     {
57         RepositoryProblem repoProblem = new RepositoryProblem();
58
59         repoProblem.setGroupId( groupId );
60         repoProblem.setArtifactId( "artifactId" );
61         repoProblem.setMessage( "message" );
62         repoProblem.setOrigin( "origin" );
63         repoProblem.setPath( "path" );
64         repoProblem.setRepositoryId( "repositoryId" );
65         repoProblem.setType( "type" );
66         repoProblem.setVersion( "version" );
67
68         return repoProblem;
69     }
70
71     public void testConstraint()
72         throws Exception
73     {
74         repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_1 ) );
75
76         repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_2 ) );
77         repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_2 ) );
78
79         repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_3 ) );
80         repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_3 ) );
81         repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_3 ) );
82
83         assertConstraint( 1, new RepositoryProblemByGroupIdConstraint( GROUP_ID_1 ) );
84         assertConstraint( 2, new RepositoryProblemByGroupIdConstraint( GROUP_ID_2 ) );
85         assertConstraint( 3, new RepositoryProblemByGroupIdConstraint( GROUP_ID_3 ) );
86         assertConstraint( 6, new RepositoryProblemByGroupIdConstraint( GROUP_ID_PARTIAL ) );
87     }
88
89     private void assertConstraint( int expectedHits, Constraint constraint )
90         throws Exception
91     {
92         List results = repoProblemDao.queryRepositoryProblems( constraint );
93         assertNotNull( "Repository Problems by Group Id: Not Null", results );
94         assertEquals( "Repository Problems by Group Id: Results.size", expectedHits, results.size() );
95     }
96 }