Skip to content

Commit be07f2e

Browse files
authored
Merge pull request #114 from docusign/using-environment-variables
Using environment variables for testing
2 parents 7726320 + 78c796c commit be07f2e

File tree

2 files changed

+14
-134
lines changed

2 files changed

+14
-134
lines changed

src/test/java/SdkUnitTests.java

Lines changed: 12 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,21 @@
3030
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
3131
public class SdkUnitTests {
3232

33-
private static final String UserName = "[email protected]";
34-
private static final String UserId = "fcc5726c-xxxx-xxxx-xxxx-40bbbe6ca126";
35-
private static final String IntegratorKey = "ae30ea4e-xxxx-xxxx-xxxx-fcb57d2dc4df";
36-
private static final String IntegratorKeyImplicit = "68c1711f-xxxx-xxxx-xxxx-b49b4211d831";
37-
//private static final String ClientSecret = "b4dccdbe-xxxx-xxxx-xxxx-b2f0f7448f8f";
38-
private static final String RedirectURI = "https://www.docusign.com/api";
33+
private static final String UserName = System.getenv("USER_NAME");
34+
private static final String UserId = System.getenv("USER_ID");
35+
private static final String IntegratorKey = System.getenv("INTEGRATOR_KEY_JWT");
36+
private static final String IntegratorKeyImplicit = System.getenv("INTEGRATOR_KEY_IMPLICIT");
37+
//private static final String ClientSecret = System.getenv("CLIENT_SECRET");
38+
private static final String RedirectURI = System.getenv("REDIRECT_URI");
3939

4040
private static final String BaseUrl = "https://demo.docusign.net/restapi";
4141
//private static final String OAuthBaseUrl = "account-d.docusign.com";
42-
private static final String privateKeyFullPath = System.getProperty("user.dir") + "/src/test/keys/docusign_private_key.txt";
42+
private static final byte[] privateKeyBytes = Base64.decode(System.getenv("PRIVATE_KEY"));
4343
private static final String brandLogoFullPath = System.getProperty("user.dir") + "/src/test/docs/DS.png";
4444

4545
private static final String SignTest1File = "/src/test/docs/SignTest1.pdf";
46-
private static final String TemplateId = "cf2a46c2-xxxx-xxxx-xxxx-752547b1a419";
47-
private static final String BrandId = "dbdaedc8-xxxx-xxxx-xxxx-b7cfd55f6b64";
46+
private static final String TemplateId = System.getenv("TEMPLATE_ID");
47+
private static final String BrandId = System.getenv("BRAND_ID");
4848
private String[] envelopeIds = new String[0];
4949
// JUnit 4.12 runs test cases in parallel, so the envelope ID needs to be initiated as well.
5050

@@ -78,7 +78,7 @@ public void tearDown() {
7878
public void JWTLoginTest() {
7979
System.out.println("\nJWTLoginTest:\n" + "===========================================");
8080
ApiClient apiClient = new ApiClient(BaseUrl);
81-
//String currentDir = System.getProperty("user.dir");
81+
//String currentDir = System.getenv("user.dir");
8282

8383
try {
8484
// IMPORTANT NOTE:
@@ -89,14 +89,6 @@ public void JWTLoginTest() {
8989
//Desktop.getDesktop().browse(URI.create(oauthLoginUrl));
9090
// END OF NOTE
9191

92-
byte[] privateKeyBytes = null;
93-
try {
94-
privateKeyBytes = Files.readAllBytes(Paths.get(privateKeyFullPath));
95-
} catch (IOException ioExcp) {
96-
Assert.assertEquals(null, ioExcp);
97-
}
98-
if (privateKeyBytes == null) return;
99-
10092
java.util.List<String> scopes = new ArrayList<String>();
10193
scopes.add(OAuth.Scope_SIGNATURE);
10294
scopes.add(OAuth.Scope_IMPERSONATION);
@@ -135,7 +127,7 @@ public void AuthorizationCodeLoginTest() {
135127
java.util.List<String> scopes = new ArrayList<String>();
136128
scopes.add(OAuth.Scope_SIGNATURE);
137129
// get DocuSign OAuth authorization url
138-
URI oauthLoginUrl = apiClient.getAuthorizationUri(IntegratorKey, scopes, RedirectURI, OAuth.CODE, randomState);
130+
//URI oauthLoginUrl = apiClient.getAuthorizationUri(IntegratorKey, scopes, RedirectURI, OAuth.CODE, randomState);
139131
// open DocuSign OAuth login in the browser
140132
//Desktop.getDesktop().browse(oauthLoginUrl);
141133
// IMPORTANT: after the login, DocuSign will send back a fresh
@@ -183,7 +175,7 @@ public void ImplicitLoginTest() {
183175
java.util.List<String> scopes = new ArrayList<String>();
184176
scopes.add(OAuth.Scope_SIGNATURE);
185177
// get DocuSign OAuth authorization url
186-
URI oAuthLoginUri = apiClient.getAuthorizationUri(IntegratorKeyImplicit, scopes, RedirectURI, OAuth.TOKEN, randomState);
178+
//URI oAuthLoginUri = apiClient.getAuthorizationUri(IntegratorKeyImplicit, scopes, RedirectURI, OAuth.TOKEN, randomState);
187179
// open DocuSign OAuth login in the browser
188180
//Desktop.getDesktop().browse(oAuthLoginUri);
189181
// IMPORTANT: after the login, DocuSign will send back a new
@@ -287,14 +279,6 @@ public void RequestASignatureTest() {
287279
//Desktop.getDesktop().browse(URI.create(oauthLoginUrl));
288280
// END OF NOTE
289281

290-
byte[] privateKeyBytes = null;
291-
try {
292-
privateKeyBytes = Files.readAllBytes(Paths.get(privateKeyFullPath));
293-
} catch (IOException ioExcp) {
294-
Assert.assertEquals(null, ioExcp);
295-
}
296-
if (privateKeyBytes == null) return;
297-
298282
java.util.List<String> scopes = new ArrayList<String>();
299283
scopes.add(OAuth.Scope_SIGNATURE);
300284

@@ -376,14 +360,6 @@ public void RequestSignatureFromTemplate() {
376360
//Desktop.getDesktop().browse(URI.create(oauthLoginUrl));
377361
// END OF NOTE
378362

379-
byte[] privateKeyBytes = null;
380-
try {
381-
privateKeyBytes = Files.readAllBytes(Paths.get(privateKeyFullPath));
382-
} catch (IOException ioExcp) {
383-
Assert.assertEquals(null, ioExcp);
384-
}
385-
if (privateKeyBytes == null) return;
386-
387363
java.util.List<String> scopes = new ArrayList<String>();
388364
scopes.add(OAuth.Scope_SIGNATURE);
389365

@@ -500,14 +476,6 @@ public void EmbeddedSigningTest() {
500476
//Desktop.getDesktop().browse(URI.create(oauthLoginUrl));
501477
// END OF NOTE
502478

503-
byte[] privateKeyBytes = null;
504-
try {
505-
privateKeyBytes = Files.readAllBytes(Paths.get(privateKeyFullPath));
506-
} catch (IOException ioExcp) {
507-
Assert.assertEquals(null, ioExcp);
508-
}
509-
if (privateKeyBytes == null) return;
510-
511479
java.util.List<String> scopes = new ArrayList<String>();
512480
scopes.add(OAuth.Scope_SIGNATURE);
513481

@@ -636,14 +604,6 @@ public void CreateTemplateTest() {
636604
//Desktop.getDesktop().browse(URI.create(oauthLoginUrl));
637605
// END OF NOTE
638606

639-
byte[] privateKeyBytes = null;
640-
try {
641-
privateKeyBytes = Files.readAllBytes(Paths.get(privateKeyFullPath));
642-
} catch (IOException ioExcp) {
643-
Assert.assertEquals(null, ioExcp);
644-
}
645-
if (privateKeyBytes == null) return;
646-
647607
java.util.List<String> scopes = new ArrayList<String>();
648608
scopes.add(OAuth.Scope_SIGNATURE);
649609

@@ -758,14 +718,6 @@ public void DownLoadEnvelopeDocumentsTest() {
758718
//Desktop.getDesktop().browse(URI.create(oauthLoginUrl));
759719
// END OF NOTE
760720

761-
byte[] privateKeyBytes = null;
762-
try {
763-
privateKeyBytes = Files.readAllBytes(Paths.get(privateKeyFullPath));
764-
} catch (IOException ioExcp) {
765-
Assert.assertEquals(null, ioExcp);
766-
}
767-
if (privateKeyBytes == null) return;
768-
769721
java.util.List<String> scopes = new ArrayList<String>();
770722
scopes.add(OAuth.Scope_SIGNATURE);
771723

@@ -836,14 +788,6 @@ public void ListDocumentsTest() {
836788
//Desktop.getDesktop().browse(URI.create(oauthLoginUrl));
837789
// END OF NOTE
838790

839-
byte[] privateKeyBytes = null;
840-
try {
841-
privateKeyBytes = Files.readAllBytes(Paths.get(privateKeyFullPath));
842-
} catch (IOException ioExcp) {
843-
Assert.assertEquals(null, ioExcp);
844-
}
845-
if (privateKeyBytes == null) return;
846-
847791
java.util.List<String> scopes = new ArrayList<String>();
848792
scopes.add(OAuth.Scope_SIGNATURE);
849793

@@ -957,14 +901,6 @@ public void ResendEnvelopeTest() {
957901
//Desktop.getDesktop().browse(URI.create(oauthLoginUrl));
958902
// END OF NOTE
959903

960-
byte[] privateKeyBytes = null;
961-
try {
962-
privateKeyBytes = Files.readAllBytes(Paths.get(privateKeyFullPath));
963-
} catch (IOException ioExcp) {
964-
Assert.assertEquals(null, ioExcp);
965-
}
966-
if (privateKeyBytes == null) return;
967-
968904
java.util.List<String> scopes = new ArrayList<String>();
969905
scopes.add(OAuth.Scope_SIGNATURE);
970906

@@ -1086,14 +1022,6 @@ public void GetDiagnosticLogsTest() {
10861022
//Desktop.getDesktop().browse(URI.create(oauthLoginUrl));
10871023
// END OF NOTE
10881024

1089-
byte[] privateKeyBytes = null;
1090-
try {
1091-
privateKeyBytes = Files.readAllBytes(Paths.get(privateKeyFullPath));
1092-
} catch (IOException ioExcp) {
1093-
Assert.assertEquals(null, ioExcp);
1094-
}
1095-
if (privateKeyBytes == null) return;
1096-
10971025
java.util.List<String> scopes = new ArrayList<String>();
10981026
scopes.add(OAuth.Scope_SIGNATURE);
10991027

@@ -1188,14 +1116,6 @@ public void ListStatusChangesTest() {
11881116
//Desktop.getDesktop().browse(URI.create(oauthLoginUrl));
11891117
// END OF NOTE
11901118

1191-
byte[] privateKeyBytes = null;
1192-
try {
1193-
privateKeyBytes = Files.readAllBytes(Paths.get(privateKeyFullPath));
1194-
} catch (IOException ioExcp) {
1195-
Assert.assertEquals(null, ioExcp);
1196-
}
1197-
if (privateKeyBytes == null) return;
1198-
11991119
java.util.List<String> scopes = new ArrayList<String>();
12001120
scopes.add(OAuth.Scope_SIGNATURE);
12011121

@@ -1253,14 +1173,6 @@ public void ListStatusTest() {
12531173
//Desktop.getDesktop().browse(URI.create(oauthLoginUrl));
12541174
// END OF NOTE
12551175

1256-
byte[] privateKeyBytes = null;
1257-
try {
1258-
privateKeyBytes = Files.readAllBytes(Paths.get(privateKeyFullPath));
1259-
} catch (IOException ioExcp) {
1260-
Assert.assertEquals(null, ioExcp);
1261-
}
1262-
if (privateKeyBytes == null) return;
1263-
12641176
java.util.List<String> scopes = new ArrayList<String>();
12651177
scopes.add(OAuth.Scope_SIGNATURE);
12661178

@@ -1320,14 +1232,6 @@ public void UpdateBulkRecipientsTest() {
13201232
//Desktop.getDesktop().browse(URI.create(oauthLoginUrl));
13211233
// END OF NOTE
13221234

1323-
byte[] privateKeyBytes = null;
1324-
try {
1325-
privateKeyBytes = Files.readAllBytes(Paths.get(privateKeyFullPath));
1326-
} catch (IOException ioExcp) {
1327-
Assert.assertEquals(null, ioExcp);
1328-
}
1329-
if (privateKeyBytes == null) return;
1330-
13311235
java.util.List<String> scopes = new ArrayList<String>();
13321236
scopes.add(OAuth.Scope_SIGNATURE);
13331237

@@ -1486,14 +1390,6 @@ public void UpdateChunkedUpload() {
14861390
//Desktop.getDesktop().browse(URI.create(oauthLoginUrl));
14871391
// END OF NOTE
14881392

1489-
byte[] privateKeyBytes = null;
1490-
try {
1491-
privateKeyBytes = Files.readAllBytes(Paths.get(privateKeyFullPath));
1492-
} catch (IOException ioExcp) {
1493-
Assert.assertEquals(null, ioExcp);
1494-
}
1495-
if (privateKeyBytes == null) return;
1496-
14971393
java.util.List<String> scopes = new ArrayList<String>();
14981394
scopes.add(OAuth.Scope_SIGNATURE);
14991395

@@ -1565,14 +1461,6 @@ public void UpdateBrandLogoByTypeTest() {
15651461
//Desktop.getDesktop().browse(URI.create(oauthLoginUrl));
15661462
// END OF NOTE
15671463

1568-
byte[] privateKeyBytes = null;
1569-
try {
1570-
privateKeyBytes = Files.readAllBytes(Paths.get(privateKeyFullPath));
1571-
} catch (IOException ioExcp) {
1572-
Assert.assertEquals(null, ioExcp);
1573-
}
1574-
if (privateKeyBytes == null) return;
1575-
15761464
java.util.List<String> scopes = new ArrayList<String>();
15771465
scopes.add(OAuth.Scope_SIGNATURE);
15781466

@@ -1626,14 +1514,6 @@ private String[] getLastTenEnvelopeIds() {
16261514
//Desktop.getDesktop().browse(URI.create(oauthLoginUrl));
16271515
// END OF NOTE
16281516

1629-
byte[] privateKeyBytes = null;
1630-
try {
1631-
privateKeyBytes = Files.readAllBytes(Paths.get(privateKeyFullPath));
1632-
} catch (IOException ioExcp) {
1633-
Assert.assertEquals(null, ioExcp);
1634-
}
1635-
if (privateKeyBytes == null) return envelopeIds;
1636-
16371517
java.util.List<String> scopes = new ArrayList<String>();
16381518
scopes.add(OAuth.Scope_SIGNATURE);
16391519

target/test-classes/SdkUnitTests.class

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ ImplicitLoginTest:
169169
RequestASignatureTest:
170170
=========================================== user.dir  /src/test/docs/SignTest1.pdf +com/docusign/esign/model/EnvelopeDefinition Please Sign my Java SDK Envelope � (Hello, Please sign my Java SDK Envelope. � !com/docusign/esign/model/Document  � TestFile.pdf � 1 �   com/docusign/esign/model/Signer [email protected] !� Pat Developer "� !com/docusign/esign/model/SignHere #� 100 $� %� 0.5 &� com/docusign/esign/model/Tabs ' () #com/docusign/esign/model/Recipients *+ ,- . /� sent 0� 1� #com/docusign/esign/api/EnvelopesApi 23� 4� 5� EnvelopeSummary:  J
171171
RequestSignatureFromTemplate:
172-
=========================================== Needs to sign $cf2a46c2-xxxx-xxxx-xxxx-752547b1a419 6� %com/docusign/esign/model/TemplateRole 7� 8  A
172+
=========================================== Needs to sign $***REMOVED*** 6� %com/docusign/esign/model/TemplateRole 7� 8  A
173173
EmbeddedSigningTest:
174174
=========================================== 2Please Sign my Java SDK Envelope (Embedded Signer) 2939 9� (http://www.docusign.com/developer-center -com/docusign/esign/model/RecipientViewRequest :� email ;� <� =>? @� ViewUrl is  @
175175
CreateTemplateTest:
@@ -192,7 +192,7 @@ UpdateBulkRecipientsTest:
192192
UpdateChunkedUpload:
193193
=========================================== -com/docusign/esign/model/ChunkedUploadRequest ij k� lmn o� p� qr st u� v� UpdateChunkedUploadResponse:  G
194194
UpdateBrandLogoByTypeTest:
195-
===========================================  "com/docusign/esign/api/AccountsApi $dbdaedc8-xxxx-xxxx-xxxx-b7cfd55f6b64 primary wx org/joda/time/DateTime yz
195+
===========================================  "com/docusign/esign/api/AccountsApi $***REMOVED*** primary wx org/joda/time/DateTime yz
196196
yyyy-MM-dd  10 {� |� }  '/src/test/keys/docusign_private_key.txt /src/test/docs/DS.png SdkUnitTests java/lang/Object /com/docusign/esign/client/auth/OAuth$OAuthToken -com/docusign/esign/client/auth/OAuth$UserInfo java/util/List java/nio/file/Path (com/docusign/esign/model/EnvelopeSummary 0com/docusign/esign/model/RecipientsUpdateSummary -com/docusign/esign/model/ApiRequestLogsResult -com/docusign/esign/model/EnvelopesInformation java/lang/System out Ljava/io/PrintStream; java/io/PrintStream println (Ljava/lang/String;)V java/nio/file/Paths get ;(Ljava/lang/String;[Ljava/lang/String;)Ljava/nio/file/Path; java/nio/file/Files readAllBytes (Ljava/nio/file/Path;)[B org/junit/Assert assertEquals '(Ljava/lang/Object;Ljava/lang/Object;)V add (Ljava/lang/Object;)Z requestJWTUserToken j(Ljava/lang/String;Ljava/lang/String;Ljava/util/List;[BJ)Lcom/docusign/esign/client/auth/OAuth$OAuthToken; assertNotSame getAccessToken ()Ljava/lang/String; getExpiresIn ()Ljava/lang/Long; setAccessToken %(Ljava/lang/String;Ljava/lang/Long;)V getUserInfo C(Ljava/lang/String;)Lcom/docusign/esign/client/auth/OAuth$UserInfo; getAccounts ()Ljava/util/List; assertNotNull (Ljava/lang/Object;)V size ()I
197197
assertTrue (Z)V append -(Ljava/lang/String;)Ljava/lang/StringBuilder; -(Ljava/lang/Object;)Ljava/lang/StringBuilder; toString (I)Ljava/lang/Object; $com/docusign/esign/client/auth/OAuth
198198
getBaseUri setBasePath 9(Ljava/lang/String;)Lcom/docusign/esign/client/ApiClient; 'com/docusign/esign/client/Configuration setDefaultApiClient ((Lcom/docusign/esign/client/ApiClient;)V fail getLocalizedMessage getAuthorizationUri h(Ljava/lang/String;Ljava/util/List;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/net/URI; getProperty &(Ljava/lang/String;)Ljava/lang/String; setEmailSubject setEmailBlurb "com/migcomponents/migbase64/Base64 encodeToString ([BZ)Ljava/lang/String; setDocumentBase64 setName setDocumentId setDocuments (Ljava/util/List;)V setEmail setRecipientId setPageNumber setXPosition setYPosition setScaleValue setSignHereTabs setTabs "(Lcom/docusign/esign/model/Tabs;)V setRecipients ((Lcom/docusign/esign/model/Recipients;)V getRecipients '()Lcom/docusign/esign/model/Recipients;

0 commit comments

Comments
 (0)