07070e33712056bf7936e6dd8d004722b96b303d
[nemo.git] / nemo-impl / src / test / java / org / opendaylight / nemo / user / tenantmanager / AAATest.java
1 /*
2  * Copyright (c) 2015 Huawei, 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 user.tenantmanager;
9
10 import junit.framework.TestCase;
11 import org.junit.Assert;
12 import org.junit.Before;
13 import org.junit.Test;
14 import org.opendaylight.nemo.user.tenantmanager.AAA;
15 import org.opendaylight.nemo.user.tenantmanager.TenantManage;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.UserId;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.users.User;
18 import java.util.HashMap;
19 import java.util.Map;
20
21 import static org.junit.Assert.*;
22 import static org.mockito.Mockito.*;
23 /**
24  * Created by zhangmeng on 2015/12/15.
25  */
26 public class AAATest extends TestCase {
27     private TenantManage tenantManage;
28     private AAA aaa;
29     @Before
30     public void setUp() throws Exception {
31         tenantManage = mock(TenantManage.class);
32         aaa = new AAA(tenantManage);
33     }
34
35     @Test
36     public void testCheckUser() throws Exception {
37         UserId userId = mock(UserId.class);
38         User user = mock(User.class);
39         Map<UserId, User> users = new HashMap<UserId, User>();
40
41         when(tenantManage.getUsers())
42                 .thenReturn(null)
43                 .thenReturn(users);
44         Assert.assertTrue(aaa.checkUser(userId).equals("The user is not exist."));
45         verify(tenantManage).getUsers();
46
47         users.put(userId, user);
48         Assert.assertTrue(users != null);
49         Assert.assertTrue(aaa.checkUser(userId) == null);
50         verify(tenantManage,times(2)).getUsers();
51     }
52 }