-
Notifications
You must be signed in to change notification settings - Fork 224
Expand file tree
/
Copy pathRetryTests.java
More file actions
55 lines (44 loc) · 2.25 KB
/
RetryTests.java
File metadata and controls
55 lines (44 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package com.bettercloud.vault;
import com.bettercloud.vault.response.LogicalResponse;
import com.bettercloud.vault.vault.VaultTestUtils;
import com.bettercloud.vault.vault.mock.RetriesMockVault;
import org.eclipse.jetty.server.Server;
import org.junit.Test;
import java.util.HashMap;
import static org.junit.Assert.assertEquals;
/**
* <p>Unit tests for the Vault driver, having no dependency on an actual Vault server instance being available. The
* tests in this class relate to handling of retry logic.</p>
*/
public class RetryTests {
@Test
public void testRetries_Read() throws Exception {
final RetriesMockVault retriesMockVault = new RetriesMockVault(5, 200,
"{\"lease_id\":\"12345\",\"renewable\":false,\"lease_duration\":10000,\"data\":{\"value\":\"mock\"}}");
final Server server = VaultTestUtils.initHttpMockVault(retriesMockVault);
server.start();
final VaultConfig vaultConfig = new VaultConfig().address("http://127.0.0.1:8999").token("mock_token").engineVersion(1).build();
final Vault vault = new Vault(vaultConfig);
final LogicalResponse response = vault.withRetries(5, 100).logical().read("secret/hello");
assertEquals(5, response.getRetries());
assertEquals("mock", response.getData().get("value"));
assertEquals("12345", response.getLeaseId());
assertEquals(false, response.getRenewable());
assertEquals(10000L, (long) response.getLeaseDuration());
VaultTestUtils.shutdownMockVault(server);
}
@Test
public void testRetries_Write() throws Exception {
final RetriesMockVault retriesMockVault = new RetriesMockVault(5, 204, null);
final Server server = VaultTestUtils.initHttpMockVault(retriesMockVault);
server.start();
final VaultConfig vaultConfig = new VaultConfig().address("http://127.0.0.1:8999").token("mock_token").build();
final Vault vault = new Vault(vaultConfig);
final LogicalResponse response = vault.withRetries(5, 100).logical()
.write("secret/hello", new HashMap<String, Object>() {{
put("value", "world");
}});
assertEquals(5, response.getRetries());
VaultTestUtils.shutdownMockVault(server);
}
}