Skip to content

Commit

Permalink
- Test whether index has patis-field;
Browse files Browse the repository at this point in the history
- Explicit dependency on Hamcrest-core, as suggested on stackoverflow to avoid NoSuchMethodError (not succesful).
  • Loading branch information
Kasper van den Berg committed Apr 5, 2013
1 parent 6c11e5d commit ac72ce1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
7 changes: 7 additions & 0 deletions Search/Indexer/pom.xml
Expand Up @@ -145,6 +145,13 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
28 changes: 26 additions & 2 deletions Search/Indexer/src/test/java/indexer/IndexerTest.java
Expand Up @@ -7,18 +7,24 @@
import java.util.logging.Logger;
import nl.maastro.eureca.aida.indexer.tika.parser.ZylabMetadataXml;
import nl.maastro.eureca.aida.indexer.tika.parser.ZylabMetadataXmlDetector;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexableField;
import org.apache.tika.detect.DefaultDetector;
import org.apache.tika.detect.Detector;
import org.apache.tika.parser.AutoDetectParser;
import org.hamcrest.FeatureMatcher;
import org.hamcrest.Matchers;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.equalTo;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasKey;
import org.junit.BeforeClass;

/**
Expand Down Expand Up @@ -137,6 +143,24 @@ public void testIndexAll() throws IOException {
assertEquals(Utilities.deleteDir(new File(indexdir)), true);

}

@Test
public void testIndexContainsField() throws IOException {
testIndexZylab();
DirectoryReader dirReader = DirectoryReader.open(iwUtil.getIndexWriter(), false);
assertEquals(dirReader.maxDoc(), 1);
// assertThat(dirReader.document(0).getFields(), hasItem(
// new FeatureMatcher<IndexableField, String>(equalTo("Patisnummer"), "Field key", "Field key") {
// @Override
// protected String featureValueOf(IndexableField actual) {
// return actual.name();
// } } ));
System.out.println(String.format("maxdoc: %d", dirReader.maxDoc()));
Document doc = dirReader.document(0);
for(IndexableField field : doc.getFields()) {
System.out.println(String.format("Field name: %s,\t value: %s", field.name(), field.stringValue()));
}
}

public void testIndexAll(boolean deleteAfterwards) throws IOException {
this.deleteAfterwards = deleteAfterwards;
Expand Down

0 comments on commit ac72ce1

Please sign in to comment.