I cannot seem to get a simple EsIntegrationTest to work in TestNg.
I get all kinds of java.security.AccessControlException exceptions.
Failing TestNg example
pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dummy</groupId>
<artifactId>test.es.integration.tests</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.8</version>
<scope>test</scope>
</dependency>
<!-- ElasticSearch integration tests -->
<dependency>
<groupId>org.elasticsearch.test</groupId>
<artifactId>framework</artifactId>
<version>5.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.6.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Example integration test class:
package com.dummy;
import java.io.IOException;
import java.net.URISyntaxException;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.test.ESIntegTestCase;
import org.testng.annotations.Test;
public class EsIntegrationTest extends ESIntegTestCase {
@Test
public void createIndexTest() throws IOException, URISyntaxException {
Client client = ESIntegTestCase.client();
assertNotNull(client);
final String indexName = "testindex";
final CreateIndexResponse createIndexResponse = client.admin().indices().prepareCreate(indexName).execute()
.actionGet();
if (!createIndexResponse.isAcknowledged()) {
fail("Could not create index: " + indexName);
}
}
}
mvn test fails with:
Running com.dummy.EsIntegrationViaJUnitTest
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator@2a33fae0
java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "accessDeclaredMembers")
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
...
Caused by: java.security.AccessControlException: access denied ("java.io.FilePermission" "F:\test.es.integration.tests\target\surefire-reports\com.dummy.EsIntegrationViaJUnitTest" "read")
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
...
JUnit works fine
Example pom:
just remove the testng dependency from the example above
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.8</version>
<scope>test</scope>
</dependency>
Test class:
replace the Test import with
import org.junit.Test;
the JUnit test starts an ES node, runs the test and succeeds.
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 6.151 sec
Question
Does this mean TestNg is not supported?
Which means I cannot migrate from 2.3 (where I still used the NodeBuilder to start ES test instances for my integration tests) to 5.0 which requires me to use ESIntegTestCase because there is no NodeBuilder alternative anymore.
I cannot switch from TestNg to JUnit, there are to much integration tests in my product that would require a rewrite.