d6181051d106f7a535174667b8e41e3b5fb62f22
[moon.git] /
1 /*
2  * Copyright (c) 2016 Red Hat, Inc.  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.idpmapping;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertTrue;
14
15 import java.util.ArrayList;
16 import java.util.HashMap;
17 import java.util.Map;
18 import org.junit.Test;
19
20 public class TokenTest {
21
22     private final Map<String, Object> namespace = new HashMap<String, Object>() {
23         {
24             put("foo1", new HashMap<String, String>() {
25                 {
26                     put("0", "1");
27                 }
28             });
29         }
30     };
31     private Object input = "$foo1[0]";
32     private Token token = new Token(input, namespace);
33     private Token mapToken = new Token(namespace, namespace);
34
35     @Test
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);
41     }
42
43     @Test
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);
52     }
53
54     @Test
55     public void testGet() {
56         assertNotNull(token.get());
57         assertTrue(token.get("0") == "1");
58         assertNotNull(mapToken.get());
59         assertTrue(mapToken.get(0) == namespace);
60     }
61
62     @Test
63     public void testGetMapValue() {
64         assertTrue(mapToken.getMapValue() == namespace);
65     }
66 }