Skip to content

Commit

Permalink
Uncommenting the ElasticSearchServiceTest
Browse files Browse the repository at this point in the history
  • Loading branch information
dadepo committed Dec 2, 2017
1 parent 8412c99 commit 81fd76e
Showing 1 changed file with 76 additions and 66 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
package org.oruko.dictionary.elasticsearch;

import org.elasticsearch.client.Client;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.test.ElasticsearchIntegrationTest;
import org.junit.Before;
import org.junit.Test;
import org.oruko.dictionary.model.NameEntry;
import org.oruko.dictionary.search.api.SearchService;

import java.io.IOException;

import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope;

/**
Expand All @@ -11,71 +21,71 @@
*/
@ClusterScope(scope = ElasticsearchIntegrationTest.Scope.TEST)
public class ElasticSearchServiceTest extends ElasticsearchIntegrationTest {
// private String dictionary = "dictionary";
// private ESConfig esConfig;
// SearchService searchService;
//
// private class TestNode implements org.elasticsearch.node.Node {
//
// @Override
// public Settings settings() {
// return null;
// }
//
// @Override
// public Client client() {
// return org.elasticsearch.test.ElasticsearchIntegrationTest.client();
// }
//
// @Override
// public org.elasticsearch.node.Node start() {
// return null;
// }
//
// @Override
// public org.elasticsearch.node.Node stop() {
// return null;
// }
//
// @Override
// public void close() {
//
// }
//
// @Override
// public boolean isClosed() {
// return false;
// }
// }
//
// @Before
// public void setup() throws IOException {
//
// esConfig = new ESConfig();
// esConfig.setDocumentType("nameentry");
// esConfig.setIndexName("dictionary");
// esConfig.setClusterName("yoruba_name_dictionary");
// esConfig.setHostName("localhost");
// esConfig.setPort(9300);
//
// createIndex(dictionary);
//
// flushAndRefresh();
//
// searchService = new ElasticSearchService(new TestNode(), esConfig);
// }
//
// @Test
// public void testGetByName() throws IOException {
// XContentBuilder lagbaja = jsonBuilder().startObject()
// .field("name", "jamo")
// .endObject();
// index(esConfig.getIndexName(), esConfig.getDocumentType(), lagbaja);
//
// flushAndRefresh();
//
// Map<String, Object> result = searchService.getByName("jamo");
// assertEquals("jamo", result.get("name"));
// }
private String dictionary = "dictionary";
private ESConfig esConfig;
SearchService searchService;

private class TestNode implements org.elasticsearch.node.Node {

@Override
public Settings settings() {
return null;
}

@Override
public Client client() {
return org.elasticsearch.test.ElasticsearchIntegrationTest.client();
}

@Override
public org.elasticsearch.node.Node start() {
return null;
}

@Override
public org.elasticsearch.node.Node stop() {
return null;
}

@Override
public void close() {

}

@Override
public boolean isClosed() {
return false;
}
}

@Before
public void setup() throws IOException {

esConfig = new ESConfig();
esConfig.setDocumentType("nameentry");
esConfig.setIndexName("dictionary");
esConfig.setClusterName("yoruba_name_dictionary");
esConfig.setHostName("localhost");
esConfig.setPort(9300);

createIndex(dictionary);

flushAndRefresh();

searchService = new ElasticSearchService(new TestNode(), esConfig);
}

@Test
public void testGetByName() throws IOException {
XContentBuilder lagbaja = jsonBuilder().startObject()
.field("name", "jamo")
.endObject();
index(esConfig.getIndexName(), esConfig.getDocumentType(), lagbaja);

flushAndRefresh();

NameEntry jamo = searchService.getByName("jamo");
assertEquals("jamo", jamo.getName());
}

}

0 comments on commit 81fd76e

Please sign in to comment.