Skip to content

Commit 573635f

Browse files
committed
Pull up testcontainer setup and teardown.
1 parent df085b0 commit 573635f

File tree

2 files changed

+67
-51
lines changed

2 files changed

+67
-51
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright (c) 2025 shift7 GmbH. All rights reserved.
3+
*/
4+
5+
package cloud.katta.cli.commands.hub;
6+
7+
import org.apache.logging.log4j.LogManager;
8+
import org.apache.logging.log4j.Logger;
9+
import org.junit.jupiter.api.AfterAll;
10+
import org.junit.jupiter.api.BeforeAll;
11+
import org.testcontainers.containers.ComposeContainer;
12+
import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy;
13+
14+
import java.io.File;
15+
import java.io.IOException;
16+
import java.net.URISyntaxException;
17+
import java.time.Duration;
18+
import java.util.HashMap;
19+
import java.util.Properties;
20+
import java.util.stream.Collectors;
21+
22+
import cloud.katta.testsetup.AbstractHubTest;
23+
import cloud.katta.testsetup.HubTestConfig;
24+
import cloud.katta.testsetup.HubTestSetupDockerExtension;
25+
26+
public class AbtractAdminCliIT extends AbstractHubTest {
27+
private static final Logger log = LogManager.getLogger(AbtractAdminCliIT.class.getName());
28+
public static ComposeContainer compose;
29+
30+
@BeforeAll
31+
public static void setupDocker() throws URISyntaxException, IOException {
32+
final HubTestConfig.Setup.DockerConfig configuration = new HubTestConfig.Setup.DockerConfig("/docker-compose-minio-localhost-hub.yml", "/.local.env", "local", "admin", "admin", "top-secret");
33+
log.info("Setup docker {}", configuration);
34+
final Properties props = new Properties();
35+
props.load(StorageProfileArchiveIT.class.getResourceAsStream(configuration.envFile));
36+
final HashMap<String, String> env = props.entrySet().stream().collect(
37+
Collectors.toMap(
38+
e -> String.valueOf(e.getKey()),
39+
e -> String.valueOf(e.getValue()),
40+
(prev, next) -> next, HashMap::new
41+
));
42+
env.put("HUB_ADMIN_USER", configuration.hubAdminUser);
43+
env.put("HUB_ADMIN_PASSWORD", configuration.hubAdminPassword);
44+
env.put("HUB_KEYCLOAK_SYSTEM_CLIENT_SECRET", configuration.hubKeycloakSystemClientSecret);
45+
compose = new ComposeContainer(
46+
new File(HubTestSetupDockerExtension.class.getResource(configuration.composeFile).toURI()))
47+
.withLocalCompose(true)
48+
.withPull(true)
49+
.withEnv(env)
50+
.withOptions(configuration.profile == null ? "" : String.format("--profile=%s", configuration.profile))
51+
.waitingFor("wait-1", new LogMessageWaitStrategy().withRegEx(".*exit 0.*").withStartupTimeout(Duration.ofMinutes(2)));
52+
compose.start();
53+
54+
log.info("Done setup docker {}", configuration);
55+
}
56+
57+
@AfterAll
58+
public static void teardownDocker() {
59+
try {
60+
compose.stop();
61+
}
62+
catch(Exception e) {
63+
log.warn(e);
64+
}
65+
}
66+
}

admin-cli/src/test/java/cloud/katta/cli/commands/hub/StorageProfileArchiveIT.java

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,13 @@
99

1010
import org.apache.logging.log4j.LogManager;
1111
import org.apache.logging.log4j.Logger;
12-
import org.junit.jupiter.api.AfterAll;
13-
import org.junit.jupiter.api.BeforeAll;
1412
import org.junit.jupiter.api.Test;
1513
import org.testcontainers.containers.ComposeContainer;
16-
import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy;
17-
18-
import java.io.File;
19-
import java.io.IOException;
20-
import java.net.URISyntaxException;
21-
import java.time.Duration;
22-
import java.util.HashMap;
23-
import java.util.Properties;
24-
import java.util.stream.Collectors;
2514

2615
import cloud.katta.protocols.hub.HubSession;
27-
import cloud.katta.testsetup.AbstractHubTest;
2816
import cloud.katta.testsetup.HubTestConfig;
29-
import cloud.katta.testsetup.HubTestSetupDockerExtension;
3017

31-
class StorageProfileArchiveIT extends AbstractHubTest {
18+
class StorageProfileArchiveIT extends AbtractAdminCliIT {
3219
private static final Logger log = LogManager.getLogger(StorageProfileArchiveIT.class.getName());
3320
public static ComposeContainer compose;
3421

@@ -43,41 +30,4 @@ public void testHubWorkflow() throws Exception {
4330

4431
new StorageProfileArchive().call("http://localhost:8280", accessToken, "732D43FA-3716-46C4-B931-66EA5405EF1C");
4532
}
46-
47-
@BeforeAll
48-
public static void setupDocker() throws URISyntaxException, IOException {
49-
final HubTestConfig.Setup.DockerConfig configuration = new HubTestConfig.Setup.DockerConfig("/docker-compose-minio-localhost-hub.yml", "/.local.env", "local", "admin", "admin", "top-secret");
50-
log.info("Setup docker {}", configuration);
51-
final Properties props = new Properties();
52-
props.load(StorageProfileArchiveIT.class.getResourceAsStream(configuration.envFile));
53-
final HashMap<String, String> env = props.entrySet().stream().collect(
54-
Collectors.toMap(
55-
e -> String.valueOf(e.getKey()),
56-
e -> String.valueOf(e.getValue()),
57-
(prev, next) -> next, HashMap::new
58-
));
59-
env.put("HUB_ADMIN_USER", configuration.hubAdminUser);
60-
env.put("HUB_ADMIN_PASSWORD", configuration.hubAdminPassword);
61-
env.put("HUB_KEYCLOAK_SYSTEM_CLIENT_SECRET", configuration.hubKeycloakSystemClientSecret);
62-
compose = new ComposeContainer(
63-
new File(HubTestSetupDockerExtension.class.getResource(configuration.composeFile).toURI()))
64-
.withLocalCompose(true)
65-
.withPull(true)
66-
.withEnv(env)
67-
.withOptions(configuration.profile == null ? "" : String.format("--profile=%s", configuration.profile))
68-
.waitingFor("wait-1", new LogMessageWaitStrategy().withRegEx(".*exit 0.*").withStartupTimeout(Duration.ofMinutes(2)));
69-
compose.start();
70-
71-
log.info("Done setup docker {}", configuration);
72-
}
73-
74-
@AfterAll
75-
public static void teardownDocker() {
76-
try {
77-
compose.stop();
78-
}
79-
catch(Exception e) {
80-
log.warn(e);
81-
}
82-
}
8333
}

0 commit comments

Comments
 (0)