-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for merging meta data files
- Loading branch information
Showing
53 changed files
with
615 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
beans/src/test/java/fr/pilato/elasticsearch/crawler/fs/beans/DocUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package fr.pilato.elasticsearch.crawler.fs.beans; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.junit.Test; | ||
|
||
import java.io.InputStream; | ||
import java.nio.file.Path; | ||
|
||
import static fr.pilato.elasticsearch.crawler.fs.beans.DocUtils.prettyPrint; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.*; | ||
|
||
public class DocUtilsTest { | ||
private static final Logger logger = LogManager.getLogger(DocUtilsTest.class); | ||
|
||
// Get the tags path from resources | ||
Path path = Path.of(DocUtilsTest.class.getResource("/tags").getPath()); | ||
|
||
@Test | ||
public void testMergeDocsWithNothing() { | ||
Doc mergedDoc = DocUtils.getMergedJsonDoc(getDocSample(), (InputStream) null); | ||
logger.trace("Merged doc: {}", prettyPrint(mergedDoc)); | ||
|
||
assertThat(mergedDoc.getContent(), is("This is a test")); | ||
assertThat(mergedDoc.getFile().getFilename(), is("foo.txt")); | ||
assertThat(mergedDoc.getMeta(), notNullValue()); | ||
assertThat(mergedDoc.getPath(), notNullValue()); | ||
assertThat(mergedDoc.getAttachment(), nullValue()); | ||
assertThat(mergedDoc.getExternal(), nullValue()); | ||
assertThat(mergedDoc.getAttributes(), nullValue()); | ||
} | ||
|
||
@Test | ||
public void testMergeDocsWithAJsonFile() { | ||
testMergeDocsWithAFile(path.resolve("meta-as-json.json")); | ||
} | ||
|
||
@Test | ||
public void testMergeDocsWithAYamlFile() { | ||
testMergeDocsWithAFile(path.resolve(".meta.yml")); | ||
} | ||
|
||
private void testMergeDocsWithAFile(Path file) { | ||
Doc mergedDoc = DocUtils.getMergedDoc(getDocSample(), file); | ||
logger.trace("Merged doc: {}", prettyPrint(mergedDoc)); | ||
|
||
assertThat(mergedDoc.getContent(), is("This is a test")); | ||
assertThat(mergedDoc.getFile().getFilename(), is("foo.txt")); | ||
assertThat(mergedDoc.getMeta(), notNullValue()); | ||
assertThat(mergedDoc.getPath(), notNullValue()); | ||
assertThat(mergedDoc.getExternal(), notNullValue()); | ||
assertThat(mergedDoc.getExternal().get("tenantId"), is(23)); | ||
assertThat(mergedDoc.getAttachment(), nullValue()); | ||
assertThat(mergedDoc.getAttributes(), nullValue()); | ||
} | ||
|
||
private Doc getDocSample() { | ||
File file = new File(); | ||
file.setFilename("foo.txt"); | ||
Doc doc = new Doc(); | ||
doc.setFile(file); | ||
doc.setContent("This is a test"); | ||
return doc; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
external: | ||
tenantId: 23 | ||
company: "shoe company" | ||
projectId: 34 | ||
project: "business development" | ||
daysOpen: | ||
- "Mon" | ||
- "Tue" | ||
- "Wed" | ||
- "Thu" | ||
- "Fri" | ||
products: | ||
- brand: "nike" | ||
size: 41 | ||
sub: "Air MAX" | ||
- brand: "reebok" | ||
size: 43 | ||
sub: "Pump" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"external": { | ||
"tenantId" : 23, | ||
"company": "shoe company", | ||
"projectId": 34, | ||
"project": "business development", | ||
"daysOpen": [ | ||
"Mon", | ||
"Tue", | ||
"Wed", | ||
"Thu", | ||
"Fri" | ||
], | ||
"products": [ | ||
{ | ||
"brand": "nike", | ||
"size": 41, | ||
"sub": "Air MAX" | ||
}, | ||
{ | ||
"brand": "reebok", | ||
"size": 43, | ||
"sub": "Pump" | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.