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