ad7fbe0c20e0fbcc11096ae2e27c1c1edd9467df
[aaf/authz.git] / auth / auth-batch / src / test / java / org / onap / aaf / auth / helpers / test / JU_Cred.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
23 package org.onap.aaf.auth.helpers.test;
24
25 import static org.junit.Assert.*;
26 import org.junit.After;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.mockito.Mock;
30 import org.mockito.Mockito;
31 import org.onap.aaf.auth.common.Define;
32 import org.onap.aaf.auth.helpers.Cred;
33 import org.onap.aaf.auth.helpers.Cred.CredCount;
34 import org.onap.aaf.auth.helpers.Cred.Instance;
35 import org.onap.aaf.cadi.CadiException;
36 import org.onap.aaf.cadi.PropAccess;
37 import org.onap.aaf.cadi.config.Config;
38 import org.onap.aaf.misc.env.Trans;
39
40 import com.datastax.driver.core.Session;
41
42 import junit.framework.Assert;
43
44 import static org.mockito.Mockito.*;
45
46 import java.io.ByteArrayOutputStream;
47 import java.io.PrintStream;
48 import java.util.Date;
49
50 import org.junit.Test;
51
52 public class JU_Cred {
53         
54         private ByteArrayOutputStream outStream;
55         private ByteArrayOutputStream errStream;
56         Cred cred;
57         Instance instance;
58         Date date;
59         Integer integer;
60         PropAccess prop;
61         Define define = new Define();
62         Trans trans;
63         Session session;
64         CredCount cc;
65
66         @Before
67         public void setUp() throws CadiException {
68                 outStream = new ByteArrayOutputStream();
69                 errStream = new ByteArrayOutputStream();
70                 System.setOut(new PrintStream(outStream));
71                 System.setErr(new PrintStream(errStream));
72                 date = new Date();
73                 integer = new Integer(20);
74                 trans = mock(Trans.class);
75                 session = mock(Session.class);
76                 cc = new CredCount(3);
77                 prop = new PropAccess();
78                 prop.setProperty(Config.AAF_ROOT_NS, "org.onap.aaf");
79                 prop.setProperty(Config.AAF_ROOT_COMPANY,"test");
80                 define.set(prop);
81                 
82                 instance = new Instance(12, date, integer, 125642678910L);
83                 cred = new Cred("myid1234@aaf.att.com");
84         }
85         
86         @Test
87         public void testLast() {                //TODO: set instances 
88                 Assert.assertNull(cred.last(null));
89         }
90         
91         @Test
92         public void testTypes() {               //TODO: set instances 
93                 Assert.assertNotNull(cred.types());
94         }
95         
96         @Test
97         public void testCount() {               //TODO: set instances 
98                 Assert.assertNotNull(cred.count(3));
99         }
100         
101         @Test
102         public void testToString() {            //TODO: set instances 
103                 Assert.assertEquals("myid1234@aaf.att.com[]", cred.toString());
104         }
105         
106         @Test
107         public void testHashCode() {            //TODO: set instances 
108                 Assert.assertEquals(-1619358251, cred.hashCode());
109         }
110         
111         @Test
112         public void testEquals() {              //TODO: set instances 
113                 Assert.assertEquals(true, cred.equals("myid1234@aaf.att.com"));
114         }
115         
116         @Test
117         public void testInc() {         
118                 Date begin = new Date(date.getTime() - 10);
119                 Date after = new Date(date.getTime() + 10);
120                 cc.inc(-1, begin, after);
121                 cc.inc(1, begin, after);
122                 cc.inc(2, begin, after);
123                 cc.inc(200, begin, after);
124         }
125         
126         @Test
127         public void testAuthCount() {           //TODO: set instances 
128                 Assert.assertEquals(0, cc.authCount(1));
129         }
130         
131         @Test
132         public void testX509Count() {           //TODO: set instances 
133                 Assert.assertEquals(0, cc.x509Count(0));
134         }
135         
136         @After
137         public void cleanUp() {
138                 System.setErr(System.err);
139                 System.setOut(System.out);
140         }
141
142 }