This repository was archived by the owner on Oct 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathNodeApiTest.java
5417 lines (4347 loc) · 235 KB
/
NodeApiTest.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
/*
* #%L
* Alfresco Remote API
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.rest.api.tests;
import static org.alfresco.rest.api.tests.util.RestApiUtil.parsePaging;
import static org.alfresco.rest.api.tests.util.RestApiUtil.toJsonAsStringNonNull;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import org.alfresco.repo.content.ContentLimitProvider.SimpleFixedLimitProvider;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.tenant.TenantService;
import org.alfresco.repo.tenant.TenantUtil;
import org.alfresco.rest.AbstractSingleNetworkSiteTest;
import org.alfresco.rest.api.Nodes;
import org.alfresco.rest.api.model.LockInfo;
import org.alfresco.rest.api.model.NodePermissions;
import org.alfresco.rest.api.model.NodeTarget;
import org.alfresco.rest.api.model.Site;
import org.alfresco.rest.api.nodes.NodesEntityResource;
import org.alfresco.rest.api.tests.client.HttpResponse;
import org.alfresco.rest.api.tests.client.PublicApiClient;
import org.alfresco.rest.api.tests.client.PublicApiClient.ExpectedPaging;
import org.alfresco.rest.api.tests.client.PublicApiClient.Paging;
import org.alfresco.rest.api.tests.client.PublicApiHttpClient.BinaryPayload;
import org.alfresco.rest.api.tests.client.data.Association;
import org.alfresco.rest.api.tests.client.data.ContentInfo;
import org.alfresco.rest.api.tests.client.data.Document;
import org.alfresco.rest.api.tests.client.data.Folder;
import org.alfresco.rest.api.tests.client.data.Node;
import org.alfresco.rest.api.tests.client.data.PathInfo;
import org.alfresco.rest.api.tests.client.data.PathInfo.ElementInfo;
import org.alfresco.rest.api.tests.client.data.SiteRole;
import org.alfresco.rest.api.tests.client.data.UserInfo;
import org.alfresco.rest.api.tests.util.MultiPartBuilder;
import org.alfresco.rest.api.tests.util.MultiPartBuilder.FileData;
import org.alfresco.rest.api.tests.util.MultiPartBuilder.MultiPartRequest;
import org.alfresco.rest.api.tests.util.RestApiUtil;
import org.alfresco.service.cmr.lock.LockType;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.security.AccessPermission;
import org.alfresco.service.cmr.security.AccessStatus;
import org.alfresco.service.cmr.security.AuthorityService;
import org.alfresco.service.cmr.security.AuthorityType;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.cmr.site.SiteVisibility;
import org.alfresco.util.GUID;
import org.alfresco.util.TempFileProvider;
import org.apache.commons.collections.map.MultiValueMap;
import org.json.simple.JSONObject;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* V1 REST API tests for Nodes (files, folders and custom node types)
*
* <ul>
* <li> {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/nodes/<nodeId>} </li>
* <li> {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/nodes/<nodeId>/children} </li>
* </ul>
*
* TODO
* - improve test 'fwk' to enable api tests to be run against remote repo (rather than embedded jetty)
* - requires replacement of remaining non-remote calls with remote (preferably public) apis
* - eg. createUser (or any other usage of repoService), permissionService, AuthenticationUtil, ...
*
* @author Jamal Kaabi-Mofrad
* @author janv
*/
public class NodeApiTest extends AbstractSingleNetworkSiteTest
{
private static final String PROP_OWNER = "cm:owner";
private static final String URL_DELETED_NODES = "deleted-nodes";
private static final String EMPTY_BODY = "{}";
protected PermissionService permissionService;
protected AuthorityService authorityService;
private String rootGroupName = null;
private String groupA = null;
private String groupB = null;
@Before
public void setup() throws Exception
{
super.setup();
permissionService = applicationContext.getBean("permissionService", PermissionService.class);
authorityService = (AuthorityService) applicationContext.getBean("AuthorityService");
}
@After
public void tearDown() throws Exception
{
super.tearDown();
}
/**
* Tests get document library children.
* <p>GET:</p>
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/nodes/<nodeId>/children}
*/
@Test
public void testListChildrenWithinSiteDocLib() throws Exception
{
setRequestContext(user1);
// create folder f0
String folder0Name = "f0-testListChildrenWithinSiteDocLib-"+RUNID;
String f0Id = createFolder(tDocLibNodeId, folder0Name).getId();
String folder1 = "folder" + RUNID + "_1";
createFolder(f0Id, folder1, null).getId();
String folder2 = "folder" + RUNID + "_2";
createFolder(f0Id, folder2, null).getId();
String content1 = "content" + RUNID + "_1";
createTextFile(f0Id, content1, "The quick brown fox jumps over the lazy dog 1.").getId();
String content2 = "content" + RUNID + "_2";
createTextFile(f0Id, content2, "The quick brown fox jumps over the lazy dog 2.").getId();
String forum1 = "forum" + RUNID + "_1";
createNode(f0Id, forum1, "fm:topic", null);
Paging paging = getPaging(0, 100);
HttpResponse response = getAll(getNodeChildrenUrl(f0Id), paging, 200);
List<Node> nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(4, nodes.size()); // forum is part of the default ignored types
// Paging
ExpectedPaging expectedPaging = RestApiUtil.parsePaging(response.getJsonResponse());
assertEquals(4, expectedPaging.getCount().intValue());
assertEquals(0, expectedPaging.getSkipCount().intValue());
assertEquals(100, expectedPaging.getMaxItems().intValue());
assertFalse(expectedPaging.getHasMoreItems().booleanValue());
// Order by folders and modified date first
Map<String, String> orderBy = Collections.singletonMap("orderBy", "isFolder DESC,modifiedAt DESC");
response = getAll(getNodeChildrenUrl(f0Id), paging, orderBy, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(4, nodes.size());
assertEquals(folder2, nodes.get(0).getName());
assertTrue(nodes.get(0).getIsFolder());
assertFalse(nodes.get(0).getIsFile());
assertEquals(folder1, nodes.get(1).getName());
assertTrue(nodes.get(1).getIsFolder());
assertFalse(nodes.get(1).getIsFile());
assertEquals(content2, nodes.get(2).getName());
assertFalse(nodes.get(2).getIsFolder());
assertTrue(nodes.get(2).getIsFile());
assertEquals(content1, nodes.get(3).getName());
assertFalse(nodes.get(3).getIsFolder());
assertTrue(nodes.get(3).getIsFile());
// Order by folders last and modified date first
orderBy = Collections.singletonMap("orderBy", "isFolder ASC,modifiedAt DESC");
response = getAll(getNodeChildrenUrl(f0Id), paging, orderBy, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(4, nodes.size());
assertEquals(content2, nodes.get(0).getName());
assertEquals(content1, nodes.get(1).getName());
assertEquals(folder2, nodes.get(2).getName());
assertEquals(folder1, nodes.get(3).getName());
// Order by folders and modified date last
orderBy = Collections.singletonMap("orderBy", "isFolder,modifiedAt");
response = getAll(getNodeChildrenUrl(f0Id), paging, orderBy, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(4, nodes.size());
assertEquals(content1, nodes.get(0).getName());
assertEquals(content2, nodes.get(1).getName());
assertEquals(folder1, nodes.get(2).getName());
assertEquals(folder2, nodes.get(3).getName());
// Order by folders and modified date first
orderBy = Collections.singletonMap("orderBy", "isFolder DESC,modifiedAt DESC");
// SkipCount=0,MaxItems=2
paging = getPaging(0, 2);
response = getAll(getNodeChildrenUrl(f0Id), paging, orderBy, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(2, nodes.size());
assertEquals(folder2, nodes.get(0).getName());
assertEquals(folder1, nodes.get(1).getName());
expectedPaging = RestApiUtil.parsePaging(response.getJsonResponse());
assertEquals(2, expectedPaging.getCount().intValue());
assertEquals(0, expectedPaging.getSkipCount().intValue());
assertEquals(2, expectedPaging.getMaxItems().intValue());
assertTrue(expectedPaging.getHasMoreItems().booleanValue());
// SkipCount=null,MaxItems=2
paging = getPaging(null, 2);
response = getAll(getNodeChildrenUrl(f0Id), paging, orderBy, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(2, nodes.size());
assertEquals(folder2, nodes.get(0).getName());
assertEquals(folder1, nodes.get(1).getName());
expectedPaging = RestApiUtil.parsePaging(response.getJsonResponse());
assertEquals(2, expectedPaging.getCount().intValue());
assertEquals(0, expectedPaging.getSkipCount().intValue());
assertEquals(2, expectedPaging.getMaxItems().intValue());
assertTrue(expectedPaging.getHasMoreItems().booleanValue());
// SkipCount=2,MaxItems=4
paging = getPaging(2, 4);
response = getAll(getNodeChildrenUrl(f0Id), paging, orderBy, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(2, nodes.size());
assertEquals(content2, nodes.get(0).getName());
assertEquals(content1, nodes.get(1).getName());
expectedPaging = RestApiUtil.parsePaging(response.getJsonResponse());
assertEquals(2, expectedPaging.getCount().intValue());
assertEquals(2, expectedPaging.getSkipCount().intValue());
assertEquals(4, expectedPaging.getMaxItems().intValue());
assertFalse(expectedPaging.getHasMoreItems().booleanValue());
// SkipCount=2,MaxItems=null
paging = getPaging(2, null);
response = getAll(getNodeChildrenUrl(f0Id), paging, orderBy, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(2, nodes.size());
assertEquals(content2, nodes.get(0).getName());
assertEquals(content1, nodes.get(1).getName());
expectedPaging = RestApiUtil.parsePaging(response.getJsonResponse());
assertEquals(2, expectedPaging.getCount().intValue());
assertEquals(2, expectedPaging.getSkipCount().intValue());
assertEquals(100, expectedPaging.getMaxItems().intValue());
assertFalse(expectedPaging.getHasMoreItems().booleanValue());
setRequestContext(user2);
// user2 tries to access user1's folder in a private docLib
paging = getPaging(0, Integer.MAX_VALUE);
getAll(getNodeChildrenUrl(f0Id), paging, 403);
setRequestContext(user1);
// -ve test - paging (via list children) cannot have skipCount < 0
paging = getPaging(-1, 4);
getAll(getNodeChildrenUrl(f0Id), paging, orderBy, 400);
// -ve test - paging (via list children) cannot have maxItems < 1
paging = getPaging(0, 0);
getAll(getNodeChildrenUrl(f0Id), paging, orderBy, 400);
}
/**
* Tests list children.
* <p>GET:</p>
* {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/nodes/<nodeId>/children}
*/
@Test
public void testListChildrenWithinMyFiles() throws Exception
{
setRequestContext(user1);
String myNodeId = getMyNodeId();
String rootChildrenUrl = getNodeChildrenUrl(Nodes.PATH_ROOT);
String folder0Name = "folder " + RUNID + " 0";
String folder0Id = createFolder(myNodeId, folder0Name, null).getId();
String childrenUrl = getNodeChildrenUrl(folder0Id);
Map<String, Object> props = new HashMap<>(1);
props.put("cm:title", "This is folder 1");
String folder1 = "folder " + RUNID + " 1";
String folder1_Id = createFolder(folder0Id, folder1, props).getId();
String contentF1 = "content" + RUNID + " in folder 1";
String contentF1_Id = createTextFile(folder1_Id, contentF1, "The quick brown fox jumps over the lazy dog 1.").getId();
props = new HashMap<>(1);
props.put("cm:title", "This is folder 2");
String folder2 = "folder " + RUNID + " 2";
String folder2_Id = createFolder(folder0Id, folder2, props).getId();
String contentF2 = "content" + RUNID + " in folder 2.txt";
String contentF2_Id = createTextFile(folder2_Id, contentF2, "The quick brown fox jumps over the lazy dog 2.").getId();
String content1 = "content" + RUNID + " 1.txt";
String content1_Id = createTextFile(folder0Id, content1, "The quick brown fox jumps over the lazy dog.").getId();
props = new HashMap<>();
props.put(PROP_OWNER, user1);
props.put("cm:lastThumbnailModification", Collections.singletonList("doclib:1444660852296"));
Node nodeUpdate = new Node();
nodeUpdate.setProperties(props);
put(URL_NODES, content1_Id, toJsonAsStringNonNull(nodeUpdate), null, 200);
List<String> folderIds = Arrays.asList(folder1_Id, folder2_Id);
List<String> contentIds = Arrays.asList(content1_Id);
Paging paging = getPaging(0, 100);
HttpResponse response = getAll(childrenUrl, paging, 200);
List<Document> nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Document.class);
assertEquals(3, nodes.size());
// Order by folders and modified date first
Map<String, String> orderBy = Collections.singletonMap("orderBy", "isFolder DESC,modifiedAt DESC");
response = getAll(childrenUrl, paging, orderBy, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Document.class);
assertEquals(3, nodes.size());
assertEquals(folder2, nodes.get(0).getName());
assertEquals(folder1, nodes.get(1).getName());
Document node = nodes.get(2);
assertEquals(content1, node.getName());
assertEquals(TYPE_CM_CONTENT, node.getNodeType());
assertEquals(content1_Id, node.getId());
UserInfo createdByUser = node.getCreatedByUser();
assertEquals(user1, createdByUser.getId());
assertEquals(UserInfo.getTestDisplayName(user1), createdByUser.getDisplayName());
UserInfo modifiedByUser = node.getModifiedByUser();
assertEquals(user1, modifiedByUser.getId());
assertEquals(UserInfo.getTestDisplayName(user1), modifiedByUser.getDisplayName());
assertEquals(MimetypeMap.MIMETYPE_TEXT_PLAIN, node.getContent().getMimeType());
assertNotNull(node.getContent().getMimeTypeName());
assertNotNull(node.getContent().getEncoding());
assertTrue(node.getContent().getSizeInBytes() > 0);
// request without "include"
Map<String, String> params = new HashMap<>();
response = getAll(childrenUrl, paging, params, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Document.class);
for (Node n : nodes)
{
assertNull("There shouldn't be a 'properties' object in the response.", n.getProperties());
assertNull("There shouldn't be a 'isLink' object in the response.", n.getIsLink());
assertNull("There shouldn't be a 'path' object in the response.", n.getPath());
assertNull("There shouldn't be a 'aspectNames' object in the response.", n.getAspectNames());
}
// request with include - example 1
params = new HashMap<>();
params.put("include", "isLink");
response = getAll(childrenUrl, paging, params, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Document.class);
for (Node n : nodes)
{
assertNotNull("There should be a 'isLink' object in the response.", n.getIsLink());
}
// request with include - example 2
params = new HashMap<>();
params.put("include", "aspectNames,properties,path,isLink");
response = getAll(childrenUrl, paging, params, 200);
nodes = jacksonUtil.parseEntries(response.getJsonResponse(), Document.class);
for (Node n : nodes)
{
assertNotNull("There should be a 'properties' object in the response.", n.getProperties()); // eg. cm:title, see above
assertNotNull("There should be a 'isLink' object in the response.", n.getIsLink());
assertNotNull("There should be a 'path' object in the response.", n.getPath());
assertNotNull("There should be a 'aspectNames' object in the response.", n.getAspectNames());
}
// request specific property via include
params = new HashMap<>();
params.put("include", "cm:lastThumbnailModification");
params.put("orderBy", "isFolder DESC,modifiedAt DESC");
response = getAll(childrenUrl, paging, params, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Document.class);
assertEquals(3, nodes.size());
assertNull("There shouldn't be a 'properties' object in the response.", nodes.get(0).getProperties());
assertNull("There shouldn't be a 'properties' object in the response.", nodes.get(1).getProperties());
assertNotNull("There should be a 'properties' object in the response.", nodes.get(2).getProperties());
Set<Entry<String, Object>> propsSet = nodes.get(2).getProperties().entrySet();
assertEquals(1, propsSet.size());
Entry<String, Object> entry = propsSet.iterator().next();
assertEquals("cm:lastThumbnailModification", entry.getKey());
assertEquals("doclib:1444660852296", ((List<?>) entry.getValue()).get(0));
// filtering, via where clause - folders only
params = new HashMap<>();
params.put("where", "("+Nodes.PARAM_ISFOLDER+"=true)");
response = getAll(childrenUrl, paging, params, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Document.class);
assertEquals(2, nodes.size());
assertTrue(nodes.get(0).getIsFolder());
assertFalse(nodes.get(0).getIsFile());
assertTrue(folderIds.contains(nodes.get(0).getId()));
assertTrue(nodes.get(1).getIsFolder());
assertFalse(nodes.get(1).getIsFile());
assertTrue(folderIds.contains(nodes.get(1).getId()));
// filtering, via where clause - content only
params = new HashMap<>();
params.put("where", "("+Nodes.PARAM_ISFILE+"=true)");
response = getAll(childrenUrl, paging, params, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Document.class);
assertEquals(1, nodes.size());
assertFalse(nodes.get(0).getIsFolder());
assertTrue(nodes.get(0).getIsFile());
assertTrue(contentIds.contains(nodes.get(0).getId()));
// list children via relativePath
params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, folder1);
response = getAll(childrenUrl, paging, params, 200);
JSONObject jsonResponse = response.getJsonResponse();
nodes = RestApiUtil.parseRestApiEntries(jsonResponse, Document.class);
assertEquals(1, nodes.size());
assertEquals(contentF1_Id, nodes.get(0).getId());
JSONObject jsonList = (JSONObject)jsonResponse.get("list");
assertNotNull(jsonList);
JSONObject jsonSrcObj = (JSONObject)jsonResponse.get("source");
assertNull(jsonSrcObj);
params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, "User Homes/" + user1 + "/" + folder0Name + "/" + folder2);
response = getAll(rootChildrenUrl, paging, params, 200);
jsonResponse = response.getJsonResponse();
nodes = RestApiUtil.parseRestApiEntries(jsonResponse, Document.class);
assertEquals(1, nodes.size());
assertEquals(contentF2_Id, nodes.get(0).getId());
jsonList = (JSONObject)jsonResponse.get("list");
assertNotNull(jsonList);
jsonSrcObj = (JSONObject)jsonResponse.get("source");
assertNull(jsonSrcObj);
// list children via relativePath and also return the source entity
params = new HashMap<>();
params.put(Nodes.PARAM_RELATIVE_PATH, "User Homes/" + user1 + "/" + folder0Name + "/" + folder2);
params.put("includeSource", "true");
params.put("include", "path,isLink");
params.put("fields", "id");
response = getAll(rootChildrenUrl, paging, params, 200);
jsonResponse = response.getJsonResponse();
nodes = RestApiUtil.parseRestApiEntries(jsonResponse, Document.class);
assertEquals(1, nodes.size());
Document doc = nodes.get(0);
assertEquals(contentF2_Id, doc.getId());
assertNotNull(doc.getPath());
assertEquals(Boolean.FALSE, doc.getIsLink());
assertNull(doc.getName());
jsonList = (JSONObject)jsonResponse.get("list");
assertNotNull(jsonList);
// source is not affected by include (or fields for that matter) - returns the default node response
Folder src = RestApiUtil.parsePojo("source", jsonList, Folder.class);
assertEquals(folder2_Id, src.getId());
assertNull(src.getPath());
assertNull(src.getIsLink());
assertNotNull(src.getName());
assertNotNull(src.getAspectNames());
assertNotNull(src.getProperties());
// -ve test - Invalid QName (Namespace prefix cm... is not mapped to a namespace URI) for the orderBy parameter.
params = Collections.singletonMap("orderBy", Nodes.PARAM_ISFOLDER+" DESC,cm" + System.currentTimeMillis() + ":modified DESC");
getAll(childrenUrl, paging, params, 400);
paging = getPaging(0, 10);
// -ve test - list folder children for unknown node should return 404
getAll(getNodeChildrenUrl(UUID.randomUUID().toString()), paging, 404);
// -ve test - user2 tries to access user1's home folder
setRequestContext(user2);
getAll(getNodeChildrenUrl(myNodeId), paging, 403);
setRequestContext(user1);
// -ve test - try to list children using relative path to unknown node
params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, "User Homes/" + user1 + "/unknown");
getAll(rootChildrenUrl, paging, params, 404);
// -ve test - try to list children using relative path to node for which user does not have read permission (expect 404 instead of 403)
params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, "User Homes/" + user2);
getAll(rootChildrenUrl, paging, params, 404);
// -ve test - list folder children with relative path to unknown node should return 400
params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, "/unknown");
getAll(getNodeChildrenUrl(content1_Id), paging, params, 400);
// filtering, via where clause - negated comparison
params = new HashMap<>();
params.put("where", "(NOT "+Nodes.PARAM_ISFILE+"=true)");
getAll(childrenUrl, paging, params, 400);
}
/**
* Tests get node with path information.
* <p>GET:</p>
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/nodes/<nodeId>?include=path}
*/
@Test
public void testGetPathElements_DocLib() throws Exception
{
setRequestContext(user1);
// user1 creates a private site and adds user2 as a site consumer
String site1Title = "site-testGetPathElements_DocLib-" + RUNID;
String site1Id = createSite(site1Title, SiteVisibility.PRIVATE).getId();
addSiteMember(site1Id, user2, SiteRole.SiteConsumer);
String site1DocLibNodeId = getSiteContainerNodeId(site1Id, "documentLibrary");
// /Company Home/Sites/RandomSite<timestamp>/documentLibrary/folder<timestamp>_A
String folderA = "folder" + RUNID + "_A";
String folderA_Id = createFolder(site1DocLibNodeId, folderA).getId();
// /Company Home/Sites/RandomSite<timestamp>/documentLibrary/folder<timestamp>_A/folder<timestamp>_B
String folderB = "folder" + RUNID + "_B";
String folderB_Id = createFolder(folderA_Id, folderB).getId();
NodeRef folderB_Ref = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, folderB_Id);
// /Company Home/Sites/RandomSite<timestamp>/documentLibrary/folder<timestamp>_A/folder<timestamp>_B/folder<timestamp>_C
String folderC = "folder" + RUNID + "_C";
String folderC_Id = createFolder(folderB_Id, folderC).getId();
NodeRef folderC_Ref = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, folderC_Id);
// /Company Home/Sites/RandomSite<timestamp>/documentLibrary/folder<timestamp>_A/folder<timestamp>_B/folder<timestamp>_C/content<timestamp>
String content = "content" + RUNID;
String content1_Id = createTextFile(folderC_Id, content, "The quick brown fox jumps over the lazy dog.").getId();
// TODO refactor with remote permission api calls (maybe use v0 until we have v1 ?)
final String tenantDomain = (networkOne != null ? networkOne.getId() : TenantService.DEFAULT_DOMAIN);
AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Void>()
{
@Override
public Void doWork() throws Exception
{
return TenantUtil.runAsTenant(new TenantUtil.TenantRunAsWork<Void>()
{
public Void doWork() throws Exception
{
// Revoke folderB inherited permissions
permissionService.setInheritParentPermissions(folderB_Ref, false);
// Grant user2 permission for folderC
permissionService.setPermission(folderC_Ref, user2, PermissionService.CONSUMER, true);
return null;
}
}, tenantDomain);
}
}, user1);
//...nodes/nodeId?include=path
Map<String, String> params = Collections.singletonMap("include", "path");
HttpResponse response = getSingle(NodesEntityResource.class, content1_Id, params, 200);
Document node = jacksonUtil.parseEntry(response.getJsonResponse(), Document.class);
PathInfo path = node.getPath();
assertNotNull(path);
assertTrue(path.getIsComplete());
assertNotNull(path.getName());
// the path should only include the parents (not the requested node)
assertFalse(path.getName().endsWith(content));
assertTrue(path.getName().startsWith("/Company Home"));
List<ElementInfo> pathElements = path.getElements();
assertEquals(7, pathElements.size());
// Check path element names and types, and one or two random aspects.
assertEquals("Company Home", pathElements.get(0).getName());
assertEquals("cm:folder", pathElements.get(0).getNodeType());
assertEquals("Sites", pathElements.get(1).getName());
assertEquals("st:sites", pathElements.get(1).getNodeType());
assertEquals(site1Id, pathElements.get(2).getName());
assertEquals("st:site", pathElements.get(2).getNodeType());
assertTrue(pathElements.get(2).getAspectNames().contains("cm:titled"));
// Check that sys:* is filtered out - to be consistent with other aspect name lists
// e.g. /nodes/{nodeId}/children?include=aspectNames
assertFalse(pathElements.get(2).getAspectNames().contains("sys:undeletable"));
assertFalse(pathElements.get(2).getAspectNames().contains("sys:unmovable"));
assertEquals("documentLibrary", pathElements.get(3).getName());
assertEquals("cm:folder", pathElements.get(3).getNodeType());
assertTrue(pathElements.get(3).getAspectNames().contains("st:siteContainer"));
assertEquals(folderA, pathElements.get(4).getName());
assertEquals("cm:folder", pathElements.get(4).getNodeType());
assertEquals(folderB, pathElements.get(5).getName());
assertEquals("cm:folder", pathElements.get(5).getNodeType());
assertEquals(folderC, pathElements.get(6).getName());
assertEquals("cm:folder", pathElements.get(6).getNodeType());
// Try the above tests with user2 (site consumer)
setRequestContext(user2);
response = getSingle(NodesEntityResource.class, content1_Id, params, 200);
node = jacksonUtil.parseEntry(response.getJsonResponse(), Document.class);
path = node.getPath();
assertNotNull(path);
assertFalse("The path is not complete as the user doesn't have permission to access the full path.", path.getIsComplete());
assertNotNull(path.getName());
// site consumer (user2) dose not have access to the folderB
assertFalse("site consumer (user2) dose not have access to the folderB", path.getName().contains(folderB));
assertFalse(path.getName().startsWith("/Company Home"));
// Go up as far as they can, before getting access denied (i.e. "/folderC")
assertTrue(path.getName().endsWith(folderC));
pathElements = path.getElements();
assertEquals(1, pathElements.size());
assertEquals(folderC, pathElements.get(0).getName());
// cleanup
setRequestContext(user1);
deleteSite(site1Id, true, 204);
}
/**
* Tests get node information.
* <p>GET:</p>
* {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/nodes/<nodeId>}
*/
@Test
public void testGetNodeInfo() throws Exception
{
setRequestContext(user1);
HttpResponse response = getSingle(NodesEntityResource.class, Nodes.PATH_ROOT, null, 200);
Node node = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
String rootNodeId = node.getId();
response = getSingle(NodesEntityResource.class, Nodes.PATH_MY, null, 200);
node = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
String myFilesNodeId = node.getId();
assertNotNull(myFilesNodeId);
assertEquals(user1, node.getName());
assertTrue(node.getIsFolder());
assertFalse(node.getIsFile());
String userHomesId = node.getParentId();
// /Company Home/User Homes/user<timestamp>/folder<timestamp>_A
String folderA = "folder" + RUNID + "_A";
String folderA_Id = createFolder(myFilesNodeId, folderA).getId();
// /Company Home/User Homes/user<timestamp>/folder<timestamp>_A/folder<timestamp>_B
String folderB = "folder" + RUNID + "_B";
String folderB_Id = createFolder(folderA_Id, folderB).getId();
// /Company Home/User Homes/user<timestamp>/folder<timestamp>_A/folder<timestamp>_B/content<timestamp>
String title = "test title";
Map<String,String> docProps = new HashMap<>();
docProps.put("cm:title", title);
String contentName = "content " + RUNID + ".txt";
String content1Id = createTextFile(folderB_Id, contentName, "The quick brown fox jumps over the lazy dog.", "UTF-8", docProps).getId();
// get node info
response = getSingle(NodesEntityResource.class, content1Id, null, 200);
Document documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
String content_Id = documentResp.getId();
// Expected result ...
UserInfo expectedUser = new UserInfo(user1);
Document d1 = new Document();
d1.setId(content_Id);
d1.setParentId(folderB_Id);
d1.setName(contentName);
d1.setNodeType(TYPE_CM_CONTENT);
ContentInfo ciExpected = new ContentInfo();
ciExpected.setMimeType("text/plain");
ciExpected.setMimeTypeName("Plain Text");
ciExpected.setSizeInBytes(44L);
ciExpected.setEncoding("ISO-8859-1");
d1.setContent(ciExpected);
d1.setCreatedByUser(expectedUser);
d1.setModifiedByUser(expectedUser);
Map<String, Object> props = new HashMap<>();
props.put("cm:title", title);
props.put("cm:versionLabel", "1.0");
props.put("cm:versionType", "MAJOR");
d1.setProperties(props);
d1.setAspectNames(Arrays.asList("cm:auditable","cm:titled","cm:versionable","cm:author"));
// Note: Path is not part of the default info
d1.expected(documentResp);
// get node info + path
//...nodes/nodeId?include=path
Map<String, String> params = Collections.singletonMap("include", "path");
response = getSingle(NodesEntityResource.class, content1Id, params, 200);
documentResp = jacksonUtil.parseEntry(response.getJsonResponse(), Document.class);
// Expected path ...
// note: the pathInfo should only include the parents (not the requested node)
List<ElementInfo> elements = new ArrayList<>(5);
elements.add(new ElementInfo(rootNodeId, "Company Home"));
elements.add(new ElementInfo(userHomesId, "User Homes"));
elements.add(new ElementInfo(myFilesNodeId, user1));
elements.add(new ElementInfo(folderA_Id, folderA));
elements.add(new ElementInfo(folderB_Id, folderB));
PathInfo expectedPath = new PathInfo("/Company Home/User Homes/"+user1+"/"+folderA+"/"+folderB, true, elements);
d1.setPath(expectedPath);
d1.expected(documentResp);
// get node info via relativePath
params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, "/"+folderA+"/"+folderB);
response = getSingle(NodesEntityResource.class, Nodes.PATH_MY, params, 200);
Folder folderResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class);
assertEquals(folderB_Id, folderResp.getId());
params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, folderA+"/"+folderB+"/"+contentName);
response = getSingle(NodesEntityResource.class, Nodes.PATH_MY, params, 200);
documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
assertEquals(content_Id, documentResp.getId());
// test path with utf-8 encoded param (eg. ¢ => )
String folderC = "folder" + RUNID + " ¢";
String folderC_Id = createFolder(folderB_Id, folderC).getId();
params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, "/"+folderA+"/"+folderB+"/"+folderC);
response = getSingle(NodesEntityResource.class, Nodes.PATH_MY, params, 200);
folderResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class);
assertEquals(folderC_Id, folderResp.getId());
// -ve test - get info for unknown node should return 404
getSingle(NodesEntityResource.class, UUID.randomUUID().toString(), null, 404);
// -ve test - user2 tries to get node info about user1's home folder
setRequestContext(user2);
getSingle(NodesEntityResource.class, myFilesNodeId, null, 403);
setRequestContext(user1);
// -ve test - try to get node info using relative path to unknown node
params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, folderA+"/unknown");
getSingle(NodesEntityResource.class, Nodes.PATH_MY, params, 404);
// -ve test - try to get node info using relative path to node for which user does not have read permission (expect 404 instead of 403)
params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, "User Homes/"+user2);
getSingle(NodesEntityResource.class, Nodes.PATH_ROOT, params, 404);
// -ve test - attempt to get node info for non-folder node with relative path should return 400
params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, "/unknown");
getSingle(NodesEntityResource.class, content_Id, params, 400);
}
/**
* Tests well-known aliases.
* <p>GET:</p>
* <ul>
* <li> {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-}</li>
* <li> {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/nodes/-my-} </li>
* <li> {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/nodes/-shared-} </li>
* </ul>
*/
@Test
public void testGetNodeWithKnownAlias() throws Exception
{
setRequestContext(user1);
HttpResponse response = getSingle(NodesEntityResource.class, Nodes.PATH_ROOT, null, 200);
Node node = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
assertEquals("Company Home", node.getName());
assertNotNull(node.getId());
assertNull(node.getPath());
// unknown alias
getSingle(NodesEntityResource.class, "testSomeUndefinedAlias", null, 404);
response = getSingle(NodesEntityResource.class, Nodes.PATH_MY, null, 200);
node = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
String myFilesNodeId = node.getId();
assertNotNull(myFilesNodeId);
assertEquals(user1, node.getName());
assertTrue(node.getIsFolder());
assertFalse(node.getIsFile());
assertNull(node.getPath()); // note: path can be optionally "include"'ed - see separate test
response = getSingle(NodesEntityResource.class, Nodes.PATH_SHARED, null, 200);
node = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
String sharedFilesNodeId = node.getId();
assertNotNull(sharedFilesNodeId);
assertEquals("Shared", node.getName());
assertTrue(node.getIsFolder());
assertFalse(node.getIsFile());
assertNull(node.getPath());
//Delete user1's home
setRequestContext(networkAdmin);
deleteNode(myFilesNodeId);
setRequestContext(user1);
getSingle(NodesEntityResource.class, Nodes.PATH_MY, null, 404); // Not found
}
/**
* Tests guess mimetype & guess encoding when uploading file/content (create or update) - also empty file/content
* <p>POST:</p>
* {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/nodes/<nodeId>/children}
* <p>PUT:</p>
* {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/nodes/<nodeId>/content}
*/
@Test
public void testGuessMimeTypeAndEncoding() throws Exception
{
setRequestContext(user1);
String fId = createFolder(getMyNodeId(), "test-folder-guess-"+RUNID).getId();
// create empty files
Document d = new Document();
d.setName("my doc");
d.setNodeType(TYPE_CM_CONTENT);
HttpResponse response = post(getNodeChildrenUrl(fId), toJsonAsStringNonNull(d), 201);
Document documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
assertEquals(MimetypeMap.MIMETYPE_BINARY, documentResp.getContent().getMimeType());
assertEquals("Binary File (Octet Stream)", documentResp.getContent().getMimeTypeName());
assertEquals(0L, documentResp.getContent().getSizeInBytes().longValue());
assertEquals("UTF-8", documentResp.getContent().getEncoding());
d = new Document();
d.setName("my doc.txt");
d.setNodeType(TYPE_CM_CONTENT);
response = post(getNodeChildrenUrl(fId), toJsonAsStringNonNull(d), 201);
documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
assertEquals(MimetypeMap.MIMETYPE_TEXT_PLAIN, documentResp.getContent().getMimeType());
assertEquals("Plain Text", documentResp.getContent().getMimeTypeName());
assertEquals(0L, documentResp.getContent().getSizeInBytes().longValue());
assertEquals("UTF-8", documentResp.getContent().getEncoding());
d = new Document();
d.setName("my doc.pdf");
d.setNodeType(TYPE_CM_CONTENT);
response = post(getNodeChildrenUrl(fId), toJsonAsStringNonNull(d), 201);
documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
assertEquals(MimetypeMap.MIMETYPE_PDF, documentResp.getContent().getMimeType());
assertEquals("Adobe PDF Document", documentResp.getContent().getMimeTypeName());
assertEquals(0L, documentResp.getContent().getSizeInBytes().longValue());
assertEquals("UTF-8", documentResp.getContent().getEncoding());
// upload files
String fileName = "quick-2.pdf";
File file = getResourceFile(fileName);
MultiPartBuilder multiPartBuilder = MultiPartBuilder.create()
.setFileData(new FileData(fileName, file));
MultiPartRequest reqBody = multiPartBuilder.build();
response = post(getNodeChildrenUrl(fId), reqBody.getBody(), null, reqBody.getContentType(), 201);
Document document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
ContentInfo contentInfo = document.getContent();
assertEquals(MimetypeMap.MIMETYPE_PDF, contentInfo.getMimeType());
assertEquals("UTF-8", contentInfo.getEncoding());
fileName = "quick-2.pdf";
file = getResourceFile(fileName);
multiPartBuilder = MultiPartBuilder.create()
.setFileData(new FileData("quick-2", file)); // note: we've deliberately dropped the file ext here
reqBody = multiPartBuilder.build();
response = post(getNodeChildrenUrl(fId), reqBody.getBody(), null, reqBody.getContentType(), 201);
document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
contentInfo = document.getContent();
assertEquals(MimetypeMap.MIMETYPE_PDF, contentInfo.getMimeType());
assertEquals("UTF-8", contentInfo.getEncoding());
fileName = "example-1.txt";
file = getResourceFile(fileName);
multiPartBuilder = MultiPartBuilder.create()
.setFileData(new FileData(fileName, file));
reqBody = multiPartBuilder.build();
response = post(getNodeChildrenUrl(fId), reqBody.getBody(), null, reqBody.getContentType(), 201);
document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
contentInfo = document.getContent();
assertEquals(MimetypeMap.MIMETYPE_TEXT_PLAIN, contentInfo.getMimeType());
assertEquals("ISO-8859-1", contentInfo.getEncoding());
fileName = "example-2.txt";
file = getResourceFile(fileName);
multiPartBuilder = MultiPartBuilder.create()
.setFileData(new FileData(fileName, file));
reqBody = multiPartBuilder.build();
response = post(getNodeChildrenUrl(fId), reqBody.getBody(), null, reqBody.getContentType(), 201);
document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
contentInfo = document.getContent();
assertEquals(MimetypeMap.MIMETYPE_TEXT_PLAIN, contentInfo.getMimeType());
assertEquals("UTF-8", contentInfo.getEncoding());
fileName = "shift-jis.txt";
file = getResourceFile(fileName);
multiPartBuilder = MultiPartBuilder.create()
.setFileData(new FileData(fileName, file));
reqBody = multiPartBuilder.build();
response = post(getNodeChildrenUrl(fId), reqBody.getBody(), null, reqBody.getContentType(), 201);
document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
contentInfo = document.getContent();
assertEquals(MimetypeMap.MIMETYPE_TEXT_PLAIN, contentInfo.getMimeType());
assertEquals("Shift_JIS", contentInfo.getEncoding());
fileName = "example-1.xml";
file = getResourceFile(fileName);
multiPartBuilder = MultiPartBuilder.create()
.setFileData(new FileData(fileName, file));
reqBody = multiPartBuilder.build();
response = post(getNodeChildrenUrl(fId), reqBody.getBody(), null, reqBody.getContentType(), 201);
document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
contentInfo = document.getContent();
assertEquals(MimetypeMap.MIMETYPE_XML, contentInfo.getMimeType());
assertEquals("ISO-8859-1", contentInfo.getEncoding());
fileName = "example-2.xml";
file = getResourceFile(fileName);
multiPartBuilder = MultiPartBuilder.create()
.setFileData(new FileData(fileName, file));
reqBody = multiPartBuilder.build();
response = post(getNodeChildrenUrl(fId), reqBody.getBody(), null, reqBody.getContentType(), 201);
document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
contentInfo = document.getContent();
assertEquals(MimetypeMap.MIMETYPE_XML, contentInfo.getMimeType());
assertEquals("UTF-8", contentInfo.getEncoding());
// upload file, rename and then update file
fileName = "quick.pdf";
file = getResourceFile(fileName);
multiPartBuilder = MultiPartBuilder.create()
.setFileData(new FileData(fileName, file));
reqBody = multiPartBuilder.build();