|
4 | 4 |
|
5 | 5 | package cloud.katta.cli.commands.hub; |
6 | 6 |
|
7 | | - |
8 | | -import ch.cyberduck.core.PasswordStoreFactory; |
9 | | - |
10 | | -import org.apache.logging.log4j.LogManager; |
11 | | -import org.apache.logging.log4j.Logger; |
12 | | -import org.junit.jupiter.api.AfterAll; |
13 | | -import org.junit.jupiter.api.BeforeAll; |
14 | 7 | import org.junit.jupiter.api.Test; |
15 | | -import org.testcontainers.containers.ComposeContainer; |
16 | | -import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy; |
| 8 | +import org.mockito.Mockito; |
17 | 9 |
|
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; |
| 10 | +import java.util.UUID; |
25 | 11 |
|
26 | | -import cloud.katta.protocols.hub.HubSession; |
27 | | -import cloud.katta.testsetup.AbstractHubTest; |
28 | | -import cloud.katta.testsetup.HubTestConfig; |
29 | | -import cloud.katta.testsetup.HubTestSetupDockerExtension; |
| 12 | +import cloud.katta.client.ApiException; |
| 13 | +import cloud.katta.client.api.StorageProfileResourceApi; |
30 | 14 |
|
31 | | -class StorageProfileArchiveTest extends AbstractHubTest { |
32 | | - private static final Logger log = LogManager.getLogger(StorageProfileArchiveTest.class.getName()); |
33 | | - public static ComposeContainer compose; |
| 15 | +import static org.mockito.ArgumentMatchers.any; |
| 16 | +import static org.mockito.Mockito.times; |
34 | 17 |
|
| 18 | +class StorageProfileArchiveTest { |
35 | 19 |
|
36 | 20 | @Test |
37 | | - public void testHubWorkflow() throws Exception { |
38 | | - HubTestConfig.Setup config = new HubTestConfig.Setup().withUserConfig( |
39 | | - new HubTestConfig.Setup.UserConfig("admin", "admin", "setupcode") |
40 | | - ).withHubURL("http://localhost:8280"); |
41 | | - final HubSession hubSession = setupConnection(config); |
42 | | - final String accessToken = PasswordStoreFactory.get().findOAuthTokens(hubSession.getHost()).getAccessToken(); |
43 | | - |
44 | | - new StorageProfileArchive().call("http://localhost:8280", accessToken, "732D43FA-3716-46C4-B931-66EA5405EF1C"); |
| 21 | + public void testCall() throws ApiException { |
| 22 | + final StorageProfileResourceApi proxyMock = Mockito.mock(StorageProfileResourceApi.class); |
| 23 | + final UUID vaultId = UUID.randomUUID(); |
| 24 | + new StorageProfileArchive().call(vaultId.toString(), proxyMock); |
| 25 | + Mockito.verify(proxyMock, times(1)).apiStorageprofileProfileIdPut(vaultId, true); |
| 26 | + Mockito.verify(proxyMock, times(1)).apiStorageprofileProfileIdPut(any(), any()); |
45 | 27 | } |
46 | 28 |
|
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(StorageProfileArchiveTest.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 | | - } |
83 | 29 | } |
0 commit comments