1 package org.apache.maven.scm.provider.accurev.command.login;
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.Matchers.is;
23 import static org.junit.Assert.assertThat;
24 import static org.mockito.Matchers.any;
25 import static org.mockito.Matchers.anyString;
26 import static org.mockito.Matchers.eq;
27 import static org.mockito.Mockito.never;
28 import static org.mockito.Mockito.verify;
29 import static org.mockito.Mockito.when;
30
31 import java.io.File;
32
33 import org.apache.maven.scm.CommandParameters;
34 import org.apache.maven.scm.ScmFileSet;
35 import org.apache.maven.scm.command.login.LoginScmResult;
36 import org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest;
37 import org.junit.Test;
38
39 public class AccuRevLoginCommandTest
40 extends AbstractAccuRevCommandTest
41 {
42
43 @Test
44 public void testWhenNotLoggedIn()
45 throws Exception
46 {
47
48 repo.setUser( "myUser" );
49 repo.setPassword( "aPassword" );
50 info.setUser( "(not logged in)" );
51 when( accurev.info( any( File.class ) ) ).thenReturn( info );
52 when( accurev.login( "myUser", "aPassword" ) ).thenReturn( true );
53 AccuRevLoginCommand command = new AccuRevLoginCommand( getLogger() );
54
55 LoginScmResult result = command.login( repo, new ScmFileSet( basedir ), new CommandParameters() );
56
57 assertThat( result.isSuccess(), is( true ) );
58 verify( accurev ).login( "myUser", "aPassword" );
59
60 }
61
62 @Test
63 public void testWhenAlreadyLoggedInAsSomeoneElse()
64 throws Exception
65 {
66 repo.setUser( "myUser" );
67 repo.setPassword( "aPassword" );
68 info.setUser( "A.N.Other" );
69 when( accurev.info( any( File.class ) ) ).thenReturn( info );
70 when( accurev.login( "myUser", "aPassword" ) ).thenReturn( true );
71 AccuRevLoginCommand command = new AccuRevLoginCommand( getLogger() );
72
73 LoginScmResult result = command.login( repo, new ScmFileSet( basedir ), new CommandParameters() );
74
75 assertThat( result.isSuccess(), is( true ) );
76 verify( accurev ).login( "myUser", "aPassword" );
77
78 }
79
80 @Test
81 public void testWhenAlreadyLoggedInAsRequiredUser()
82 throws Exception
83 {
84
85 repo.setUser( "myUser" );
86 repo.setPassword( "aPassword" );
87 info.setUser( "myUser" );
88 when( accurev.info( any( File.class ) ) ).thenReturn( info );
89 AccuRevLoginCommand command = new AccuRevLoginCommand( getLogger() );
90
91 LoginScmResult result = command.login( repo, new ScmFileSet( basedir ), new CommandParameters() );
92
93 assertThat( result.isSuccess(), is( true ) );
94
95
96 verify( accurev, never() ).login( eq( "myUser" ), anyString() );
97
98 }
99
100 @Test
101 public void testWhenNoUserSuppliedAndAlreadyLoggedIn()
102 throws Exception
103 {
104
105 repo.setUser( null );
106 info.setUser( "anyUser" );
107 when( accurev.info( any( File.class ) ) ).thenReturn( info );
108 AccuRevLoginCommand command = new AccuRevLoginCommand( getLogger() );
109
110 LoginScmResult result = command.login( repo, new ScmFileSet( basedir ), new CommandParameters() );
111
112 assertThat( result.isSuccess(), is( true ) );
113 verify( accurev, never() ).login( anyString(), anyString() );
114
115 }
116
117 @Test
118 public void testFailsWhenNoUserSuppliedAndNotLoggedIn()
119 throws Exception
120 {
121
122 repo.setUser( null );
123 info.setUser( "(not logged in)" );
124 when( accurev.info( any( File.class ) ) ).thenReturn( info );
125 AccuRevLoginCommand command = new AccuRevLoginCommand( getLogger() );
126
127 LoginScmResult result = command.login( repo, new ScmFileSet( basedir ), new CommandParameters() );
128
129 assertThat( result.isSuccess(), is( false ) );
130 verify( accurev, never() ).login( anyString(), anyString() );
131
132 }
133 }