1 package org.apache.maven.archiva.database.constraints;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
32
33 public class RangeConstraintTest
34 extends AbstractArchivaDatabaseTestCase
35 {
36 private RepositoryProblemDAO repoProblemDao;
37
38 protected void setUp()
39 throws Exception
40 {
41 super.setUp();
42
43 ArchivaDAO dao = (ArchivaDAO) lookup( ArchivaDAO.ROLE, "jdo" );
44 repoProblemDao = dao.getRepositoryProblemDAO();
45 }
46
47 public RepositoryProblem createRepoProblem()
48 {
49 RepositoryProblem repoProblem = new RepositoryProblem();
50
51 repoProblem.setGroupId( "groupId" );
52 repoProblem.setArtifactId( "artifactId" );
53 repoProblem.setMessage( "message" );
54 repoProblem.setOrigin( "origin" );
55 repoProblem.setPath( "path" );
56 repoProblem.setRepositoryId( "repositoryId" );
57 repoProblem.setType( "type" );
58 repoProblem.setVersion( "version" );
59
60 return repoProblem;
61 }
62
63 public void testConstraint()
64 throws Exception
65 {
66 repoProblemDao.saveRepositoryProblem( createRepoProblem() );
67 repoProblemDao.saveRepositoryProblem( createRepoProblem() );
68 repoProblemDao.saveRepositoryProblem( createRepoProblem() );
69 repoProblemDao.saveRepositoryProblem( createRepoProblem() );
70 repoProblemDao.saveRepositoryProblem( createRepoProblem() );
71
72 assertConstraint( 0, new RangeConstraint( new int[]{5, 10} ) );
73 assertConstraint( 1, new RangeConstraint( new int[]{0, 1} ) );
74 assertConstraint( 2, new RangeConstraint( new int[]{0, 2} ) );
75 assertConstraint( 3, new RangeConstraint( new int[]{0, 3} ) );
76 assertConstraint( 4, new RangeConstraint( new int[]{0, 4} ) );
77 assertConstraint( 5, new RangeConstraint( new int[]{0, 5} ) );
78 assertConstraint( 5, new RangeConstraint() );
79 }
80
81 private void assertConstraint( int expectedHits, Constraint constraint )
82 throws Exception
83 {
84 List<RepositoryProblem> results = repoProblemDao.queryRepositoryProblems( constraint );
85 assertNotNull( "Range Constraint: Not Null", results );
86 assertEquals( "Range Constraint: Results.size", expectedHits, results.size() );
87 }
88 }