Commit 8722d3f741e7454eecb94bb44a8a31deb8a4e71a

Authored by Sergey Matvienko
1 parent 41371a4f

dependency org.apache.httpcomponents httpclient moved from blackboxtests to the …

…room POM. httpclient used in edge, but not explicitly added by dependency management. httpclient version with no change.
... ... @@ -63,6 +63,21 @@
63 63 <scope>test</scope>
64 64 </dependency>
65 65 <dependency>
  66 + <groupId>org.springframework.boot</groupId>
  67 + <artifactId>spring-boot-starter-test</artifactId>
  68 + <scope>test</scope>
  69 + </dependency>
  70 + <dependency>
  71 + <groupId>org.junit.vintage</groupId>
  72 + <artifactId>junit-vintage-engine</artifactId>
  73 + <scope>test</scope>
  74 + </dependency>
  75 + <dependency>
  76 + <groupId>org.awaitility</groupId>
  77 + <artifactId>awaitility</artifactId>
  78 + <scope>test</scope>
  79 + </dependency>
  80 + <dependency>
66 81 <groupId>ch.qos.logback</groupId>
67 82 <artifactId>logback-classic</artifactId>
68 83 </dependency>
... ...
... ... @@ -16,20 +16,25 @@
16 16 package org.thingsboard.server.msa;
17 17
18 18 import lombok.extern.slf4j.Slf4j;
  19 +import org.apache.commons.io.FileUtils;
  20 +import org.junit.Assert;
19 21 import org.junit.ClassRule;
20 22 import org.junit.extensions.cpsuite.ClasspathSuite;
21   -import org.junit.rules.ExternalResource;
22 23 import org.junit.runner.RunWith;
23 24 import org.testcontainers.containers.DockerComposeContainer;
24 25 import org.testcontainers.containers.wait.strategy.Wait;
25   -import org.testcontainers.utility.Base58;
26 26
27 27 import java.io.File;
  28 +import java.io.IOException;
  29 +import java.nio.charset.StandardCharsets;
  30 +import java.nio.file.Files;
  31 +import java.nio.file.Path;
28 32 import java.time.Duration;
29   -import java.util.Arrays;
30   -import java.util.HashMap;
31   -import java.util.List;
32   -import java.util.Map;
  33 +
  34 +import static org.hamcrest.CoreMatchers.containsString;
  35 +import static org.hamcrest.CoreMatchers.is;
  36 +import static org.hamcrest.CoreMatchers.not;
  37 +import static org.hamcrest.MatcherAssert.assertThat;
33 38
34 39 @RunWith(ClasspathSuite.class)
35 40 @ClasspathSuite.ClassnameFilters({"org.thingsboard.server.msa.*Test"})
... ... @@ -50,7 +55,7 @@ public class ContainerTestSuite {
50 55 String transportsLogRegexp = ".*Going to recalculate partitions.*";
51 56
52 57 testContainer = new DockerComposeContainer<>(
53   - new File("./../../docker/docker-compose.yml"),
  58 + new File(removeContainerName("./../../docker/docker-compose.yml")),
54 59 new File("./../../docker/docker-compose.postgres.yml"),
55 60 new File("./../../docker/docker-compose.postgres.volumes.yml"),
56 61 new File("./../../docker/docker-compose.kafka.yml"))
... ... @@ -73,4 +78,31 @@ public class ContainerTestSuite {
73 78 }
74 79 return testContainer;
75 80 }
  81 +
  82 + /**
  83 + * This workaround is actual until issue will be resolved:
  84 + * Support container_name in docker-compose file #2472 https://github.com/testcontainers/testcontainers-java/issues/2472
  85 + * docker-compose files which contain container_name are not supported and the creation of DockerComposeContainer fails due to IllegalStateException.
  86 + * This has been introduced in #1151 as a quick fix for unintuitive feedback. https://github.com/testcontainers/testcontainers-java/issues/1151
  87 + * Using the latest testcontainers and waiting for the fix...
  88 + * */
  89 + private static String removeContainerName(String sourceFilename) {
  90 + String outputFilename = null;
  91 + try {
  92 + String sourceContent = FileUtils.readFileToString(new File(sourceFilename), StandardCharsets.UTF_8);
  93 + String outputContent = sourceContent.replace("container_name: \"${LOAD_BALANCER_NAME}\"", "");
  94 + assertThat(outputContent, (not(containsString("container_name"))));
  95 +
  96 + Path tempFile = Files.createTempFile("docker-compose", ".yml"); // the file looks like /tmp/docker-compose713972234379430232.yml
  97 + log.info("tempFile is {}", tempFile.toFile().getAbsolutePath());
  98 +
  99 + FileUtils.writeStringToFile(tempFile.toFile(), outputContent, StandardCharsets.UTF_8);
  100 + outputFilename = tempFile.toFile().getAbsolutePath();
  101 + assertThat(FileUtils.readFileToString(new File(outputFilename), StandardCharsets.UTF_8), is(outputContent));
  102 +
  103 + } catch (IOException e) {
  104 + Assert.fail("failed to create tmp file " + e.getMessage());
  105 + }
  106 + return outputFilename;
  107 + }
76 108 }
... ...
... ... @@ -1731,6 +1731,12 @@
1731 1731 <artifactId>testcontainers</artifactId>
1732 1732 <version>${testcontainers.version}</version>
1733 1733 <scope>test</scope>
  1734 + <exclusions>
  1735 + <exclusion>
  1736 + <groupId>junit</groupId>
  1737 + <artifactId>junit</artifactId>
  1738 + </exclusion>
  1739 + </exclusions>
1734 1740 </dependency>
1735 1741 <dependency>
1736 1742 <groupId>org.zeroturnaround</groupId>
... ...