2 * Copyright (c) 2014, 2015 Hewlett-Packard Development Company, L.P. and others. All rights reserved.
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
9 package org.opendaylight.aaa.store;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNull;
13 import static org.mockito.Mockito.mock;
14 import static org.opendaylight.aaa.store.DefaultTokenStore.MAX_CACHED_DISK;
15 import static org.opendaylight.aaa.store.DefaultTokenStore.MAX_CACHED_MEMORY;
16 import static org.opendaylight.aaa.store.DefaultTokenStore.SECS_TO_IDLE;
17 import static org.opendaylight.aaa.store.DefaultTokenStore.SECS_TO_LIVE;
19 import java.util.Dictionary;
20 import java.util.Hashtable;
21 import org.apache.felix.dm.Component;
22 import org.junit.After;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.opendaylight.aaa.AuthenticationBuilder;
26 import org.opendaylight.aaa.ClaimBuilder;
27 import org.opendaylight.aaa.api.Authentication;
28 import org.osgi.service.cm.ConfigurationException;
30 public class DefaultTokenStoreTest {
31 private static final String FOO_TOKEN = "foo_token";
32 private final DefaultTokenStore dts = new DefaultTokenStore();
33 private static final Dictionary<String, String> config = new Hashtable<>();
35 config.put(MAX_CACHED_MEMORY, Long.toString(3));
36 config.put(MAX_CACHED_DISK, Long.toString(3));
37 config.put(SECS_TO_IDLE, Long.toString(1));
38 config.put(SECS_TO_LIVE, Long.toString(1));
42 public void setup() throws ConfigurationException {
43 dts.init(mock(Component.class));
48 public void teardown() {
53 public void testCache() throws InterruptedException {
54 Authentication auth = new AuthenticationBuilder(new ClaimBuilder().setUser("foo")
56 .addRole("admin").build()).build();
57 dts.put(FOO_TOKEN, auth);
58 assertEquals(auth, dts.get(FOO_TOKEN));
59 dts.delete(FOO_TOKEN);
60 assertNull(dts.get(FOO_TOKEN));
61 dts.put(FOO_TOKEN, auth);
63 assertNull(dts.get(FOO_TOKEN));