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 * RepositoryProblemConstraintTest
33 public class RepositoryProblemConstraintTest
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_4 = "org.apache.maven.archiva.test.4";
44 private static final String REPO_ID_1 = "test-repo-1";
46 private static final String REPO_ID_2 = "test-repo-2";
48 private static final String REPO_ID_3 = "test-repo-3";
50 private static final String REPO_ID_4 = "test-repo-4";
52 private RepositoryProblemDAO repoProblemDao;
54 protected void setUp()
59 ArchivaDAO dao = (ArchivaDAO) lookup( ArchivaDAO.ROLE, "jdo" );
60 repoProblemDao = dao.getRepositoryProblemDAO();
63 public RepositoryProblem createRepoProblem( String groupId, String repoId )
65 RepositoryProblem repoProblem = new RepositoryProblem();
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" );
79 public void testGroupIdConstraint()
82 repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_1, REPO_ID_1 ) );
84 repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_2, REPO_ID_1 ) );
85 repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_2, REPO_ID_1 ) );
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 ) );
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 ) );
97 public void testRepoIdConstraint()
100 repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_1, REPO_ID_1 ) );
102 repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_1, REPO_ID_2 ) );
103 repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_1, REPO_ID_2 ) );
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 ) );
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 ) );
115 private void assertConstraint( int expectedHits, Constraint constraint )
118 List results = repoProblemDao.queryRepositoryProblems( constraint );
119 assertNotNull( "Repository Problems: Not Null", results );
120 assertEquals( "Repository Problems: Results.size", expectedHits, results.size() );