-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathSkyflowTests.java
More file actions
92 lines (81 loc) · 3.47 KB
/
SkyflowTests.java
File metadata and controls
92 lines (81 loc) · 3.47 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package com.skyflow;
import com.skyflow.config.Credentials;
import com.skyflow.config.VaultConfig;
import com.skyflow.enums.Env;
import com.skyflow.enums.LogLevel;
import com.skyflow.errors.ErrorCode;
import com.skyflow.errors.ErrorMessage;
import com.skyflow.errors.SkyflowException;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
public class SkyflowTests {
private static final String INVALID_EXCEPTION_THROWN = "Should not have thrown any exception";
private static final String EXCEPTION_NOT_THROWN = "Should have thrown an exception";
private static String vaultID = null;
private static String clusterID = null;
private static String newClusterID = null;
private static String token = null;
private static String anotherToken = null;
@BeforeClass
public static void setup() {
vaultID = "test_vault_id";
clusterID = "test_cluster_id";
newClusterID = "new_test_cluster_id";
token = "test_token";
anotherToken = "another_test_token";
}
@Test
public void testAddingInvalidVaultConfig() {
try {
VaultConfig config = new VaultConfig();
config.setVaultId("");
config.setClusterId(clusterID);
config.setEnv(Env.SANDBOX);
Skyflow.builder().addVaultConfig(config).build();
Assert.fail(EXCEPTION_NOT_THROWN);
} catch (SkyflowException e) {
Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode());
Assert.assertEquals(ErrorMessage.EmptyVaultId.getMessage(), e.getMessage());
}
}
@Test
public void testAddingAnotherVaultConfig() {
try {
VaultConfig config = new VaultConfig();
config.setVaultId(vaultID);
config.setClusterId(clusterID);
config.setEnv(Env.SANDBOX);
Skyflow.builder().addVaultConfig(config).addVaultConfig(config).build();
Assert.fail(EXCEPTION_NOT_THROWN);
} catch (SkyflowException e) {
Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode());
Assert.assertEquals(ErrorMessage.VaultIdAlreadyInConfigList.getMessage(), e.getMessage());
}
}
@Test
public void testUpdatingValidVaultConfig() {
try {
VaultConfig config = new VaultConfig();
config.setVaultId(vaultID);
config.setClusterId(clusterID);
config.setEnv(Env.SANDBOX);
// Set the config
Skyflow skyflowClient = Skyflow.builder().addVaultConfig(config).build();
Credentials credentials = new Credentials();
credentials.setToken(token);
// Updating the config directly
config.setClusterId(newClusterID);
config.setEnv(Env.PROD);
config.setCredentials(credentials);
Assert.assertNotEquals(newClusterID, skyflowClient.getVaultConfig().getClusterId());
Assert.assertEquals(clusterID, skyflowClient.getVaultConfig().getClusterId());
Assert.assertNotEquals(Env.PROD, skyflowClient.getVaultConfig().getEnv());
Assert.assertEquals(Env.SANDBOX, skyflowClient.getVaultConfig().getEnv());
Assert.assertNotEquals(credentials, skyflowClient.getVaultConfig().getCredentials());
Assert.assertNull(skyflowClient.getVaultConfig().getCredentials());
} catch (SkyflowException e) {
Assert.fail(INVALID_EXCEPTION_THROWN);
}
}
}