1 /*******************************************************************************
2 * ============LICENSE_START====================================================
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
11 * * http://www.apache.org/licenses/LICENSE-2.0
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====================================================
21 ******************************************************************************/
22 package org.onap.aaf.auth.local.test;
24 import static org.junit.Assert.*;
25 import static org.mockito.Matchers.*;
26 import static org.mockito.Mockito.*;
28 import java.io.BufferedWriter;
30 import java.io.FileOutputStream;
31 import java.io.IOException;
32 import java.io.OutputStreamWriter;
33 import java.io.Writer;
34 import java.lang.reflect.Constructor;
35 import java.lang.reflect.InvocationTargetException;
36 import java.lang.reflect.Method;
37 import java.security.Principal;
39 import org.junit.Before;
40 import org.junit.Test;
41 import org.junit.runner.RunWith;
42 import org.mockito.Mock;
43 import org.mockito.Mockito;
44 import org.mockito.runners.MockitoJUnitRunner;
45 import org.onap.aaf.auth.env.AuthzTrans;
46 import org.onap.aaf.auth.env.AuthzTransFilter;
47 import org.onap.aaf.auth.local.AbsData.Reuse;
48 import org.onap.aaf.auth.local.AbsData;
49 import org.onap.aaf.auth.local.DataFile;
50 import org.onap.aaf.auth.local.TextIndex;
51 import org.onap.aaf.auth.local.TextIndex.Iter;
52 import org.onap.aaf.auth.local.test.JU_AbsData;
53 import org.onap.aaf.misc.env.Env;
54 import org.onap.aaf.misc.env.TimeTaken;
55 import org.onap.aaf.misc.env.Trans;
57 @RunWith(MockitoJUnitRunner.class)
58 public class JU_TextIndex {
66 private class AbsDataStub extends AbsData {
69 public AbsDataStub(File dataf, char sepChar, int maxLineSize, int fieldOffset) {
70 super(dataf, sepChar, maxLineSize, fieldOffset);
71 // TODO Auto-generated constructor stub
78 public void setUp() throws IOException{
80 String filePath = "test/output_key";
81 File keyfile = new File(filePath);
82 FileOutputStream is = new FileOutputStream(keyfile);
83 OutputStreamWriter osw = new OutputStreamWriter(is);
84 BufferedWriter w = new BufferedWriter(osw);
85 for(int i = 0; i< 10; i++) { //Write lines to file
86 w.write("a\nsdfasdfxasdf" + i + "\n");
90 datafile = new DataFile(keyfile, "r");
92 datafile = new DataFile(keyfile, "rws");// "S" for synchronized
95 trans = mock(Trans.class);
96 TimeTaken ttMock = mock(TimeTaken.class);
97 TimeTaken ttMock1 = mock(TimeTaken.class);
98 when(trans.start("Open Files", Env.SUB)).thenReturn(ttMock);
99 when(trans.start("Read", Env.SUB)).thenReturn(ttMock);
100 textIndex = new TextIndex(keyfile);
103 //textIndex.create(trans, datafile, 4, character, 2, 0); //TODO: AAF-111 once actual input is aquired
106 iter = textIndex.new Iter();
110 public void testClose() throws IOException {
115 public void testFind() throws IOException {
116 char character = 'x';
117 String filePath = "test/output_.key";
118 File keyfile = new File(filePath);
119 AbsDataStub ads = new AbsDataStub(keyfile, character, 0, 0);
120 Reuse reuse = ads.reuse();
121 textIndex.find("a", reuse , 0);
125 public void testIterNext() {
131 public void testIdx() throws ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
132 TextIndex outerObject = new TextIndex(file);
133 Class<?> idxClass = TextIndex.class.getDeclaredClasses()[0];
134 Constructor<?> idxConstructor = idxClass.getDeclaredConstructors()[0];
135 Class[] cArg = new Class[2];
136 cArg[0] = Object.class;
137 cArg[1] = Integer.class;
138 idxConstructor.setAccessible(true);
139 //Object innerObject = idxConstructor.newInstance(outerObject,cArg);
140 //idxConstructor.hashCode(); //TODO: AAF-111 access inner private class