-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for new extra-tags function
- Loading branch information
Showing
4 changed files
with
147 additions
and
6 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
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
67 changes: 67 additions & 0 deletions
67
src/test/java/de/komoot/photon/utils/ConvertToJsonTest.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,67 @@ | ||
package de.komoot.photon.utils; | ||
|
||
import de.komoot.photon.ESBaseTester; | ||
import de.komoot.photon.PhotonDoc; | ||
import de.komoot.photon.elasticsearch.Importer; | ||
import org.elasticsearch.action.search.SearchResponse; | ||
import org.elasticsearch.action.search.SearchType; | ||
import org.elasticsearch.index.query.QueryBuilders; | ||
import org.json.JSONObject; | ||
import org.junit.After; | ||
import org.junit.Test; | ||
import static org.junit.Assert.*; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class ConvertToJsonTest extends ESBaseTester { | ||
|
||
@After | ||
public void tearDown() { | ||
deleteIndex(); | ||
shutdownES(); | ||
} | ||
|
||
private SearchResponse databaseFromDoc(PhotonDoc doc) throws IOException { | ||
setUpES(); | ||
Importer instance = new Importer(getClient(), "en", "maxspeed,website"); | ||
instance.add(doc); | ||
instance.finish(); | ||
refresh(); | ||
|
||
return getClient().prepareSearch("photon") | ||
.setSearchType(SearchType.QUERY_THEN_FETCH) | ||
.setQuery(QueryBuilders.matchAllQuery()) | ||
.execute() | ||
.actionGet(); | ||
} | ||
|
||
@Test | ||
public void testConvertWithExtraTags() throws IOException { | ||
Map<String, String> extratags = new HashMap<>(); | ||
extratags.put("website", "foo"); | ||
extratags.put("maxspeed", "100 mph"); | ||
|
||
SearchResponse response = databaseFromDoc(new PhotonDoc(1234, "N", 1000, "place", "city").extraTags(extratags)); | ||
|
||
List<JSONObject> json = new ConvertToJson("de").convert(response); | ||
|
||
JSONObject extra = json.get(0).getJSONObject("properties").getJSONObject("extra"); | ||
|
||
assertEquals(2, extra.length()); | ||
assertEquals("foo", extra.getString("website")); | ||
assertEquals("100 mph", extra.getString("maxspeed")); | ||
} | ||
|
||
|
||
@Test | ||
public void testConvertWithoutExtraTags() throws IOException { | ||
SearchResponse response = databaseFromDoc(new PhotonDoc(1234, "N", 1000, "place", "city")); | ||
|
||
List<JSONObject> json = new ConvertToJson("de").convert(response); | ||
|
||
assertNull(json.get(0).getJSONObject("properties").optJSONObject("extra")); | ||
} | ||
} |