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