View Javadoc
1   package org.apache.maven.scm.provider.accurev.command.status;
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 static org.apache.maven.scm.ScmFileMatcher.assertHasScmFile;
23  import static org.apache.maven.scm.ScmFileMatcher.scmFile;
24  import static org.hamcrest.Matchers.hasItems;
25  import static org.hamcrest.Matchers.is;
26  import static org.hamcrest.Matchers.not;
27  import static org.hamcrest.Matchers.notNullValue;
28  import static org.junit.Assert.assertThat;
29  import static org.mockito.Matchers.anyListOf;
30  import static org.mockito.Matchers.argThat;
31  import static org.mockito.Matchers.eq;
32  import static org.mockito.Mockito.when;
33  
34  import java.io.File;
35  import java.util.Arrays;
36  import java.util.Collection;
37  import java.util.List;
38  
39  import org.apache.maven.scm.CommandParameters;
40  import org.apache.maven.scm.ScmFile;
41  import org.apache.maven.scm.ScmFileSet;
42  import org.apache.maven.scm.ScmFileStatus;
43  import org.apache.maven.scm.command.status.StatusScmResult;
44  import org.apache.maven.scm.provider.accurev.AccuRevStat;
45  import org.apache.maven.scm.provider.accurev.CategorisedElements;
46  import org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest;
47  import org.hamcrest.Matchers;
48  import org.junit.Test;
49  
50  public class AccuRevStatusCommandTest
51      extends AbstractAccuRevCommandTest
52  {
53  
54      @Test
55      public void testStatus()
56          throws Exception
57      {
58  
59          final ScmFileSet testFileSet = getScmFileSet();
60  
61          File keptFile = new File( "kept/file" );
62          File keptAdded = new File( "kept/added" );
63          // this is the special one, it is returned by both the kept and defunct stat calls, so the command
64          // needs to filter it out.
65          File keptDefunct = new File( "kept/defunct" );
66          File modifiedFile = new File( "modified/file" );
67          File modifiedAdded = new File( "modified/added" );
68          File missingFile = new File( "missing/file" );
69          File externalFile = new File( "external/file" );
70  
71          when( accurev.stat( eq( basedir ), anyListOf( File.class ), eq( AccuRevStat.DEFUNCT ) ) ).thenReturn(
72                                                                                                                Arrays.asList( keptDefunct ) );
73          when( accurev.stat( eq( basedir ), anyListOf( File.class ), eq( AccuRevStat.MODIFIED ) ) ).thenReturn(
74                                                                                                                 Arrays.asList( modifiedFile,modifiedAdded ) );
75          when( accurev.stat( eq( basedir ), anyListOf( File.class ), eq( AccuRevStat.KEPT ) ) ).thenReturn(
76                                                                                                             Arrays.asList(
77                                                                                                                            keptDefunct,
78                                                                                                                            keptFile,
79                                                                                                                            keptAdded ) );
80  
81          when( accurev.stat( eq( basedir ), anyListOf( File.class ), eq( AccuRevStat.MISSING ) ) ).thenReturn(
82                                                                                                                Arrays.asList( missingFile ) );
83  
84          when( accurev.stat( eq( basedir ), anyListOf( File.class ), eq( AccuRevStat.EXTERNAL ) ) ).thenReturn(
85                                                                                                                 Arrays.asList( externalFile ) );
86  
87          CategorisedElements catElems = new CategorisedElements();
88          catElems.getMemberElements().addAll( Arrays.asList( modifiedFile, keptFile ) );
89          catElems.getNonMemberElements().addAll( Arrays.asList( modifiedAdded, keptAdded ) );
90          when(
91                accurev.statBackingStream( eq( basedir ), (Collection<File>) argThat( hasItems( modifiedFile,
92                                                                                                modifiedAdded, keptFile,
93                                                                                                keptAdded ) ) ) ).thenReturn(
94                                                                                                                              catElems );
95  
96          AccuRevStatusCommand command = new AccuRevStatusCommand( getLogger() );
97  
98          CommandParameters commandParameters = new CommandParameters();
99          StatusScmResult result = command.status( repo, testFileSet, commandParameters );
100 
101         assertThat( result.isSuccess(), is( true ) );
102         assertThat( result.getChangedFiles().size(), is( 7 ) );
103 
104         assertThat( (List<ScmFile>) result.getChangedFiles(),
105                     not( Matchers.<ScmFile>hasItem( scmFile( "kept/defunct", ScmFileStatus.MODIFIED ) ) ) );
106         assertHasScmFile( result.getChangedFiles(), "kept/file", ScmFileStatus.MODIFIED );
107         assertHasScmFile( result.getChangedFiles(), "kept/added", ScmFileStatus.ADDED );
108         assertHasScmFile( result.getChangedFiles(), "kept/defunct", ScmFileStatus.DELETED );
109         assertHasScmFile( result.getChangedFiles(), "modified/file", ScmFileStatus.MODIFIED );
110         assertHasScmFile( result.getChangedFiles(), "modified/added", ScmFileStatus.ADDED );
111         assertHasScmFile( result.getChangedFiles(), "missing/file", ScmFileStatus.MISSING );
112         assertHasScmFile( result.getChangedFiles(), "external/file", ScmFileStatus.UNKNOWN );
113 
114     }
115 
116     @Test
117     public void testFailure()
118         throws Exception
119     {
120 
121         final ScmFileSet testFileSet = getScmFileSet();
122 
123         when( accurev.stat( basedir, testFileSet.getFileList(), AccuRevStat.MODIFIED ) ).thenReturn( null );
124 
125         AccuRevStatusCommand command = new AccuRevStatusCommand( getLogger() );
126 
127         CommandParameters commandParameters = new CommandParameters();
128         StatusScmResult result = command.status( repo, testFileSet, commandParameters );
129 
130         assertThat( result.isSuccess(), is( false ) );
131         assertThat( result.getProviderMessage(), notNullValue() );
132 
133     }
134 
135 }