# Java Security Exception when inheriting from ESIntegTestCase

**URL:** <https://discuss.elastic.co/t/java-security-exception-when-inheriting-from-esintegtestcase/115546>\
**Category:** Elasticsearch\
**Created:** [January 15, 2018, 12:48pm UTC](https://discuss.elastic.co/t/java-security-exception-when-inheriting-from-esintegtestcase/115546 "2018-01-15T12:48:16Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![prakharjain17](https://avatars.discourse-cdn.com/v4/letter/p/d2c977/32.png) [@prakharjain17](https://discuss.elastic.co/u/prakharjain17)\
**Post date:** [January 15, 2018, 12:48pm UTC](https://discuss.elastic.co/t/java-security-exception-when-inheriting-from-esintegtestcase/115546/1 "2018-01-15T12:48:16Z")

</div>

Hi,  
I need to run elasticsearch for my tests, so I thought of using ESIntegTestCase.  
But, I am getting this error when am running tests :

```
java.security.AccessControlException: access denied ("java.lang.RuntimePermission" 
"accessClassInPackage.sun.reflect")
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
```

---

<div class="post-metadata">

**Author:** ![prakharjain17](https://avatars.discourse-cdn.com/v4/letter/p/d2c977/32.png) [@prakharjain17](https://discuss.elastic.co/u/prakharjain17)\
**Post date:** [January 15, 2018, 12:56pm UTC](https://discuss.elastic.co/t/java-security-exception-when-inheriting-from-esintegtestcase/115546/2 "2018-01-15T12:56:25Z")

</div>

Down the logs, I am getting this error:

```
REPRODUCE WITH: gradle null -Dtests.seed=A49214270E342DC -
Dtests.class=com.tesco.productservice.elasticsearch.ElasticsearchClientTest -
Dtests.method="test_termQuery_success" -Dtests.locale=tr -Dtests.timezone=Asia/Aden

NotSerializableExceptionWrapper[class_cast_exception: org.apache.logging.slf4j.SLF4JLoggerContext 
cannot be cast to org.apache.logging.log4j.core.LoggerContext
```

---

<div class="post-metadata">

**Author:** ![prakharjain17](https://avatars.discourse-cdn.com/v4/letter/p/d2c977/32.png) [@prakharjain17](https://discuss.elastic.co/u/prakharjain17)\
**Post date:** [January 15, 2018, 1:09pm UTC](https://discuss.elastic.co/t/java-security-exception-when-inheriting-from-esintegtestcase/115546/3 "2018-01-15T13:09:14Z")

</div>

Resolved it using

```
-Dtests.security.manager=false

```

But, now I am getting this error:

```
NotSerializableExceptionWrapper[class_cast_exception: org.apache.logging.slf4j.SLF4JLoggerContext 
cannot be cast to org.apache.logging.log4j.core.LoggerContext
]
    at __randomizedtesting.SeedInfo.seed([B3478902C17CBF90:CF246C1FE8179A6D]:0)
```

---

<div class="post-metadata">

**Author:** ![prakharjain17](https://avatars.discourse-cdn.com/v4/letter/p/d2c977/32.png) [@prakharjain17](https://discuss.elastic.co/u/prakharjain17)\
**Post date:** [January 15, 2018, 1:24pm UTC](https://discuss.elastic.co/t/java-security-exception-when-inheriting-from-esintegtestcase/115546/4 "2018-01-15T13:24:53Z")

</div>

Here is my gradle file for reference:

```
compile fileTree (dir: 'libs')
compile (
        'javax.json:javax.json-api:1.0',
        'org.elasticsearch.client:elasticsearch-rest-high-level-client:6.1.1',
        'com.fasterxml.jackson.module:jackson-module-afterburner:2.1.5',
        'com.wordnik:swagger-core_2.10:1.3.0',
        'org.apache.commons:commons-jexl:2.1.1',
        'commons-collections:commons-collections:3.2.1',
        'commons-io:commons-io:2.2',
        'org.slf4j:slf4j-api:1.7.24',
        'org.apache.logging.log4j:log4j-to-slf4j:2.9.1',
        'org.apache.logging.log4j:log4j-api:2.9.1',
        'org.apache.logging.log4j:log4j-core:2.9.1'
)
compile('com.tesco.productservice:RSCouchBase:5.3.2') {
    exclude group: 'org.mockito'
    exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
compile('io.dropwizard:dropwizard-core:0.9.1') {
    exclude group: 'org.glassfish.hk2.external'
    exclude group: 'org.slf4j'
    exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
compile('io.dropwizard:dropwizard-client:0.9.1') {
    exclude group: 'org.glassfish.hk2.external'
    exclude group: 'org.slf4j'
    exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
compile('io.dropwizard:dropwizard-assets:0.9.1') {
    exclude group: 'org.glassfish.hk2.external'
    exclude group: 'org.slf4j'
    exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
compile('io.dropwizard:dropwizard-testing:0.9.1') {
    exclude group: 'org.glassfish.hk2.external'
    exclude group: 'org.slf4j'
    exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
compile('com.tesco.productservice:common-auth:1.0.0') {
    exclude group: 'org.glassfish.hk2.external'
    exclude group: 'org.slf4j'
    exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
compile ('com.wordnik:swagger-jaxrs_2.10:1.3.0') {
    exclude group: 'javax.ws.rs', module: 'jsr311-api'
    exclude group: 'org.reflections'
    exclude group: 'org.scala-lang'
}
// https://mvnrepository.com/artifact/org.slf4j/jul-to-slf4j
compile group: 'org.slf4j', name: 'jul-to-slf4j', version: '1.7.25'

def withoutHamcrestCore = {exclude group: 'org.hamcrest', module: 'hamcrest-core'}
def withoutSecureMock = {exclude group: 'org.elasticsearch', module: 'securemock'}

testCompile (
        'org.slf4j:slf4j-api:1.7.24',
        'org.apache.logging.log4j:log4j-to-slf4j:2.9.1',
        'org.apache.logging.log4j:log4j-api:2.9.1',
        'org.apache.logging.log4j:log4j-core:2.9.1'
)
testCompile 'info.cukes:cucumber-picocontainer:1.2.4', withoutHamcrestCore
testCompile 'info.cukes:cucumber-java:1.2.4', withoutHamcrestCore
testCompile 'info.cukes:cucumber-junit:1.2.4', withoutHamcrestCore
testCompile 'junit:junit:4.11', withoutHamcrestCore
testCompile 'org.elasticsearch.test:framework:6.1.1', withoutSecureMock
testCompile 'org.apache.lucene:lucene-test-framework:6.1.1'
```

---

<div class="post-metadata">

**Author:** ![prakharjain17](https://avatars.discourse-cdn.com/v4/letter/p/d2c977/32.png) [@prakharjain17](https://discuss.elastic.co/u/prakharjain17)\
**Post date:** [January 15, 2018, 1:57pm UTC](https://discuss.elastic.co/t/java-security-exception-when-inheriting-from-esintegtestcase/115546/5 "2018-01-15T13:57:42Z")

</div>

Close this, I have read all the issues and found out it is better to spin new instances from maven plugin and not use ESIntegTestCase.

What a waste of time!

I request community to remove Testing Column in Elastic search guide and provide a good library for creating local nodes for testing purpose. (I don't use maven and I am having problem to learn maven and convert that plugin to suit my needs)

---

<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:** [January 15, 2018, 2:10pm UTC](https://discuss.elastic.co/t/java-security-exception-when-inheriting-from-esintegtestcase/115546/6 "2018-01-15T14:10:56Z")

</div>

Some ideas there:

> [@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:** ![prakharjain17](https://avatars.discourse-cdn.com/v4/letter/p/d2c977/32.png) [@prakharjain17](https://discuss.elastic.co/u/prakharjain17)\
**Post date:** [January 15, 2018, 2:15pm UTC](https://discuss.elastic.co/t/java-security-exception-when-inheriting-from-esintegtestcase/115546/7 "2018-01-15T14:15:43Z")

</div>

Just tell me why this is written here:  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/testing.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/testing.html)

---

<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:** [February 12, 2018, 2:15pm UTC](https://discuss.elastic.co/t/java-security-exception-when-inheriting-from-esintegtestcase/115546/8 "2018-02-12T14:15:54Z")

</div>

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