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;
33 public class RangeConstraintTest
34 extends AbstractArchivaDatabaseTestCase
36 private RepositoryProblemDAO repoProblemDao;
38 protected void setUp()
43 ArchivaDAO dao = (ArchivaDAO) lookup( ArchivaDAO.ROLE, "jdo" );
44 repoProblemDao = dao.getRepositoryProblemDAO();
47 public RepositoryProblem createRepoProblem()
49 RepositoryProblem repoProblem = new RepositoryProblem();
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" );
63 public void testConstraint()
66 repoProblemDao.saveRepositoryProblem( createRepoProblem() );
67 repoProblemDao.saveRepositoryProblem( createRepoProblem() );
68 repoProblemDao.saveRepositoryProblem( createRepoProblem() );
69 repoProblemDao.saveRepositoryProblem( createRepoProblem() );
70 repoProblemDao.saveRepositoryProblem( createRepoProblem() );
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() );
81 private void assertConstraint( int expectedHits, Constraint constraint )
84 List results = repoProblemDao.queryRepositoryProblems( constraint );
85 assertNotNull( "Range Constraint: Not Null", results );
86 assertEquals( "Range Constraint: Results.size", expectedHits, results.size() );