001package org.apache.maven.scm.provider.accurev.cli; 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.hamcrest.CoreMatchers.is; 023import static org.junit.Assert.assertNull; 024import static org.junit.Assert.assertThat; 025 026import java.io.BufferedReader; 027import java.io.File; 028import java.io.IOException; 029import java.io.InputStreamReader; 030 031import org.apache.maven.scm.provider.accurev.AccuRevInfo; 032import org.codehaus.plexus.util.cli.StreamConsumer; 033import org.junit.Test; 034 035public class InfoConsumerTest 036{ 037 038 @Test 039 public void testConsumeOutsideWorkspace() 040 throws Exception 041 { 042 043 AccuRevInfo info = consume( "/info.outsideworkspace.txt" ); 044 045 assertNull( info.getBasis() ); 046 assertNull( info.getTop() ); 047 assertNull( info.getWorkSpace() ); 048 assertThat( info.getUser(), is( "ggardner" ) ); 049 assertThat( info.isLoggedIn(), is( true ) ); 050 051 } 052 053 @Test 054 public void testConsumeInsideWorkspace() 055 throws Exception 056 { 057 AccuRevInfo info = consume( "/info.inworkspace.txt" ); 058 059 assertThat( info.getBasis(), is( "maventst" ) ); 060 assertThat( info.getTop(), is( "/home/ggardner/accurev/ws/maventst" ) ); 061 assertThat( info.getWorkSpace(), is( "maventst_ggardner" ) ); 062 assertThat( info.getUser(), is( "ggardner" ) ); 063 064 } 065 066 @Test 067 public void testNotLoggedIn() 068 throws Exception 069 { 070 AccuRevInfo info = consume( "/info.notloggedin.txt" ); 071 assertThat( info.isLoggedIn(), is( false ) ); 072 } 073 074 private AccuRevInfo consume( String resource ) 075 throws IOException 076 { 077 AccuRevInfo info = new AccuRevInfo( new File( "/my/project/dir" ) ); 078 StreamConsumer consumer = new InfoConsumer( info ); 079 080 BufferedReader reader = 081 new BufferedReader( new InputStreamReader( this.getClass().getResourceAsStream( resource ) ) ); 082 083 String line = reader.readLine(); 084 while ( line != null ) 085 { 086 consumer.consumeLine( line ); 087 line = reader.readLine(); 088 } 089 return info; 090 } 091 092}