2 * Copyright (c) 2016 Red Hat, Inc. 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.idpmapping;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertTrue;
15 import java.util.ArrayList;
16 import java.util.HashMap;
18 import org.junit.Test;
20 public class TokenTest {
22 private final Map<String, Object> namespace = new HashMap<String, Object>() {
24 put("foo1", new HashMap<String, String>() {
31 private Object input = "$foo1[0]";
32 private Token token = new Token(input, namespace);
33 private Token mapToken = new Token(namespace, namespace);
36 public void testToken() {
37 assertEquals(token.toString(), input);
38 assertTrue(token.storageType == TokenStorageType.VARIABLE);
39 assertEquals(mapToken.toString(), "{foo1={0=1}}");
40 assertTrue(mapToken.storageType == TokenStorageType.CONSTANT);
44 public void testClassify() {
45 assertEquals(Token.classify(new ArrayList<>()), TokenType.ARRAY);
46 assertEquals(Token.classify(true), TokenType.BOOLEAN);
47 assertEquals(Token.classify(new Long(365)), TokenType.INTEGER);
48 assertEquals(Token.classify(new HashMap<String, Object>()), TokenType.MAP);
49 assertEquals(Token.classify(null), TokenType.NULL);
50 assertEquals(Token.classify(365.00), TokenType.REAL);
51 assertEquals(Token.classify("foo_str"), TokenType.STRING);
55 public void testGet() {
56 assertNotNull(token.get());
57 assertTrue(token.get("0") == "1");
58 assertNotNull(mapToken.get());
59 assertTrue(mapToken.get(0) == namespace);
63 public void testGetMapValue() {
64 assertTrue(mapToken.getMapValue() == namespace);