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