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 static final String GROUP_ID_PARTIAL = "org.apache.maven.archiva";
44 private RepositoryProblemDAO repoProblemDao;
46 protected void setUp()
51 ArchivaDAO dao = (ArchivaDAO) lookup( ArchivaDAO.ROLE, "jdo" );
52 repoProblemDao = dao.getRepositoryProblemDAO();
55 public RepositoryProblem createRepoProblem( String groupId )
57 RepositoryProblem repoProblem = new RepositoryProblem();
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" );
71 public void testConstraint()
74 repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_1 ) );
76 repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_2 ) );
77 repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_2 ) );
79 repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_3 ) );
80 repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_3 ) );
81 repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_3 ) );
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 ) );
89 private void assertConstraint( int expectedHits, Constraint constraint )
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() );