forked from docusign/code-examples-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestConfig.java
More file actions
116 lines (86 loc) · 3.79 KB
/
TestConfig.java
File metadata and controls
116 lines (86 loc) · 3.79 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
package tests.common;
import com.docusign.click.model.ClickwrapVersionSummaryResponse;
import com.docusign.esign.model.Brand;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import lombok.Getter;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import lombok.Setter;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@Getter
@Setter
public class TestConfig {
private String ClientId;
private String Host;
private String AccountId;
private String SignerEmail;
private String SignerName;
private String ImpersonatedUserId;
private String OAuthBasePath;
private String PrivateKeyPath;
private String PrivateKey;
private String AccessToken;
private String BasePath;
private String BatchId;
private String TemplateId;
private ClickwrapVersionSummaryResponse inactiveClickwrap;
private Brand brand;
public String PathToDocuments;
private static TestConfig single_instance = null;
public static TestConfig getInstance() throws IOException {
if (single_instance == null)
single_instance = new TestConfig();
return single_instance;
}
public TestConfig() throws IOException {
PathToDocuments = System.getProperty("user.dir") + "//src//main//resources//";
Host = "https://demo.docusign.net";
OAuthBasePath = "account-d.docusign.com";
PrivateKeyPath = PathToDocuments + "private.key";
BasePath = "https://demo.docusign.net";
try {
var isFilePresentInTheRepository = Files.exists(Path.of(PathToDocuments + "application.json"));
if (isFilePresentInTheRepository) {
String source = new String(Files.readAllBytes(Paths.get(PathToDocuments + "application.json")));
Gson gson = new GsonBuilder().setPrettyPrinting().create();
JsonObject originalJsonValue = gson.fromJson(source, JsonObject.class);
JsonObject jwtConfigurationValues = originalJsonValue
.getAsJsonObject("spring")
.getAsJsonObject("security")
.getAsJsonObject("oauth2")
.getAsJsonObject("client")
.getAsJsonObject("registration")
.getAsJsonObject("jwt")
.getAsJsonObject();
Object impersonatedUserId = jwtConfigurationValues.get("impersonated-user-guid").toString();
Object clientId = jwtConfigurationValues.get("client-id").toString();
Object signerEmail = new JSONObject(source).get("DS_SIGNER_EMAIL");
Object signerName = new JSONObject(source).get("DS_SIGNER_NAME");
if (impersonatedUserId == null || clientId == null || signerEmail == null || signerName == null) {
throw new JSONException("The wrong format of the application.json file.");
}
ImpersonatedUserId = impersonatedUserId.toString().replace("\"", "");
ClientId = clientId.toString().replace("\"", "");
SignerEmail = signerEmail.toString();
SignerName = signerName.toString();
} else {
ImpersonatedUserId = System.getenv("IMPERSONATED_USER_ID");
ClientId = System.getenv("CLIENT_ID");
SignerEmail = System.getenv("SIGNER_EMAIL");
SignerName = System.getenv("SIGNER_NAME");
PrivateKey = System.getenv("PRIVATE_KEY");
}
} catch (JSONException e){
e.printStackTrace();
}
}
}