6d4daa90d0ea437b1d370e2d26a6b198b771fed8
[aaf/authz.git] / auth / auth-core / src / test / java / org / onap / aaf / auth / local / test / JU_AbsData.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 package org.onap.aaf.auth.local.test;
22
23 import static org.junit.Assert.*;
24
25 import org.junit.Test;
26 import org.mockito.Mock;
27 import org.mockito.Mockito;
28 import org.onap.aaf.auth.env.AuthzTrans;
29 import org.onap.aaf.auth.env.AuthzTransFilter;
30 import org.onap.aaf.auth.local.AbsData;
31 import org.onap.aaf.auth.local.DataFile;
32 import org.onap.aaf.auth.local.TextIndex;
33 import org.onap.aaf.auth.local.AbsData.Iter;
34 import org.onap.aaf.auth.local.AbsData.Reuse;
35
36 import junit.framework.Assert;
37
38 import static org.junit.Assert.*;
39 import static org.mockito.Matchers.*;
40 import static org.mockito.Mockito.*;
41
42 import java.io.BufferedWriter;
43 import java.io.File;
44 import java.io.FileOutputStream;
45 import java.io.IOException;
46 import java.io.OutputStreamWriter;
47 import java.lang.reflect.InvocationTargetException;
48 import java.lang.reflect.Method;
49 import java.security.Principal;
50
51 public class JU_AbsData {
52         char character = 'x';
53         String filePath = "test/output_.key";
54         File keyfile = new File(filePath);
55         AuthzTrans trans = mock(AuthzTrans.class);
56         
57         private class AbsDataStub extends AbsData {
58
59                 
60                 public AbsDataStub(File dataf, char sepChar, int maxLineSize, int fieldOffset) {
61                         super(dataf, sepChar, maxLineSize, fieldOffset);
62                         // TODO Auto-generated constructor stub
63                 }
64                 
65         }
66
67         @Test
68         public void testStub() throws IOException {
69                 char character = 'x';
70                 String filePath = "test/output_.key";
71                 File keyfile = new File(filePath);
72                 FileOutputStream is = new FileOutputStream(keyfile);
73         OutputStreamWriter osw = new OutputStreamWriter(is);
74         BufferedWriter  w = new BufferedWriter(osw);
75         for(int i = 0; i< 10; i++) {            //Write lines to file
76                 w.write("a\nsdfasdfxasdf" + i + "\n");
77         }
78         w.close();
79                 AbsDataStub ads = new AbsDataStub(keyfile, character, 0, 0);
80                 ads.skipLines(0);
81                 ads.name();
82                 
83                 long lng = 1823286886660L;
84                 //ads.open(trans, lng);
85                 keyfile.delete();
86         }
87         
88         @Test
89         public void testClose() throws IOException {
90                 AbsDataStub ads = new AbsDataStub(keyfile, character, 0, 0);
91                 ads.close(trans);
92         }
93         
94         @Test
95         public void testReuse() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
96                 char character = 'x';
97                 AbsDataStub ads = new AbsDataStub(keyfile, character, 0, 0);
98                 Reuse reuse = ads.reuse();
99                 reuse.reset();
100                 Assert.assertEquals("", reuse.at(1));
101                 Assert.assertNull(reuse.next());
102                 //reuse.atToEnd(0);
103                 //reuse.pos(10);
104                 keyfile.delete();
105         }
106         
107         @Test
108         public void testIter() throws IOException {
109                 AbsDataStub ads = new AbsDataStub(keyfile, character, 0, 0);
110                 TextIndex textIndex = new TextIndex(keyfile);
111                 //Iter iter = ads.iterator();           //Need actual input to run textIndex.create to have a datafile to read
112
113         }
114
115 }