forked from DSpace/DSpace
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
16159f3
commit b923e13
Showing
2 changed files
with
116 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -998,7 +998,7 @@ public void createWithEPersonTest() throws Exception { | |
AtomicReference<Integer> idRef = new AtomicReference<Integer>(); | ||
try { | ||
Community community = CommunityBuilder.createCommunity(context) | ||
.withName("My commynity") | ||
.withName("My community") | ||
.build(); | ||
|
||
EPerson eperson1 = EPersonBuilder.createEPerson(context) | ||
|
@@ -1045,6 +1045,98 @@ public void createWithEPersonTest() throws Exception { | |
ResourcePolicyBuilder.delete(idRef.get()); | ||
} | ||
} | ||
@Test | ||
public void createWithGroupTest() throws Exception { | ||
context.turnOffAuthorisationSystem(); | ||
|
||
AtomicReference<Integer> idRef = new AtomicReference<Integer>(); | ||
try { | ||
Community community = CommunityBuilder.createCommunity(context) | ||
.withName("My community") | ||
.build(); | ||
|
||
EPerson eperson1 = EPersonBuilder.createEPerson(context) | ||
.withEmail("[email protected]") | ||
.withPassword("qwerty01") | ||
.build(); | ||
|
||
Group group1 = GroupBuilder.createGroup(context) | ||
.withName("Group 1") | ||
.addMember(eperson1) | ||
.build(); | ||
|
||
context.restoreAuthSystemState(); | ||
|
||
ObjectMapper mapper = new ObjectMapper(); | ||
ResourcePolicyRest resourcePolicyRest = new ResourcePolicyRest(); | ||
|
||
resourcePolicyRest.setPolicyType(ResourcePolicy.TYPE_SUBMISSION); | ||
resourcePolicyRest.setAction(Constants.actionText[Constants.READ]); | ||
|
||
String authToken = getAuthToken(admin.getEmail(), password); | ||
getClient(authToken) | ||
.perform(post("/api/authz/resourcepolicies") | ||
.content(mapper.writeValueAsBytes(resourcePolicyRest)) | ||
.param("resource", community.getID().toString()) | ||
.param("group", group1.getID().toString()) | ||
.param("projections", "full") | ||
.contentType(contentType)) | ||
.andExpect(status().isCreated()) | ||
.andExpect(content().contentType(contentType)) | ||
.andExpect(jsonPath("$", ResourcePolicyMatcher.matchFullEmbeds())) | ||
.andExpect(jsonPath("$", Matchers.allOf( | ||
hasJsonPath("$.name", is(resourcePolicyRest.getName())), | ||
hasJsonPath("$.description", is(resourcePolicyRest.getDescription())), | ||
hasJsonPath("$.policyType", is(resourcePolicyRest.getPolicyType())), | ||
hasJsonPath("$.action", is(resourcePolicyRest.getAction())), | ||
hasJsonPath("$.startDate", is(resourcePolicyRest.getStartDate())), | ||
hasJsonPath("$.endDate", is(resourcePolicyRest.getEndDate())), | ||
hasJsonPath("$.type", is(resourcePolicyRest.getType()))))) | ||
.andDo(result -> idRef.set(read(result.getResponse().getContentAsString(), "$.id"))); | ||
|
||
String authToken1 = getAuthToken(eperson1.getEmail(), "qwerty01"); | ||
getClient(authToken1).perform(get("/api/authz/resourcepolicies/" + idRef.get())) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().contentType(contentType)) | ||
.andExpect(jsonPath("$._links.self.href", | ||
Matchers.containsString("/api/authz/resourcepolicies/" + idRef.get()))); | ||
} finally { | ||
ResourcePolicyBuilder.delete(idRef.get()); | ||
} | ||
} | ||
|
||
@Test | ||
public void createWithoutGroupOrPersonTest() throws Exception { | ||
context.turnOffAuthorisationSystem(); | ||
Community community = CommunityBuilder.createCommunity(context) | ||
.withName("My commynity") | ||
.build(); | ||
|
||
|
||
context.restoreAuthSystemState(); | ||
|
||
ObjectMapper mapper = new ObjectMapper(); | ||
ResourcePolicyRest resourcePolicyRest = new ResourcePolicyRest(); | ||
|
||
resourcePolicyRest.setPolicyType(ResourcePolicy.TYPE_SUBMISSION); | ||
resourcePolicyRest.setAction(Constants.actionText[Constants.ADMIN]); | ||
|
||
String authToken = getAuthToken(admin.getEmail(), password); | ||
getClient(authToken).perform(post("/api/authz/resourcepolicies") | ||
.content(mapper.writeValueAsBytes(resourcePolicyRest)) | ||
.param("resource", community.getID().toString()) | ||
.contentType(contentType)) | ||
.andExpect(status().isBadRequest()); | ||
|
||
getClient(authToken).perform(get("/api/authz/resourcepolicies/search/resource") | ||
.param("uuid", community.getID().toString()) | ||
.param("action", "ADMIN")) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().contentType(contentType)) | ||
.andExpect(jsonPath("$._links.self.href", | ||
Matchers.containsString("api/authz/resourcepolicies/search/resource"))) | ||
.andExpect(jsonPath("$.page.totalElements", is(0))); | ||
} | ||
|
||
@Test | ||
public void createOneUnAuthenticatedTest() throws Exception { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters