View Javadoc
1   package org.apache.maven.scm.provider.accurev.cli;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *    http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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  }