View Javadoc

1   package org.apache.maven.continuum.release.phase;
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.continuum.release.config.ContinuumReleaseDescriptor;
23  import org.apache.maven.settings.Settings;
24  import org.apache.maven.shared.release.phase.ReleasePhase;
25  import org.codehaus.plexus.spring.PlexusInSpringTestCase;
26  import org.codehaus.plexus.util.FileUtils;
27  
28  import java.io.File;
29  
30  public class UpdateWorkingCopyPhaseTest
31      extends PlexusInSpringTestCase
32  {
33      private UpdateWorkingCopyPhase phase;
34  
35      protected void setUp()
36          throws Exception
37      {
38          super.setUp();
39  
40          phase = (UpdateWorkingCopyPhase) lookup( ReleasePhase.ROLE, "update-working-copy" );
41  
42          // set up project scm
43          File scmPathFile = new File( getBasedir(), "target/scm-src" ).getAbsoluteFile();
44          File scmTargetPathFile = new File( getBasedir(), "/target/scm-test" ).getAbsoluteFile();
45          FileUtils.copyDirectoryStructure( scmPathFile, scmTargetPathFile );
46      }
47  
48      public void testWorkingDirDoesNotExist()
49          throws Exception
50      {
51          assertNotNull( phase );
52  
53          ContinuumReleaseDescriptor releaseDescriptor = createReleaseDescriptor();
54  
55          File workingDirectory = new File( releaseDescriptor.getWorkingDirectory() );
56  
57          FileUtils.deleteDirectory( workingDirectory );
58          assertFalse( workingDirectory.exists() );
59  
60          phase.execute( releaseDescriptor, new Settings(), null );
61  
62          assertTrue( workingDirectory.exists() );
63      }
64  
65      public void testWorkingDirAlreadyExistsWithProjectCheckout()
66          throws Exception
67      {
68          assertNotNull( phase );
69  
70          ContinuumReleaseDescriptor releaseDescriptor = createReleaseDescriptor();
71  
72          File workingDirectory = new File( releaseDescriptor.getWorkingDirectory() );
73  
74          // assert working directory already exists with project checkout
75          assertTrue( workingDirectory.exists() );
76          assertTrue( workingDirectory.listFiles().length > 0 );
77  
78          phase.execute( releaseDescriptor, new Settings(), null );
79  
80          assertTrue( workingDirectory.exists() );
81      }
82  
83      public void testWorkingDirAlreadyExistsNoProjectCheckout()
84          throws Exception
85      {
86          assertNotNull( phase );
87  
88          ContinuumReleaseDescriptor releaseDescriptor = createReleaseDescriptor();
89  
90          File workingDirectory = new File( releaseDescriptor.getWorkingDirectory() );
91          FileUtils.deleteDirectory( workingDirectory );
92          workingDirectory.mkdirs();
93  
94          // assert empty working directory
95          assertTrue( workingDirectory.exists() );
96          assertTrue( workingDirectory.listFiles().length == 0 );
97  
98          phase.execute( releaseDescriptor, new Settings(), null );
99  
100         assertTrue( workingDirectory.exists() );
101     }
102 
103     private ContinuumReleaseDescriptor createReleaseDescriptor()
104     {
105         // project source and working directory paths
106         String projectUrl = getBasedir() + "/target/scm-test/trunk";
107         String workingDirPath = getBasedir() + "/target/test-classes/updateWorkingCopy_working-directory";
108 
109         // create release descriptor
110         ContinuumReleaseDescriptor releaseDescriptor = new ContinuumReleaseDescriptor();
111         releaseDescriptor.setScmSourceUrl( "scm:svn:file://localhost/" + projectUrl );
112         releaseDescriptor.setWorkingDirectory( workingDirPath );
113 
114         return releaseDescriptor;
115     }
116 }