-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDetectControllerTests.java
More file actions
152 lines (137 loc) · 6.46 KB
/
DetectControllerTests.java
File metadata and controls
152 lines (137 loc) · 6.46 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package com.skyflow.vault.controller;
import com.skyflow.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.ErrorMessage;
import com.skyflow.errors.HttpStatus;
import com.skyflow.errors.SkyflowException;
import com.skyflow.utils.Constants;
import com.skyflow.utils.Utils;
import com.skyflow.vault.detect.DeidentifyTextRequest;
import com.skyflow.vault.detect.ReidentifyTextRequest;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
public class DetectControllerTests {
private static final String EXCEPTION_NOT_THROWN = "Should have thrown an exception";
private static String vaultID = null;
private static String clusterID = null;
private static VaultConfig vaultConfig = null;
private static Skyflow skyflowClient = null;
@BeforeClass
public static void setup() throws SkyflowException, NoSuchMethodException {
vaultID = "vault123";
clusterID = "cluster123";
Credentials credentials = new Credentials();
credentials.setToken("valid-token");
vaultConfig = new VaultConfig();
vaultConfig.setVaultId(vaultID);
vaultConfig.setClusterId(clusterID);
vaultConfig.setEnv(Env.DEV);
vaultConfig.setCredentials(credentials);
skyflowClient = Skyflow.builder()
.setLogLevel(LogLevel.DEBUG)
.addVaultConfig(vaultConfig)
.build();
}
@Test
public void testNullTextInRequestInDeidentifyStringMethod() {
try {
DeidentifyTextRequest request = DeidentifyTextRequest.builder().text(null).build();
skyflowClient = Skyflow.builder().setLogLevel(LogLevel.DEBUG).addVaultConfig(vaultConfig).build();
skyflowClient.detect(vaultID).deidentifyText(request);
Assert.fail(EXCEPTION_NOT_THROWN);
} catch (SkyflowException e) {
Assert.assertEquals(
Utils.parameterizedString(ErrorMessage.InvalidTextInDeIdentify.getMessage(), Constants.SDK_PREFIX),
e.getMessage()
);
Assert.assertNull(e.getRequestId());
Assert.assertNull(e.getGrpcCode());
Assert.assertEquals(HttpStatus.BAD_REQUEST.getHttpStatus(), e.getHttpStatus());
}
}
@Test
public void testEmptyTextInRequestInDeidentifyStringMethod() {
try {
DeidentifyTextRequest request = DeidentifyTextRequest.builder().text("").build();
skyflowClient = Skyflow.builder().setLogLevel(LogLevel.DEBUG).addVaultConfig(vaultConfig).build();
skyflowClient.detect(vaultID).deidentifyText(request);
Assert.fail(EXCEPTION_NOT_THROWN);
} catch (SkyflowException e) {
Assert.assertEquals(
Utils.parameterizedString(ErrorMessage.InvalidTextInDeIdentify.getMessage(), Constants.SDK_PREFIX),
e.getMessage()
);
Assert.assertNull(e.getRequestId());
Assert.assertNull(e.getGrpcCode());
Assert.assertEquals(HttpStatus.BAD_REQUEST.getHttpStatus(), e.getHttpStatus());
}
}
@Test
public void testNullTextInRequestInReidentifyStringMethod() {
try {
ReidentifyTextRequest request = ReidentifyTextRequest.builder().text(null).build();
skyflowClient = Skyflow.builder().setLogLevel(LogLevel.DEBUG).addVaultConfig(vaultConfig).build();
skyflowClient.detect(vaultID).reidentifyText(request);
Assert.fail(EXCEPTION_NOT_THROWN);
} catch (SkyflowException e) {
Assert.assertEquals(
Utils.parameterizedString(ErrorMessage.InvalidTextInReIdentify.getMessage(), Constants.SDK_PREFIX),
e.getMessage()
);
Assert.assertNull(e.getRequestId());
Assert.assertNull(e.getGrpcCode());
Assert.assertEquals(HttpStatus.BAD_REQUEST.getHttpStatus(), e.getHttpStatus());
}
}
@Test
public void testEmptyTextInRequestInReidentifyStringMethod() {
try {
ReidentifyTextRequest request = ReidentifyTextRequest.builder().text("").build();
skyflowClient = Skyflow.builder().setLogLevel(LogLevel.DEBUG).addVaultConfig(vaultConfig).build();
skyflowClient.detect(vaultID).reidentifyText(request);
Assert.fail(EXCEPTION_NOT_THROWN);
} catch (SkyflowException e) {
Assert.assertEquals(
Utils.parameterizedString(ErrorMessage.InvalidTextInReIdentify.getMessage(), Constants.SDK_PREFIX),
e.getMessage()
);
Assert.assertNull(e.getRequestId());
Assert.assertNull(e.getGrpcCode());
Assert.assertEquals(HttpStatus.BAD_REQUEST.getHttpStatus(), e.getHttpStatus());
}
}
@Test
public void testApiClientExceptionInDeidentifyTextMethod() {
try {
DeidentifyTextRequest request = DeidentifyTextRequest.builder().text("Sensitive text").build();
skyflowClient = Skyflow.builder().setLogLevel(LogLevel.DEBUG).addVaultConfig(vaultConfig).build();
skyflowClient.detect(vaultID).deidentifyText(request);
Assert.fail(EXCEPTION_NOT_THROWN);
} catch (SkyflowException e) {
Assert.assertEquals("Network error executing HTTP request", e.getMessage());
Assert.assertNull(e.getRequestId());
Assert.assertNull(e.getGrpcCode());
Assert.assertNull(e.getDetails());
Assert.assertEquals(com.skyflow.errors.ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode());
}
}
@Test
public void testApiClientExceptionInReidentifyTextMethod() {
try {
ReidentifyTextRequest request = ReidentifyTextRequest.builder().text("Deidentified text").build();
skyflowClient = Skyflow.builder().setLogLevel(LogLevel.DEBUG).addVaultConfig(vaultConfig).build();
skyflowClient.detect(vaultID).reidentifyText(request);
Assert.fail(EXCEPTION_NOT_THROWN);
} catch (SkyflowException e) {
Assert.assertEquals("Network error executing HTTP request", e.getMessage());
Assert.assertNull(e.getRequestId());
Assert.assertNull(e.getGrpcCode());
Assert.assertNull(e.getDetails());
Assert.assertEquals(com.skyflow.errors.ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode());
}
}
}