View Javadoc

1   package org.apache.maven.archiva.scheduled.tasks;
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 java.io.File;
23  
24  import org.codehaus.plexus.spring.PlexusInSpringTestCase;
25  
26  public class TaskCreatorTest
27      extends PlexusInSpringTestCase
28  {
29      private static final String REPO_ID = "test-repo";
30  
31      public void testCreateRepositoryTask()
32          throws Exception
33      {
34          RepositoryTask task = TaskCreator.createRepositoryTask( REPO_ID );
35  
36          assertEquals( "Incorrect repository id set.", REPO_ID, task.getRepositoryId() );
37      }
38  
39      public void testCreateRepositoryTaskWithTaskNameSuffix()
40          throws Exception
41      {
42          RepositoryTask task = TaskCreator.createRepositoryTask( REPO_ID );
43  
44          assertBasicTaskDetails( task );
45      }
46  
47      public void testCreateRepositoryTaskScanAllArtifacts()
48          throws Exception
49      {
50          RepositoryTask task = TaskCreator.createRepositoryTask( REPO_ID, true );
51  
52          assertBasicTaskDetails( task );
53          assertTrue( task.isScanAll() );
54      }
55  
56      public void testCreateRepositoryTaskDoNotScanAllArtifacts()
57          throws Exception
58      {
59          RepositoryTask task = TaskCreator.createRepositoryTask( REPO_ID, false );
60  
61          assertBasicTaskDetails( task );
62          assertFalse( task.isScanAll() );
63      }
64  
65      public void testCreateRepositoryTaskForArtifactUpdateAllRelated()
66          throws Exception
67      {
68          File resource = new File( getBasedir(), "target/test-classes/test.jar" );
69          RepositoryTask task = TaskCreator.createRepositoryTask( REPO_ID, resource, true );
70  
71          assertBasicTaskDetails( task );
72          assertEquals( "Incorrect resource file set.", resource, task.getResourceFile() );
73          assertTrue( task.isUpdateRelatedArtifacts() );
74      }
75  
76      public void testCreateRepositoryTaskForArtifactDoNotUpdateAllRelated()
77          throws Exception
78      {
79          File resource = new File( getBasedir(), "target/test-classes/test.jar" );
80          RepositoryTask task = TaskCreator.createRepositoryTask( REPO_ID, resource, false );
81  
82          assertBasicTaskDetails( task );
83          assertEquals( "Incorrect resource file set.", resource, task.getResourceFile() );
84          assertFalse( task.isUpdateRelatedArtifacts() );
85      }
86  
87      private void assertBasicTaskDetails( RepositoryTask task )
88      {
89          assertEquals( "Incorrect repository id set.", REPO_ID, task.getRepositoryId() );
90      }
91  
92  }