11d58ea0e53bf18d6da4db61c1599d7d9796533c
[aaf/authz.git] / cadi / aaf / src / test / java / org / onap / aaf / cadi / oauth / test / JU_AAFToken.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
4  * ===========================================================================
5  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6  * ===========================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END====================================================
19  *
20  */
21
22 package org.onap.aaf.cadi.oauth.test;
23
24 import static org.junit.Assert.*;
25 import org.junit.*;
26
27 import java.util.UUID;
28
29 import org.onap.aaf.cadi.CadiException;
30 import org.onap.aaf.cadi.oauth.AAFToken;
31
32 public class JU_AAFToken {
33
34         @Test
35         public void testMax() throws CadiException {
36                 UUID uuid = new UUID(Long.MAX_VALUE,Long.MAX_VALUE);
37                 String token = AAFToken.toToken(uuid);
38                 UUID uuid2 = AAFToken.fromToken(token);
39                 assertEquals(uuid, uuid2);
40         }
41         
42         @Test
43         public void testMin() throws CadiException {
44                 UUID uuid = new UUID(Long.MIN_VALUE,Long.MIN_VALUE);
45                 String token = AAFToken.toToken(uuid);
46                 UUID uuid2 = AAFToken.fromToken(token);
47                 assertEquals(uuid, uuid2);
48         }
49
50         @Test
51         public void testRandom() throws CadiException {
52                 for(int i=0;i<100;++i) {
53                         UUID uuid = UUID.randomUUID();
54                         String token = AAFToken.toToken(uuid);
55                         UUID uuid2 = AAFToken.fromToken(token);
56                         assertEquals(uuid, uuid2);
57                 }
58         }
59
60         @Test
61         public void nullTest() {
62                 // Invalid characters
63                 assertNull(AAFToken.fromToken("~~invalid characters~~"));
64                 
65                 // Invalid CADI tokens
66                 assertNull(AAFToken.fromToken("ABCDEF"));
67                 assertNull(AAFToken.fromToken("12345678901234567890123456789012345678"));
68         }
69
70 }