001package org.apache.maven.scm.provider.local.command.checkout; 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 java.io.File; 023import java.io.FileReader; 024import java.io.Reader; 025import java.util.List; 026 027import org.apache.maven.scm.ScmFile; 028import org.apache.maven.scm.command.checkout.CheckOutScmResult; 029import org.apache.maven.scm.provider.local.metadata.LocalScmMetadata; 030import org.apache.maven.scm.provider.local.metadata.io.xpp3.LocalScmMetadataXpp3Reader; 031import org.apache.maven.scm.tck.command.checkout.CheckOutCommandTckTest; 032import org.codehaus.plexus.util.FileUtils; 033import org.codehaus.plexus.util.IOUtil; 034 035/** 036 * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a> 037 * 038 */ 039public class LocalCheckOutCommandTckTest 040 extends CheckOutCommandTckTest 041{ 042 private String module = "check-out"; 043 044 public String getScmUrl() 045 throws Exception 046 { 047 return "scm:local|" + getRepositoryRoot().getAbsolutePath() + "|" + module; 048 } 049 050 public void initRepo() 051 throws Exception 052 { 053 File root = new File( getRepositoryRoot() + "/" + module ); 054 055 makeFile( root, "/pom.xml" ); 056 057 makeFile( root, "/readme.txt" ); 058 059 makeFile( root, "/src/main/java/Application.java" ); 060 061 makeFile( root, "/src/test/java/Test.java" ); 062 063 makeDirectory( root, "/src/test/resources" ); 064 } 065 066 /** 067 * Tests that the metadata file .maven-scm-local is written correctly 068 */ 069 public void testMetadata() 070 throws Exception 071 { 072 FileUtils.deleteDirectory( getWorkingCopy() ); 073 074 CheckOutScmResult result = checkOut( getWorkingCopy(), getScmRepository() ); 075 076 assertResultIsSuccess( result ); 077 078 List<ScmFile> checkedOutFiles = result.getCheckedOutFiles(); 079 080 assertEquals( 4, checkedOutFiles.size() ); 081 082 // ---------------------------------------------------------------------- 083 // Assert metadata file 084 // ---------------------------------------------------------------------- 085 File metadataFile = new File( getWorkingCopy(), ".maven-scm-local" ); 086 assertTrue( "Expected metadata file .maven-scm-local does not exist", metadataFile.exists() ); 087 Reader reader = new FileReader( metadataFile ); 088 LocalScmMetadata metadata; 089 try 090 { 091 metadata = new LocalScmMetadataXpp3Reader().read( reader ); 092 } 093 finally 094 { 095 IOUtil.close( reader ); 096 } 097 File root = new File( getRepositoryRoot() + "/" + module ); 098 @SuppressWarnings( "unchecked" ) 099 List<String> fileNames = FileUtils.getFileNames( root, "**", null, false ); 100 assertEquals( fileNames, metadata.getRepositoryFileNames() ); 101 } 102}