forked from DSpace/DSpace
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVersionedHandleIdentifierProviderIT.java
More file actions
120 lines (100 loc) · 4.92 KB
/
Copy pathVersionedHandleIdentifierProviderIT.java
File metadata and controls
120 lines (100 loc) · 4.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.identifier;
import static org.junit.Assert.assertEquals;
import java.sql.SQLException;
import java.util.List;
import org.dspace.authorize.AuthorizeException;
import org.dspace.builder.CollectionBuilder;
import org.dspace.builder.CommunityBuilder;
import org.dspace.builder.ItemBuilder;
import org.dspace.builder.VersionBuilder;
import org.dspace.content.Collection;
import org.dspace.content.Community;
import org.dspace.content.Item;
import org.dspace.content.MetadataValue;
import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
public class VersionedHandleIdentifierProviderIT extends AbstractIdentifierProviderIT {
private String firstHandle;
private String dspaceUrl;
private Collection collection;
private Item itemV1;
private Item itemV2;
private Item itemV3;
@Before
@Override
public void setUp() throws Exception {
super.setUp();
context.turnOffAuthorisationSystem();
dspaceUrl = DSpaceServicesFactory.getInstance().getConfigurationService().getProperty("dspace.ui.url");
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
collection = CollectionBuilder.createCollection(context, parentCommunity)
.withName("Collection")
.build();
context.restoreAuthSystemState();
}
private void createVersions() throws SQLException, AuthorizeException {
context.turnOffAuthorisationSystem();
itemV1 = ItemBuilder.createItem(context, collection)
.withTitle("First version")
.build();
firstHandle = itemV1.getHandle();
itemV2 = VersionBuilder.createVersion(context, itemV1, "Second version").build().getItem();
itemV3 = VersionBuilder.createVersion(context, itemV1, "Third version").build().getItem();
context.restoreAuthSystemState();
}
@Ignore // This test is ignored because it is not applicable to the current version of DSpace.
@Test
public void testDefaultVersionedHandleProvider() throws Exception {
createVersions();
// Confirm the original item only has its original handle
assertEquals(firstHandle, itemV1.getHandle());
assertEquals(1, itemV1.getHandles().size());
// Confirm the second item has the correct version handle
assertEquals(firstHandle + ".2", itemV2.getHandle());
assertEquals(1, itemV2.getHandles().size());
// Confirm the last item has the correct version handle
assertEquals(firstHandle + ".3", itemV3.getHandle());
assertEquals(1, itemV3.getHandles().size());
}
@Test
public void testCollectionHandleMetadata() {
context.turnOffAuthorisationSystem();
Community testCommunity = CommunityBuilder.createCommunity(context)
.withName("Test community")
.build();
Collection testCollection = CollectionBuilder.createCollection(context, testCommunity)
.withName("Test Collection")
.build();
context.restoreAuthSystemState();
List<MetadataValue> metadata = ContentServiceFactory.getInstance().getDSpaceObjectService(testCollection)
.getMetadata(testCollection, "dc", "identifier", "uri",
Item.ANY);
assertEquals(1, metadata.size());
assertEquals(dspaceUrl + "/handle/" + testCollection.getHandle(), metadata.get(0).getValue());
}
@Test
public void testCommunityHandleMetadata() {
context.turnOffAuthorisationSystem();
Community testCommunity = CommunityBuilder.createCommunity(context)
.withName("Test community")
.build();
context.restoreAuthSystemState();
List<MetadataValue> metadata = ContentServiceFactory.getInstance().getDSpaceObjectService(testCommunity)
.getMetadata(testCommunity, "dc", "identifier", "uri",
Item.ANY);
assertEquals(1, metadata.size());
assertEquals(dspaceUrl + "/handle/" + testCommunity.getHandle(), metadata.get(0).getValue());
}
}