1 package org.apache.maven.archiva.database.constraints;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
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;
28 import java.util.List;
31 * RepositoryProblemByGroupIdConstraintTest
33 public class RepositoryProblemByGroupIdConstraintTest
34 extends AbstractArchivaDatabaseTestCase
36 private static final String GROUP_ID_1 = "org.apache.maven.archiva.test.1";
38 private static final String GROUP_ID_2 = "org.apache.maven.archiva.test.2";
40 private static final String GROUP_ID_3 = "org.apache.maven.archiva.test.3";
42 private RepositoryProblemDAO repoProblemDao;
44 protected void setUp()
49 ArchivaDAO dao = (ArchivaDAO) lookup( ArchivaDAO.ROLE, "jdo" );
50 repoProblemDao = dao.getRepositoryProblemDAO();
53 public RepositoryProblem createRepoProblem( String groupId )
55 RepositoryProblem repoProblem = new RepositoryProblem();
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" );
69 public void testConstraint()
72 repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_1 ) );
74 repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_2 ) );
75 repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_2 ) );
77 repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_3 ) );
78 repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_3 ) );
79 repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_3 ) );
81 assertConstraint( 1, new RepositoryProblemByGroupIdConstraint( GROUP_ID_1 ) );
82 assertConstraint( 2, new RepositoryProblemByGroupIdConstraint( GROUP_ID_2 ) );
83 assertConstraint( 3, new RepositoryProblemByGroupIdConstraint( GROUP_ID_3 ) );
86 private void assertConstraint( int expectedHits, Constraint constraint )
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() );