001package org.apache.maven.scm.provider.perforce.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 org.apache.maven.scm.ScmFile; 023import org.apache.maven.scm.ScmFileStatus; 024import org.apache.maven.scm.ScmTestCase; 025import org.apache.maven.scm.util.ConsumerUtils; 026 027import java.io.File; 028 029/** 030 * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a> 031 * 032 */ 033public class PerforceCheckOutConsumerTest 034 extends ScmTestCase 035{ 036 public void testGoodParse() 037 throws Exception 038 { 039 File testFile = getTestFile( "src/test/resources/perforce/checkout_good.txt" ); 040 041 PerforceCheckOutConsumer consumer = new PerforceCheckOutConsumer( "test-test-maven", "//depot/modules" ); 042 consumer.consumeLine( "Client test-test-maven saved." ); 043 assertEquals( "", consumer.getOutput() ); 044 assertTrue( consumer.isSuccess() ); 045 046 ConsumerUtils.consumeFile( testFile, consumer ); 047 048 assertTrue( consumer.getOutput(), consumer.isSuccess() ); 049 assertEquals( "", consumer.getOutput() ); 050 assertEquals( 4, consumer.getCheckedout().size() ); 051 ScmFile file = (ScmFile) consumer.getCheckedout().get( 0 ); 052 assertEquals( "cordoba/runtime-ear/.j2ee", file.getPath() ); 053 assertEquals( ScmFileStatus.DELETED, file.getStatus() ); 054 } 055 056 public void testBadParse() 057 throws Exception 058 { 059 File testFile = getTestFile( "src/test/resources/perforce/checkout_bad.txt" ); 060 061 PerforceCheckOutConsumer consumer = new PerforceCheckOutConsumer( "test-test-maven", "//depot/modules" ); 062 consumer.consumeLine( "Something bad happened." ); 063 assertFalse( consumer.isSuccess() ); 064 065 consumer = new PerforceCheckOutConsumer( "test-test-maven", "" ); 066 consumer.consumeLine( "Client test-test-maven saved." ); 067 assertTrue( consumer.isSuccess() ); 068 069 ConsumerUtils.consumeFile( testFile, consumer ); 070 071 assertFalse( consumer.getOutput(), consumer.isSuccess() ); 072 assertTrue( consumer.getOutput(), consumer.getOutput().length() > 0 ); 073 assertContains( consumer.getOutput(), "Invalid" ); 074 assertContains( consumer.getOutput(), "somelabel" ); 075 } 076 077 private void assertContains( String block, String element ) 078 { 079 if ( block.indexOf( element ) == -1 ) 080 { 081 fail( "Block '" + block + "' does not contain element '" + element + "'" ); 082 } 083 } 084}