001package org.apache.maven.scm.provider.accurev.command.status; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import static org.apache.maven.scm.ScmFileMatcher.assertHasScmFile; 023import static org.apache.maven.scm.ScmFileMatcher.scmFile; 024import static org.hamcrest.Matchers.hasItems; 025import static org.hamcrest.Matchers.is; 026import static org.hamcrest.Matchers.not; 027import static org.hamcrest.Matchers.notNullValue; 028import static org.junit.Assert.assertThat; 029import static org.mockito.Matchers.anyListOf; 030import static org.mockito.Matchers.argThat; 031import static org.mockito.Matchers.eq; 032import static org.mockito.Mockito.when; 033 034import java.io.File; 035import java.util.Arrays; 036import java.util.Collection; 037import java.util.List; 038 039import org.apache.maven.scm.CommandParameters; 040import org.apache.maven.scm.ScmFile; 041import org.apache.maven.scm.ScmFileSet; 042import org.apache.maven.scm.ScmFileStatus; 043import org.apache.maven.scm.command.status.StatusScmResult; 044import org.apache.maven.scm.provider.accurev.AccuRevStat; 045import org.apache.maven.scm.provider.accurev.CategorisedElements; 046import org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest; 047import org.hamcrest.Matchers; 048import org.junit.Test; 049 050public class AccuRevStatusCommandTest 051 extends AbstractAccuRevCommandTest 052{ 053 054 @Test 055 public void testStatus() 056 throws Exception 057 { 058 059 final ScmFileSet testFileSet = getScmFileSet(); 060 061 File keptFile = new File( "kept/file" ); 062 File keptAdded = new File( "kept/added" ); 063 // this is the special one, it is returned by both the kept and defunct stat calls, so the command 064 // needs to filter it out. 065 File keptDefunct = new File( "kept/defunct" ); 066 File modifiedFile = new File( "modified/file" ); 067 File modifiedAdded = new File( "modified/added" ); 068 File missingFile = new File( "missing/file" ); 069 File externalFile = new File( "external/file" ); 070 071 when( accurev.stat( eq( basedir ), anyListOf( File.class ), eq( AccuRevStat.DEFUNCT ) ) ).thenReturn( 072 Arrays.asList( keptDefunct ) ); 073 when( accurev.stat( eq( basedir ), anyListOf( File.class ), eq( AccuRevStat.MODIFIED ) ) ).thenReturn( 074 Arrays.asList( modifiedFile,modifiedAdded ) ); 075 when( accurev.stat( eq( basedir ), anyListOf( File.class ), eq( AccuRevStat.KEPT ) ) ).thenReturn( 076 Arrays.asList( 077 keptDefunct, 078 keptFile, 079 keptAdded ) ); 080 081 when( accurev.stat( eq( basedir ), anyListOf( File.class ), eq( AccuRevStat.MISSING ) ) ).thenReturn( 082 Arrays.asList( missingFile ) ); 083 084 when( accurev.stat( eq( basedir ), anyListOf( File.class ), eq( AccuRevStat.EXTERNAL ) ) ).thenReturn( 085 Arrays.asList( externalFile ) ); 086 087 CategorisedElements catElems = new CategorisedElements(); 088 catElems.getMemberElements().addAll( Arrays.asList( modifiedFile, keptFile ) ); 089 catElems.getNonMemberElements().addAll( Arrays.asList( modifiedAdded, keptAdded ) ); 090 when( 091 accurev.statBackingStream( eq( basedir ), (Collection<File>) argThat( hasItems( modifiedFile, 092 modifiedAdded, keptFile, 093 keptAdded ) ) ) ).thenReturn( 094 catElems ); 095 096 AccuRevStatusCommand command = new AccuRevStatusCommand( getLogger() ); 097 098 CommandParameters commandParameters = new CommandParameters(); 099 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}