AT&T 2.0.19 Code drop, stage 3
[aaf/authz.git] / auth / auth-deforg / src / test / java / org / onap / aaf / org / test / JU_Identities.java
1 /*******************************************************************************
2  * ============LICENSE_START====================================================
3  * * org.onap.aaf
4  * * ===========================================================================
5  * * Copyright © 2017 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  * 
24  */
25 package org.onap.aaf.org.test;
26
27 import java.io.File;
28 import java.io.IOException;
29
30 import org.junit.After;
31 import org.junit.AfterClass;
32 import org.junit.Assert;
33 import org.junit.Before;
34 import org.junit.BeforeClass;
35 import org.junit.Test;
36 import org.onap.aaf.auth.env.AuthzEnv;
37 import org.onap.aaf.auth.env.AuthzTrans;
38 import org.onap.aaf.auth.local.AbsData.Reuse;
39 import org.onap.aaf.org.Identities;
40 import org.onap.aaf.org.Identities.Data;
41
42 /**
43  *
44  */
45 public class JU_Identities {
46
47         private static final String DATA_IDENTITIES = "/opt/app/onap/data/identities.dat";
48         private static File fids;
49         private static Identities ids;
50         private static AuthzEnv env;
51
52         /**
53          * @throws java.lang.Exception
54          */
55         @BeforeClass
56         public static void setUpBeforeClass() throws Exception {
57                 env = new AuthzEnv();
58                 AuthzTrans trans = env.newTransNoAvg();
59                 // Note: utilize TimeTaken, from trans.start if you want to time.
60                 fids = new File(DATA_IDENTITIES);
61                 if(fids.exists()) {
62                         ids = new Identities(fids);
63                         ids.open(trans, 5000);
64                 } else {
65                         
66                         throw new Exception("Data File for Tests, \"" + DATA_IDENTITIES 
67                                         + "\" must exist before test can run. (Current dir is " + System.getProperty("user.dir") + ")");
68                 }
69         }
70
71         /**
72          * @throws java.lang.Exception
73          */
74         @AfterClass
75         public static void tearDownAfterClass() throws Exception {
76                 AuthzTrans trans = env.newTransNoAvg();
77                 if(ids!=null) {
78                         ids.close(trans);
79                 }
80         }
81
82         /**
83          * @throws java.lang.Exception
84          */
85         @Before
86         public void setUp() throws Exception {
87         }
88
89         /**
90          * @throws java.lang.Exception
91          */
92         @After
93         public void tearDown() throws Exception {
94         }
95  
96         @Test
97         public void test() throws IOException {
98                 Reuse reuse = ids.reuse(); // this object can be reused within the same thread.
99                 Data id = ids.find("osaaf",reuse);
100                 Assert.assertNotNull(id);
101                 System.out.println(id);
102
103                 id = ids.find("mmanager",reuse);
104                 Assert.assertNotNull(id);
105                 System.out.println(id);
106
107                 //TODO Fill out JUnit with Tests of all Methods in "Data id"
108         }
109
110 }