switch twitter-history-elasticsearch to testng
Project: http://git-wip-us.apache.org/repos/asf/incubator-streams-examples/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-streams-examples/commit/f49b3a11 Tree: http://git-wip-us.apache.org/repos/asf/incubator-streams-examples/tree/f49b3a11 Diff: http://git-wip-us.apache.org/repos/asf/incubator-streams-examples/diff/f49b3a11 Branch: refs/heads/master Commit: f49b3a11497402c8ef141e88bad2a594024f99d3 Parents: e7bcb0d Author: Steve Blackmon @steveblackmon <sblack...@apache.org> Authored: Thu Dec 15 12:57:02 2016 -0600 Committer: Steve Blackmon @steveblackmon <sblack...@apache.org> Committed: Thu Dec 15 12:57:02 2016 -0600 ---------------------------------------------------------------------- local/twitter-history-elasticsearch/pom.xml | 19 +++++-------- .../test/TwitterHistoryElasticsearchIT.java | 30 +++++++++++++------- 2 files changed, 26 insertions(+), 23 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-streams-examples/blob/f49b3a11/local/twitter-history-elasticsearch/pom.xml ---------------------------------------------------------------------- diff --git a/local/twitter-history-elasticsearch/pom.xml b/local/twitter-history-elasticsearch/pom.xml index a220568..6fb6048 100644 --- a/local/twitter-history-elasticsearch/pom.xml +++ b/local/twitter-history-elasticsearch/pom.xml @@ -61,6 +61,12 @@ <type>test-jar</type> </dependency> <dependency> + <groupId>org.testng</groupId> + <artifactId>testng</artifactId> + <version>${testng.version}</version> + <scope>test</scope> + </dependency> + <dependency> <groupId>org.hamcrest</groupId> <artifactId>hamcrest-all</artifactId> <version>1.3</version> @@ -258,21 +264,10 @@ <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-failsafe-plugin</artifactId> - <configuration> - <!-- Run integration test suite rather than individual tests. --> - <excludes> - <exclude>**/*Test.java</exclude> - <exclude>**/*Tests.java</exclude> - </excludes> - <includes> - <include>**/*IT.java</include> - <include>**/*ITs.java</include> - </includes> - </configuration> <dependencies> <dependency> <groupId>org.apache.maven.surefire</groupId> - <artifactId>surefire-junit47</artifactId> + <artifactId>surefire-testng</artifactId> <version>${failsafe.plugin.version}</version> </dependency> </dependencies> http://git-wip-us.apache.org/repos/asf/incubator-streams-examples/blob/f49b3a11/local/twitter-history-elasticsearch/src/test/java/org/apache/streams/example/test/TwitterHistoryElasticsearchIT.java ---------------------------------------------------------------------- diff --git a/local/twitter-history-elasticsearch/src/test/java/org/apache/streams/example/test/TwitterHistoryElasticsearchIT.java b/local/twitter-history-elasticsearch/src/test/java/org/apache/streams/example/test/TwitterHistoryElasticsearchIT.java index dc1b443..07c1d88 100644 --- a/local/twitter-history-elasticsearch/src/test/java/org/apache/streams/example/test/TwitterHistoryElasticsearchIT.java +++ b/local/twitter-history-elasticsearch/src/test/java/org/apache/streams/example/test/TwitterHistoryElasticsearchIT.java @@ -18,15 +18,19 @@ package org.apache.streams.example.test; -import com.typesafe.config.Config; -import com.typesafe.config.ConfigFactory; -import com.typesafe.config.ConfigParseOptions; import org.apache.streams.config.ComponentConfigurator; import org.apache.streams.elasticsearch.ElasticsearchClientManager; import org.apache.streams.example.TwitterHistoryElasticsearch; import org.apache.streams.example.TwitterHistoryElasticsearchConfiguration; + +import com.typesafe.config.Config; +import com.typesafe.config.ConfigFactory; +import com.typesafe.config.ConfigParseOptions; + import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; +import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; +import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse; import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest; import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse; import org.elasticsearch.action.search.SearchRequestBuilder; @@ -34,15 +38,16 @@ import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.client.Client; import org.elasticsearch.client.Requests; import org.elasticsearch.cluster.health.ClusterHealthStatus; -import org.junit.Before; -import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; import java.io.File; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNotEquals; +import static org.testng.AssertJUnit.assertTrue; /** * Example stream that populates elasticsearch with activities from twitter userstream in real-time @@ -56,7 +61,7 @@ public class TwitterHistoryElasticsearchIT { private int count = 0; - @Before + @BeforeClass public void prepareTest() throws Exception { Config reference = ConfigFactory.load(); @@ -65,7 +70,7 @@ public class TwitterHistoryElasticsearchIT { Config testResourceConfig = ConfigFactory.parseFileAnySyntax(conf_file, ConfigParseOptions.defaults().setAllowMissing(false)); Config typesafe = testResourceConfig.withFallback(reference).resolve(); testConfiguration = new ComponentConfigurator<>(TwitterHistoryElasticsearchConfiguration.class).detectConfiguration(typesafe); - testClient = new ElasticsearchClientManager(testConfiguration.getElasticsearch()).getClient(); + testClient = ElasticsearchClientManager.getInstance(testConfiguration.getElasticsearch()).client(); ClusterHealthRequest clusterHealthRequest = Requests.clusterHealthRequest(); ClusterHealthResponse clusterHealthResponse = testClient.admin().cluster().health(clusterHealthRequest).actionGet(); @@ -73,8 +78,11 @@ public class TwitterHistoryElasticsearchIT { IndicesExistsRequest indicesExistsRequest = Requests.indicesExistsRequest(testConfiguration.getElasticsearch().getIndex()); IndicesExistsResponse indicesExistsResponse = testClient.admin().indices().exists(indicesExistsRequest).actionGet(); - assertFalse(indicesExistsResponse.isExists()); - + if(indicesExistsResponse.isExists()) { + DeleteIndexRequest deleteIndexRequest = Requests.deleteIndexRequest(testConfiguration.getElasticsearch().getIndex()); + DeleteIndexResponse deleteIndexResponse = testClient.admin().indices().delete(deleteIndexRequest).actionGet(); + assertTrue(deleteIndexResponse.isAcknowledged()); + }; } @Test