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