Skip to content

Commit

Permalink
106812: Fix and add new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
YanaDePauw committed Sep 29, 2023
1 parent 16159f3 commit b923e13
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6719,7 +6719,9 @@ public void patchAccesConditionDiscoverableTest() throws Exception {
.build();
witem.getItem().setDiscoverable(false);

ResourcePolicyBuilder.createResourcePolicy(context, null, adminGroup)
ResourcePolicyBuilder.createResourcePolicy(context, null, adminGroup).withDspaceObject(witem.getItem())
.withPolicyType(TYPE_CUSTOM)
.withName("administrator")
.build();

ResourcePolicyBuilder.createResourcePolicy(context, null, anonymousGroup)
Expand Down Expand Up @@ -7116,7 +7118,10 @@ public void patchRemoveSpecificAccesConditionsTest() throws Exception {
.build();

ResourcePolicyBuilder.createResourcePolicy(context, null, adminGroup)
.build();
.withDspaceObject(witem.getItem())
.withPolicyType(TYPE_CUSTOM)
.withName("administrator")
.build();

Calendar calendar = Calendar.getInstance();

Expand Down Expand Up @@ -7195,7 +7200,10 @@ public void patchRemoveFirstAccesConditionsTest() throws Exception {
.build();

ResourcePolicyBuilder.createResourcePolicy(context, null, adminGroup)
.build();
.withDspaceObject(witem.getItem())
.withPolicyType(TYPE_CUSTOM)
.withName("administrator")
.build();

context.restoreAuthSystemState();

Expand Down Expand Up @@ -7255,7 +7263,10 @@ public void patchRemoveAccesConditionsIdxNotSupportedTest() throws Exception {
.build();

ResourcePolicyBuilder.createResourcePolicy(context, null, adminGroup)
.build();
.withDspaceObject(witem.getItem())
.withPolicyType(TYPE_CUSTOM)
.withName("administrator")
.build();

context.restoreAuthSystemState();

Expand Down Expand Up @@ -7317,7 +7328,10 @@ public void patchRemoveAccesConditionsUnprocessableEntityTest() throws Exception
.build();

ResourcePolicyBuilder.createResourcePolicy(context, null, adminGroup)
.build();
.withDspaceObject(witem.getItem())
.withPolicyType(TYPE_CUSTOM)
.withName("administrator")
.build();

context.restoreAuthSystemState();

Expand Down Expand Up @@ -7379,7 +7393,10 @@ public void patchReplaceAccesConditionTest() throws Exception {
.build();

ResourcePolicyBuilder.createResourcePolicy(context, null, adminGroup)
.build();
.withDspaceObject(witem.getItem())
.withPolicyType(TYPE_CUSTOM)
.withName("administrator")
.build();

context.restoreAuthSystemState();

Expand Down

0 comments on commit b923e13

Please sign in to comment.