View Javadoc

1   package org.apache.maven.archiva.database.constraints;
2   
3   /*
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
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
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
19   * under the License.
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   * RangeConstraintTest
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  }