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