forked from DSpace/DSpace
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathItemIT.java
More file actions
102 lines (85 loc) · 3.51 KB
/
ItemIT.java
File metadata and controls
102 lines (85 loc) · 3.51 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
/**
* 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.content;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import java.util.UUID;
import org.apache.logging.log4j.Logger;
import org.dspace.AbstractIntegrationTestWithDatabase;
import org.dspace.authorize.service.AuthorizeService;
import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.CollectionService;
import org.dspace.content.service.CommunityService;
import org.dspace.content.service.InstallItemService;
import org.dspace.content.service.ItemService;
import org.dspace.content.service.WorkspaceItemService;
import org.junit.Test;
/**
* Integration Tests for class Item
*
* @author milanmajchrak
*/
public class ItemIT extends AbstractIntegrationTestWithDatabase {
/**
* log4j category
*/
protected static final Logger log = org.apache.logging.log4j.LogManager.getLogger(ItemTest.class);
/**
* Item instance for the tests
*/
protected Item it;
protected ItemService itemService = ContentServiceFactory.getInstance()
.getItemService();
protected CommunityService communityService = ContentServiceFactory.getInstance()
.getCommunityService();
protected CollectionService collectionService = ContentServiceFactory.getInstance()
.getCollectionService();
protected WorkspaceItemService workspaceItemService = ContentServiceFactory.getInstance()
.getWorkspaceItemService();
protected InstallItemService installItemService = ContentServiceFactory.getInstance()
.getInstallItemService();
protected Collection collection;
protected Community owningCommunity;
/**
* Spy of AuthorizeService to use for tests
* (initialized / setup in @Before method)
*/
private AuthorizeService authorizeServiceSpy;
/**
* Test of update item and find method.
*/
@Test
public void dtqExampleTest() throws Exception {
// create item
//we have to create a new community in the database
context.turnOffAuthorisationSystem();
this.owningCommunity = communityService.create(null, context);
this.collection = collectionService.create(context, owningCommunity);
WorkspaceItem workspaceItem = workspaceItemService.create(context, collection, true);
this.it = installItemService.installItem(context, workspaceItem);
context.restoreAuthSystemState();
// Find by id
// Get ID of item created in init()
UUID id = it.getID();
// Make sure we can find it via its ID
Item found = itemService.find(context, id);
assertThat("dtqExampleTest 0", found.getID(), equalTo(id));
// default discoverable should be true
assertThat("dtqExampleTest 1", found.isDiscoverable(), equalTo(true));
context.turnOffAuthorisationSystem();
// set discoverable and update
found.setDiscoverable(false);
itemService.update(context, found);
context.restoreAuthSystemState();
// find by id
Item foundAfterUpdate = itemService.find(context, id);
assertThat("dtqExampleTest 2", foundAfterUpdate.getID(), equalTo(id));
// check if discoverable changed
assertThat("dtqExampleTest 1", foundAfterUpdate.isDiscoverable(), equalTo(false));
}
}