Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dadoonet committed Mar 27, 2019
1 parent 9f0caa7 commit 33defd5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public void testDocumentWithExternalTags() throws Exception {
assertThat(hit.getSourceAsMap(), hasKey("file"));
assertThat((Map<String, Object>) hit.getSourceAsMap().get("file"), hasKey("extension"));
assertThat(hit.getSourceAsMap(), hasKey("meta"));
assertThat((Map<String, Object>) hit.getSourceAsMap().get("meta"), hasKey("raw"));
assertThat((Map<String, Object>) hit.getSourceAsMap().get("meta"), not(hasKey("raw")));

assertThat(hit.getSourceAsMap(), hasKey("external"));
Map<String, Object> external = (Map<String, Object>) hit.getSourceAsMap().get("external");
Expand Down Expand Up @@ -171,7 +171,7 @@ public void testDocumentWithExternalTags() throws Exception {
assertThat(hit.getSourceAsMap(), hasKey("file"));
assertThat((Map<String, Object>) hit.getSourceAsMap().get("file"), hasKey("extension"));
assertThat(hit.getSourceAsMap(), hasKey("meta"));
assertThat((Map<String, Object>) hit.getSourceAsMap().get("meta"), hasKey("raw"));
assertThat((Map<String, Object>) hit.getSourceAsMap().get("meta"), not(hasKey("raw")));

assertThat(hit.getSourceAsMap(), hasKey("external"));
Map<String, Object> external = (Map<String, Object>) hit.getSourceAsMap().get("external");
Expand Down Expand Up @@ -211,7 +211,7 @@ public void testDocumentWithExternalTags() throws Exception {
assertThat(hit.getSourceAsMap(), hasKey("file"));
assertThat((Map<String, Object>) hit.getSourceAsMap().get("file"), hasKey("extension"));
assertThat(hit.getSourceAsMap(), hasKey("meta"));
assertThat((Map<String, Object>) hit.getSourceAsMap().get("meta"), hasKey("raw"));
assertThat((Map<String, Object>) hit.getSourceAsMap().get("meta"), not(hasKey("raw")));

assertThat(hit.getSourceAsMap(), not(hasKey("external")));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,12 @@ public void test_mapping() throws Exception {

@Test
public void test_disable_raw() throws Exception {
Fs fs = startCrawlerDefinition()
.setRawMetadata(false)
.build();
startCrawler(getCrawlerName(), fs, endCrawlerDefinition(getCrawlerName()), null);
Fs.Builder builder = startCrawlerDefinition();
if (rarely()) {
// Sometimes we explicitly disable it but this is also the default value
builder.setRawMetadata(false);
}
startCrawler(getCrawlerName(), builder.build(), endCrawlerDefinition(getCrawlerName()), null);
ESSearchResponse searchResponse = countTestHelper(new ESSearchRequest().withIndex(getCrawlerName()), 1L, null);
for (ESSearchHit hit : searchResponse.getHits()) {
assertThat(extractFromPath(hit.getSourceAsMap(), Doc.FIELD_NAMES.META).get("raw"), nullValue());
Expand All @@ -86,12 +88,10 @@ public void test_disable_raw() throws Exception {

@Test
public void test_enable_raw() throws Exception {
Fs.Builder builder = startCrawlerDefinition();
if (rarely()) {
// Sometimes we explicitly set it but this is also the default value
builder.setRawMetadata(true);
}
startCrawler(getCrawlerName(), builder.build(), endCrawlerDefinition(getCrawlerName()), null);
Fs fs = startCrawlerDefinition()
.setRawMetadata(true)
.build();
startCrawler(getCrawlerName(), fs, endCrawlerDefinition(getCrawlerName()), null);
ESSearchResponse searchResponse = countTestHelper(new ESSearchRequest().withIndex(getCrawlerName()), 1L, null);
for (ESSearchHit hit : searchResponse.getHits()) {
assertThat(extractFromPath(hit.getSourceAsMap(), Doc.FIELD_NAMES.META).get("raw"), notNullValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private void defaultSettingsTester(FsSettings settings) {
assertThat(settings.getFs().isIndexFolders(), is(true));
assertThat(settings.getFs().isJsonSupport(), is(false));
assertThat(settings.getFs().isLangDetect(), is(false));
assertThat(settings.getFs().isRawMetadata(), is(true));
assertThat(settings.getFs().isRawMetadata(), is(false));
assertThat(settings.getFs().isRemoveDeleted(), is(true));
assertThat(settings.getFs().isStoreSource(), is(false));
assertThat(settings.getFs().isXmlSupport(), is(false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ public void testPdfIssue221() throws IOException {
*/
@Test
public void testXmlIssue163() throws IOException {
Doc doc = extractFromFile("issue-163.xml");
FsSettings fsSettings = FsSettings.builder(getCurrentTestName())
.setFs(Fs.builder().setRawMetadata(true).build())
.build();
Doc doc = extractFromFile("issue-163.xml", fsSettings);

// Extracted content
assertThat(doc.getContent(), is(" \n"));
Expand Down Expand Up @@ -747,7 +750,10 @@ public void testProtectedDocument() throws IOException {
}

private Doc extractFromFileExtension(String extension) throws IOException {
return extractFromFile("test." + extension);
FsSettings fsSettings = FsSettings.builder(getCurrentTestName())
.setFs(Fs.builder().setRawMetadata(true).build())
.build();
return extractFromFile("test." + extension, fsSettings);
}

private Doc extractFromFile(String filename) throws IOException {
Expand Down

0 comments on commit 33defd5

Please sign in to comment.