# Testing rest clients in Java

**URL:** <https://discuss.elastic.co/t/testing-rest-clients-in-java/106836>\
**Category:** Elasticsearch\
**Created:** [November 8, 2017, 9:50am UTC](https://discuss.elastic.co/t/testing-rest-clients-in-java/106836 "2017-11-08T09:50:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gringogordo](https://avatars.discourse-cdn.com/v4/letter/g/a87d85/32.png) [@gringogordo](https://discuss.elastic.co/u/gringogordo)\
**Post date:** [November 8, 2017, 9:50am UTC](https://discuss.elastic.co/t/testing-rest-clients-in-java/106836/1 "2017-11-08T09:50:25Z")

</div>

I would like to add some basic tests into my Java app. I'm using es 5.6 with low & high level rest client. Essentially, at this early stage I would just like to create an index, add some documents & validate them. Having had a 1/2 hour scoot around the web I'm thinking the easiest thing to do is to just create an index on the local server (dev/test etc) and then tear it down at the end.

It strikes me that if there is a failure in the process I will leave some 'orphaned' mini indexes in place but I can probably live with that and maybe even write some code to list indexes and tidy the node at some later point (or just restore a clean node!).

Anyway I was just wondering if this is a reasonable approach or whether there is some kind of clever (in memory ?) process to do this off the main elasticSearch installation ? (Even better if someone has some code to help a simpleton onto the right track 😉 but really I'm mainly looking for guidance as to the approach I should take.

Thanks

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 8, 2017, 10:14am UTC](https://discuss.elastic.co/t/testing-rest-clients-in-java/106836/2 "2017-11-08T10:14:55Z")

</div>

You can read:

> [@In memory testing with RestHighLevelClient](https://discuss.elastic.co/t/in-memory-testing-with-resthighlevelclient/106196/6):
>
> This will not happen. To do integration tests, you can: Use the Gradle tools elasticsearch already has. You can read some information about this here: [#21119](https://github.com/elastic/elasticsearch/issues/21119). This [sample project](https://github.com/joel-costigliola/elastic-search-test) shows how to use Elasticsearch Test Classes Use the Maven plugin: [GitHub - alexcojocaru/elasticsearch-maven-plugin: A Maven plugin to run a single node Elasticsearch cluster during the integration test phase of a build](https://github.com/alexcojocaru/elasticsearch-maven-plugin) Use Ant scripts like [https://david.pilato.fr/blog/2016-07-29-elasticsearch-real-integration-tests/](http://david.pilato.fr/blog/2016/10/18/elasticsearch-real-integration-tests-updated-for-ga/) …

---

<div class="post-metadata">

**Author:** ![gringogordo](https://avatars.discourse-cdn.com/v4/letter/g/a87d85/32.png) [@gringogordo](https://discuss.elastic.co/u/gringogordo)\
**Post date:** [November 8, 2017, 10:31am UTC](https://discuss.elastic.co/t/testing-rest-clients-in-java/106836/3 "2017-11-08T10:31:57Z")

</div>

Thanks and apologies for not finding that for myself, I kept getting results more pertinent to previous versions. Let me know if I should delete this post & immolate myself StackOverflow style 😉

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 8, 2017, 10:55am UTC](https://discuss.elastic.co/t/testing-rest-clients-in-java/106836/4 "2017-11-08T10:55:28Z")

</div>

I had hard time TBH to find my own answer! 😛

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 6, 2017, 10:56am UTC](https://discuss.elastic.co/t/testing-rest-clients-in-java/106836/5 "2017-12-06T10:56:05Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
