1 package org.apache.maven.scm.provider.accurev.cli;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import static org.hamcrest.CoreMatchers.is;
23 import static org.junit.Assert.assertNull;
24 import static org.junit.Assert.assertThat;
25
26 import java.io.BufferedReader;
27 import java.io.File;
28 import java.io.IOException;
29 import java.io.InputStreamReader;
30
31 import org.apache.maven.scm.provider.accurev.AccuRevInfo;
32 import org.codehaus.plexus.util.cli.StreamConsumer;
33 import org.junit.Test;
34
35 public class InfoConsumerTest
36 {
37
38 @Test
39 public void testConsumeOutsideWorkspace()
40 throws Exception
41 {
42
43 AccuRevInfo info = consume( "/info.outsideworkspace.txt" );
44
45 assertNull( info.getBasis() );
46 assertNull( info.getTop() );
47 assertNull( info.getWorkSpace() );
48 assertThat( info.getUser(), is( "ggardner" ) );
49 assertThat( info.isLoggedIn(), is( true ) );
50
51 }
52
53 @Test
54 public void testConsumeInsideWorkspace()
55 throws Exception
56 {
57 AccuRevInfo info = consume( "/info.inworkspace.txt" );
58
59 assertThat( info.getBasis(), is( "maventst" ) );
60 assertThat( info.getTop(), is( "/home/ggardner/accurev/ws/maventst" ) );
61 assertThat( info.getWorkSpace(), is( "maventst_ggardner" ) );
62 assertThat( info.getUser(), is( "ggardner" ) );
63
64 }
65
66 @Test
67 public void testNotLoggedIn()
68 throws Exception
69 {
70 AccuRevInfo info = consume( "/info.notloggedin.txt" );
71 assertThat( info.isLoggedIn(), is( false ) );
72 }
73
74 private AccuRevInfo consume( String resource )
75 throws IOException
76 {
77 AccuRevInfo info = new AccuRevInfo( new File( "/my/project/dir" ) );
78 StreamConsumer consumer = new InfoConsumer( info );
79
80 BufferedReader reader =
81 new BufferedReader( new InputStreamReader( this.getClass().getResourceAsStream( resource ) ) );
82
83 String line = reader.readLine();
84 while ( line != null )
85 {
86 consumer.consumeLine( line );
87 line = reader.readLine();
88 }
89 return info;
90 }
91
92 }