1858526e3dfc866ce4d78a6237bdf9830398ec60
[aaa.git] / aaa-shiro / impl / src / test / java / org / opendaylight / aaa / datastore / h2 / H2TokenStoreTest.java
1 /*
2  * Copyright (c) 2016, 2017 Inocybe Technologies. 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
9 package org.opendaylight.aaa.datastore.h2;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNull;
13
14 import org.junit.After;
15 import org.junit.Test;
16 import org.opendaylight.aaa.api.Authentication;
17 import org.opendaylight.aaa.shiro.tokenauthrealm.auth.AuthenticationBuilder;
18 import org.opendaylight.aaa.shiro.tokenauthrealm.auth.ClaimBuilder;
19
20 /**
21  * Unit Test for H2TokenStore.
22  *
23  * @author mserngawy
24  */
25 public class H2TokenStoreTest {
26
27     private final H2TokenStore h2TokenStore = new H2TokenStore(36000, 3600);
28
29     @After
30     public void teardown() throws Exception {
31         h2TokenStore.close();
32     }
33
34     @Test
35     public void testTokenStore() throws InterruptedException {
36         final String fooToken = "foo_token";
37         Authentication auth = new AuthenticationBuilder(
38                 new ClaimBuilder().setUser("foo").setUserId("1234").addRole("admin").build()).build();
39         h2TokenStore.put(fooToken, auth);
40         assertEquals(auth, h2TokenStore.get(fooToken));
41         h2TokenStore.delete(fooToken);
42         assertNull(h2TokenStore.get(fooToken));
43     }
44 }