How to use testElasticsearch8SecureByDefault method of org.testcontainers.elasticsearch.ElasticsearchContainerTest class

Best Testcontainers-java code snippet using org.testcontainers.elasticsearch.ElasticsearchContainerTest.testElasticsearch8SecureByDefault

Source:ElasticsearchContainerTest.java Github

copy

Full Screen

...258 .as("We should not be able to activate security with an OSS License")259 .isInstanceOf(IllegalArgumentException.class);260 }261 @Test262 public void testElasticsearch8SecureByDefault() throws Exception {263 try (264 ElasticsearchContainer container = new ElasticsearchContainer(265 "docker.elastic.co/elasticsearch/elasticsearch:8.1.2"266 )267 ) {268 // Start the container. This step might take some time...269 container.start();270 Response response = getClusterHealth(container);271 assertThat(response.getStatusLine().getStatusCode()).isEqualTo(200);272 assertThat(EntityUtils.toString(response.getEntity())).contains("cluster_name");273 }274 }275 @Test276 public void testElasticsearch8SecureByDefaultCustomCaCertFails() throws Exception {277 final MountableFile mountableFile = MountableFile.forClasspathResource("http_ca.crt");278 String caPath = "/tmp/http_ca.crt";279 try (280 ElasticsearchContainer container = new ElasticsearchContainer(281 "docker.elastic.co/elasticsearch/elasticsearch:8.1.2"282 )283 .withCopyToContainer(mountableFile, caPath)284 .withCertPath(caPath)285 ) {286 container.start();287 // this is expected, as a different cert is used for creating the SSL context288 assertThat(catchThrowable(() -> getClusterHealth(container)))289 .as(290 "PKIX path validation failed: java.security.cert.CertPathValidatorException: Path does not chain with any of the trust anchors"291 )292 .isInstanceOf(SSLHandshakeException.class);293 }294 }295 @Test296 public void testElasticsearch8SecureByDefaultHttpWaitStrategy() throws Exception {297 final HttpWaitStrategy httpsWaitStrategy = Wait298 .forHttps("/")299 .forPort(9200)300 .forStatusCode(200)301 .withBasicCredentials(ELASTICSEARCH_USERNAME, ELASTICSEARCH_PASSWORD)302 // trusting self-signed certificate303 .allowInsecure();304 try (305 ElasticsearchContainer container = new ElasticsearchContainer(306 "docker.elastic.co/elasticsearch/elasticsearch:8.1.2"307 )308 .waitingFor(httpsWaitStrategy)309 ) {310 // Start the container. This step might take some time...311 container.start();312 Response response = getClusterHealth(container);313 assertThat(response.getStatusLine().getStatusCode()).isEqualTo(200);314 assertThat(EntityUtils.toString(response.getEntity())).contains("cluster_name");315 }316 }317 @Test318 public void testElasticsearch8SecureByDefaultFailsSilentlyOnLatestImages() throws Exception {319 // this test exists for custom images by users that use the `latest` tag320 // even though the version might be older than version 8321 // this tags an old 7.x version as :latest322 tagImage("docker.elastic.co/elasticsearch/elasticsearch:7.9.2", "elasticsearch-tc-older-release", "latest");323 DockerImageName image = DockerImageName324 .parse("elasticsearch-tc-older-release:latest")325 .asCompatibleSubstituteFor("docker.elastic.co/elasticsearch/elasticsearch");326 try (ElasticsearchContainer container = new ElasticsearchContainer(image)) {327 container.start();328 Response response = getClient(container).performRequest(new Request("GET", "/_cluster/health"));329 assertThat(response.getStatusLine().getStatusCode()).isEqualTo(200);330 assertThat(EntityUtils.toString(response.getEntity())).contains("cluster_name");331 }332 }...

Full Screen

Full Screen

testElasticsearch8SecureByDefault

Using AI Code Generation

copy

Full Screen

1package org.testcontainers.elasticsearch;2import org.junit.Test;3import org.testcontainers.containers.Network;4import org.testcontainers.elasticsearch.ElasticsearchContainer;5import org.testcontainers.junit.jupiter.Container;6import org.testcontainers.junit.jupiter.Testcontainers;7public class ElasticsearchContainerTest {8 private static final ElasticsearchContainer elasticsearch = new ElasticsearchContainer("docker.elastic.co/elasticsearch/elasticsearch:7.6.2")9 .withNetwork(Network.SHARED)10 .withNetworkAliases("elasticsearch");11 public void testElasticsearch8SecureByDefault() {12 elasticsearch.start();13 }14}

Full Screen

Full Screen

testElasticsearch8SecureByDefault

Using AI Code Generation

copy

Full Screen

1public class ElasticsearchContainerTest {2 public void testElasticsearch8SecureByDefault() {3 try (ElasticsearchContainer container = new ElasticsearchContainer(ElasticsearchImageName.parse("docker.elastic.co/elasticsearch/elasticsearch:8.0.0-SNAPSHOT"))) {4 container.start();5 RestHighLevelClient client = container.createClient();6 }7 }8}9public class ElasticsearchContainerTest {10 public void testElasticsearch8SecureByDefault() {11 try (ElasticsearchContainer container = new ElasticsearchContainer(ElasticsearchImageName.parse("docker.elastic.co/elasticsearch/elasticsearch:8.0.0-SNAPSHOT"))) {12 container.start();13 RestHighLevelClient client = container.createClient();14 }15 }16}17public class ElasticsearchContainerTest {18 public void testElasticsearch8SecureByDefault() {19 try (ElasticsearchContainer container = new ElasticsearchContainer(ElasticsearchImageName.parse("docker.elastic.co/elasticsearch/elasticsearch:8.0.0-SNAPSHOT"))) {20 container.start();21 RestHighLevelClient client = container.createClient();22 }23 }24}25public class ElasticsearchContainerTest {26 public void testElasticsearch8SecureByDefault() {27 try (ElasticsearchContainer container = new ElasticsearchContainer(ElasticsearchImageName.parse("docker.elastic.co/elasticsearch/elasticsearch:8.0.0-SNAPSHOT"))) {28 container.start();29 RestHighLevelClient client = container.createClient();30 }31 }32}33public class ElasticsearchContainerTest {34 public void testElasticsearch8SecureByDefault() {35 try (ElasticsearchContainer container = new ElasticsearchContainer(Elasticsearch

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful