mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
[Task 69130] applied feedback to the breadcrumbs functionality
This commit is contained in:
@@ -22,6 +22,7 @@ import org.dspace.core.Context;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
@@ -43,6 +44,7 @@ public class CollectionParentCommunityLinkRepository extends AbstractDSpaceRestR
|
||||
* @param projection The current Projection
|
||||
* @return The Parent Community REST object
|
||||
*/
|
||||
@PreAuthorize("hasPermission(#collectionId, 'COLLECTION', 'READ')")
|
||||
public CommunityRest getParentCommunity(@Nullable HttpServletRequest httpServletRequest,
|
||||
UUID collectionId,
|
||||
@Nullable Pageable optionalPageable,
|
||||
|
@@ -20,6 +20,7 @@ import org.dspace.core.Context;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
@@ -41,6 +42,7 @@ public class CommunityParentCommunityLinkRepository extends AbstractDSpaceRestRe
|
||||
* @param projection The current Projection
|
||||
* @return The Parent Community REST object
|
||||
*/
|
||||
@PreAuthorize("hasPermission(#communityId, 'COMMUNITY', 'READ')")
|
||||
public CommunityRest getParentCommunity(@Nullable HttpServletRequest httpServletRequest,
|
||||
UUID communityId,
|
||||
@Nullable Pageable optionalPageable,
|
||||
@@ -48,10 +50,10 @@ public class CommunityParentCommunityLinkRepository extends AbstractDSpaceRestRe
|
||||
try {
|
||||
Context context = obtainContext();
|
||||
Community community = communityService.find(context, communityId);
|
||||
Community parentCommunity = (Community) communityService.getParentObject(context, community);
|
||||
if (community == null) {
|
||||
throw new ResourceNotFoundException("No such community: " + community);
|
||||
}
|
||||
Community parentCommunity = (Community) communityService.getParentObject(context, community);
|
||||
if (parentCommunity == null) {
|
||||
return null;
|
||||
}
|
||||
|
@@ -78,8 +78,10 @@ public class CollectionRestRepositoryIT extends AbstractControllerIntegrationTes
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$._embedded.collections", Matchers.containsInAnyOrder(
|
||||
CollectionMatcher.matchCollectionEntry(col1.getName(), col1.getID(), col1.getHandle()),
|
||||
CollectionMatcher.matchCollectionEntry(col2.getName(), col2.getID(), col2.getHandle())
|
||||
CollectionMatcher.matchCollectionEntryFullProjection(col1.getName(), col1.getID(),
|
||||
col1.getHandle()),
|
||||
CollectionMatcher.matchCollectionEntryFullProjection(col2.getName(), col2.getID(),
|
||||
col2.getHandle())
|
||||
)));
|
||||
}
|
||||
|
||||
@@ -110,11 +112,13 @@ public class CollectionRestRepositoryIT extends AbstractControllerIntegrationTes
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$._embedded.collections", Matchers.contains(
|
||||
CollectionMatcher.matchCollectionEntry(col1.getName(), col1.getID(), col1.getHandle())
|
||||
CollectionMatcher.matchCollectionEntryFullProjection(col1.getName(), col1.getID(),
|
||||
col1.getHandle())
|
||||
)))
|
||||
.andExpect(jsonPath("$._embedded.collections", Matchers.not(
|
||||
Matchers.contains(
|
||||
CollectionMatcher.matchCollectionEntry(col2.getName(), col2.getID(), col2.getHandle())
|
||||
CollectionMatcher.matchCollectionEntryFullProjection(col2.getName(), col2.getID(),
|
||||
col2.getHandle())
|
||||
)
|
||||
)));
|
||||
|
||||
@@ -125,11 +129,13 @@ public class CollectionRestRepositoryIT extends AbstractControllerIntegrationTes
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$._embedded.collections", Matchers.contains(
|
||||
CollectionMatcher.matchCollectionEntry(col2.getName(), col2.getID(), col2.getHandle())
|
||||
CollectionMatcher.matchCollectionEntryFullProjection(col2.getName(), col2.getID(),
|
||||
col2.getHandle())
|
||||
)))
|
||||
.andExpect(jsonPath("$._embedded.collections", Matchers.not(
|
||||
Matchers.contains(
|
||||
CollectionMatcher.matchCollectionEntry(col1.getName(), col1.getID(), col1.getHandle())
|
||||
CollectionMatcher.matchCollectionEntryFullProjection(col1.getName(), col1.getID(),
|
||||
col1.getHandle())
|
||||
)
|
||||
)));
|
||||
}
|
||||
@@ -202,11 +208,13 @@ public class CollectionRestRepositoryIT extends AbstractControllerIntegrationTes
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$", is(
|
||||
CollectionMatcher.matchCollectionEntry(col1.getName(), col1.getID(), col1.getHandle())
|
||||
CollectionMatcher.matchCollectionEntryFullProjection(col1.getName(), col1.getID(),
|
||||
col1.getHandle())
|
||||
)))
|
||||
.andExpect(jsonPath("$", Matchers.not(
|
||||
is(
|
||||
CollectionMatcher.matchCollectionEntry(col2.getName(), col2.getID(), col2.getHandle())
|
||||
CollectionMatcher.matchCollectionEntryFullProjection(col2.getName(), col2.getID(),
|
||||
col2.getHandle())
|
||||
)))
|
||||
)
|
||||
;
|
||||
@@ -348,11 +356,13 @@ public class CollectionRestRepositoryIT extends AbstractControllerIntegrationTes
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$", is(
|
||||
CollectionMatcher.matchCollectionEntry(col1.getName(), col1.getID(), col1.getHandle())
|
||||
CollectionMatcher.matchCollectionEntryFullProjection(col1.getName(), col1.getID(),
|
||||
col1.getHandle())
|
||||
)))
|
||||
.andExpect(jsonPath("$", Matchers.not(
|
||||
is(
|
||||
CollectionMatcher.matchCollectionEntry(col2.getName(), col2.getID(), col2.getHandle())
|
||||
CollectionMatcher.matchCollectionEntryFullProjection(col2.getName(), col2.getID(),
|
||||
col2.getHandle())
|
||||
))));
|
||||
}
|
||||
|
||||
@@ -376,7 +386,8 @@ public class CollectionRestRepositoryIT extends AbstractControllerIntegrationTes
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$", Matchers.is(
|
||||
CollectionMatcher.matchCollectionEntry(col1.getName(), col1.getID(), col1.getHandle())
|
||||
CollectionMatcher.matchCollectionEntryFullProjection(col1.getName(), col1.getID(),
|
||||
col1.getHandle())
|
||||
)))
|
||||
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/collections")))
|
||||
;
|
||||
@@ -403,7 +414,7 @@ public class CollectionRestRepositoryIT extends AbstractControllerIntegrationTes
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$", Matchers.is(
|
||||
CollectionMatcher.matchCollectionEntry("Electronic theses and dissertations",
|
||||
CollectionMatcher.matchCollectionEntryFullProjection("Electronic theses and dissertations",
|
||||
col1.getID(), col1.getHandle())
|
||||
)))
|
||||
.andExpect(jsonPath("$._links.self.href",
|
||||
@@ -445,10 +456,11 @@ public class CollectionRestRepositoryIT extends AbstractControllerIntegrationTes
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$", Matchers.is(
|
||||
CollectionMatcher.matchCollectionEntry(col1.getName(), col1.getID(), col1.getHandle())
|
||||
CollectionMatcher.matchCollectionEntryFullProjection(col1.getName(), col1.getID(),
|
||||
col1.getHandle())
|
||||
)))
|
||||
.andExpect(jsonPath("$._links.self.href",
|
||||
Matchers.containsString("/api/core/collections"))) ;
|
||||
Matchers.containsString("/api/core/collections")));
|
||||
getClient(token).perform(delete("/api/core/collections/" + col1.getID().toString()))
|
||||
.andExpect(status().isNoContent())
|
||||
;
|
||||
@@ -489,10 +501,11 @@ public class CollectionRestRepositoryIT extends AbstractControllerIntegrationTes
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$", Matchers.is(
|
||||
CollectionMatcher.matchCollectionEntry(col1.getName(), col1.getID(), col1.getHandle())
|
||||
CollectionMatcher.matchCollectionEntryFullProjection(col1.getName(), col1.getID(),
|
||||
col1.getHandle())
|
||||
)))
|
||||
.andExpect(jsonPath("$._links.self.href",
|
||||
Matchers.containsString("/api/core/collections"))) ;
|
||||
Matchers.containsString("/api/core/collections")));
|
||||
getClient().perform(delete("/api/core/collections/" + col1.getID().toString()))
|
||||
.andExpect(status().isUnauthorized())
|
||||
;
|
||||
@@ -701,10 +714,11 @@ public class CollectionRestRepositoryIT extends AbstractControllerIntegrationTes
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$", Matchers.is(
|
||||
CollectionMatcher.matchCollectionEntry(col1.getName(), col1.getID(), col1.getHandle())
|
||||
CollectionMatcher.matchCollectionEntryFullProjection(col1.getName(), col1.getID(),
|
||||
col1.getHandle())
|
||||
)))
|
||||
.andExpect(jsonPath("$._links.self.href",
|
||||
Matchers.containsString("/api/core/collections"))) ;
|
||||
Matchers.containsString("/api/core/collections")));
|
||||
getClient(token).perform(delete("/api/core/collections/" + col1.getID().toString()))
|
||||
.andExpect(status().isNoContent())
|
||||
;
|
||||
@@ -737,7 +751,8 @@ public class CollectionRestRepositoryIT extends AbstractControllerIntegrationTes
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$", Matchers.is(
|
||||
CollectionMatcher.matchCollectionEntry(col1.getName(), col1.getID(), col1.getHandle())
|
||||
CollectionMatcher.matchCollectionEntryFullProjection(col1.getName(), col1.getID(),
|
||||
col1.getHandle())
|
||||
)))
|
||||
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/collections")))
|
||||
;
|
||||
@@ -767,7 +782,7 @@ public class CollectionRestRepositoryIT extends AbstractControllerIntegrationTes
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$", Matchers.is(
|
||||
CollectionMatcher.matchCollectionEntry("Electronic theses and dissertations",
|
||||
CollectionMatcher.matchCollectionEntryFullProjection("Electronic theses and dissertations",
|
||||
col1.getID(), col1.getHandle())
|
||||
)))
|
||||
.andExpect(jsonPath("$._links.self.href",
|
||||
@@ -908,9 +923,12 @@ public class CollectionRestRepositoryIT extends AbstractControllerIntegrationTes
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$._embedded.collections", Matchers.containsInAnyOrder(
|
||||
CollectionMatcher.matchCollectionEntry(col1.getName(), col1.getID(), col1.getHandle()),
|
||||
CollectionMatcher.matchCollectionEntry(col2.getName(), col2.getID(), col2.getHandle())
|
||||
CollectionMatcher.matchCollectionEntryFullProjection(col1.getName(), col1.getID(),
|
||||
col1.getHandle()),
|
||||
CollectionMatcher.matchCollectionEntryFullProjection(col2.getName(), col2.getID(),
|
||||
col2.getHandle())
|
||||
)))
|
||||
.andExpect(jsonPath("$.page", PageMatcher.pageEntryWithTotalPagesAndElements(0, 20, 1, 2)));
|
||||
.andExpect(jsonPath("$.page", PageMatcher.pageEntryWithTotalPagesAndElements(0, 20,
|
||||
1, 2)));
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,374 @@
|
||||
/**
|
||||
* 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.app.rest;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.not;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.dspace.app.rest.builder.CollectionBuilder;
|
||||
import org.dspace.app.rest.builder.CommunityBuilder;
|
||||
import org.dspace.app.rest.builder.ItemBuilder;
|
||||
import org.dspace.app.rest.matcher.CollectionMatcher;
|
||||
import org.dspace.app.rest.matcher.CommunityMatcher;
|
||||
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.authorize.service.AuthorizeService;
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.content.Community;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.content.service.CollectionService;
|
||||
import org.dspace.content.service.CommunityService;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
public class CommunityCollectionItemParentIT extends AbstractControllerIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private CollectionService collectionService;
|
||||
|
||||
@Autowired
|
||||
private CommunityService communityService;
|
||||
|
||||
@Autowired
|
||||
private AuthorizeService authorizeService;
|
||||
|
||||
Community communityA;
|
||||
Community communityB;
|
||||
Community communityAA;
|
||||
Community communityAB;
|
||||
|
||||
Collection colAA1;
|
||||
Collection colAA2;
|
||||
Collection colAB1;
|
||||
|
||||
Item itemAA1;
|
||||
Item itemAA1MappedInAA2;
|
||||
Item itemAA2;
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() throws SQLException, AuthorizeException {
|
||||
//We turn off the authorization system in order to create the structure as defined below
|
||||
context.turnOffAuthorisationSystem();
|
||||
//** GIVEN **
|
||||
//1. A community-collection structure with one parent community with sub-community and one collection.
|
||||
communityA = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent CommunityA")
|
||||
.build();
|
||||
communityB = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent CommunityB")
|
||||
.build();
|
||||
communityAA = CommunityBuilder.createSubCommunity(context, communityA)
|
||||
.withName("Sub Community")
|
||||
.build();
|
||||
communityAB = CommunityBuilder.createSubCommunity(context, communityA)
|
||||
.withName("Sub Community Two")
|
||||
.build();
|
||||
colAA1 = CollectionBuilder.createCollection(context, communityAA).withName("Collection 1").build();
|
||||
colAA2 = CollectionBuilder.createCollection(context, communityAA).withName("Collection 2").build();
|
||||
colAB1 = CollectionBuilder.createCollection(context, communityAB).withName("Collection 3").build();
|
||||
communityService.addCollection(context, communityAB, colAA2);
|
||||
|
||||
|
||||
itemAA1 = ItemBuilder.createItem(context, colAA1)
|
||||
.withTitle("Public item 1")
|
||||
.withIssueDate("2017-10-17")
|
||||
.withAuthor("Smith, Donald").withAuthor("Doe, John")
|
||||
.withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
itemAA1MappedInAA2 = ItemBuilder.createItem(context, colAA1)
|
||||
.withTitle("Public item 1")
|
||||
.withIssueDate("2017-10-17")
|
||||
.withAuthor("Smith, Donald").withAuthor("Doe, John")
|
||||
.withSubject("ExtraEntry")
|
||||
.build();
|
||||
collectionService.addItem(context, colAA2, itemAA1MappedInAA2);
|
||||
itemAA2 = ItemBuilder.createItem(context, colAA2)
|
||||
.withTitle("Public item 1")
|
||||
.withIssueDate("2017-10-17")
|
||||
.withAuthor("Smith, Donald").withAuthor("Doe, John")
|
||||
.withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
context.restoreAuthSystemState();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void itemXOwningCollectionTest() throws Exception {
|
||||
|
||||
String token = getAuthToken(admin.getEmail(), password);
|
||||
getClient(token).perform(get("/api/core/items/" + itemAA1.getID() + "/owningCollection"))
|
||||
.andExpect(jsonPath("$", is(CollectionMatcher.matchCollectionEntry(colAA1.getName(),
|
||||
colAA1.getID(),
|
||||
colAA1.getHandle()))))
|
||||
.andExpect(jsonPath("$", Matchers
|
||||
.not(is(CollectionMatcher
|
||||
.matchCollectionEntry(colAA2.getName(), colAA2.getID(), colAA2.getHandle())))));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void itemYOwningCollectionTest() throws Exception {
|
||||
|
||||
String token = getAuthToken(admin.getEmail(), password);
|
||||
getClient(token).perform(get("/api/core/items/" + itemAA1MappedInAA2.getID() + "/owningCollection"))
|
||||
.andExpect(jsonPath("$", is(CollectionMatcher.matchCollectionEntry(colAA1.getName(),
|
||||
colAA1.getID(),
|
||||
colAA1.getHandle()))))
|
||||
.andExpect(jsonPath("$", Matchers
|
||||
.not(is(CollectionMatcher
|
||||
.matchCollectionEntry(colAA2.getName(), colAA2.getID(), colAA2.getHandle())))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void itemZOwningCollectionTest() throws Exception {
|
||||
|
||||
String token = getAuthToken(admin.getEmail(), password);
|
||||
getClient(token).perform(get("/api/core/items/" + itemAA2.getID() + "/owningCollection"))
|
||||
.andExpect(jsonPath("$", is(CollectionMatcher.matchCollectionEntry(colAA2.getName(),
|
||||
colAA2.getID(),
|
||||
colAA2.getHandle()))))
|
||||
.andExpect(jsonPath("$", Matchers
|
||||
.not(is(CollectionMatcher
|
||||
.matchCollectionEntry(colAA1.getName(), colAA1.getID(), colAA1.getHandle())))));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void col1ParentCommunityTest() throws Exception {
|
||||
|
||||
String token = getAuthToken(admin.getEmail(), password);
|
||||
getClient(token).perform(get("/api/core/collections/" + colAA1.getID() + "/parentCommunity"))
|
||||
.andExpect(jsonPath("$", is(CommunityMatcher
|
||||
.matchCommunityEntry(communityAA.getName(), communityAA.getID(),
|
||||
communityAA.getHandle()))))
|
||||
.andExpect(jsonPath("$", not(is(CommunityMatcher.matchCommunityEntry(communityA.getName(),
|
||||
communityA.getID(),
|
||||
communityA.getHandle())))))
|
||||
.andExpect(jsonPath("$", not(is(CommunityMatcher.matchCommunityEntry(communityAB.getName(),
|
||||
communityAB.getID(),
|
||||
communityAB
|
||||
.getHandle())))));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void comAAParentCommunityTest() throws Exception {
|
||||
|
||||
String token = getAuthToken(admin.getEmail(), password);
|
||||
getClient(token)
|
||||
.perform(get("/api/core/communities/" + communityAA.getID() + "/parentCommunity"))
|
||||
.andExpect(jsonPath("$", Matchers
|
||||
.is(CommunityMatcher.matchCommunityEntry(communityA.getID(), communityA.getHandle()))))
|
||||
.andExpect(jsonPath("$", Matchers
|
||||
.not(Matchers.is(CommunityMatcher.matchCommunityEntry(communityB.getID(), communityB.getHandle())))));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void comAParentCommunityTest() throws Exception {
|
||||
|
||||
String token = getAuthToken(admin.getEmail(), password);
|
||||
getClient(token).perform(get("/api/core/communities/" + communityA.getID() + "/parentCommunity"))
|
||||
.andExpect(status().isNoContent());
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parentCommunityWrongUUIDTest() throws Exception {
|
||||
|
||||
String token = getAuthToken(admin.getEmail(), password);
|
||||
getClient(token).perform(get("/api/core/communities/" + UUID.randomUUID() + "/parentCommunity"))
|
||||
.andExpect(status().isNotFound());
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parentCommunityPrivateCommunityUnAuthorizedTest() throws Exception {
|
||||
|
||||
context.turnOffAuthorisationSystem();
|
||||
authorizeService.removeAllPolicies(context, communityAA);
|
||||
context.restoreAuthSystemState();
|
||||
getClient().perform(get("/api/core/communities/" + communityAA.getID() + "/parentCommunity"))
|
||||
.andExpect(status().isUnauthorized());
|
||||
|
||||
}
|
||||
|
||||
//Enable this test when this security level has been supported
|
||||
@Ignore
|
||||
@Test
|
||||
public void parentCommunityPrivateParentCommunityUnAuthorizedTest() throws Exception {
|
||||
|
||||
context.turnOffAuthorisationSystem();
|
||||
authorizeService.removeAllPolicies(context, communityA);
|
||||
context.restoreAuthSystemState();
|
||||
getClient().perform(get("/api/core/communities/" + communityAA.getID() + "/parentCommunity"))
|
||||
.andExpect(status().isUnauthorized());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parentCommunityPrivateCommunityForbiddenTest() throws Exception {
|
||||
|
||||
context.turnOffAuthorisationSystem();
|
||||
authorizeService.removeAllPolicies(context, communityAA);
|
||||
context.restoreAuthSystemState();
|
||||
String token = getAuthToken(eperson.getEmail(), password);
|
||||
getClient(token).perform(get("/api/core/communities/" + communityAA.getID() + "/parentCommunity"))
|
||||
.andExpect(status().isForbidden());
|
||||
|
||||
}
|
||||
|
||||
//Enable this test when this security level has been supported
|
||||
@Ignore
|
||||
@Test
|
||||
public void parentCommunityPrivateParentCommunityForbiddenTest() throws Exception {
|
||||
|
||||
context.turnOffAuthorisationSystem();
|
||||
authorizeService.removeAllPolicies(context, communityA);
|
||||
context.restoreAuthSystemState();
|
||||
String token = getAuthToken(eperson.getEmail(), password);
|
||||
getClient(token).perform(get("/api/core/communities/" + communityAA.getID() + "/parentCommunity"))
|
||||
.andExpect(status().isForbidden());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parentCommunityForCollectionWrongUUIDTest() throws Exception {
|
||||
|
||||
String token = getAuthToken(admin.getEmail(), password);
|
||||
getClient(token).perform(get("/api/core/collections/" + UUID.randomUUID() + "/parentCommunity"))
|
||||
.andExpect(status().isNotFound());
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parentCommunityForCollectionPrivateCollectionUnAuthorizedTest() throws Exception {
|
||||
|
||||
context.turnOffAuthorisationSystem();
|
||||
authorizeService.removeAllPolicies(context, colAA1);
|
||||
context.restoreAuthSystemState();
|
||||
getClient().perform(get("/api/core/collections/" + colAA1.getID() + "/parentCommunity"))
|
||||
.andExpect(status().isUnauthorized());
|
||||
|
||||
}
|
||||
|
||||
//Enable this test when this security level has been supported
|
||||
@Ignore
|
||||
@Test
|
||||
public void parentCommunityForCollectionPrivateParentCommunityUnAuthorizedTest() throws Exception {
|
||||
|
||||
context.turnOffAuthorisationSystem();
|
||||
authorizeService.removeAllPolicies(context, communityAA);
|
||||
context.restoreAuthSystemState();
|
||||
getClient().perform(get("/api/core/collections/" + colAA1.getID() + "/parentCommunity"))
|
||||
.andExpect(status().isUnauthorized());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parentCommunityForCollectionPrivateCollectionForbiddenTest() throws Exception {
|
||||
|
||||
context.turnOffAuthorisationSystem();
|
||||
authorizeService.removeAllPolicies(context, colAA1);
|
||||
context.restoreAuthSystemState();
|
||||
String token = getAuthToken(eperson.getEmail(), password);
|
||||
getClient(token).perform(get("/api/core/collections/" + colAA1.getID() + "/parentCommunity"))
|
||||
.andExpect(status().isForbidden());
|
||||
|
||||
}
|
||||
|
||||
//Enable this test when this security level has been supported
|
||||
@Ignore
|
||||
@Test
|
||||
public void parentCommunityForCollectionPrivateParentCommunityForbiddenTest() throws Exception {
|
||||
|
||||
context.turnOffAuthorisationSystem();
|
||||
authorizeService.removeAllPolicies(context, communityAA);
|
||||
context.restoreAuthSystemState();
|
||||
String token = getAuthToken(eperson.getEmail(), password);
|
||||
getClient(token).perform(get("/api/core/collections/" + colAA1.getID() + "/parentCommunity"))
|
||||
.andExpect(status().isForbidden());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void owningCollectionForItemWrongUUIDTest() throws Exception {
|
||||
|
||||
String token = getAuthToken(admin.getEmail(), password);
|
||||
getClient(token).perform(get("/api/core/items/" + UUID.randomUUID() + "/owningCollection"))
|
||||
.andExpect(status().isNotFound());
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void owningCollectionForItemPrivateItemUnAuthorizedTest() throws Exception {
|
||||
|
||||
context.turnOffAuthorisationSystem();
|
||||
authorizeService.removeAllPolicies(context, itemAA1);
|
||||
context.restoreAuthSystemState();
|
||||
|
||||
getClient().perform(get("/api/core/items/" + itemAA1.getID() + "/owningCollection"))
|
||||
.andExpect(status().isUnauthorized());
|
||||
|
||||
}
|
||||
|
||||
|
||||
//Enable this test when this security level has been supported
|
||||
@Ignore
|
||||
@Test
|
||||
public void owningCollectionForItemPrivateOwningCollectionUnAuthorizedTest() throws Exception {
|
||||
|
||||
context.turnOffAuthorisationSystem();
|
||||
authorizeService.removeAllPolicies(context, colAA1);
|
||||
context.restoreAuthSystemState();
|
||||
getClient().perform(get("/api/core/items/" + itemAA1.getID() + "/owningCollection"))
|
||||
.andExpect(status().isUnauthorized());
|
||||
|
||||
}
|
||||
|
||||
//Enable this test when this security level has been supported
|
||||
@Ignore
|
||||
@Test
|
||||
public void owningCollectionForItemPrivateOwningCollectionForbiddenTest() throws Exception {
|
||||
|
||||
context.turnOffAuthorisationSystem();
|
||||
authorizeService.removeAllPolicies(context, colAA1);
|
||||
context.restoreAuthSystemState();
|
||||
String token = getAuthToken(eperson.getEmail(), password);
|
||||
getClient(token).perform(get("/api/core/items/" + itemAA1.getID() + "/owningCollection"))
|
||||
.andExpect(status().isForbidden());
|
||||
|
||||
}
|
||||
@Test
|
||||
public void owningCollectionForItemPrivateItemForbiddenTest() throws Exception {
|
||||
|
||||
context.turnOffAuthorisationSystem();
|
||||
authorizeService.removeAllPolicies(context, itemAA1);
|
||||
context.restoreAuthSystemState();
|
||||
String token = getAuthToken(eperson.getEmail(), password);
|
||||
getClient(token).perform(get("/api/core/items/" + itemAA1.getID() + "/owningCollection"))
|
||||
.andExpect(status().isForbidden());
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -1,218 +0,0 @@
|
||||
/**
|
||||
* 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.app.rest;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.not;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.dspace.app.rest.builder.CollectionBuilder;
|
||||
import org.dspace.app.rest.builder.CommunityBuilder;
|
||||
import org.dspace.app.rest.builder.ItemBuilder;
|
||||
import org.dspace.app.rest.matcher.CollectionMatcher;
|
||||
import org.dspace.app.rest.matcher.CommunityMatcher;
|
||||
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.content.Community;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.content.service.CollectionService;
|
||||
import org.dspace.content.service.CommunityService;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
public class CommunityCollectionParentIT extends AbstractControllerIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private CollectionService collectionService;
|
||||
|
||||
@Autowired
|
||||
private CommunityService communityService;
|
||||
|
||||
Community communityA;
|
||||
Community communityB;
|
||||
Community communityAA;
|
||||
Community communityAB;
|
||||
|
||||
Collection col1;
|
||||
Collection col2;
|
||||
Collection col3;
|
||||
|
||||
Item itemX;
|
||||
Item itemY;
|
||||
Item itemZ;
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() throws SQLException, AuthorizeException {
|
||||
//We turn off the authorization system in order to create the structure as defined below
|
||||
context.turnOffAuthorisationSystem();
|
||||
//** GIVEN **
|
||||
//1. A community-collection structure with one parent community with sub-community and one collection.
|
||||
communityA = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent CommunityA")
|
||||
.build();
|
||||
communityB = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent CommunityB")
|
||||
.build();
|
||||
communityAA = CommunityBuilder.createSubCommunity(context, communityA)
|
||||
.withName("Sub Community")
|
||||
.build();
|
||||
communityAB = CommunityBuilder.createSubCommunity(context, communityA)
|
||||
.withName("Sub Community Two")
|
||||
.build();
|
||||
col1 = CollectionBuilder.createCollection(context, communityAA).withName("Collection 1").build();
|
||||
col2 = CollectionBuilder.createCollection(context, communityAA).withName("Collection 2").build();
|
||||
col3 = CollectionBuilder.createCollection(context, communityAB).withName("Collection 3").build();
|
||||
communityService.addCollection(context, communityAB, col2);
|
||||
|
||||
|
||||
itemX = ItemBuilder.createItem(context, col1)
|
||||
.withTitle("Public item 1")
|
||||
.withIssueDate("2017-10-17")
|
||||
.withAuthor("Smith, Donald").withAuthor("Doe, John")
|
||||
.withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
itemY = ItemBuilder.createItem(context, col1)
|
||||
.withTitle("Public item 1")
|
||||
.withIssueDate("2017-10-17")
|
||||
.withAuthor("Smith, Donald").withAuthor("Doe, John")
|
||||
.withSubject("ExtraEntry")
|
||||
.build();
|
||||
collectionService.addItem(context, col2, itemY);
|
||||
itemZ = ItemBuilder.createItem(context, col2)
|
||||
.withTitle("Public item 1")
|
||||
.withIssueDate("2017-10-17")
|
||||
.withAuthor("Smith, Donald").withAuthor("Doe, John")
|
||||
.withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
context.restoreAuthSystemState();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void itemXOwningCollectionTest() throws Exception {
|
||||
|
||||
String token = getAuthToken(admin.getEmail(), password);
|
||||
getClient(token).perform(get("/api/core/items/" + itemX.getID() + "/owningCollection"))
|
||||
.andExpect(jsonPath("$", is(CollectionMatcher.matchCollectionEntry(col1.getName(), col1.getID(),
|
||||
col1.getHandle()))))
|
||||
.andExpect(jsonPath("$", Matchers
|
||||
.not(is(CollectionMatcher
|
||||
.matchCollectionEntry(col2.getName(), col2.getID(), col2.getHandle())))));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void itemYOwningCollectionTest() throws Exception {
|
||||
|
||||
String token = getAuthToken(admin.getEmail(), password);
|
||||
getClient(token).perform(get("/api/core/items/" + itemY.getID() + "/owningCollection"))
|
||||
.andExpect(jsonPath("$", is(CollectionMatcher.matchCollectionEntry(col1.getName(), col1.getID(),
|
||||
col1.getHandle()))))
|
||||
.andExpect(jsonPath("$", Matchers
|
||||
.not(is(CollectionMatcher
|
||||
.matchCollectionEntry(col2.getName(), col2.getID(), col2.getHandle())))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void itemZOwningCollectionTest() throws Exception {
|
||||
|
||||
String token = getAuthToken(admin.getEmail(), password);
|
||||
getClient(token).perform(get("/api/core/items/" + itemZ.getID() + "/owningCollection"))
|
||||
.andExpect(jsonPath("$", is(CollectionMatcher.matchCollectionEntry(col2.getName(), col2.getID(),
|
||||
col2.getHandle()))))
|
||||
.andExpect(jsonPath("$", Matchers
|
||||
.not(is(CollectionMatcher
|
||||
.matchCollectionEntry(col1.getName(), col1.getID(), col1.getHandle())))));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void col1ParentCommunityTest() throws Exception {
|
||||
|
||||
String token = getAuthToken(admin.getEmail(), password);
|
||||
getClient(token).perform(get("/api/core/collections/" + col1.getID() + "/parentCommunity"))
|
||||
.andExpect(jsonPath("$", is(CommunityMatcher
|
||||
.matchCommunityEntry(communityAA.getName(), communityAA.getID(),
|
||||
communityAA.getHandle()))))
|
||||
.andExpect(jsonPath("$", not(is(CommunityMatcher.matchCommunityEntry(communityA.getName(),
|
||||
communityA.getID(),
|
||||
communityA.getHandle())))))
|
||||
.andExpect(jsonPath("$", not(is(CommunityMatcher.matchCommunityEntry(communityAB.getName(),
|
||||
communityAB.getID(),
|
||||
communityAB
|
||||
.getHandle())))));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void col2ParentCommunityTest() throws Exception {
|
||||
|
||||
String token = getAuthToken(admin.getEmail(), password);
|
||||
getClient(token)
|
||||
.perform(get("/api/core/collections/" + col2.getID() + "/parentCommunity"))
|
||||
.andExpect(jsonPath("$", is(CommunityMatcher.matchCommunityEntry(communityAA.getName(), communityAA.getID(),
|
||||
communityAA.getHandle()))))
|
||||
.andExpect(jsonPath("$", not(is(CommunityMatcher
|
||||
.matchCommunityEntry(communityA.getName(), communityA.getID(),
|
||||
communityA.getHandle())))))
|
||||
.andExpect(jsonPath("$", not(is(CommunityMatcher
|
||||
.matchCommunityEntry(communityAB.getName(), communityAB.getID(),
|
||||
communityAB.getHandle())))));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void col3ParentCommunityTest() throws Exception {
|
||||
|
||||
String token = getAuthToken(admin.getEmail(), password);
|
||||
getClient(token)
|
||||
.perform(get("/api/core/collections/" + col3.getID() + "/parentCommunity"))
|
||||
.andExpect(jsonPath("$", is(CommunityMatcher.matchCommunityEntry(communityAB.getName(), communityAB.getID(),
|
||||
communityAB.getHandle()))))
|
||||
.andExpect(jsonPath("$", not(is(CommunityMatcher
|
||||
.matchCommunityEntry(communityA.getName(), communityA.getID(),
|
||||
communityA.getHandle())))))
|
||||
.andExpect(jsonPath("$", not(is(CommunityMatcher
|
||||
.matchCommunityEntry(communityAA.getName(), communityAA.getID(),
|
||||
communityAA.getHandle())))));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void comAAParentCommunityTest() throws Exception {
|
||||
|
||||
String token = getAuthToken(admin.getEmail(), password);
|
||||
getClient(token)
|
||||
.perform(get("/api/core/communities/" + communityAA.getID() + "/parentCommunity"))
|
||||
.andExpect(jsonPath("$", Matchers
|
||||
.is(CommunityMatcher.matchCommunityEntry(communityA.getID(), communityA.getHandle()))))
|
||||
.andExpect(jsonPath("$", Matchers
|
||||
.not(Matchers.is(CommunityMatcher.matchCommunityEntry(communityB.getID(), communityB.getHandle())))));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void comAParentCommunityTest() throws Exception {
|
||||
|
||||
String token = getAuthToken(admin.getEmail(), password);
|
||||
getClient(token).perform(get("/api/core/communities/" + communityA.getID() + "/parentCommunity"))
|
||||
.andExpect(status().isNoContent());
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -307,10 +307,11 @@ public class CommunityRestRepositoryIT extends AbstractControllerIntegrationTest
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$._embedded.communities", Matchers.containsInAnyOrder(
|
||||
CommunityMatcher.matchCommunityEntry(parentCommunity.getName(), parentCommunity.getID(),
|
||||
parentCommunity.getHandle()),
|
||||
CommunityMatcher.matchCommunityEntryFullProjection(parentCommunity.getName(),
|
||||
parentCommunity.getID(),
|
||||
parentCommunity.getHandle()),
|
||||
CommunityMatcher
|
||||
.matchCommunityEntry(child1.getName(), child1.getID(), child1.getHandle())
|
||||
.matchCommunityEntryFullProjection(child1.getName(), child1.getID(), child1.getHandle())
|
||||
)))
|
||||
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/communities")))
|
||||
.andExpect(jsonPath("$.page.size", is(20)))
|
||||
@@ -334,13 +335,15 @@ public class CommunityRestRepositoryIT extends AbstractControllerIntegrationTest
|
||||
.build();
|
||||
|
||||
|
||||
getClient().perform(get("/api/core/communities").param("size", "2").param("projection", "full"))
|
||||
getClient().perform(get("/api/core/communities").param("size", "2").param("projection",
|
||||
"full"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$._embedded.communities", Matchers.containsInAnyOrder(
|
||||
CommunityMatcher.matchCommunityEntryMultipleTitles(titles, parentCommunity.getID(),
|
||||
parentCommunity.getHandle()),
|
||||
CommunityMatcher.matchCommunityEntry(child1.getID(), child1.getHandle())
|
||||
CommunityMatcher.matchCommunityEntryFullProjection(child1.getName(), child1.getID(),
|
||||
child1.getHandle())
|
||||
)))
|
||||
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/communities")))
|
||||
.andExpect(jsonPath("$.page.totalElements", is(2)))
|
||||
@@ -357,50 +360,60 @@ public class CommunityRestRepositoryIT extends AbstractControllerIntegrationTest
|
||||
.withTitle(titles.get(2))
|
||||
.withTitle(titles.get(3))
|
||||
.build();
|
||||
Community childCommunity = CommunityBuilder.createSubCommunity(context, parentCommunity).build();
|
||||
Community childCommunity = CommunityBuilder.createSubCommunity(context, parentCommunity).withName("test")
|
||||
.build();
|
||||
Community secondParentCommunity = CommunityBuilder.createCommunity(context).withName("testing").build();
|
||||
Community thirdParentCommunity = CommunityBuilder.createCommunity(context).withName("testingTitleTwo").build();
|
||||
|
||||
context.restoreAuthSystemState();
|
||||
|
||||
getClient().perform(get("/api/core/communities").param("size", "2").param("projection", "full"))
|
||||
getClient().perform(get("/api/core/communities").param("size", "2").param("projection",
|
||||
"full"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$._embedded.communities", Matchers.containsInAnyOrder(
|
||||
CommunityMatcher.matchCommunityEntryMultipleTitles(titles, parentCommunity.getID(),
|
||||
parentCommunity.getHandle()),
|
||||
CommunityMatcher.matchCommunityEntry(childCommunity.getID(), childCommunity.getHandle())
|
||||
CommunityMatcher.matchCommunityEntryFullProjection(childCommunity.getName(),
|
||||
childCommunity.getID(),
|
||||
childCommunity.getHandle())
|
||||
)))
|
||||
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/communities")))
|
||||
.andExpect(jsonPath("$.page", PageMatcher.pageEntryWithTotalPagesAndElements(0, 2, 2, 4)));
|
||||
.andExpect(jsonPath("$._links.self.href",
|
||||
Matchers.containsString("/api/core/communities")))
|
||||
.andExpect(jsonPath("$.page", PageMatcher.pageEntryWithTotalPagesAndElements(0, 2,
|
||||
2, 4)));
|
||||
|
||||
getClient().perform(get("/api/core/communities").param("size", "2").param("page", "1")
|
||||
.param("projection", "full"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$._embedded.communities", Matchers.containsInAnyOrder(
|
||||
CommunityMatcher.matchCommunityEntry(secondParentCommunity.getID(),
|
||||
secondParentCommunity.getHandle()),
|
||||
CommunityMatcher.matchCommunityEntry(thirdParentCommunity.getID(),
|
||||
thirdParentCommunity.getHandle())
|
||||
CommunityMatcher.matchCommunityEntryFullProjection(secondParentCommunity.getName(),
|
||||
secondParentCommunity.getID(),
|
||||
secondParentCommunity.getHandle()),
|
||||
CommunityMatcher.matchCommunityEntryFullProjection(thirdParentCommunity.getName(),
|
||||
thirdParentCommunity.getID(),
|
||||
thirdParentCommunity.getHandle())
|
||||
)))
|
||||
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/communities")))
|
||||
.andExpect(jsonPath("$.page", PageMatcher.pageEntryWithTotalPagesAndElements(1, 2, 2, 4)));
|
||||
.andExpect(jsonPath("$.page", PageMatcher.pageEntryWithTotalPagesAndElements(1, 2,
|
||||
2, 4)));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void findAllNoNameCommunityIsReturned() throws Exception {
|
||||
context.turnOffAuthorisationSystem();
|
||||
parentCommunity = CommunityBuilder.createCommunity(context).build();
|
||||
parentCommunity = CommunityBuilder.createCommunity(context).withName("test").build();
|
||||
|
||||
getClient().perform(get("/api/core/communities")
|
||||
.param("projection", "full"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$._embedded.communities", Matchers.contains(
|
||||
CommunityMatcher.matchCommunityEntry(parentCommunity.getID(),
|
||||
parentCommunity.getHandle())
|
||||
CommunityMatcher.matchCommunityEntryFullProjection(parentCommunity.getName(),
|
||||
parentCommunity.getID(),
|
||||
parentCommunity.getHandle())
|
||||
)))
|
||||
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/communities")))
|
||||
.andExpect(jsonPath("$.page.totalElements", is(1)));
|
||||
@@ -462,12 +475,14 @@ public class CommunityRestRepositoryIT extends AbstractControllerIntegrationTest
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$._embedded.communities", Matchers.contains(
|
||||
CommunityMatcher.matchCommunityEntry(parentCommunity.getName(), parentCommunity.getID(),
|
||||
parentCommunity.getHandle())
|
||||
CommunityMatcher.matchCommunityEntryFullProjection(parentCommunity.getName(),
|
||||
parentCommunity.getID(),
|
||||
parentCommunity.getHandle())
|
||||
)))
|
||||
.andExpect(jsonPath("$._embedded.communities", Matchers.not(
|
||||
Matchers.contains(
|
||||
CommunityMatcher.matchCommunityEntry(child1.getName(), child1.getID(), child1.getHandle())
|
||||
CommunityMatcher.matchCommunityEntryFullProjection(child1.getName(), child1.getID(),
|
||||
child1.getHandle())
|
||||
)
|
||||
)))
|
||||
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/communities")))
|
||||
@@ -480,12 +495,14 @@ public class CommunityRestRepositoryIT extends AbstractControllerIntegrationTest
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$._embedded.communities", Matchers.contains(
|
||||
CommunityMatcher.matchCommunityEntry(child1.getName(), child1.getID(), child1.getHandle())
|
||||
CommunityMatcher.matchCommunityEntryFullProjection(child1.getName(), child1.getID(),
|
||||
child1.getHandle())
|
||||
)))
|
||||
.andExpect(jsonPath("$._embedded.communities", Matchers.not(
|
||||
Matchers.contains(
|
||||
CommunityMatcher.matchCommunityEntry(parentCommunity.getName(), parentCommunity.getID(),
|
||||
parentCommunity.getHandle())
|
||||
CommunityMatcher.matchCommunityEntryFullProjection(parentCommunity.getName(),
|
||||
parentCommunity.getID(),
|
||||
parentCommunity.getHandle())
|
||||
)
|
||||
)))
|
||||
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/communities")))
|
||||
@@ -553,12 +570,14 @@ public class CommunityRestRepositoryIT extends AbstractControllerIntegrationTest
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$", Matchers.is(
|
||||
CommunityMatcher.matchCommunityEntry(parentCommunity.getName(), parentCommunity.getID(),
|
||||
parentCommunity.getHandle())
|
||||
CommunityMatcher.matchCommunityEntryFullProjection(parentCommunity.getName(),
|
||||
parentCommunity.getID(),
|
||||
parentCommunity.getHandle())
|
||||
)))
|
||||
.andExpect(jsonPath("$", Matchers.not(
|
||||
Matchers.is(
|
||||
CommunityMatcher.matchCommunityEntry(child1.getName(), child1.getID(), child1.getHandle())
|
||||
CommunityMatcher.matchCommunityEntryFullProjection(child1.getName(), child1.getID(),
|
||||
child1.getHandle())
|
||||
)
|
||||
)))
|
||||
.andExpect(jsonPath("$._links.self.href", Matchers
|
||||
@@ -633,14 +652,18 @@ public class CommunityRestRepositoryIT extends AbstractControllerIntegrationTest
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$._embedded.communities", Matchers.containsInAnyOrder(
|
||||
CommunityMatcher.matchCommunityEntry(parentCommunity.getName(), parentCommunity.getID(),
|
||||
parentCommunity.getHandle()),
|
||||
CommunityMatcher.matchCommunityEntry(parentCommunity2.getName(), parentCommunity2.getID(),
|
||||
parentCommunity2.getHandle())
|
||||
CommunityMatcher.matchCommunityEntryFullProjection(parentCommunity.getName(),
|
||||
parentCommunity.getID(),
|
||||
parentCommunity.getHandle()),
|
||||
CommunityMatcher.matchCommunityEntryFullProjection(parentCommunity2.getName(),
|
||||
parentCommunity2.getID(),
|
||||
parentCommunity2.getHandle())
|
||||
)))
|
||||
.andExpect(jsonPath("$._embedded.communities", Matchers.not(Matchers.containsInAnyOrder(
|
||||
CommunityMatcher.matchCommunityEntry(child1.getName(), child1.getID(), child1.getHandle()),
|
||||
CommunityMatcher.matchCommunityEntry(child12.getName(), child12.getID(), child12.getHandle())
|
||||
CommunityMatcher.matchCommunityEntryFullProjection(child1.getName(), child1.getID(),
|
||||
child1.getHandle()),
|
||||
CommunityMatcher.matchCommunityEntryFullProjection(child12.getName(), child12.getID(),
|
||||
child12.getHandle())
|
||||
))))
|
||||
.andExpect(
|
||||
jsonPath("$._links.self.href", Matchers.containsString("/api/core/communities/search/top")))
|
||||
@@ -697,25 +720,25 @@ public class CommunityRestRepositoryIT extends AbstractControllerIntegrationTest
|
||||
.andExpect(content().contentType(contentType))
|
||||
//Checking that these communities are present
|
||||
.andExpect(jsonPath("$._embedded.communities", Matchers.containsInAnyOrder(
|
||||
CommunityMatcher.matchCommunityEntry(parentCommunityChild1.getName(),
|
||||
CommunityMatcher.matchCommunityEntryFullProjection(parentCommunityChild1.getName(),
|
||||
parentCommunityChild1.getID(),
|
||||
parentCommunityChild1.getHandle()),
|
||||
CommunityMatcher.matchCommunityEntry(parentCommunityChild2.getName(),
|
||||
CommunityMatcher.matchCommunityEntryFullProjection(parentCommunityChild2.getName(),
|
||||
parentCommunityChild2.getID(),
|
||||
parentCommunityChild2.getHandle())
|
||||
)))
|
||||
//Checking that these communities are not present
|
||||
.andExpect(jsonPath("$._embedded.communities", Matchers.not(Matchers.anyOf(
|
||||
CommunityMatcher.matchCommunityEntry(parentCommunity.getName(),
|
||||
CommunityMatcher.matchCommunityEntryFullProjection(parentCommunity.getName(),
|
||||
parentCommunity.getID(),
|
||||
parentCommunity.getHandle()),
|
||||
CommunityMatcher.matchCommunityEntry(parentCommunity2.getName(),
|
||||
CommunityMatcher.matchCommunityEntryFullProjection(parentCommunity2.getName(),
|
||||
parentCommunity2.getID(),
|
||||
parentCommunity2.getHandle()),
|
||||
CommunityMatcher.matchCommunityEntry(parentCommunity2Child1.getName(),
|
||||
CommunityMatcher.matchCommunityEntryFullProjection(parentCommunity2Child1.getName(),
|
||||
parentCommunity2Child1.getID(),
|
||||
parentCommunity2Child1.getHandle()),
|
||||
CommunityMatcher.matchCommunityEntry(parentCommunityChild2Child1.getName(),
|
||||
CommunityMatcher.matchCommunityEntryFullProjection(parentCommunityChild2Child1.getName(),
|
||||
parentCommunityChild2Child1.getID(),
|
||||
parentCommunityChild2Child1.getHandle())
|
||||
))))
|
||||
@@ -732,25 +755,25 @@ public class CommunityRestRepositoryIT extends AbstractControllerIntegrationTest
|
||||
.andExpect(content().contentType(contentType))
|
||||
//Checking that these communities are present
|
||||
.andExpect(jsonPath("$._embedded.communities", Matchers.contains(
|
||||
CommunityMatcher.matchCommunityEntry(parentCommunityChild2Child1.getName(),
|
||||
CommunityMatcher.matchCommunityEntryFullProjection(parentCommunityChild2Child1.getName(),
|
||||
parentCommunityChild2Child1.getID(),
|
||||
parentCommunityChild2Child1.getHandle())
|
||||
)))
|
||||
//Checking that these communities are not present
|
||||
.andExpect(jsonPath("$._embedded.communities", Matchers.not(Matchers.anyOf(
|
||||
CommunityMatcher.matchCommunityEntry(parentCommunity.getName(),
|
||||
CommunityMatcher.matchCommunityEntryFullProjection(parentCommunity.getName(),
|
||||
parentCommunity.getID(),
|
||||
parentCommunity.getHandle()),
|
||||
CommunityMatcher.matchCommunityEntry(parentCommunity2.getName(),
|
||||
CommunityMatcher.matchCommunityEntryFullProjection(parentCommunity2.getName(),
|
||||
parentCommunity2.getID(),
|
||||
parentCommunity2.getHandle()),
|
||||
CommunityMatcher.matchCommunityEntry(parentCommunity2Child1.getName(),
|
||||
CommunityMatcher.matchCommunityEntryFullProjection(parentCommunity2Child1.getName(),
|
||||
parentCommunity2Child1.getID(),
|
||||
parentCommunity2Child1.getHandle()),
|
||||
CommunityMatcher.matchCommunityEntry(parentCommunityChild2Child1.getName(),
|
||||
CommunityMatcher.matchCommunityEntryFullProjection(parentCommunityChild2Child1.getName(),
|
||||
parentCommunityChild2Child1.getID(),
|
||||
parentCommunityChild2Child1.getHandle()),
|
||||
CommunityMatcher.matchCommunityEntry(parentCommunityChild1.getName(),
|
||||
CommunityMatcher.matchCommunityEntryFullProjection(parentCommunityChild1.getName(),
|
||||
parentCommunityChild1.getID(),
|
||||
parentCommunityChild1.getHandle())
|
||||
))))
|
||||
@@ -824,12 +847,14 @@ public class CommunityRestRepositoryIT extends AbstractControllerIntegrationTest
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$", Matchers.is(
|
||||
CommunityMatcher.matchCommunityEntry(parentCommunity.getName(), parentCommunity.getID(),
|
||||
parentCommunity.getHandle())
|
||||
CommunityMatcher.matchCommunityEntryFullProjection(parentCommunity.getName(),
|
||||
parentCommunity.getID(),
|
||||
parentCommunity.getHandle())
|
||||
)))
|
||||
.andExpect(jsonPath("$", Matchers.not(
|
||||
Matchers.is(
|
||||
CommunityMatcher.matchCommunityEntry(child1.getName(), child1.getID(), child1.getHandle())
|
||||
CommunityMatcher.matchCommunityEntryFullProjection(child1.getName(), child1.getID(),
|
||||
child1.getHandle())
|
||||
)
|
||||
)))
|
||||
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/communities")))
|
||||
@@ -857,7 +882,7 @@ public class CommunityRestRepositoryIT extends AbstractControllerIntegrationTest
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$", Matchers.is(
|
||||
CommunityMatcher.matchCommunityEntry("Electronic theses and dissertations",
|
||||
CommunityMatcher.matchCommunityEntryFullProjection("Electronic theses and dissertations",
|
||||
parentCommunity.getID(),
|
||||
parentCommunity.getHandle())
|
||||
)))
|
||||
@@ -912,11 +937,12 @@ public class CommunityRestRepositoryIT extends AbstractControllerIntegrationTest
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$", Matchers.is(
|
||||
CommunityMatcher.matchCommunityEntry(parentCommunity.getName(), parentCommunity.getID(),
|
||||
parentCommunity.getHandle())
|
||||
CommunityMatcher.matchCommunityEntryFullProjection(parentCommunity.getName(),
|
||||
parentCommunity.getID(),
|
||||
parentCommunity.getHandle())
|
||||
)))
|
||||
.andExpect(jsonPath("$._links.self.href",
|
||||
Matchers.containsString("/api/core/communities"))) ;
|
||||
Matchers.containsString("/api/core/communities")));
|
||||
getClient(token).perform(delete("/api/core/communities/" + parentCommunity.getID().toString()))
|
||||
.andExpect(status().isNoContent())
|
||||
;
|
||||
@@ -974,11 +1000,12 @@ public class CommunityRestRepositoryIT extends AbstractControllerIntegrationTest
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$", Matchers.is(
|
||||
CommunityMatcher.matchCommunityEntry(parentCommunity.getName(), parentCommunity.getID(),
|
||||
parentCommunity.getHandle())
|
||||
CommunityMatcher.matchCommunityEntryFullProjection(parentCommunity.getName(),
|
||||
parentCommunity.getID(),
|
||||
parentCommunity.getHandle())
|
||||
)))
|
||||
.andExpect(jsonPath("$._links.self.href",
|
||||
Matchers.containsString("/api/core/communities"))) ;
|
||||
Matchers.containsString("/api/core/communities")));
|
||||
getClient().perform(delete("/api/core/communities/" + parentCommunity.getID().toString()))
|
||||
.andExpect(status().isUnauthorized())
|
||||
;
|
||||
@@ -1007,11 +1034,12 @@ public class CommunityRestRepositoryIT extends AbstractControllerIntegrationTest
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$", Matchers.is(
|
||||
CommunityMatcher.matchCommunityEntry(parentCommunity.getName(), parentCommunity.getID(),
|
||||
parentCommunity.getHandle())
|
||||
CommunityMatcher.matchCommunityEntryFullProjection(parentCommunity.getName(),
|
||||
parentCommunity.getID(),
|
||||
parentCommunity.getHandle())
|
||||
)))
|
||||
.andExpect(jsonPath("$._links.self.href",
|
||||
Matchers.containsString("/api/core/communities"))) ;
|
||||
Matchers.containsString("/api/core/communities")));
|
||||
getClient(token).perform(delete("/api/core/communities/" + parentCommunity.getID().toString()))
|
||||
.andExpect(status().isNoContent())
|
||||
;
|
||||
@@ -1041,12 +1069,14 @@ public class CommunityRestRepositoryIT extends AbstractControllerIntegrationTest
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$", Matchers.is(
|
||||
CommunityMatcher.matchCommunityEntry(parentCommunity.getName(), parentCommunity.getID(),
|
||||
parentCommunity.getHandle())
|
||||
CommunityMatcher.matchCommunityEntryFullProjection(parentCommunity.getName(),
|
||||
parentCommunity.getID(),
|
||||
parentCommunity.getHandle())
|
||||
)))
|
||||
.andExpect(jsonPath("$", Matchers.not(
|
||||
Matchers.is(
|
||||
CommunityMatcher.matchCommunityEntry(child1.getName(), child1.getID(), child1.getHandle())
|
||||
CommunityMatcher.matchCommunityEntryFullProjection(child1.getName(), child1.getID(),
|
||||
child1.getHandle())
|
||||
)
|
||||
)))
|
||||
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/communities")))
|
||||
@@ -1077,7 +1107,7 @@ public class CommunityRestRepositoryIT extends AbstractControllerIntegrationTest
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$", Matchers.is(
|
||||
CommunityMatcher.matchCommunityEntry("Electronic theses and dissertations",
|
||||
CommunityMatcher.matchCommunityEntryFullProjection("Electronic theses and dissertations",
|
||||
parentCommunity.getID(),
|
||||
parentCommunity.getHandle())
|
||||
)))
|
||||
|
@@ -62,8 +62,8 @@ public class MappedCollectionRestRepositoryIT extends AbstractControllerIntegrat
|
||||
.build();
|
||||
context.restoreAuthSystemState();
|
||||
|
||||
// collectionService.addItem(context, col2, publicItem1);
|
||||
// collectionService.update(context, col2);
|
||||
// collectionService.addItem(context, colAA2, publicItem1);
|
||||
// collectionService.update(context, colAA2);
|
||||
// itemService.update(context, publicItem1);
|
||||
|
||||
getClient().perform(get("/api/core/items/" + publicItem1.getID() + "/mappedCollections")
|
||||
@@ -626,8 +626,8 @@ public class MappedCollectionRestRepositoryIT extends AbstractControllerIntegrat
|
||||
.build();
|
||||
context.restoreAuthSystemState();
|
||||
|
||||
// collectionService.addItem(context, col2, publicItem1);
|
||||
// collectionService.update(context, col2);
|
||||
// collectionService.addItem(context, colAA2, publicItem1);
|
||||
// collectionService.update(context, colAA2);
|
||||
// itemService.update(context, publicItem1);
|
||||
|
||||
context.restoreAuthSystemState();
|
||||
@@ -667,8 +667,8 @@ public class MappedCollectionRestRepositoryIT extends AbstractControllerIntegrat
|
||||
.build();
|
||||
context.restoreAuthSystemState();
|
||||
|
||||
// collectionService.addItem(context, col2, publicItem1);
|
||||
// collectionService.update(context, col2);
|
||||
// collectionService.addItem(context, colAA2, publicItem1);
|
||||
// collectionService.update(context, colAA2);
|
||||
// itemService.update(context, publicItem1);
|
||||
|
||||
getClient().perform(
|
||||
@@ -704,8 +704,8 @@ public class MappedCollectionRestRepositoryIT extends AbstractControllerIntegrat
|
||||
.build();
|
||||
context.restoreAuthSystemState();
|
||||
|
||||
// collectionService.addItem(context, col2, publicItem1);
|
||||
// collectionService.update(context, col2);
|
||||
// collectionService.addItem(context, colAA2, publicItem1);
|
||||
// collectionService.update(context, colAA2);
|
||||
// itemService.update(context, publicItem1);
|
||||
|
||||
|
||||
|
@@ -1439,7 +1439,7 @@ public class TaskRestRepositoriesIT extends AbstractControllerIntegrationTest {
|
||||
.withName("Sub Community")
|
||||
.build();
|
||||
|
||||
// the reviewer2 is a reviewer in a different step for the col1 and with the same role than reviewer1 for
|
||||
// the reviewer2 is a reviewer in a different step for the colAA1 and with the same role than reviewer1 for
|
||||
// another collection
|
||||
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1")
|
||||
.withWorkflowGroup(1, reviewer1)
|
||||
@@ -1613,7 +1613,7 @@ public class TaskRestRepositoriesIT extends AbstractControllerIntegrationTest {
|
||||
.withName("Sub Community")
|
||||
.build();
|
||||
|
||||
// the reviewer2 is a reviewer in a different step for the col1 and with the same role than reviewer1 for
|
||||
// the reviewer2 is a reviewer in a different step for the colAA1 and with the same role than reviewer1 for
|
||||
// another collection
|
||||
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1")
|
||||
.withWorkflowGroup(1, reviewer1)
|
||||
|
@@ -468,14 +468,14 @@ public class WorkspaceItemRestRepositoryIT extends AbstractControllerIntegration
|
||||
Collection col2 = CollectionBuilder.createCollection(context, child1).withName("Collection 2").build();
|
||||
String authToken = getAuthToken(admin.getEmail(), password);
|
||||
|
||||
// create a workspaceitem explicitly in the col1
|
||||
// create a workspaceitem explicitly in the colAA1
|
||||
getClient(authToken).perform(post("/api/submission/workspaceitems")
|
||||
.param("owningCollection", col1.getID().toString())
|
||||
.contentType(org.springframework.http.MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isCreated())
|
||||
.andExpect(jsonPath("$._embedded.collection.id", is(col1.getID().toString())));
|
||||
|
||||
// create a workspaceitem explicitly in the col2
|
||||
// create a workspaceitem explicitly in the colAA2
|
||||
getClient(authToken).perform(post("/api/submission/workspaceitems")
|
||||
.param("owningCollection", col2.getID().toString())
|
||||
.contentType(org.springframework.http.MediaType.APPLICATION_JSON))
|
||||
@@ -483,7 +483,7 @@ public class WorkspaceItemRestRepositoryIT extends AbstractControllerIntegration
|
||||
.andExpect(jsonPath("$._embedded.collection.id", is(col2.getID().toString())));
|
||||
|
||||
// create a workspaceitem without an explicit collection, this will go in the first valid collection for the
|
||||
// user: the col1
|
||||
// user: the colAA1
|
||||
getClient(authToken).perform(post("/api/submission/workspaceitems")
|
||||
.contentType(org.springframework.http.MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isCreated())
|
||||
@@ -518,7 +518,7 @@ public class WorkspaceItemRestRepositoryIT extends AbstractControllerIntegration
|
||||
final MockMultipartFile bibtexFile = new MockMultipartFile("file", "bibtex-test.bib", "application/x-bibtex",
|
||||
bibtex);
|
||||
|
||||
// bulk create workspaceitems in the default collection (col1)
|
||||
// bulk create workspaceitems in the default collection (colAA1)
|
||||
getClient(authToken).perform(fileUpload("/api/submission/workspaceitems")
|
||||
.file(bibtexFile))
|
||||
// bulk create should return 200, 201 (created) is better for single resource
|
||||
@@ -539,7 +539,7 @@ public class WorkspaceItemRestRepositoryIT extends AbstractControllerIntegration
|
||||
jsonPath("$._embedded.workspaceitems[*]._embedded.upload").doesNotExist())
|
||||
;
|
||||
|
||||
// bulk create workspaceitems explicitly in the col2
|
||||
// bulk create workspaceitems explicitly in the colAA2
|
||||
getClient(authToken).perform(fileUpload("/api/submission/workspaceitems")
|
||||
.file(bibtexFile)
|
||||
.param("collection", col2.getID().toString()))
|
||||
@@ -654,7 +654,7 @@ public class WorkspaceItemRestRepositoryIT extends AbstractControllerIntegration
|
||||
)))))
|
||||
;
|
||||
|
||||
// create an empty workspaceitem explicitly in the col1, check validation on creation
|
||||
// create an empty workspaceitem explicitly in the colAA1, check validation on creation
|
||||
getClient(authToken).perform(post("/api/submission/workspaceitems")
|
||||
.param("collection", col1.getID().toString())
|
||||
.contentType(org.springframework.http.MediaType.APPLICATION_JSON))
|
||||
|
@@ -35,6 +35,21 @@ public class CollectionMatcher {
|
||||
);
|
||||
}
|
||||
|
||||
public static Matcher<? super Object> matchCollectionEntryFullProjection(String name, UUID uuid, String handle) {
|
||||
return matchCollectionEntryFullProjection(name, uuid, handle, null);
|
||||
|
||||
}
|
||||
|
||||
public static Matcher<? super Object> matchCollectionEntryFullProjection(String name, UUID uuid, String handle,
|
||||
Bitstream logo) {
|
||||
return allOf(
|
||||
matchProperties(name, uuid, handle),
|
||||
matchLinks(uuid),
|
||||
matchLogo(logo),
|
||||
matchFullEmbeds()
|
||||
);
|
||||
}
|
||||
|
||||
public static Matcher<? super Object> matchProperties(String name, UUID uuid, String handle) {
|
||||
return allOf(
|
||||
hasJsonPath("$.uuid", is(uuid.toString())),
|
||||
|
@@ -57,6 +57,15 @@ public class CommunityMatcher {
|
||||
);
|
||||
}
|
||||
|
||||
public static Matcher<? super Object> matchCommunityEntryFullProjection(String name, UUID uuid, String handle) {
|
||||
return allOf(
|
||||
matchProperties(name, uuid, handle),
|
||||
hasJsonPath("$._embedded.collections", Matchers.not(Matchers.empty())),
|
||||
hasJsonPath("$._embedded.logo", Matchers.not(Matchers.empty())),
|
||||
matchLinks(uuid)
|
||||
);
|
||||
}
|
||||
|
||||
public static Matcher<? super Object> matchProperties(String name, UUID uuid, String handle) {
|
||||
return allOf(
|
||||
hasJsonPath("$.uuid", is(uuid.toString())),
|
||||
|
Reference in New Issue
Block a user