EftarFileTest.java revision 137
442N/A/*
442N/A * CDDL HEADER START
442N/A *
442N/A * The contents of this file are subject to the terms of the
442N/A * Common Development and Distribution License (the "License").
442N/A * You may not use this file except in compliance with the License.
442N/A *
442N/A * See LICENSE.txt included in this distribution for the specific
442N/A * language governing permissions and limitations under the License.
442N/A *
442N/A * When distributing Covered Code, include this CDDL HEADER in each
442N/A * file and include the License file at LICENSE.txt.
442N/A * If applicable, add the following below this CDDL HEADER, with the
442N/A * fields enclosed by brackets "[]" replaced with your own identifying
442N/A * information: Portions Copyright [yyyy] [name of copyright owner]
442N/A *
442N/A * CDDL HEADER END
442N/A */
442N/A
442N/A/*
442N/A * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
442N/A * Use is subject to license terms.
442N/A */
442N/Apackage org.opensolaris.opengrok.web;
442N/A
442N/Aimport java.io.File;
472N/Aimport java.io.FileWriter;
442N/Aimport java.io.PrintWriter;
442N/Aimport org.junit.After;
442N/Aimport org.junit.AfterClass;
442N/Aimport org.junit.Before;
442N/Aimport org.junit.BeforeClass;
442N/Aimport org.junit.Test;
442N/Aimport static org.junit.Assert.*;
442N/A
442N/A/**
442N/A * JUnit test to test the EftarFile-system
442N/A */
442N/Apublic class EftarFileTest {
442N/A
442N/A private static File tsv;
442N/A private static File eftar;
442N/A
442N/A public EftarFileTest() {
442N/A }
442N/A
442N/A @BeforeClass
442N/A public static void setUpClass() throws Exception {
442N/A tsv = File.createTempFile("paths", ".tsv");
442N/A eftar = File.createTempFile("paths", ".eftar");
442N/A
442N/A PrintWriter out = null;
442N/A try {
442N/A out = new PrintWriter(new FileWriter(tsv));
442N/A StringBuilder sb = new StringBuilder();
442N/A for (int ii = 0; ii < 100; ii++) {
442N/A sb.append("/path");
442N/A sb.append(Integer.toString(ii));
442N/A out.print(sb.toString());
442N/A out.print("\tDescription ");
442N/A out.println(Integer.toString(ii));
442N/A }
442N/A out.flush();
472N/A } finally {
472N/A try { out.close(); } catch (Exception e) { }
472N/A }
472N/A }
472N/A
513N/A @AfterClass
472N/A public static void tearDownClass() throws Exception {
472N/A if (tsv != null) {
472N/A tsv.delete();
472N/A }
472N/A
472N/A if (eftar != null) {
472N/A eftar.delete();
442N/A }
442N/A }
442N/A
442N/A @Before
513N/A public void setUp() throws Exception {
472N/A }
442N/A
442N/A @After
472N/A public void tearDown() throws Exception {
442N/A }
442N/A
442N/A /**
442N/A * Test creation of an EftarFile
472N/A * @throws java.lang.Exception if an error occurs while creating the
472N/A * eftar file
472N/A */
472N/A @Test
472N/A public void createEftarFile() throws Exception {
472N/A String[] args = new String[2];
513N/A args[0] = tsv.getAbsolutePath();
472N/A args[1] = eftar.getAbsolutePath();
472N/A
472N/A EftarFile ef = new EftarFile();
472N/A ef.create(args);
472N/A }
472N/A
472N/A /**
472N/A * Test usage of an EftarFile
472N/A * @throws java.lang.Exception if an error occurs while accessing the
1024N/A * eftar file
*/
@Test
public void searchEftarFile() throws Exception {
System.out.println("search");
EftarFileReader er = new EftarFileReader(eftar.getAbsolutePath());
StringBuilder sb = new StringBuilder();
StringBuilder match = new StringBuilder();
match.append("Description ");
int offset = match.length();
for (int ii = 0; ii < 100; ii++) {
sb.append("/path");
sb.append(Integer.toString(ii));
match.setLength(offset);
match.append(Integer.toString(ii));
assertEquals(match.toString(), er.get(sb.toString()));
}
er.close();
}
}