2 * Copyright (c) 2016 Cisco Systems, Inc. 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.authn.mdsal.store.util;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
14 import java.util.ArrayList;
15 import java.util.List;
16 import org.junit.Test;
17 import org.junit.runner.RunWith;
18 import org.mockito.Mock;
19 import org.opendaylight.aaa.api.Authentication;
20 import org.opendaylight.yang.gen.v1.urn.aaa.yang.authn.claims.rev141029.token_cache_times.token_list.UserTokens;
21 import org.opendaylight.yang.gen.v1.urn.aaa.yang.authn.claims.rev141029.tokencache.Claims;
22 import org.opendaylight.yang.gen.v1.urn.aaa.yang.authn.claims.rev141029.tokencache.ClaimsBuilder;
23 import org.opendaylight.yang.gen.v1.urn.aaa.yang.authn.claims.rev141029.tokencache.ClaimsKey;
24 import org.powermock.modules.junit4.PowerMockRunner;
26 @RunWith(PowerMockRunner.class)
27 public class AuthNStoreUtilTest {
29 private String token = "foo_token_test";
30 private String userId = "123";
31 private Long expire = new Long(365);
33 private Authentication auth;
35 private UserTokens tokens;
37 private Claims claims;
40 public void testCreateInstIdentifierForTokencache() {
41 assertTrue(AuthNStoreUtil.createInstIdentifierForTokencache("") == null);
42 assertNotNull(AuthNStoreUtil.createInstIdentifierForTokencache(token));
46 public void testCreateInstIdentifierUserTokens() {
47 assertTrue(AuthNStoreUtil.createInstIdentifierUserTokens("", "") == null);
48 assertNotNull(AuthNStoreUtil.createInstIdentifierUserTokens(userId, token));
52 public void testCreateClaimsRecord() {
53 assertTrue(AuthNStoreUtil.createClaimsRecord("", null) == null);
54 assertNotNull(AuthNStoreUtil.createClaimsRecord(token, auth));
58 public void testCreateUserTokens() {
59 assertTrue(AuthNStoreUtil.createUserTokens("", null) == null);
60 assertNotNull(AuthNStoreUtil.createUserTokens(token, expire));
64 public void testCreateTokenList() {
65 assertTrue(AuthNStoreUtil.createTokenList(null, "") == null);
66 assertNotNull(AuthNStoreUtil.createTokenList(tokens, userId));
70 public void testConvertClaimToAuthentication() {
71 ClaimsKey claimsKey = new ClaimsKey(token);
72 ClaimsBuilder claimsBuilder = new ClaimsBuilder();
73 claimsBuilder.setClientId("123");
74 claimsBuilder.setDomain("foo_domain");
75 claimsBuilder.setKey(claimsKey);
76 List<String> roles = new ArrayList<String>();
77 roles.add("foo_role");
78 claimsBuilder.setRoles(roles);
79 claimsBuilder.setToken(token);
80 claimsBuilder.setUser("foo_usr");
81 claimsBuilder.setUserId(userId);
82 Claims fooClaims = claimsBuilder.build();
84 assertTrue(AuthNStoreUtil.convertClaimToAuthentication(null, expire) == null);
85 assertNotNull(AuthNStoreUtil.convertClaimToAuthentication(fooClaims, expire));