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
77 public void setUp() throws IOException{
79 String filePath = "test/output_key";
80 File keyfile = new File(filePath);
81 FileOutputStream is = new FileOutputStream(keyfile);
82 OutputStreamWriter osw = new OutputStreamWriter(is);
83 BufferedWriter w = new BufferedWriter(osw);
84 for(int i = 0; i< 10; i++) { //Write lines to file
85 w.write("a\nsdfasdfxasdf" + i + "\n");
89 datafile = new DataFile(keyfile, "r");
91 datafile = new DataFile(keyfile, "rws");// "S" for synchronized
94 trans = mock(Trans.class);
95 TimeTaken ttMock = mock(TimeTaken.class);
96 TimeTaken ttMock1 = mock(TimeTaken.class);
97 when(trans.start("Open Files", Env.SUB)).thenReturn(ttMock);
98 when(trans.start("Read", Env.SUB)).thenReturn(ttMock);
99 textIndex = new TextIndex(keyfile);
102 //textIndex.create(trans, datafile, 4, character, 2, 0); //TODO: AAF-111 once actual input is aquired
105 iter = textIndex.new Iter();
109 public void testClose() throws IOException {
114 public void testFind() throws IOException {
115 char character = 'x';
116 String filePath = "test/output_.key";
117 File keyfile = new File(filePath);
118 AbsDataStub ads = new AbsDataStub(keyfile, character, 0, 0);
119 Reuse reuse = ads.reuse();
120 textIndex.find("a", reuse , 0);
124 public void testIterNext() {
130 public void testIdx() throws ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
131 TextIndex outerObject = new TextIndex(file);
132 Class<?> idxClass = TextIndex.class.getDeclaredClasses()[0];
133 Constructor<?> idxConstructor = idxClass.getDeclaredConstructors()[0];
134 Class[] cArg = new Class[2];
135 cArg[0] = Object.class;
136 cArg[1] = Integer.class;
137 idxConstructor.setAccessible(true);
138 //Object innerObject = idxConstructor.newInstance(outerObject,cArg);
139 //idxConstructor.hashCode(); //TODO: AAF-111 access inner private class