-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathDigitalOceanIntegrationTest.java
1356 lines (1007 loc) · 41.2 KB
/
DigitalOceanIntegrationTest.java
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* The MIT License
*
* <p>Copyright (c) 2013-2020 Jeevanandam M. (jeeva@myjeeva.com)
*
* <p>Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* <p>The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* <p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.myjeeva.digitalocean;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import com.myjeeva.digitalocean.common.ActionType;
import com.myjeeva.digitalocean.common.Environment;
import com.myjeeva.digitalocean.common.LoadBalancingAlgorithm;
import com.myjeeva.digitalocean.common.Protocol;
import com.myjeeva.digitalocean.common.ResourceType;
import com.myjeeva.digitalocean.common.StickySessionType;
import com.myjeeva.digitalocean.exception.DigitalOceanException;
import com.myjeeva.digitalocean.exception.RequestUnsuccessfulException;
import com.myjeeva.digitalocean.impl.DigitalOceanClient;
import com.myjeeva.digitalocean.pojo.Account;
import com.myjeeva.digitalocean.pojo.Action;
import com.myjeeva.digitalocean.pojo.Actions;
import com.myjeeva.digitalocean.pojo.Backup;
import com.myjeeva.digitalocean.pojo.Backups;
import com.myjeeva.digitalocean.pojo.Certificate;
import com.myjeeva.digitalocean.pojo.Delete;
import com.myjeeva.digitalocean.pojo.Destinations;
import com.myjeeva.digitalocean.pojo.Domain;
import com.myjeeva.digitalocean.pojo.DomainRecord;
import com.myjeeva.digitalocean.pojo.DomainRecords;
import com.myjeeva.digitalocean.pojo.Droplet;
import com.myjeeva.digitalocean.pojo.Droplets;
import com.myjeeva.digitalocean.pojo.Firewall;
import com.myjeeva.digitalocean.pojo.FloatingIP;
import com.myjeeva.digitalocean.pojo.ForwardingRules;
import com.myjeeva.digitalocean.pojo.HealthCheck;
import com.myjeeva.digitalocean.pojo.Image;
import com.myjeeva.digitalocean.pojo.InboundRules;
import com.myjeeva.digitalocean.pojo.Kernel;
import com.myjeeva.digitalocean.pojo.Kernels;
import com.myjeeva.digitalocean.pojo.Key;
import com.myjeeva.digitalocean.pojo.LoadBalancer;
import com.myjeeva.digitalocean.pojo.Neighbors;
import com.myjeeva.digitalocean.pojo.OutboundRules;
import com.myjeeva.digitalocean.pojo.Project;
import com.myjeeva.digitalocean.pojo.Projects;
import com.myjeeva.digitalocean.pojo.Region;
import com.myjeeva.digitalocean.pojo.Resource;
import com.myjeeva.digitalocean.pojo.Response;
import com.myjeeva.digitalocean.pojo.Snapshot;
import com.myjeeva.digitalocean.pojo.Snapshots;
import com.myjeeva.digitalocean.pojo.Sources;
import com.myjeeva.digitalocean.pojo.StickySessions;
import com.myjeeva.digitalocean.pojo.Tag;
import com.myjeeva.digitalocean.pojo.Volume;
import com.myjeeva.digitalocean.pojo.Volumes;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Junit Integration Test case for DigitalOcean API client wrapper methods
*
* <p><strong>Please Note:</strong> <i>Kindly go through and update private variable value before
* using executing this test case(s).</i>
*
* @author Jeevanandam M. (jeeva@myjeeva.com)
*/
// Marked as Ignore since its a Integration Test case with real values
@Ignore
@RunWith(JUnit4.class)
public class DigitalOceanIntegrationTest {
private final Logger log = LoggerFactory.getLogger(DigitalOceanIntegrationTest.class);
/**
* This is testing values of my own respective to DigitalOcean account, to real-time integration
* with API. So place your's for integration test case before use
*/
private final String authTokenRW = "";
private final Integer dropletIdForInfo = 10001; // to be placed before use
private final String volumeIdForInfo = "10001"; // to be placed before use
private final String volumeNameForInfo = "test-volume"; // to be placed before use, should have
private final String loadBalancerIdForInfo =
"155fa6cd-3e74-406d-90bd-5671488c7157"; // to be placed
// before use
private final String firewallIdForInfo =
"190ceeb7-779a-4b04-9091-4dd175de65ec"; // to be placed before use
private final String domainName = "";
private String projectId;
private final DigitalOcean apiClient = new DigitalOceanClient(authTokenRW);
// Droplet test cases
@Test
public void testGetDropletKernels() throws DigitalOceanException, RequestUnsuccessfulException {
Kernels kernels = apiClient.getDropletKernels(dropletIdForInfo, 1, 20);
assertNotNull(kernels);
assertFalse((kernels.getKernels().isEmpty()));
int i = 1;
for (Kernel k : kernels.getKernels()) {
log.info(i++ + " -> " + k.toString());
}
}
@Test
public void testGetDropletSnapshots() throws DigitalOceanException, RequestUnsuccessfulException {
Snapshots snapshots = apiClient.getDropletSnapshots(dropletIdForInfo, 1, 20);
assertNotNull(snapshots);
assertFalse((snapshots.getSnapshots().isEmpty()));
for (Snapshot s : snapshots.getSnapshots()) {
log.info(s.toString());
}
}
@Test
public void testGetDropletBackups() throws DigitalOceanException, RequestUnsuccessfulException {
Backups backups = apiClient.getDropletBackups(dropletIdForInfo, 1, 10);
assertNotNull(backups);
assertFalse((backups.getBackups().isEmpty()));
for (Backup b : backups.getBackups()) {
log.info(b.toString());
}
}
@Test
public void testGetDropletInfo() throws DigitalOceanException, RequestUnsuccessfulException {
Droplet droplet = apiClient.getDropletInfo(dropletIdForInfo);
assertNotNull(droplet);
log.info(droplet.toString());
}
@Test
public void testCreateDropletByImageId()
throws DigitalOceanException, RequestUnsuccessfulException {
Droplet droplet = new Droplet();
droplet.setName("api-client-test-host-byid");
droplet.setSize("512mb");
droplet.setImage(new Image(1601));
droplet.setRegion(new Region("sgp1"));
droplet.setEnableBackup(Boolean.TRUE);
droplet.setEnableIpv6(Boolean.TRUE);
droplet.setEnablePrivateNetworking(Boolean.TRUE);
// Adding SSH key info
List<Key> keys = new ArrayList<Key>();
keys.add(new Key(513618));
droplet.setKeys(keys);
// Adding Metadata API - User Data
/*
* droplet .setUserData("#!/bin/bash" + "apt-get -y update" + "apt-get -y install nginx" +
* "export HOSTNAME=$(curl -s http://169.254.169.254/metadata/v1/hostname)" +
* "export PUBLIC_IPV4=$(curl -s http://169.254.169.254/metadata/v1/interfaces/public/0/ipv4/address)"
* + "echo Droplet: $HOSTNAME, IP Address: $PUBLIC_IPV4 > /usr/share/nginx/html/index.html");
*/
Droplet d = apiClient.createDroplet(droplet);
assertNotNull(d);
assertNotNull(d.getId());
log.info(d.toString());
}
@Test
public void testCreateDropletByImageSlug()
throws DigitalOceanException, RequestUnsuccessfulException {
Droplet droplet = new Droplet();
droplet.setName("api-client-test-host-byslug1");
droplet.setSize("512mb");
droplet.setImage(new Image("centos-5-8-x64"));
droplet.setRegion(new Region("sgp1"));
droplet.setEnableBackup(Boolean.TRUE);
droplet.setEnableIpv6(Boolean.TRUE);
droplet.setEnablePrivateNetworking(Boolean.TRUE);
// Adding SSH key info
List<Key> keys = new ArrayList<Key>();
keys.add(new Key(513618));
droplet.setKeys(keys);
Droplet d = apiClient.createDroplet(droplet);
assertNotNull(d);
assertNotNull(d.getId());
log.info(d.toString());
}
@Test
public void testCreateDropletsByImageSlug()
throws DigitalOceanException, RequestUnsuccessfulException {
Droplet droplet = new Droplet();
droplet.setNames(Arrays.asList("sub-01.example.com", "sub-02.example.com"));
droplet.setName("not allowed");
droplet.setSize("512mb");
droplet.setImage(new Image("ubuntu-14-04-x64"));
droplet.setRegion(new Region("sgp1"));
Droplets droplets = apiClient.createDroplets(droplet);
assertNotNull(droplets);
assertFalse((droplets.getDroplets().isEmpty()));
for (Droplet d : droplets.getDroplets()) {
log.info(d.toString());
}
}
@Test
public void testDeleteDroplet() throws DigitalOceanException, RequestUnsuccessfulException {
Delete result = apiClient.deleteDroplet(2258153);
assertNotNull(result);
log.info("Delete Request Object: " + result);
}
@Test
public void testDeleteDropletByTagName()
throws DigitalOceanException, RequestUnsuccessfulException {
Delete result = apiClient.deleteDropletByTagName("delete-me");
assertNotNull(result);
log.info("Delete by tag name Request Object: " + result);
}
@Test
public void testGetDropletNeighbors() throws DigitalOceanException, RequestUnsuccessfulException {
Droplets droplets = apiClient.getDropletNeighbors(dropletIdForInfo, 1);
assertNotNull(droplets);
for (Droplet d : droplets.getDroplets()) {
log.info(d.toString());
}
}
@Test
public void testGetAllDropletNeighbors()
throws DigitalOceanException, RequestUnsuccessfulException {
Neighbors neighbors = apiClient.getAllDropletNeighbors(1);
assertNotNull(neighbors);
for (Droplet d : neighbors.getNeighbors()) {
log.info(d.toString());
}
}
@Test
public void testGetAvailableDropletsByTagName()
throws DigitalOceanException, RequestUnsuccessfulException {
Droplets droplets = apiClient.getAvailableDropletsByTagName("mytagtest1", 1, 25);
assertNotNull(droplets);
for (Droplet d : droplets.getDroplets()) {
log.info(d.toString());
}
}
@Test
public void testRebootDroplet() throws DigitalOceanException, RequestUnsuccessfulException {
Action action = apiClient.rebootDroplet(2258136);
assertNotNull(action);
log.info(action.toString());
}
@Test
public void testPowerCycleDroplet() throws DigitalOceanException, RequestUnsuccessfulException {
Action action = apiClient.rebootDroplet(2258136);
assertNotNull(action);
log.info(action.toString());
}
@Test
public void testShutdownDroplet() throws DigitalOceanException, RequestUnsuccessfulException {
Action action = apiClient.shutdownDroplet(4124871); // 2258168
assertNotNull(action);
log.info(action.toString());
}
@Test
public void testPowerOffDroplet() throws DigitalOceanException, RequestUnsuccessfulException {
Action action = apiClient.powerOffDroplet(2258168);
assertNotNull(action);
log.info(action.toString());
}
@Test
public void testPowerOnDroplet() throws DigitalOceanException, RequestUnsuccessfulException {
Action action = apiClient.powerOnDroplet(2258136);
assertNotNull(action);
log.info(action.toString());
}
@Test
public void testResetDropletPassword()
throws DigitalOceanException, RequestUnsuccessfulException {
Action action = apiClient.resetDropletPassword(2258168);
assertNotNull(action);
log.info(action.toString());
}
@Test
public void testResizeDroplet() throws DigitalOceanException, RequestUnsuccessfulException {
Action action = apiClient.resizeDroplet(2258136, "1gb");
assertNotNull(action);
log.info(action.toString());
}
@Test
public void testTakeDropletSnapshot() throws DigitalOceanException, RequestUnsuccessfulException {
// Action action = apiClient.takeDropletSnapshot(2258168, "api-client-test-snapshot1");
Action action = apiClient.takeDropletSnapshot(2258136);
assertNotNull(action);
log.info(action.toString());
}
@Test
public void testRestoreDroplet() throws DigitalOceanException, RequestUnsuccessfulException {
Action action = apiClient.restoreDroplet(2258168, 5489522); // Snapshot id
assertNotNull(action);
log.info(action.toString());
}
@Test
public void testRebuildDroplet() throws DigitalOceanException, RequestUnsuccessfulException {
Action action = apiClient.rebuildDroplet(2258136, 3445812); // Debian 7.0 x64
assertNotNull(action);
log.info(action.toString());
}
@Test
public void testEnableDropletBackups()
throws DigitalOceanException, RequestUnsuccessfulException {
Action action = apiClient.enableDropletBackups(9662284);
assertNotNull(action);
log.info(action.toString());
}
@Test
public void testDisableDropletBackups()
throws DigitalOceanException, RequestUnsuccessfulException {
Action action = apiClient.disableDropletBackups(2258168);
assertNotNull(action);
log.info(action.toString());
}
@Test
public void testRenameDroplet() throws DigitalOceanException, RequestUnsuccessfulException {
Action action = apiClient.renameDroplet(2258168, "renamed-droplet-name-test");
assertNotNull(action);
log.info(action.toString());
}
@Test
public void testChangeDropletKernel() throws DigitalOceanException, RequestUnsuccessfulException {
Action action = apiClient.changeDropletKernel(2258168, 1649);
assertNotNull(action);
log.info(action.toString());
}
@Test
public void testEnableDropletIpv6() throws DigitalOceanException, RequestUnsuccessfulException {
Action action = apiClient.enableDropletIpv6(2258168);
assertNotNull(action);
log.info(action.toString());
}
@Test
public void testEnableDropletPrivateNetworking()
throws DigitalOceanException, RequestUnsuccessfulException {
Action action = apiClient.enableDropletPrivateNetworking(2258168);
assertNotNull(action);
log.info(action.toString());
}
// Account Test cases
@Test
public void testGetAccountInfo() throws DigitalOceanException, RequestUnsuccessfulException {
Account account = apiClient.getAccountInfo();
assertNotNull(account);
log.info(account.toString());
}
// Action Test cases
@Test
public void testGetAvailableActions() throws DigitalOceanException, RequestUnsuccessfulException {
Actions actions = apiClient.getAvailableActions(2, 30);
assertNotNull(actions);
assertFalse((actions.getActions().isEmpty()));
log.info(actions.getLinks().toString());
int i = 1;
for (Action a : actions.getActions()) {
log.info(i++ + " -> " + a.toString());
}
}
@Test
public void testGetActionInfo() throws DigitalOceanException, RequestUnsuccessfulException {
Action action = apiClient.getActionInfo(28336352);
assertNotNull(action);
log.info(action.toString());
}
@Test
public void testGetAvailableDropletActions()
throws DigitalOceanException, RequestUnsuccessfulException {
Actions actions = apiClient.getAvailableDropletActions(dropletIdForInfo, 1, 20);
Actions actions3 = apiClient.getAvailableDropletActions(dropletIdForInfo, 3, 20);
assertNotNull(actions);
assertFalse((actions.getActions().isEmpty()));
assertNotNull(actions3);
assertFalse((actions3.getActions().isEmpty()));
for (Action a : actions.getActions()) {
log.info(a.toString());
}
}
@Test
public void testGetAvailableImageActions()
throws DigitalOceanException, RequestUnsuccessfulException {
Actions actions = apiClient.getAvailableImageActions(3794738, 1, 20);
assertNotNull(actions);
assertFalse((actions.getActions().isEmpty()));
for (Action a : actions.getActions()) {
log.info(a.toString());
}
}
@Test
public void testGetAvailableFloatingIPActions()
throws DigitalOceanException, RequestUnsuccessfulException {
Actions actions = apiClient.getAvailableFloatingIPActions("159.203.146.100", 1, 10);
log.info(actions.toString());
assertNotNull(actions);
int i = 1;
for (Action action : actions.getActions()) {
log.info(i++ + " -> " + action.toString());
}
}
@Test
public void testGetFloatingIPActionInfo()
throws DigitalOceanException, RequestUnsuccessfulException {
Action action = apiClient.getFloatingIPActionInfo("159.203.146.100", 76697074);
log.info(action.toString());
assertNotNull(action);
}
// Image test cases
@Test
public void testCreateCustomImage() throws DigitalOceanException, RequestUnsuccessfulException {
Image input =
new Image(
"ubuntu-18.04-minimal",
"http://cloud-images.ubuntu.com/minimal/releases/bionic/release/ubuntu-18.04-minimal-cloudimg-amd64.img",
"nyc3");
input.setDescription("Cloud-optimized image w/ small footprint");
input.setDistribution("Ubuntu");
input.setTags(Arrays.asList("base-image", "prod"));
Image image = apiClient.updateImage(input);
assertNotNull(image);
log.info(image.toString());
}
@Test
public void testUpdateImageInfo() throws DigitalOceanException, RequestUnsuccessfulException {
Image input = new Image();
input.setId(3897539);
input.setName("test-myjeeva.com-before-wp-upgrade");
Image image = apiClient.updateImage(input);
assertNotNull(image);
log.info(image.toString());
}
@Test
public void testDeleteImage() throws DigitalOceanException, RequestUnsuccessfulException {
Delete result = apiClient.deleteImage(3897539);
assertNotNull(result);
log.info("Delete Request result: " + result);
}
@Test
public void testTransferImage() throws DigitalOceanException, RequestUnsuccessfulException {
Action action = apiClient.transferImage(5489522, "lon1");
assertNotNull(action);
log.info(action.toString());
}
@Test
public void testConvertImage() throws DigitalOceanException, RequestUnsuccessfulException {
Action action = apiClient.convertImage(5489522);
assertNotNull(action);
log.info(action.toString());
}
// Domain test cases
@Test
public void testCreateDomain() throws DigitalOceanException, RequestUnsuccessfulException {
String domainIp = "127.0.0.1";
Domain input = new Domain(domainName, domainIp);
Domain domain = apiClient.createDomain(input);
assertNotNull(domain);
assertNotNull(domain.getName());
log.info(domain.toString());
}
@Test
public void testDeleteDomain() throws DigitalOceanException, RequestUnsuccessfulException {
Delete result = apiClient.deleteDomain(domainName);
assertNotNull(result);
log.info("Delete Request Object: " + result);
}
@Test
public void testGetDomainRecords() throws DigitalOceanException, RequestUnsuccessfulException {
DomainRecords domainRecords = apiClient.getDomainRecords("jeeutil.com", 1, null);
assertNotNull(domainRecords);
assertFalse((domainRecords.getDomainRecords().isEmpty()));
for (DomainRecord dr : domainRecords.getDomainRecords()) {
log.info(dr.toString());
}
}
@Test
public void testGetDomainRecordInfo() throws DigitalOceanException, RequestUnsuccessfulException {
DomainRecord domainRecord = apiClient.getDomainRecordInfo("jeeutil.com", 160448);
assertNotNull(domainRecord);
log.info(domainRecord.toString());
}
@Test
public void testCreateDomainRecord() throws DigitalOceanException, RequestUnsuccessfulException {
DomainRecord input = new DomainRecord("test1", "@", "CNAME");
DomainRecord domainRecord = apiClient.createDomainRecord("jeeutil.com", input);
assertNotNull(domainRecord);
log.info(domainRecord.toString());
}
@Test
public void testUpdateDomainRecord() throws DigitalOceanException, RequestUnsuccessfulException {
DomainRecord record = new DomainRecord("testjs", "@", "CNAME");
DomainRecord domainRecord = apiClient.updateDomainRecord("example.me", 10989796, record);
assertNotNull(domainRecord);
log.info(domainRecord.toString());
}
@Test
public void testDeleteDomainRecord() throws DigitalOceanException, RequestUnsuccessfulException {
Delete result = apiClient.deleteDomainRecord("jeeutil.com", 3253734);
assertNotNull(result);
log.info("Delete Request Object: " + result.toString());
}
// SSH Key test cases
@Test
public void testCreateKey() throws DigitalOceanException, RequestUnsuccessfulException {
// Key key = new Key("TestKey1",
// "ssh-rsa
// AAAAB3NzaC1yc2EAAAADAQABAAABAQDDiyGRkL26BEFPkce1Xtv8u05t8IYHZ63EVDEoAfvg/HCM7SEauBogDGknd4aMd7p9XtxuEIiojiNDIpTnoYbS0RojzhtomefQ/Lx02Rpfsbj1U3zg1H/MMObgJILGIYyHwfT+1rkkRxJQBVcs2Yj7IOmsrmE6SkAZaDLnMxq74HWzd7sPHxx/Dmv6fE0VMaZa+l7Fwr/2Tm46RMF5vzb93QwwmShV+08Ik/0NjGgP7QcNzT11lrI1eCjwCFyT00sGXR+xa4n+M80NB3b8GqDJDAMKqxELcFkpGyGAqESlYt4DXoCRDmnUwhhHReOuutOUHqrSMCym94FFeJ6p6M1f
// jenkinsci@dexmedia.com");
Key key =
new Key(
"TestKey1",
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCqMycrkDQdWJUuI5/yx5+Du2BD/W5CXRPnd1xr60MV1zSaRA7OI6sShBontgdI7iepq33hMNaBdr1VttagCjeVJpIsM78Dkcq2NmJ2DKqPnzmfcuJOfcVXO0al2kn4wkYhCKoCV1u3YFCSBW5h3KWOXnptUq30cLUnjgOpAHpugNatJS5Wk8h9V53V2m06FOOty9TY3L8BLQlG3Btl201XMQasFb25izoablwupRLeItzzOHSlwbXWDcrkEQz7o+doOsgpdUfPdQrC1Nv9ujV/Va7BIuUBVVQSznBddCvxmIv/9LIRR7S+Hk+jB8ZgSBcFdmfjdzdQxU39xri5OFTF madanje");
Key resultKey = apiClient.createKey(key);
assertNotNull(resultKey);
assertNotNull(resultKey.getId());
log.info(resultKey.toString());
}
@Test
public void testGetKeyById() throws DigitalOceanException, RequestUnsuccessfulException {
Key resultKey = apiClient.getKeyInfo(245798);
assertNotNull(resultKey);
assertNotNull(resultKey.getId());
log.info(resultKey.toString());
}
@Test
public void testGetKeyByFingerprint() throws DigitalOceanException, RequestUnsuccessfulException {
Key resultKey = apiClient.getKeyInfo("3b:0b:99:54:ef:75:cb:88:88:66:3c:8d:10:64:74:32");
assertNotNull(resultKey);
assertNotNull(resultKey.getId());
log.info(resultKey.toString());
}
@Test
public void testUpdateKeyById() throws DigitalOceanException, RequestUnsuccessfulException {
Key resultKey = apiClient.updateKey(245798, "TestKey5");
assertNotNull(resultKey);
assertNotNull(resultKey.getId());
log.info(resultKey.toString());
}
@Test
public void testUpdateKeyByFingerprint()
throws DigitalOceanException, RequestUnsuccessfulException {
Key resultKey =
apiClient.updateKey("3b:0b:99:54:ef:75:cb:88:88:66:3c:8d:10:64:74:32", "TestKey4");
assertNotNull(resultKey);
assertNotNull(resultKey.getId());
log.info(resultKey.toString());
}
@Test
public void testDeleteKeyById() throws DigitalOceanException, RequestUnsuccessfulException {
Delete result = apiClient.deleteKey(245798);
assertNotNull(result);
log.info("Delete Key Request Object: " + result);
}
@Test
public void testDeleteKeyByFingerprint()
throws DigitalOceanException, RequestUnsuccessfulException {
Delete result = apiClient.deleteKey("3b:0b:99:54:ef:75:cb:88:88:66:3c:8d:10:64:74:32");
assertNotNull(result);
log.info("Delete Key Request Object: " + result);
}
// Floating IPs test cases
@Test
public void testCreateFloatingIPForDroplet()
throws DigitalOceanException, RequestUnsuccessfulException {
FloatingIP floatingIP = apiClient.createFloatingIP(9674996);
assertNotNull(floatingIP);
log.info(floatingIP.toString());
}
@Test
public void testCreateFloatingIPForRegion()
throws DigitalOceanException, RequestUnsuccessfulException {
FloatingIP floatingIP = apiClient.createFloatingIP("nyc3");
assertNotNull(floatingIP);
log.info(floatingIP.toString());
}
@Test
public void testGetFloatingIPInfo() throws DigitalOceanException, RequestUnsuccessfulException {
FloatingIP floatingIP = apiClient.getFloatingIPInfo("159.203.146.100");
assertNotNull(floatingIP);
log.info(floatingIP.toString());
}
@Test
public void testDeleteFloatingIP() throws DigitalOceanException, RequestUnsuccessfulException {
Delete result = apiClient.deleteFloatingIP("159.203.146.109");
assertNotNull(result);
log.info("Delete Floating IP Request Object: " + result);
}
@Test
public void testAssignFloatingIP() throws DigitalOceanException, RequestUnsuccessfulException {
Action action = apiClient.assignFloatingIP(9674996, "159.203.146.100");
log.info(action.toString());
assertNotNull(action);
assertEquals(ActionType.ASSIGN_FLOATING_IP, action.getType());
assertEquals(ResourceType.FLOATING_IP, action.getResourceType());
}
@Test
public void testUnassignFloatingIP() throws DigitalOceanException, RequestUnsuccessfulException {
Action action = apiClient.unassignFloatingIP("159.203.146.100");
log.info(action.toString());
assertNotNull(action);
assertEquals(ActionType.UNASSIGN_FLOATING_IP, action.getType());
assertEquals(ResourceType.FLOATING_IP, action.getResourceType());
}
@Test
public void testCreateTag() throws DigitalOceanException, RequestUnsuccessfulException {
Tag tag = apiClient.createTag("blr");
log.info(tag.toString());
assertNotNull(tag);
assertEquals("blr", tag.getName());
}
@Test
public void testGetTag() throws DigitalOceanException, RequestUnsuccessfulException {
Tag tag = apiClient.getTag("blog");
log.info(tag.toString());
assertNotNull(tag);
assertEquals("blog", tag.getName());
}
@Test
public void testDeleteTag() throws DigitalOceanException, RequestUnsuccessfulException {
Delete result = apiClient.deleteTag("blr");
assertNotNull(result);
log.info("Delete Tag Object: " + result);
}
@Test
public void testTagResources() throws DigitalOceanException, RequestUnsuccessfulException {
List<Resource> resources = new ArrayList<Resource>();
resources.add(new Resource("3794738", ResourceType.DROPLET));
Response result = apiClient.tagResources("lab", resources);
assertNotNull(result);
log.info("Response of Tag resources: " + result);
}
@Test
public void testUntagResources() throws DigitalOceanException, RequestUnsuccessfulException {
List<Resource> resources = new ArrayList<Resource>();
resources.add(new Resource("3794738", ResourceType.DROPLET));
Response result = apiClient.untagResources("lab", resources);
assertNotNull(result);
log.info("Response of Tag resources: " + result);
}
@Test
public void testCreateVolume() throws DigitalOceanException, RequestUnsuccessfulException {
Volume volume = new Volume();
volume.setName("api-client-test-host-volume");
volume.setDescription("Test Volume Description");
volume.setRegion(new Region("nyc1"));
volume.setSize(1);
// different ID from volumeIdForInfo and created
// in nyc1 region
// to be placed before use
String volumeSnapshotIdForCreate = "197e26b6-c242-11e7-bd8b-0242ac113802";
volume.setSnapshotId(volumeSnapshotIdForCreate);
Volume v = apiClient.createVolume(volume);
assertNotNull(v);
assertNotNull(v.getId());
log.info(v.toString());
}
@Test
public void testGetVolumeInfo() throws DigitalOceanException, RequestUnsuccessfulException {
Volume volume = apiClient.getVolumeInfo(volumeIdForInfo);
assertNotNull(volume);
log.info(volume.toString());
}
@Test
public void testGetVolumeInfoByName() throws DigitalOceanException, RequestUnsuccessfulException {
Volumes volumes = apiClient.getVolumeInfo(volumeNameForInfo, "nyc1");
assertNotNull(volumes);
assertFalse((volumes.getVolumes().isEmpty()));
int i = 1;
for (Volume volume : volumes.getVolumes()) {
log.info(i++ + " -> " + volume.toString());
}
}
@Test
public void testAtachVolume() throws DigitalOceanException, RequestUnsuccessfulException {
Action action = apiClient.attachVolume(dropletIdForInfo, volumeIdForInfo, "nyc1");
assertNotNull(action);
log.info(action.toString());
}
@Test
public void testAttachVolumeByName() throws DigitalOceanException, RequestUnsuccessfulException {
Action action = apiClient.attachVolumeByName(dropletIdForInfo, volumeNameForInfo, "nyc1");
assertNotNull(action);
log.info(action.toString());
}
@Test
public void testResizeVolume() throws DigitalOceanException, RequestUnsuccessfulException {
Action action = apiClient.resizeVolume(volumeIdForInfo, "nyc1", 3D);
assertNotNull(action);
log.info(action.toString());
}
@Test
public void testDeachVolume() throws DigitalOceanException, RequestUnsuccessfulException {
Action action = apiClient.detachVolume(dropletIdForInfo, volumeIdForInfo, "nyc1");
assertNotNull(action);
log.info(action.toString());
}
@Test
public void testDetachVolumeByName() throws DigitalOceanException, RequestUnsuccessfulException {
Action action = apiClient.detachVolumeByName(dropletIdForInfo, volumeNameForInfo, "nyc1");
assertNotNull(action);
log.info(action.toString());
}
@Test
public void testAvailableVolumeActions()
throws DigitalOceanException, RequestUnsuccessfulException {
Actions actions = apiClient.getAvailableVolumeActions(volumeIdForInfo);
assertNotNull(actions);
assertFalse((actions.getActions().isEmpty()));
log.info(actions.getLinks().toString());
int i = 1;
for (Action a : actions.getActions()) {
log.info(i++ + " -> " + a.toString());
}
}
@Test
public void testAvailableVolumeAction()
throws DigitalOceanException, RequestUnsuccessfulException {
Actions actions = apiClient.getAvailableVolumeActions(volumeIdForInfo);
assertNotNull(actions);
assertFalse((actions.getActions().isEmpty()));
Action action = actions.getActions().get(0);
apiClient.getVolumeAction(volumeIdForInfo, action.getId());
assertNotNull(action);
log.info(action.toString());
}
@Test
public void testDeleteVolume() throws DigitalOceanException, RequestUnsuccessfulException {
Delete result = apiClient.deleteVolume(volumeIdForInfo);
assertNotNull(result);
log.info("Delete Request Object: " + result);
}
@Test
public void testDeleteVolumeByName() throws DigitalOceanException, RequestUnsuccessfulException {
Delete result = apiClient.deleteVolume(volumeNameForInfo, "nyc1");
assertNotNull(result);
log.info("Delete Request Object: " + result);
}
@Test
public void testGetVolumeSnapshots() throws DigitalOceanException, RequestUnsuccessfulException {
Snapshots snapshots =