Skip to content

Commit 19def0d

Browse files
committed
Update JsonToElasticsearchBulkTest to reflect changed behaviour when ID key/path is omitted.
Without ID key (i.e., with empty ID path) the bulk action metadata no longer include the `_id` field.
1 parent 35ce879 commit 19def0d

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

metafacture-elasticsearch/src/test/java/org/metafacture/elasticsearch/JsonToElasticsearchBulkTest.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public final class JsonToElasticsearchBulkTest {
4545
private static final String TYPE1 = "T1";
4646
private static final String INDEX1 = "I1";
4747

48-
private static final String METADATA = "{'index':{'_index':'I1','_type':'T1','_id':%s}}";
48+
private static final String METADATA = "{'index':{'_index':'I1','_type':'T1'%s}}";
4949

5050
private static final String ENTITY_SEPARATOR1 = ".";
5151
private static final String ENTITY_SEPARATOR2 = ":";
@@ -122,7 +122,13 @@ public void testShouldNotExtractEmptyIdKey() {
122122
@Test
123123
public void testShouldNotExtractEmptyIdPath() {
124124
setBulk(new String[0]);
125-
shouldNotExtractId("{'L1':'V1','L2':'V2','L3':'V3'}");
125+
shouldExtractId("{'L1':'V1','L2':'V2','L3':'V3'}", null);
126+
}
127+
128+
@Test
129+
public void testShouldNotExtractOmittedIdPath() {
130+
bulk = new JsonToElasticsearchBulk(TYPE1, INDEX1);
131+
shouldExtractId("{'L1':'V1','L2':'V2','L3':'V3'}", null);
126132
}
127133

128134
@Test
@@ -220,7 +226,9 @@ private void shouldExtractId(final String obj, final String idValue, final Strin
220226
bulk.setReceiver(receiver);
221227
bulk.process(fixQuotes(obj));
222228

223-
verify(receiver).process(fixQuotes(String.format(METADATA, idValue) + "\n" + resultObj));
229+
final String metadata = String.format(METADATA, idValue != null ? ",'_id':" + idValue : "");
230+
231+
verify(receiver).process(fixQuotes(metadata + "\n" + resultObj));
224232
verifyNoMoreInteractions(receiver);
225233
}
226234

0 commit comments

Comments
 (0)