b82434c0d88882a4e4766fb998eaca6c7416ba3d
[netconf.git] / netconf / netconf-netty-util / src / test / java / org / opendaylight / netconf / nettyutil / handler / ssh / authentication / LoginPasswordHandlerTest.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.netconf.nettyutil.handler.ssh.authentication;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.mockito.Mockito.doNothing;
12 import static org.mockito.Mockito.doReturn;
13 import static org.mockito.Mockito.mock;
14 import static org.mockito.Mockito.verify;
15
16 import org.junit.Test;
17 import org.opendaylight.netconf.shaded.sshd.client.future.AuthFuture;
18 import org.opendaylight.netconf.shaded.sshd.client.session.ClientSession;
19
20 public class LoginPasswordHandlerTest {
21     @Test
22     public void testLoginPassword() throws Exception {
23         final LoginPasswordHandler loginPasswordHandler = new LoginPasswordHandler("user", "pwd");
24         assertEquals("user", loginPasswordHandler.getUsername());
25
26         final ClientSession session = mock(ClientSession.class);
27         doNothing().when(session).addPasswordIdentity("pwd");
28         doReturn(mock(AuthFuture.class)).when(session).auth();
29         loginPasswordHandler.authenticate(session);
30
31         verify(session).addPasswordIdentity("pwd");
32         verify(session).auth();
33     }
34 }