mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-12 04:23:13 +00:00
Merge pull request #1893 from atmire/DS-3762_write-missing-tests
DS-3762: Write integration tests for initial endpoints
This commit is contained in:
@@ -43,7 +43,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
*
|
||||
* @version $Revision$
|
||||
*/
|
||||
public class Context
|
||||
public class Context implements AutoCloseable
|
||||
{
|
||||
private static final Logger log = Logger.getLogger(Context.class);
|
||||
protected static final AtomicBoolean databaseUpdated = new AtomicBoolean(false);
|
||||
@@ -573,6 +573,13 @@ public class Context
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
if(isValid()) {
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Find out if this context is valid. Returns <code>false</code> if this
|
||||
|
@@ -270,6 +270,45 @@ public class ContextTest extends AbstractUnitTest
|
||||
cleanupContext(instance);
|
||||
cleanupContext(newInstance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of close method, of class Context.
|
||||
*/
|
||||
@Test
|
||||
public void testClose() throws SQLException, AuthorizeException
|
||||
{
|
||||
new NonStrictExpectations(authorizeService.getClass())
|
||||
{{
|
||||
// Allow Admin permissions - needed to create a new EPerson
|
||||
authorizeService.isAdmin((Context) any); result = true;
|
||||
}};
|
||||
|
||||
String createdEmail = "susie@email.com";
|
||||
|
||||
// To test close() we need a new Context object in a try-with-resources block
|
||||
try(Context instance = new Context()) {
|
||||
|
||||
// Create a new EPerson (DO NOT COMMIT IT)
|
||||
EPerson newUser = ePersonService.create(instance);
|
||||
newUser.setFirstName(context, "Susan");
|
||||
newUser.setLastName(context, "Doe");
|
||||
newUser.setEmail(createdEmail);
|
||||
newUser.setCanLogIn(true);
|
||||
newUser.setLanguage(context, I18nUtil.getDefaultLocale().getLanguage());
|
||||
|
||||
}
|
||||
|
||||
// Open a new context, let's make sure that EPerson isn't there
|
||||
Context newInstance = new Context();
|
||||
EPerson found = ePersonService.findByEmail(newInstance, createdEmail);
|
||||
assertThat("testClose 0", found, nullValue());
|
||||
|
||||
// Cleanup our contexts
|
||||
cleanupContext(newInstance);
|
||||
|
||||
//Calling close on a finished context should not result in errors
|
||||
newInstance.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of abort method, of class Context.
|
||||
|
@@ -44,7 +44,7 @@ import org.springframework.beans.factory.annotation.Required;
|
||||
* <p>
|
||||
*
|
||||
* @author Aaron Zeckoski (azeckoski @ gmail.com)
|
||||
* @author Atmire
|
||||
* @author Tom Desair (tom dot desair at atmire dot com)
|
||||
*/
|
||||
public final class StatelessRequestServiceImpl implements RequestService, InitializedService, ShutdownService {
|
||||
|
||||
|
@@ -37,7 +37,8 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
* Rest controller that handles authentication on the REST API together with the Spring Security filters
|
||||
* configured in {@link org.dspace.app.rest.security.WebSecurityConfiguration}
|
||||
*
|
||||
* @author Atmire NV (info at atmire dot com)
|
||||
* @author Frederic Van Reet (frederic dot vanreet at atmire dot com)
|
||||
* @author Tom Desair (tom dot desair at atmire dot com)
|
||||
*/
|
||||
@RequestMapping(value = "/api/" + AuthnRest.CATEGORY)
|
||||
@RestController
|
||||
|
@@ -12,7 +12,8 @@ import org.dspace.app.rest.AuthenticationRestController;
|
||||
/**
|
||||
* Root rest object for the /api/authn endpoint
|
||||
*
|
||||
* @author Atmire NV (info at atmire dot com)
|
||||
* @author Frederic Van Reet (frederic dot vanreet at atmire dot com)
|
||||
* @author Tom Desair (tom dot desair at atmire dot com)
|
||||
*/
|
||||
public class AuthnRest extends BaseObjectRest<Integer>{
|
||||
|
||||
|
@@ -14,7 +14,8 @@ import org.dspace.app.rest.utils.Utils;
|
||||
/**
|
||||
* Status Resource, wraps the status object and the authenticated EPerson
|
||||
*
|
||||
* @author Atmire NV (info at atmire dot com)
|
||||
* @author Frederic Van Reet (frederic dot vanreet at atmire dot com)
|
||||
* @author Tom Desair (tom dot desair at atmire dot com)
|
||||
*/
|
||||
@RelNameDSpaceResource(AuthenticationStatusRest.NAME)
|
||||
public class AuthenticationStatusResource extends DSpaceResource<AuthenticationStatusRest> {
|
||||
|
@@ -21,7 +21,8 @@ import org.springframework.hateoas.Link;
|
||||
/**
|
||||
* Authn Rest Resource, used to link to login, logout, status, ...
|
||||
*
|
||||
* @author Atmire NV (info at atmire dot com)
|
||||
* @author Frederic Van Reet (frederic dot vanreet at atmire dot com)
|
||||
* @author Tom Desair (tom dot desair at atmire dot com)
|
||||
*/
|
||||
@RelNameDSpaceResource(AuthnRest.NAME)
|
||||
public class AuthnResource extends DSpaceResource<AuthnRest> {
|
||||
|
@@ -23,7 +23,8 @@ import org.springframework.stereotype.Component;
|
||||
/**
|
||||
* Custom logout handler to support stateless sessions
|
||||
*
|
||||
* @author Atmire NV (info at atmire dot com)
|
||||
* @author Frederic Van Reet (frederic dot vanreet at atmire dot com)
|
||||
* @author Tom Desair (tom dot desair at atmire dot com)
|
||||
*/
|
||||
@Component
|
||||
public class CustomLogoutHandler implements LogoutHandler {
|
||||
|
@@ -18,7 +18,8 @@ import org.springframework.security.core.GrantedAuthority;
|
||||
/**
|
||||
* Custom Authentication for use with DSpace
|
||||
*
|
||||
* @author Atmire NV (info at atmire dot com)
|
||||
* @author Frederic Van Reet (frederic dot vanreet at atmire dot com)
|
||||
* @author Tom Desair (tom dot desair at atmire dot com)
|
||||
*/
|
||||
public class DSpaceAuthentication implements Authentication {
|
||||
|
||||
|
@@ -39,7 +39,8 @@ import org.springframework.stereotype.Component;
|
||||
/**
|
||||
* This class is reponsible for authenticating a user via REST
|
||||
*
|
||||
* @author Atmire NV (info at atmire dot com)
|
||||
* @author Frederic Van Reet (frederic dot vanreet at atmire dot com)
|
||||
* @author Tom Desair (tom dot desair at atmire dot com)
|
||||
*/
|
||||
@Component
|
||||
public class EPersonRestAuthenticationProvider implements AuthenticationProvider{
|
||||
|
@@ -19,7 +19,8 @@ import org.springframework.stereotype.Service;
|
||||
/**
|
||||
* Interface for a service that can provide authentication for the REST API
|
||||
*
|
||||
* @author Atmire NV (info at atmire dot com)
|
||||
* @author Frederic Van Reet (frederic dot vanreet at atmire dot com)
|
||||
* @author Tom Desair (tom dot desair at atmire dot com)
|
||||
*/
|
||||
@Service
|
||||
public interface RestAuthenticationService {
|
||||
|
@@ -31,7 +31,8 @@ import org.springframework.security.web.authentication.www.BasicAuthenticationFi
|
||||
* Custom Spring authentication filter for Stateless authentication, intercepts requests to check for valid
|
||||
* authentication
|
||||
*
|
||||
* @author Atmire NV (info at atmire dot com)
|
||||
* @author Frederic Van Reet (frederic dot vanreet at atmire dot com)
|
||||
* @author Tom Desair (tom dot desair at atmire dot com)
|
||||
*/
|
||||
public class StatelessAuthenticationFilter extends BasicAuthenticationFilter{
|
||||
|
||||
|
@@ -24,7 +24,8 @@ import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
|
||||
/**
|
||||
* This class will filter login requests to try and authenticate them
|
||||
*
|
||||
* @author Atmire NV (info at atmire dot com)
|
||||
* @author Frederic Van Reet (frederic dot vanreet at atmire dot com)
|
||||
* @author Tom Desair (tom dot desair at atmire dot com)
|
||||
*/
|
||||
public class StatelessLoginFilter extends AbstractAuthenticationProcessingFilter {
|
||||
|
||||
|
@@ -26,7 +26,8 @@ import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
|
||||
/**
|
||||
* Spring Security configuration for DSpace Spring Rest
|
||||
*
|
||||
* @author Atmire NV (info at atmire dot com)
|
||||
* @author Frederic Van Reet (frederic dot vanreet at atmire dot com)
|
||||
* @author Tom Desair (tom dot desair at atmire dot com)
|
||||
*/
|
||||
@EnableWebSecurity
|
||||
@Configuration
|
||||
|
@@ -22,7 +22,8 @@ import org.springframework.stereotype.Component;
|
||||
/**
|
||||
* Provides a claim for a JSON Web Token, this claim is responsible for adding the EPerson ID to it
|
||||
*
|
||||
* @author Atmire NV (info at atmire dot com)
|
||||
* @author Frederic Van Reet (frederic dot vanreet at atmire dot com)
|
||||
* @author Tom Desair (tom dot desair at atmire dot com)
|
||||
*/
|
||||
@Component
|
||||
public class EPersonClaimProvider implements JWTClaimProvider{
|
||||
|
@@ -18,7 +18,8 @@ import org.dspace.core.Context;
|
||||
* Interface to be implemented if you want to add a custom claim to a JSON Web Token, annotate with @Component
|
||||
* to include it's implementation in the token
|
||||
*
|
||||
* @author Atmire NV (info at atmire dot com)
|
||||
* @author Frederic Van Reet (frederic dot vanreet at atmire dot com)
|
||||
* @author Tom Desair (tom dot desair at atmire dot com)
|
||||
*/
|
||||
public interface JWTClaimProvider {
|
||||
|
||||
|
@@ -51,7 +51,8 @@ import org.springframework.stereotype.Component;
|
||||
/**
|
||||
* Class responsible for creating and parsing JWTs, supports both JWS and JWE
|
||||
*
|
||||
* @author Atmire NV (info at atmire dot com)
|
||||
* @author Frederic Van Reet (frederic dot vanreet at atmire dot com)
|
||||
* @author Tom Desair (tom dot desair at atmire dot com)
|
||||
*/
|
||||
@Component
|
||||
public class JWTTokenHandler implements InitializingBean {
|
||||
|
@@ -35,7 +35,8 @@ import org.springframework.stereotype.Component;
|
||||
/**
|
||||
* Rest Authentication implementation for JSON Web Tokens
|
||||
*
|
||||
* @author Atmire NV (info at atmire dot com)
|
||||
* @author Frederic Van Reet (frederic dot vanreet at atmire dot com)
|
||||
* @author Tom Desair (tom dot desair at atmire dot com)
|
||||
*/
|
||||
@Component
|
||||
public class JWTTokenRestAuthenticationServiceImpl implements RestAuthenticationService, InitializingBean {
|
||||
|
@@ -29,7 +29,8 @@ import org.springframework.stereotype.Component;
|
||||
/**
|
||||
* JWT claim provider to read and set the special groups of an eperson on a JWT token
|
||||
*
|
||||
* @author Atmire NV (info at atmire dot com)
|
||||
* @author Frederic Van Reet (frederic dot vanreet at atmire dot com)
|
||||
* @author Tom Desair (tom dot desair at atmire dot com)
|
||||
*/
|
||||
@Component
|
||||
public class SpecialGroupClaimProvider implements JWTClaimProvider {
|
||||
|
@@ -27,7 +27,8 @@ import org.junit.Test;
|
||||
/**
|
||||
* Integration test that covers various authentication scenarios
|
||||
*
|
||||
* @author Atmire NV (info at atmire dot com)
|
||||
* @author Frederic Van Reet (frederic dot vanreet at atmire dot com)
|
||||
* @author Tom Desair (tom dot desair at atmire dot com)
|
||||
*/
|
||||
public class AuthenticationRestControllerIT extends AbstractControllerIntegrationTest {
|
||||
|
||||
|
@@ -288,9 +288,6 @@ public class BitstreamContentRestControllerIT extends AbstractControllerIntegrat
|
||||
//An unauthorized request should not log statistics
|
||||
checkNumberOfStatsRecords(bitstream, 0);
|
||||
|
||||
} finally {
|
||||
//** CLEANUP **
|
||||
GroupBuilder.cleaner().delete(internalGroup);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,92 @@
|
||||
/**
|
||||
* 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 org.dspace.app.rest.builder.BitstreamFormatBuilder;
|
||||
import org.dspace.app.rest.matcher.BitstreamFormatMatcher;
|
||||
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
|
||||
import org.dspace.content.BitstreamFormat;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
/**
|
||||
* @author Jonas Van Goolen - (jonas@atmire.com)
|
||||
*/
|
||||
|
||||
public class BitstreamFormatRestRepositoryIT extends AbstractControllerIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void findAllPaginationTest() throws Exception {
|
||||
getClient().perform(get("/api/core/bitstreamformats"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$.page.size", is(20)))
|
||||
.andExpect(jsonPath("$._links.self.href", startsWith(REST_SERVER_URL)))
|
||||
.andExpect(jsonPath("$._links.self.href", endsWith("/api/core/bitstreamformats")))
|
||||
;
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void unknownFormatRequiredByDefault() throws Exception {
|
||||
getClient().perform(get("/api/core/bitstreamformats"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$.page.size", is(20)))
|
||||
.andExpect(jsonPath("$.page.totalElements", is(1)))
|
||||
.andExpect(jsonPath("$._links.self.href", startsWith(REST_SERVER_URL)))
|
||||
.andExpect(jsonPath("$._links.self.href", endsWith("/api/core/bitstreamformats")))
|
||||
.andExpect(jsonPath("$._embedded.bitstreamformats", Matchers.is(
|
||||
BitstreamFormatMatcher.matchBitstreamFormatMimeType("Unknown")
|
||||
)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void findAllMimeTypeCheck() throws Exception {
|
||||
context.turnOffAuthorisationSystem();
|
||||
BitstreamFormat bitstreamFormat = BitstreamFormatBuilder.createBitstreamFormat(context)
|
||||
.withMimeType("application/octet-stream")
|
||||
.withDescription("Description")
|
||||
.build();
|
||||
getClient().perform(get("/api/core/bitstreamformats"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$.page.totalElements", is(2)))
|
||||
.andExpect(jsonPath("$._embedded.bitstreamformats", Matchers.contains(
|
||||
BitstreamFormatMatcher.matchBitstreamFormat(bitstreamFormat.getMIMEType(), bitstreamFormat.getDescription())
|
||||
)))
|
||||
;
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void findOne() throws Exception {
|
||||
context.turnOffAuthorisationSystem();
|
||||
BitstreamFormat bitstreamFormat = BitstreamFormatBuilder.createBitstreamFormat(context)
|
||||
.withMimeType("application/octet-stream")
|
||||
.withDescription("Description")
|
||||
.build();
|
||||
|
||||
getClient().perform(get("/api/core/bitstreamformats/" + bitstreamFormat.getID()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$.description", is(bitstreamFormat.getDescription())))
|
||||
.andExpect(jsonPath("$.mimetype", is(bitstreamFormat.getMIMEType())))
|
||||
.andExpect(jsonPath("$.type", is("bitstreamformat")))
|
||||
.andExpect(jsonPath("$._links.self.href", startsWith(REST_SERVER_URL)))
|
||||
.andExpect(jsonPath("$._links.self.href", endsWith("/api/core/bitstreamformats/"+bitstreamFormat.getID())))
|
||||
;
|
||||
}
|
||||
}
|
@@ -0,0 +1,384 @@
|
||||
/**
|
||||
* 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 org.apache.commons.codec.CharEncoding;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.dspace.app.rest.builder.BitstreamBuilder;
|
||||
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.BitstreamFormatMatcher;
|
||||
import org.dspace.app.rest.matcher.BitstreamMatcher;
|
||||
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
|
||||
import org.dspace.content.Bitstream;
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.content.Community;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.content.service.BitstreamService;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private BitstreamService bitstreamService;
|
||||
|
||||
@Test
|
||||
public void findAllTest() throws Exception{
|
||||
//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.
|
||||
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent Community")
|
||||
.build();
|
||||
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community")
|
||||
.build();
|
||||
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
|
||||
|
||||
//2. One public items that is readable by Anonymous
|
||||
Item publicItem1 = ItemBuilder.createItem(context, col1)
|
||||
.withTitle("Test")
|
||||
.withIssueDate("2010-10-17")
|
||||
.withAuthor("Smith, Donald")
|
||||
.withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
String bitstreamContent = "ThisIsSomeDummyText";
|
||||
//Add a bitstream to an item
|
||||
Bitstream bitstream = null;
|
||||
try(InputStream is = IOUtils.toInputStream(bitstreamContent, CharEncoding.UTF_8)) {
|
||||
bitstream = BitstreamBuilder.
|
||||
createBitstream(context, publicItem1, is)
|
||||
.withName("Bitstream")
|
||||
.withDescription("description")
|
||||
.withMimeType("text/plain")
|
||||
.build();
|
||||
}
|
||||
|
||||
//Add a bitstream to an item
|
||||
Bitstream bitstream1 = null;
|
||||
try(InputStream is = IOUtils.toInputStream(bitstreamContent, CharEncoding.UTF_8)) {
|
||||
bitstream1 = BitstreamBuilder.
|
||||
createBitstream(context, publicItem1, is)
|
||||
.withName("Bitstream1")
|
||||
.withDescription("description123")
|
||||
.withMimeType("text/plain")
|
||||
.build();
|
||||
}
|
||||
|
||||
getClient().perform(get("/api/core/bitstreams/"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$._embedded.bitstreams", Matchers.containsInAnyOrder(
|
||||
BitstreamMatcher.matchBitstreamEntry(bitstream),
|
||||
BitstreamMatcher.matchBitstreamEntry(bitstream1)
|
||||
)))
|
||||
|
||||
;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findAllPaginationTest() throws Exception{
|
||||
//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.
|
||||
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent Community")
|
||||
.build();
|
||||
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community")
|
||||
.build();
|
||||
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
|
||||
|
||||
//2. One public items that is readable by Anonymous
|
||||
Item publicItem1 = ItemBuilder.createItem(context, col1)
|
||||
.withTitle("Test")
|
||||
.withIssueDate("2010-10-17")
|
||||
.withAuthor("Smith, Donald")
|
||||
.withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
String bitstreamContent = "ThisIsSomeDummyText";
|
||||
//Add a bitstream to an item
|
||||
Bitstream bitstream = null;
|
||||
try(InputStream is = IOUtils.toInputStream(bitstreamContent, CharEncoding.UTF_8)) {
|
||||
bitstream = BitstreamBuilder.
|
||||
createBitstream(context, publicItem1, is)
|
||||
.withName("Bitstream")
|
||||
.withDescription("descr")
|
||||
.withMimeType("text/plain")
|
||||
.build();
|
||||
}
|
||||
|
||||
//Add a bitstream to an item
|
||||
Bitstream bitstream1 = null;
|
||||
try(InputStream is = IOUtils.toInputStream(bitstreamContent, CharEncoding.UTF_8)) {
|
||||
bitstream1 = BitstreamBuilder.
|
||||
createBitstream(context, publicItem1, is)
|
||||
.withName("Bitstream1")
|
||||
.withDescription("desscrip1")
|
||||
.withMimeType("text/plain")
|
||||
.build();
|
||||
}
|
||||
|
||||
getClient().perform(get("/api/core/bitstreams/")
|
||||
.param("size","1"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$._embedded.bitstreams", Matchers.contains(
|
||||
BitstreamMatcher.matchBitstreamEntry(bitstream))
|
||||
))
|
||||
.andExpect(jsonPath("$._embedded.bitstreams", Matchers.not(
|
||||
Matchers.contains(
|
||||
BitstreamMatcher.matchBitstreamEntry(bitstream1))
|
||||
)
|
||||
))
|
||||
|
||||
;
|
||||
|
||||
getClient().perform(get("/api/core/bitstreams/")
|
||||
.param("size","1")
|
||||
.param("page", "1"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$._embedded.bitstreams", Matchers.contains(
|
||||
BitstreamMatcher.matchBitstreamEntry(bitstream1)
|
||||
)))
|
||||
.andExpect(jsonPath("$._embedded.bitstreams", Matchers.not(
|
||||
Matchers.contains(
|
||||
BitstreamMatcher.matchBitstreamEntry(bitstream)
|
||||
)
|
||||
)))
|
||||
|
||||
;
|
||||
}
|
||||
|
||||
//TODO Re-enable test after https://jira.duraspace.org/browse/DS-3774 is fixed
|
||||
@Ignore
|
||||
@Test
|
||||
public void findAllWithDeletedTest() throws Exception{
|
||||
//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.
|
||||
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent Community")
|
||||
.build();
|
||||
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community")
|
||||
.build();
|
||||
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
|
||||
|
||||
//2. One public items that is readable by Anonymous
|
||||
Item publicItem1 = ItemBuilder.createItem(context, col1)
|
||||
.withTitle("Test")
|
||||
.withIssueDate("2010-10-17")
|
||||
.withAuthor("Smith, Donald")
|
||||
.build();
|
||||
|
||||
String bitstreamContent = "This is an archived bitstream";
|
||||
//Add a bitstream to an item
|
||||
Bitstream bitstream = null;
|
||||
try(InputStream is = IOUtils.toInputStream(bitstreamContent, CharEncoding.UTF_8)) {
|
||||
bitstream = BitstreamBuilder.
|
||||
createBitstream(context, publicItem1, is)
|
||||
.withName("Bitstream")
|
||||
.withMimeType("text/plain")
|
||||
.build();
|
||||
}
|
||||
|
||||
//Add a bitstream to an item
|
||||
bitstreamContent = "This is a deleted bitstream";
|
||||
Bitstream bitstream1 = null;
|
||||
try(InputStream is = IOUtils.toInputStream(bitstreamContent, CharEncoding.UTF_8)) {
|
||||
bitstream1 = BitstreamBuilder.
|
||||
createBitstream(context, publicItem1, is)
|
||||
.withName("Bitstream1")
|
||||
.withMimeType("text/plain")
|
||||
.build();
|
||||
}
|
||||
|
||||
//Delete the last bitstream
|
||||
bitstreamService.delete(context, bitstream1);
|
||||
context.commit();
|
||||
|
||||
getClient().perform(get("/api/core/bitstreams/"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$._embedded.bitstreams", contains(
|
||||
BitstreamMatcher.matchBitstreamEntry(bitstream)
|
||||
)))
|
||||
|
||||
;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findOneBitstreamTest() throws Exception {
|
||||
|
||||
//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.
|
||||
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent Community")
|
||||
.build();
|
||||
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community")
|
||||
.build();
|
||||
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
|
||||
|
||||
//2. One public items that is readable by Anonymous
|
||||
Item publicItem1 = ItemBuilder.createItem(context, col1)
|
||||
.withTitle("Test")
|
||||
.withIssueDate("2010-10-17")
|
||||
.withAuthor("Smith, Donald")
|
||||
.withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
String bitstreamContent = "ThisIsSomeDummyText";
|
||||
//Add a bitstream to an item
|
||||
Bitstream bitstream = null;
|
||||
try(InputStream is = IOUtils.toInputStream(bitstreamContent, CharEncoding.UTF_8)) {
|
||||
bitstream = BitstreamBuilder.
|
||||
createBitstream(context, publicItem1, is)
|
||||
.withName("Bitstream")
|
||||
.withDescription("Description")
|
||||
.withMimeType("text/plain")
|
||||
.build();
|
||||
}
|
||||
|
||||
//Add a bitstream to an item
|
||||
Bitstream bitstream1 = null;
|
||||
try(InputStream is = IOUtils.toInputStream(bitstreamContent, CharEncoding.UTF_8)) {
|
||||
bitstream1 = BitstreamBuilder.
|
||||
createBitstream(context, publicItem1, is)
|
||||
.withName("Bitstream1")
|
||||
.withDescription("Description1")
|
||||
.withMimeType("text/plain")
|
||||
.build();
|
||||
}
|
||||
|
||||
getClient().perform(get("/api/core/bitstreams/"+bitstream.getID()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$", BitstreamMatcher.matchBitstreamEntry(bitstream)))
|
||||
.andExpect(jsonPath("$", not(BitstreamMatcher.matchBitstreamEntry(bitstream1))))
|
||||
;
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findOneBitstreamRelsTest() throws Exception {
|
||||
|
||||
//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.
|
||||
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent Community")
|
||||
.build();
|
||||
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community")
|
||||
.build();
|
||||
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
|
||||
|
||||
//2. One public items that is readable by Anonymous
|
||||
Item publicItem1 = ItemBuilder.createItem(context, col1)
|
||||
.withTitle("Test")
|
||||
.withIssueDate("2010-10-17")
|
||||
.withAuthor("Smith, Donald")
|
||||
.withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
String bitstreamContent = "ThisIsSomeDummyText";
|
||||
//Add a bitstream to an item
|
||||
Bitstream bitstream = null;
|
||||
try(InputStream is = IOUtils.toInputStream(bitstreamContent, CharEncoding.UTF_8)) {
|
||||
bitstream = BitstreamBuilder.
|
||||
createBitstream(context, publicItem1, is)
|
||||
.withName("Bitstream")
|
||||
.withDescription("Description")
|
||||
.withMimeType("text/plain")
|
||||
.build();
|
||||
}
|
||||
|
||||
//Add a bitstream to an item
|
||||
Bitstream bitstream1 = null;
|
||||
try(InputStream is = IOUtils.toInputStream(bitstreamContent, CharEncoding.UTF_8)) {
|
||||
bitstream1 = BitstreamBuilder.
|
||||
createBitstream(context, publicItem1, is)
|
||||
.withName("Bitstream1")
|
||||
.withDescription("Description1234")
|
||||
.withMimeType("text/plain")
|
||||
.build();
|
||||
}
|
||||
|
||||
getClient().perform(get("/api/core/bitstreams/"+bitstream.getID()+"/format"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$", BitstreamFormatMatcher.matchBitstreamFormatMimeType("text/plain")))
|
||||
;
|
||||
|
||||
|
||||
getClient().perform(get("/api/core/bitstreams/"+bitstream.getID()+"/self"))
|
||||
.andExpect(status().isOk())
|
||||
;
|
||||
|
||||
|
||||
getClient().perform(get("/api/core/bitstreams/"+bitstream.getID()+"/content"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().string("ThisIsSomeDummyText"))
|
||||
;
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findOneWrongUUID() throws Exception {
|
||||
|
||||
//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.
|
||||
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent Community")
|
||||
.build();
|
||||
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community")
|
||||
.build();
|
||||
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
|
||||
|
||||
getClient().perform(get("/api/core/bitstreams/"+ UUID.randomUUID()))
|
||||
.andExpect(status().isNotFound())
|
||||
;
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -37,8 +37,8 @@ import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
|
||||
* Integration test to test the /api/discover/browses endpoint
|
||||
* (Class has to start or end with IT to be picked up by the failsafe plugin)
|
||||
*
|
||||
* @author Frederic Van Reet (frederic dot vanreet at atmire dot com)
|
||||
* @author Tom Desair (tom dot desair at atmire dot com)
|
||||
* @author Raf Ponsaerts (raf dot ponsaerts at atmire dot com)
|
||||
*/
|
||||
public class BrowsesResourceControllerIT extends AbstractControllerIntegrationTest {
|
||||
|
||||
@@ -377,9 +377,6 @@ public class BrowsesResourceControllerIT extends AbstractControllerIntegrationTe
|
||||
.andExpect(jsonPath("$._embedded.items[*].metadata[?(@.key=='dc.title')].value",
|
||||
not(hasItem("Internal publication"))))
|
||||
;
|
||||
|
||||
//** CLEANUP **
|
||||
GroupBuilder.cleaner().delete(internalGroup);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -0,0 +1,272 @@
|
||||
/**
|
||||
* 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 org.dspace.app.rest.builder.CollectionBuilder;
|
||||
import org.dspace.app.rest.builder.CommunityBuilder;
|
||||
import org.dspace.app.rest.matcher.CollectionMatcher;
|
||||
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
|
||||
import org.dspace.authorize.factory.AuthorizeServiceFactory;
|
||||
import org.dspace.authorize.service.AuthorizeService;
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.content.Community;
|
||||
import org.dspace.content.factory.ContentServiceFactory;
|
||||
import org.dspace.eperson.EPerson;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
public class CollectionRestRepositoryIT extends AbstractControllerIntegrationTest{
|
||||
|
||||
|
||||
@Test
|
||||
public void findAllTest() throws Exception {
|
||||
|
||||
//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.
|
||||
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent Community")
|
||||
.build();
|
||||
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community")
|
||||
.build();
|
||||
Community child2 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community Two")
|
||||
.build();
|
||||
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
|
||||
Collection col2 = CollectionBuilder.createCollection(context, child2).withName("Collection 2").build();
|
||||
|
||||
|
||||
|
||||
getClient().perform(get("/api/core/collections"))
|
||||
.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())
|
||||
)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findAllPaginationTest() throws Exception {
|
||||
|
||||
//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.
|
||||
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent Community")
|
||||
.build();
|
||||
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community")
|
||||
.build();
|
||||
Community child2 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community Two")
|
||||
.build();
|
||||
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
|
||||
Collection col2 = CollectionBuilder.createCollection(context, child2).withName("Collection 2").build();
|
||||
|
||||
|
||||
|
||||
getClient().perform(get("/api/core/collections")
|
||||
.param("size", "1"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$._embedded.collections", Matchers.contains(
|
||||
CollectionMatcher.matchCollectionEntry(col1.getName(), col1.getID(), col1.getHandle())
|
||||
)))
|
||||
.andExpect(jsonPath("$._embedded.collections", Matchers.not(
|
||||
Matchers.contains(
|
||||
CollectionMatcher.matchCollectionEntry(col2.getName(), col2.getID(), col2.getHandle())
|
||||
)
|
||||
)));
|
||||
|
||||
getClient().perform(get("/api/core/collections")
|
||||
.param("size", "1")
|
||||
.param("page", "1"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$._embedded.collections", Matchers.contains(
|
||||
CollectionMatcher.matchCollectionEntry(col2.getName(), col2.getID(), col2.getHandle())
|
||||
)))
|
||||
.andExpect(jsonPath("$._embedded.collections", Matchers.not(
|
||||
Matchers.contains(
|
||||
CollectionMatcher.matchCollectionEntry(col1.getName(), col1.getID(), col1.getHandle())
|
||||
)
|
||||
)));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void findOneCollectionTest() throws Exception {
|
||||
|
||||
//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.
|
||||
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent Community")
|
||||
.build();
|
||||
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community")
|
||||
.build();
|
||||
Community child2 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community Two")
|
||||
.build();
|
||||
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
|
||||
Collection col2 = CollectionBuilder.createCollection(context, child2).withName("Collection 2").build();
|
||||
|
||||
|
||||
|
||||
getClient().perform(get("/api/core/collections/" + col1.getID()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.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 findOneCollectionRelsTest() throws Exception {
|
||||
|
||||
//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.
|
||||
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent Community")
|
||||
.build();
|
||||
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community")
|
||||
.build();
|
||||
Community child2 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community Two")
|
||||
.build();
|
||||
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").withLogo("TestingContentForLogo").build();
|
||||
Collection col2 = CollectionBuilder.createCollection(context, child2).withName("Collection 2").build();
|
||||
|
||||
getClient().perform(get("/api/core/collections/" + col1.getID()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$", is(
|
||||
CollectionMatcher.matchCollectionEntry(col1.getName(), col1.getID(), col1.getHandle())
|
||||
)))
|
||||
.andExpect(jsonPath("$", Matchers.not(
|
||||
is(
|
||||
CollectionMatcher.matchCollectionEntry(col2.getName(), col2.getID(), col2.getHandle())
|
||||
)))
|
||||
)
|
||||
;
|
||||
|
||||
getClient().perform(get("/api/core/collections/" + col1.getID() + "/logo"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$._links.format.href", Matchers.containsString("/api/core/bitstreams"))).andExpect(jsonPath("$._links.format.href", Matchers.containsString("/format")))
|
||||
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/bitstreams")))
|
||||
.andExpect(jsonPath("$._links.content.href", Matchers.containsString("/api/core/bitstreams"))).andExpect(jsonPath("$._links.content.href", Matchers.containsString("/content")))
|
||||
;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void findAuthorizedTest() throws Exception {
|
||||
|
||||
//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.
|
||||
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent Community")
|
||||
.build();
|
||||
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community")
|
||||
.build();
|
||||
Community child2 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community Two")
|
||||
.build();
|
||||
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
|
||||
Collection col2 = CollectionBuilder.createCollection(context, child2).withName("Collection 2").build();
|
||||
|
||||
getClient().perform(get("/api/core/collections/search/findAuthorized"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$.page.totalElements", is(0)))
|
||||
.andExpect(jsonPath("$._embedded").doesNotExist())
|
||||
;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void findAuthorizedByCommunityTest() throws Exception {
|
||||
|
||||
//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.
|
||||
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent Community")
|
||||
.build();
|
||||
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community")
|
||||
.build();
|
||||
Community child2 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community Two")
|
||||
.build();
|
||||
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
|
||||
Collection col2 = CollectionBuilder.createCollection(context, child2).withName("Collection 2").build();
|
||||
|
||||
getClient().perform(get("/api/core/collections/search/findAuthorizedByCommunity"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$.page.totalElements", is(0)))
|
||||
.andExpect(jsonPath("$._embedded").doesNotExist());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findOneCollectionTestWrongUUID() throws Exception {
|
||||
|
||||
//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.
|
||||
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent Community")
|
||||
.build();
|
||||
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community")
|
||||
.build();
|
||||
Community child2 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community Two")
|
||||
.build();
|
||||
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
|
||||
Collection col2 = CollectionBuilder.createCollection(context, child2).withName("Collection 2").build();
|
||||
|
||||
|
||||
|
||||
getClient().perform(get("/api/core/collections/" + UUID.randomUUID()))
|
||||
.andExpect(status().isNotFound());
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,341 @@
|
||||
/**
|
||||
* 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 org.dspace.app.rest.builder.CollectionBuilder;
|
||||
import org.dspace.app.rest.builder.CommunityBuilder;
|
||||
import org.dspace.app.rest.matcher.CommunityMatcher;
|
||||
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.content.Community;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
public class CommunityRestRepositoryIT extends AbstractControllerIntegrationTest{
|
||||
|
||||
@Test
|
||||
public void findAllTest() throws Exception{
|
||||
//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.
|
||||
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent Community")
|
||||
.build();
|
||||
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community")
|
||||
.build();
|
||||
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
|
||||
|
||||
getClient().perform(get("/api/core/communities"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$._embedded.communities", Matchers.containsInAnyOrder(
|
||||
CommunityMatcher.matchCommunityEntry(parentCommunity.getName(), parentCommunity.getID(), parentCommunity.getHandle()),
|
||||
CommunityMatcher.matchCommunityEntry(child1.getName(), child1.getID(), child1.getHandle())
|
||||
)))
|
||||
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/communities")))
|
||||
.andExpect(jsonPath("$.page.size", is(20)))
|
||||
.andExpect(jsonPath("$.page.totalElements", is(2)))
|
||||
;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findAllPaginationTest() throws Exception{
|
||||
//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.
|
||||
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent Community")
|
||||
.build();
|
||||
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community")
|
||||
.build();
|
||||
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
|
||||
|
||||
getClient().perform(get("/api/core/communities")
|
||||
.param("size", "1"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$._embedded.communities", Matchers.contains(
|
||||
CommunityMatcher.matchCommunityEntry(parentCommunity.getName(), parentCommunity.getID(), parentCommunity.getHandle())
|
||||
)))
|
||||
.andExpect(jsonPath("$._embedded.communities", Matchers.not(
|
||||
Matchers.contains(
|
||||
CommunityMatcher.matchCommunityEntry(child1.getName(), child1.getID(), child1.getHandle())
|
||||
)
|
||||
)))
|
||||
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/communities")))
|
||||
;
|
||||
|
||||
getClient().perform(get("/api/core/communities")
|
||||
.param("size", "1")
|
||||
.param("page", "1"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$._embedded.communities", Matchers.contains(
|
||||
CommunityMatcher.matchCommunityEntry(child1.getName(), child1.getID(), child1.getHandle())
|
||||
)))
|
||||
.andExpect(jsonPath("$._embedded.communities", Matchers.not(
|
||||
Matchers.contains(
|
||||
CommunityMatcher.matchCommunityEntry(parentCommunity.getName(), parentCommunity.getID(), parentCommunity.getHandle())
|
||||
)
|
||||
)))
|
||||
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/communities")))
|
||||
.andExpect(jsonPath("$.page.size", is(1)))
|
||||
.andExpect(jsonPath("$.page.totalElements", is(2)))
|
||||
;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findOneTest() throws Exception{
|
||||
//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.
|
||||
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent Community")
|
||||
.build();
|
||||
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community")
|
||||
.build();
|
||||
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
|
||||
|
||||
getClient().perform(get("/api/core/communities/" + parentCommunity.getID().toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$", Matchers.is(
|
||||
CommunityMatcher.matchCommunityEntry(parentCommunity.getName(), parentCommunity.getID(), parentCommunity.getHandle())
|
||||
)))
|
||||
.andExpect(jsonPath("$", Matchers.not(
|
||||
Matchers.is(
|
||||
CommunityMatcher.matchCommunityEntry(child1.getName(), child1.getID(), child1.getHandle())
|
||||
)
|
||||
)))
|
||||
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/communities")))
|
||||
;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findOneRelsTest() throws Exception{
|
||||
//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.
|
||||
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent Community")
|
||||
.withLogo("ThisIsSomeDummyText")
|
||||
.build();
|
||||
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community")
|
||||
.build();
|
||||
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
|
||||
|
||||
getClient().perform(get("/api/core/communities/" + parentCommunity.getID().toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$", Matchers.is(
|
||||
CommunityMatcher.matchCommunityEntry(parentCommunity.getName(), parentCommunity.getID(), parentCommunity.getHandle())
|
||||
)))
|
||||
.andExpect(jsonPath("$", Matchers.not(
|
||||
Matchers.is(
|
||||
CommunityMatcher.matchCommunityEntry(child1.getName(), child1.getID(), child1.getHandle())
|
||||
)
|
||||
)))
|
||||
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/communities/" + parentCommunity.getID().toString())))
|
||||
.andExpect(jsonPath("$._links.logo.href", Matchers.containsString("/api/core/communities/" + parentCommunity.getID().toString() + "/logo")))
|
||||
.andExpect(jsonPath("$._links.collections.href", Matchers.containsString("/api/core/communities/" + parentCommunity.getID().toString() + "/collections")))
|
||||
;
|
||||
|
||||
getClient().perform(get("/api/core/communities/" + parentCommunity.getID().toString() + "/logo"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType));
|
||||
|
||||
getClient().perform(get("/api/core/communities/" + child1.getID().toString() + "/logo"))
|
||||
.andExpect(status().isOk());
|
||||
|
||||
getClient().perform(get("/api/core/communities/" + parentCommunity.getID().toString() + "/collections"))
|
||||
.andExpect(status().isOk());
|
||||
|
||||
getClient().perform(get("/api/core/communities/" + child1.getID().toString() + "/collections"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void findAllSearchTop() throws Exception{
|
||||
|
||||
//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.
|
||||
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent Community")
|
||||
.withLogo("ThisIsSomeDummyText")
|
||||
.build();
|
||||
|
||||
Community parentCommunity2 = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent Community 2")
|
||||
.withLogo("SomeTest")
|
||||
.build();
|
||||
|
||||
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community")
|
||||
.build();
|
||||
|
||||
Community child12 = CommunityBuilder.createSubCommunity(context, child1)
|
||||
.withName("Sub Sub Community")
|
||||
.build();
|
||||
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
|
||||
|
||||
|
||||
getClient().perform(get("/api/core/communities/search/top"))
|
||||
.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())
|
||||
)))
|
||||
.andExpect(jsonPath("$._embedded.communities", Matchers.not(Matchers.containsInAnyOrder(
|
||||
CommunityMatcher.matchCommunityEntry(child1.getName(), child1.getID(), child1.getHandle()),
|
||||
CommunityMatcher.matchCommunityEntry(child12.getName(), child12.getID(), child12.getHandle())
|
||||
))))
|
||||
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/communities/search/top")))
|
||||
.andExpect(jsonPath("$.page.size", is(20)))
|
||||
.andExpect(jsonPath("$.page.totalElements", is(2)))
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//TODO The test fails, 404 resource not found. remove @Ignore when this is implemented
|
||||
@Test
|
||||
@Ignore
|
||||
public void findAllSubCommunities() throws Exception{
|
||||
|
||||
//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.
|
||||
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent Community")
|
||||
.withLogo("ThisIsSomeDummyText")
|
||||
.build();
|
||||
|
||||
Community parentCommunity2 = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent Community 2")
|
||||
.withLogo("SomeTest")
|
||||
.build();
|
||||
|
||||
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community")
|
||||
.build();
|
||||
|
||||
Community child12 = CommunityBuilder.createSubCommunity(context, child1)
|
||||
.withName("Sub Sub Community")
|
||||
.build();
|
||||
|
||||
Community child2 = CommunityBuilder.createSubCommunity(context, parentCommunity2)
|
||||
.withName("Sub2 Community")
|
||||
.build();
|
||||
|
||||
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
|
||||
|
||||
getClient().perform(get("/api/core/communities/search/subCommunities/" + parentCommunity.getID()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$._embedded.communities", Matchers.containsInAnyOrder(
|
||||
CommunityMatcher.matchCommunityEntry(child1.getName(), child1.getID(), child1.getHandle()),
|
||||
CommunityMatcher.matchCommunityEntry(child12.getName(), child12.getID(), child12.getHandle())
|
||||
)))
|
||||
.andExpect(jsonPath("$._embedded.communities", Matchers.not(Matchers.containsInAnyOrder(
|
||||
CommunityMatcher.matchCommunityEntry(parentCommunity.getName(), parentCommunity.getID(), parentCommunity.getHandle()),
|
||||
CommunityMatcher.matchCommunityEntry(parentCommunity2.getName(), parentCommunity2.getID(), parentCommunity2.getHandle()),
|
||||
CommunityMatcher.matchCommunityEntry(child2.getName(), child2.getID(), child2.getHandle())
|
||||
))))
|
||||
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/communities/search/subCommunities")))
|
||||
.andExpect(jsonPath("$.page.size", is(20)))
|
||||
.andExpect(jsonPath("$.page.totalElements", is(3)))
|
||||
;
|
||||
}
|
||||
|
||||
//TODO The test fails, 404 resource not found. remove @Ignore when this is implemented
|
||||
@Test
|
||||
@Ignore
|
||||
public void findAllSubCommunitiesWithoutUUID() throws Exception{
|
||||
|
||||
//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.
|
||||
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent Community")
|
||||
.withLogo("ThisIsSomeDummyText")
|
||||
.build();
|
||||
|
||||
Community parentCommunity2 = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent Community 2")
|
||||
.withLogo("SomeTest")
|
||||
.build();
|
||||
|
||||
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community")
|
||||
.build();
|
||||
|
||||
Community child12 = CommunityBuilder.createSubCommunity(context, child1)
|
||||
.withName("Sub Sub Community")
|
||||
.build();
|
||||
|
||||
Community child2 = CommunityBuilder.createSubCommunity(context, parentCommunity2)
|
||||
.withName("Sub2 Community")
|
||||
.build();
|
||||
|
||||
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
|
||||
|
||||
getClient().perform(get("/api/core/communities/search/subCommunities"))
|
||||
.andExpect(status().isUnprocessableEntity())
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void findOneTestWrongUUID() throws Exception{
|
||||
//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.
|
||||
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent Community")
|
||||
.build();
|
||||
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community")
|
||||
.build();
|
||||
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
|
||||
|
||||
getClient().perform(get("/api/core/communities/" + UUID.randomUUID())).andExpect(status().isNotFound());
|
||||
}
|
||||
}
|
@@ -0,0 +1,162 @@
|
||||
/**
|
||||
* 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 org.dspace.app.rest.builder.EPersonBuilder;
|
||||
import org.dspace.app.rest.matcher.EPersonMatcher;
|
||||
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
|
||||
import org.dspace.eperson.EPerson;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
public class EPersonRestRepositoryIT extends AbstractControllerIntegrationTest{
|
||||
|
||||
@Test
|
||||
public void findAllTest() throws Exception{
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
EPerson ePerson = EPersonBuilder.createEPerson(context)
|
||||
.withNameInMetadata("John", "Doe")
|
||||
.withEmail("Johndoe@gmail.com")
|
||||
.build();
|
||||
|
||||
getClient().perform(get("/api/eperson/eperson"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$._embedded.epersons", Matchers.containsInAnyOrder(
|
||||
EPersonMatcher.matchEPersonEntry(ePerson),
|
||||
EPersonMatcher.matchDefaultTestEPerson()
|
||||
)))
|
||||
.andExpect(jsonPath("$.page.size", is(20)))
|
||||
.andExpect(jsonPath("$.page.totalElements", is(2)))
|
||||
;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findAllPaginationTest() throws Exception{
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
EPerson ePerson = EPersonBuilder.createEPerson(context)
|
||||
.withNameInMetadata("John", "Doe")
|
||||
.withEmail("Johndoe@gmail.com")
|
||||
.build();
|
||||
|
||||
getClient().perform(get("/api/eperson/eperson")
|
||||
.param("size", "1"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$._embedded.epersons", Matchers.contains(
|
||||
EPersonMatcher.matchDefaultTestEPerson()
|
||||
)))
|
||||
.andExpect(jsonPath("$._embedded.epersons", Matchers.not(
|
||||
Matchers.contains(
|
||||
EPersonMatcher.matchEPersonEntry(ePerson)
|
||||
)
|
||||
)))
|
||||
.andExpect(jsonPath("$.page.size", is(1)))
|
||||
.andExpect(jsonPath("$.page.totalElements", is(2)))
|
||||
;
|
||||
|
||||
getClient().perform(get("/api/eperson/eperson")
|
||||
.param("size", "1")
|
||||
.param("page", "1"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$._embedded.epersons", Matchers.contains(
|
||||
EPersonMatcher.matchEPersonEntry(ePerson)
|
||||
)))
|
||||
.andExpect(jsonPath("$.page.size", is(1)))
|
||||
.andExpect(jsonPath("$.page.totalElements", is(2)))
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void findOneTest() throws Exception{
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
EPerson ePerson = EPersonBuilder.createEPerson(context)
|
||||
.withNameInMetadata("John", "Doe")
|
||||
.withEmail("Johndoe@gmail.com")
|
||||
.build();
|
||||
|
||||
EPerson ePerson2 = EPersonBuilder.createEPerson(context)
|
||||
.withNameInMetadata("Jane", "Smith")
|
||||
.withEmail("janesmith@gmail.com")
|
||||
.build();
|
||||
|
||||
getClient().perform(get("/api/eperson/epersons/" + ePerson2.getID()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$", is(
|
||||
EPersonMatcher.matchEPersonEntry(ePerson2)
|
||||
)))
|
||||
.andExpect(jsonPath("$", Matchers.not(
|
||||
is(
|
||||
EPersonMatcher.matchEPersonEntry(ePerson)
|
||||
)
|
||||
)));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findOneRelsTest() throws Exception{
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
EPerson ePerson = EPersonBuilder.createEPerson(context)
|
||||
.withNameInMetadata("John", "Doe")
|
||||
.withEmail("Johndoe@gmail.com")
|
||||
.build();
|
||||
|
||||
EPerson ePerson2 = EPersonBuilder.createEPerson(context)
|
||||
.withNameInMetadata("Jane", "Smith")
|
||||
.withEmail("janesmith@gmail.com")
|
||||
.build();
|
||||
|
||||
getClient().perform(get("/api/eperson/epersons/" + ePerson2.getID()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$", is(
|
||||
EPersonMatcher.matchEPersonEntry(ePerson2)
|
||||
)))
|
||||
.andExpect(jsonPath("$", Matchers.not(
|
||||
is(
|
||||
EPersonMatcher.matchEPersonEntry(ePerson)
|
||||
)
|
||||
)))
|
||||
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/eperson/epersons/" + ePerson2.getID())));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void findOneTestWrongUUID() throws Exception{
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
EPerson ePerson = EPersonBuilder.createEPerson(context)
|
||||
.withNameInMetadata("John", "Doe")
|
||||
.withEmail("Johndoe@gmail.com")
|
||||
.build();
|
||||
|
||||
EPerson ePerson2 = EPersonBuilder.createEPerson(context)
|
||||
.withNameInMetadata("Jane", "Smith")
|
||||
.withEmail("janesmith@gmail.com")
|
||||
.build();
|
||||
|
||||
getClient().perform(get("/api/eperson/epersons/" + UUID.randomUUID()))
|
||||
.andExpect(status().isNotFound());
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,132 @@
|
||||
/**
|
||||
* 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 org.dspace.app.rest.builder.GroupBuilder;
|
||||
import org.dspace.app.rest.matcher.GroupMatcher;
|
||||
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
|
||||
import org.dspace.eperson.Group;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
/**
|
||||
* @author Jonas Van Goolen - (jonas@atmire.com)
|
||||
*/
|
||||
|
||||
public class GroupRestRepositoryIT extends AbstractControllerIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void findAllTest() throws Exception {
|
||||
//When we call the root endpoint
|
||||
getClient().perform(get("/api/eperson/groups"))
|
||||
//The status has to be 200 OK
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
//The array of groups should have a size 2
|
||||
.andExpect(jsonPath("$._embedded.groups", hasSize(2)))
|
||||
// The default groups should consist of "Anonymous" and "Anonymous"
|
||||
.andExpect(jsonPath("$._embedded.groups", Matchers.containsInAnyOrder(
|
||||
GroupMatcher.matchGroupWithName("Administrator"),
|
||||
GroupMatcher.matchGroupWithName("Anonymous")
|
||||
)))
|
||||
;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findAllPaginationTest() throws Exception{
|
||||
context.turnOffAuthorisationSystem();
|
||||
getClient().perform(get("/api/eperson/groups"))
|
||||
//The status has to be 200 OK
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$.page.size", is(20)))
|
||||
.andExpect(jsonPath("$.page.totalElements", is(2)))
|
||||
.andExpect(jsonPath("$.page.totalPages", is(1)))
|
||||
.andExpect(jsonPath("$.page.number", is(0)));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void findOneTest() throws Exception {
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
String testGroupName = "Test group";
|
||||
Group group = GroupBuilder.createGroup(context)
|
||||
.withName(testGroupName)
|
||||
.build();
|
||||
|
||||
String generatedGroupId = group.getID().toString();
|
||||
String groupIdCall = "/api/eperson/groups/" + generatedGroupId;
|
||||
getClient().perform(get(groupIdCall))
|
||||
//The status has to be 200 OK
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$",Matchers.is(
|
||||
GroupMatcher.matchGroupEntry(group.getID(), group.getName())
|
||||
)))
|
||||
;
|
||||
getClient().perform(get("/api/eperson/groups"))
|
||||
//The status has to be 200 OK
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
|
||||
.andExpect(jsonPath("$.page.totalElements", is(3)));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findOneRelsTest() throws Exception{
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
Group group = GroupBuilder.createGroup(context)
|
||||
.withName("Group1")
|
||||
.build();
|
||||
|
||||
Group group2 = GroupBuilder.createGroup(context)
|
||||
.withName("Group2")
|
||||
.build();
|
||||
|
||||
getClient().perform(get("/api/eperson/groups/" + group2.getID()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$", Matchers.is(
|
||||
GroupMatcher.matchGroupEntry(group2.getID(), group2.getName())
|
||||
)))
|
||||
.andExpect(jsonPath("$", Matchers.not(
|
||||
Matchers.is(
|
||||
GroupMatcher.matchGroupEntry(group.getID(), group.getName())
|
||||
)
|
||||
)))
|
||||
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/eperson/groups/" + group2.getID())));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findOneTestWrongUUID() throws Exception {
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
String testGroupName = "Test group";
|
||||
Group group = GroupBuilder.createGroup(context)
|
||||
.withName(testGroupName)
|
||||
.build();
|
||||
|
||||
String generatedGroupId = group.getID().toString();
|
||||
String groupIdCall = "/api/eperson/groups/" + UUID.randomUUID();
|
||||
getClient().perform(get(groupIdCall))
|
||||
//The status has to be 200 OK
|
||||
.andExpect(status().isNotFound())
|
||||
;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,310 @@
|
||||
/**
|
||||
* 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 org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.CharEncoding;
|
||||
import org.dspace.app.rest.builder.BitstreamBuilder;
|
||||
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.ItemMatcher;
|
||||
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
|
||||
import org.dspace.content.Bitstream;
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.content.Community;
|
||||
import org.dspace.content.Item;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class ItemRestRepositoryIT extends AbstractControllerIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void findAllTest() throws Exception{
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
//** GIVEN **
|
||||
//1. A community-collection structure with one parent community with sub-community and two collections.
|
||||
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent Community")
|
||||
.build();
|
||||
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community")
|
||||
.build();
|
||||
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
|
||||
Collection col2 = CollectionBuilder.createCollection(context, child1).withName("Collection 2").build();
|
||||
|
||||
//2. Three public items that are readable by Anonymous with different subjects
|
||||
Item publicItem1 = ItemBuilder.createItem(context, col1)
|
||||
.withTitle("Public item 1")
|
||||
.withIssueDate("2017-10-17")
|
||||
.withAuthor("Smith, Donald").withAuthor("Doe, John")
|
||||
.withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
Item publicItem2 = ItemBuilder.createItem(context, col2)
|
||||
.withTitle("Public item 2")
|
||||
.withIssueDate("2016-02-13")
|
||||
.withAuthor("Smith, Maria").withAuthor("Doe, Jane")
|
||||
.withSubject("TestingForMore").withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
Item publicItem3 = ItemBuilder.createItem(context, col2)
|
||||
.withTitle("Public item 3")
|
||||
.withIssueDate("2016-02-13")
|
||||
.withAuthor("Smith, Maria").withAuthor("Doe, Jane")
|
||||
.withSubject("AnotherTest").withSubject("TestingForMore").withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
|
||||
getClient().perform(get("/api/core/items"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$._embedded.items", Matchers.containsInAnyOrder(
|
||||
ItemMatcher.matchItemWithTitleAndDateIssued(publicItem1, "Public item 1", "2017-10-17"),
|
||||
ItemMatcher.matchItemWithTitleAndDateIssued(publicItem2, "Public item 2", "2016-02-13"),
|
||||
ItemMatcher.matchItemWithTitleAndDateIssued(publicItem3, "Public item 3", "2016-02-13")
|
||||
)))
|
||||
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/items")))
|
||||
.andExpect(jsonPath("$.page.size", is(20)))
|
||||
.andExpect(jsonPath("$.page.totalElements", is(3)))
|
||||
;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findAllWithPaginationTest() throws Exception{
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
//** GIVEN **
|
||||
//1. A community-collection structure with one parent community with sub-community and two collections.
|
||||
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent Community")
|
||||
.build();
|
||||
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community")
|
||||
.build();
|
||||
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
|
||||
Collection col2 = CollectionBuilder.createCollection(context, child1).withName("Collection 2").build();
|
||||
|
||||
//2. Three public items that are readable by Anonymous with different subjects
|
||||
Item publicItem1 = ItemBuilder.createItem(context, col1)
|
||||
.withTitle("Public item 1")
|
||||
.withIssueDate("2017-10-17")
|
||||
.withAuthor("Smith, Donald").withAuthor("Doe, John")
|
||||
.withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
Item publicItem2 = ItemBuilder.createItem(context, col2)
|
||||
.withTitle("Public item 2")
|
||||
.withIssueDate("2016-02-13")
|
||||
.withAuthor("Smith, Maria").withAuthor("Doe, Jane")
|
||||
.withSubject("TestingForMore").withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
Item publicItem3 = ItemBuilder.createItem(context, col2)
|
||||
.withTitle("Public item 3")
|
||||
.withIssueDate("2016-02-13")
|
||||
.withAuthor("Smith, Maria").withAuthor("Doe, Jane")
|
||||
.withSubject("AnotherTest").withSubject("TestingForMore").withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
getClient().perform(get("/api/core/items")
|
||||
.param("size", "2"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$._embedded.items", Matchers.containsInAnyOrder(
|
||||
ItemMatcher.matchItemWithTitleAndDateIssued(publicItem1, "Public item 1", "2017-10-17"),
|
||||
ItemMatcher.matchItemWithTitleAndDateIssued(publicItem2, "Public item 2", "2016-02-13")
|
||||
)))
|
||||
.andExpect(jsonPath("$._embedded.items", Matchers.not(
|
||||
Matchers.contains(
|
||||
ItemMatcher.matchItemWithTitleAndDateIssued(publicItem3, "Public item 3", "2016-02-13")
|
||||
)
|
||||
)))
|
||||
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/items")))
|
||||
;
|
||||
|
||||
getClient().perform(get("/api/core/items")
|
||||
.param("size", "2")
|
||||
.param("page", "1"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$._embedded.items", Matchers.contains(
|
||||
ItemMatcher.matchItemWithTitleAndDateIssued(publicItem3, "Public item 3", "2016-02-13")
|
||||
)))
|
||||
.andExpect(jsonPath("$._embedded.items", Matchers.not(
|
||||
Matchers.contains(
|
||||
ItemMatcher.matchItemWithTitleAndDateIssued(publicItem1, "Public item 1", "2017-10-17"),
|
||||
ItemMatcher.matchItemWithTitleAndDateIssued(publicItem2, "Public item 2", "2016-02-13")
|
||||
)
|
||||
)))
|
||||
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/items")))
|
||||
.andExpect(jsonPath("$.page.size", is(2)))
|
||||
.andExpect(jsonPath("$.page.totalElements", is(3)))
|
||||
;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findOneTest() throws Exception{
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
//** GIVEN **
|
||||
//1. A community-collection structure with one parent community with sub-community and two collections.
|
||||
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent Community")
|
||||
.build();
|
||||
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community")
|
||||
.build();
|
||||
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
|
||||
Collection col2 = CollectionBuilder.createCollection(context, child1).withName("Collection 2").build();
|
||||
|
||||
//2. Three public items that are readable by Anonymous with different subjects
|
||||
Item publicItem1 = ItemBuilder.createItem(context, col1)
|
||||
.withTitle("Public item 1")
|
||||
.withIssueDate("2017-10-17")
|
||||
.withAuthor("Smith, Donald").withAuthor("Doe, John")
|
||||
.withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
Item publicItem2 = ItemBuilder.createItem(context, col2)
|
||||
.withTitle("Public item 2")
|
||||
.withIssueDate("2016-02-13")
|
||||
.withAuthor("Smith, Maria").withAuthor("Doe, Jane")
|
||||
.withSubject("TestingForMore").withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
Item publicItem3 = ItemBuilder.createItem(context, col2)
|
||||
.withTitle("Public item 3")
|
||||
.withIssueDate("2016-02-13")
|
||||
.withAuthor("Smith, Maria").withAuthor("Doe, Jane")
|
||||
.withSubject("AnotherTest").withSubject("TestingForMore").withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
|
||||
getClient().perform(get("/api/core/items/" + publicItem1.getID()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$", Matchers.is(
|
||||
ItemMatcher.matchItemWithTitleAndDateIssued(publicItem1, "Public item 1", "2017-10-17")
|
||||
)))
|
||||
.andExpect(jsonPath("$", Matchers.not(
|
||||
Matchers.is(
|
||||
ItemMatcher.matchItemWithTitleAndDateIssued(publicItem2, "Public item 2", "2016-02-13")
|
||||
)
|
||||
)))
|
||||
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/items")))
|
||||
;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findOneRelsTest() throws Exception{
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
//** GIVEN **
|
||||
//1. A community-collection structure with one parent community with sub-community and two collections.
|
||||
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent Community")
|
||||
.build();
|
||||
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community")
|
||||
.build();
|
||||
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
|
||||
Collection col2 = CollectionBuilder.createCollection(context, child1).withName("Collection 2").build();
|
||||
|
||||
//2. Three public items that are readable by Anonymous with different subjects
|
||||
Item publicItem1 = ItemBuilder.createItem(context, col1)
|
||||
.withTitle("Public item 1")
|
||||
.withIssueDate("2017-10-17")
|
||||
.withAuthor("Smith, Donald").withAuthor("Doe, John")
|
||||
.withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
Item publicItem2 = ItemBuilder.createItem(context, col2)
|
||||
.withTitle("Public item 2")
|
||||
.withIssueDate("2016-02-13")
|
||||
.withAuthor("Smith, Maria").withAuthor("Doe, Jane")
|
||||
.withSubject("TestingForMore").withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
Item publicItem3 = ItemBuilder.createItem(context, col2)
|
||||
.withTitle("Public item 3")
|
||||
.withIssueDate("2016-02-13")
|
||||
.withAuthor("Smith, Maria").withAuthor("Doe, Jane")
|
||||
.withSubject("AnotherTest").withSubject("TestingForMore").withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
//Add a bitstream to an item
|
||||
String bitstreamContent = "ThisIsSomeDummyText";
|
||||
Bitstream bitstream1 = null;
|
||||
try(InputStream is = IOUtils.toInputStream(bitstreamContent, CharEncoding.UTF_8)) {
|
||||
bitstream1 = BitstreamBuilder.
|
||||
createBitstream(context, publicItem1, is)
|
||||
.withName("Bitstream1")
|
||||
.withMimeType("text/plain")
|
||||
.build();
|
||||
}
|
||||
|
||||
getClient().perform(get("/api/core/items/" + publicItem1.getID()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$", Matchers.is(
|
||||
ItemMatcher.matchItemWithTitleAndDateIssued(publicItem1, "Public item 1", "2017-10-17")
|
||||
)))
|
||||
.andExpect(jsonPath("$", Matchers.not(
|
||||
Matchers.is(
|
||||
ItemMatcher.matchItemWithTitleAndDateIssued(publicItem2, "Public item 2", "2016-02-13")
|
||||
)
|
||||
)))
|
||||
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/items")))
|
||||
;
|
||||
|
||||
getClient().perform(get("/api/core/items/" + publicItem1.getID() + "/bitstreams"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/items/" + publicItem1.getID() + "/bitstreams")))
|
||||
;
|
||||
|
||||
getClient().perform(get("/api/core/items/" + publicItem1.getID() + "/owningCollection"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/collections")))
|
||||
;
|
||||
|
||||
getClient().perform(get("/api/core/items/" + publicItem1.getID() + "/templateItemOf"))
|
||||
.andExpect(status().isOk())
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void findOneTestWrongUUID() throws Exception{
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
//** GIVEN **
|
||||
//1. A community-collection structure with one parent community with sub-community and two collections.
|
||||
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent Community")
|
||||
.build();
|
||||
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community")
|
||||
.build();
|
||||
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
|
||||
Collection col2 = CollectionBuilder.createCollection(context, child1).withName("Collection 2").build();
|
||||
|
||||
getClient().perform(get("/api/core/items/" + UUID.randomUUID()))
|
||||
.andExpect(status().isNotFound());
|
||||
;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* 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 org.dspace.app.rest.repository.MetadataFieldRestRepository;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.dspace.app.rest.builder.MetadataFieldBuilder;
|
||||
import org.dspace.app.rest.matcher.MetadataFieldMatcher;
|
||||
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
|
||||
import org.dspace.content.MetadataField;
|
||||
import org.dspace.content.service.MetadataFieldService;
|
||||
import org.dspace.core.Context;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class MetadatafieldRestRepositoryIT extends AbstractControllerIntegrationTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void findAll() throws Exception{
|
||||
|
||||
context.turnOffAuthorisationSystem();
|
||||
MetadataField metadataField = MetadataFieldBuilder.createMetadataField(context, "AnElement", "AQualifier", "AScopeNote").build();
|
||||
|
||||
getClient().perform(get("/api/core/metadatafields"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$._embedded.metadatafields", Matchers.hasItem(
|
||||
MetadataFieldMatcher.matchMetadataField()
|
||||
)))
|
||||
.andExpect(jsonPath("$._links.first.href", Matchers.containsString("/api/core/metadatafields")))
|
||||
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/metadatafields")))
|
||||
.andExpect(jsonPath("$._links.next.href", Matchers.containsString("/api/core/metadatafields")))
|
||||
.andExpect(jsonPath("$._links.last.href", Matchers.containsString("/api/core/metadatafields")))
|
||||
|
||||
.andExpect(jsonPath("$.page.size", is(20)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void findOne() throws Exception{
|
||||
|
||||
context.turnOffAuthorisationSystem();
|
||||
MetadataField metadataField = MetadataFieldBuilder.createMetadataField(context, "AnElement", "AQualifier", "AScopeNote").build();
|
||||
|
||||
getClient().perform(get("/api/core/metadatafields/" + metadataField.getID()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$._embedded.metadatafields", Matchers.hasItem(
|
||||
MetadataFieldMatcher.matchMetadataField(metadataField)
|
||||
)))
|
||||
|
||||
.andExpect(jsonPath("$.page.size", is(20)));
|
||||
}
|
||||
}
|
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* 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 org.dspace.app.rest.builder.MetadataSchemaBuilder;
|
||||
import org.dspace.app.rest.matcher.MetadataschemaMatcher;
|
||||
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
|
||||
import org.dspace.content.MetadataSchema;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class MetadataschemaRestRepositoryIT extends AbstractControllerIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void findAll() throws Exception{
|
||||
|
||||
context.turnOffAuthorisationSystem();
|
||||
MetadataSchema metadataSchema = MetadataSchemaBuilder.createMetadataSchema(context, "ATest", "ANamespace").build();
|
||||
|
||||
getClient().perform(get("/api/core/metadataschemas"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$._embedded.metadataschemas", Matchers.hasItem(
|
||||
MetadataschemaMatcher.matchEntry()
|
||||
)))
|
||||
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/metadataschemas")))
|
||||
.andExpect(jsonPath("$.page.size", is(20)));
|
||||
}
|
||||
|
||||
|
||||
//TODO This test fails, reactivate when endpoint is fixed
|
||||
@Test
|
||||
@Ignore
|
||||
public void findOne() throws Exception{
|
||||
|
||||
context.turnOffAuthorisationSystem();
|
||||
MetadataSchema metadataSchema = MetadataSchemaBuilder.createMetadataSchema(context, "ATest", "ANamespace").build();
|
||||
|
||||
getClient().perform(get("/api/core/metadataschemas/" + metadataSchema.getID()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$", is(
|
||||
MetadataschemaMatcher.matchEntry(metadataSchema)
|
||||
)));
|
||||
}
|
||||
}
|
@@ -17,8 +17,8 @@ import org.junit.Test;
|
||||
/**
|
||||
* Integration test for the {@link RootRestResourceController}
|
||||
*
|
||||
* @author Frederic Van Reet (frederic dot vanreet at atmire dot com)
|
||||
* @author Tom Desair (tom dot desair at atmire dot com)
|
||||
* @author Raf Ponsaerts (raf dot ponsaerts at atmire dot com)
|
||||
*/
|
||||
public class RootRestResourceControllerIT extends AbstractControllerIntegrationTest {
|
||||
|
||||
|
@@ -0,0 +1,72 @@
|
||||
/**
|
||||
* 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 org.dspace.app.rest.builder.SiteBuilder;
|
||||
import org.dspace.app.rest.matcher.SiteMatcher;
|
||||
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
|
||||
import org.dspace.content.Site;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
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;
|
||||
|
||||
public class SiteRestRepositoryIT extends AbstractControllerIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void findAll() throws Exception{
|
||||
|
||||
|
||||
context.turnOffAuthorisationSystem();
|
||||
//This will always return just one site, DSpace doesn't allow for more to be created
|
||||
Site site = SiteBuilder.createSite(context).build();
|
||||
|
||||
|
||||
|
||||
getClient().perform(get("/api/core/sites"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$._embedded.sites[0]", SiteMatcher.matchEntry(site)))
|
||||
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/sites")))
|
||||
.andExpect(jsonPath("$.page.size", is(20)));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findOne() throws Exception{
|
||||
|
||||
|
||||
context.turnOffAuthorisationSystem();
|
||||
//This will always return just one site, DSpace doesn't allow for more to be created
|
||||
Site site = SiteBuilder.createSite(context).build();
|
||||
|
||||
|
||||
|
||||
getClient().perform(get("/api/core/sites/" + site.getID()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$", SiteMatcher.matchEntry(site)))
|
||||
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/sites")));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void findOneWrongUUID() throws Exception{
|
||||
|
||||
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
getClient().perform(get("/api/core/sites/" + UUID.randomUUID()))
|
||||
.andExpect(status().isNotFound());
|
||||
|
||||
}
|
||||
}
|
@@ -8,39 +8,38 @@
|
||||
package org.dspace.app.rest.builder;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.authorize.ResourcePolicy;
|
||||
import org.dspace.authorize.factory.AuthorizeServiceFactory;
|
||||
import org.dspace.authorize.service.AuthorizeService;
|
||||
import org.dspace.authorize.service.ResourcePolicyService;
|
||||
import org.dspace.content.DSpaceObject;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.content.factory.ContentServiceFactory;
|
||||
import org.dspace.content.service.*;
|
||||
import org.dspace.core.Constants;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.discovery.IndexingService;
|
||||
import org.dspace.eperson.Group;
|
||||
import org.dspace.eperson.factory.EPersonServiceFactory;
|
||||
import org.dspace.eperson.service.EPersonService;
|
||||
import org.dspace.eperson.service.GroupService;
|
||||
import org.dspace.eperson.service.RegistrationDataService;
|
||||
import org.dspace.services.factory.DSpaceServicesFactory;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.joda.time.MutablePeriod;
|
||||
import org.joda.time.format.PeriodFormat;
|
||||
import org.dspace.versioning.factory.VersionServiceFactory;
|
||||
import org.dspace.versioning.service.VersionHistoryService;
|
||||
import org.dspace.xmlworkflow.storedcomponents.service.ClaimedTaskService;
|
||||
import org.dspace.xmlworkflow.storedcomponents.service.InProgressUserService;
|
||||
import org.dspace.xmlworkflow.storedcomponents.service.PoolTaskService;
|
||||
import org.dspace.xmlworkflow.storedcomponents.service.WorkflowItemRoleService;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Abstract builder to construct DSpace Objects
|
||||
* Abstract builder class that holds references to all available services
|
||||
*
|
||||
* @author Tom Desair (tom dot desair at atmire dot com)
|
||||
* @author Raf Ponsaerts (raf dot ponsaerts at atmire dot com)
|
||||
* @author Jonas Van Goolen - (jonas@atmire.com)
|
||||
*/
|
||||
public abstract class AbstractBuilder<T extends DSpaceObject> {
|
||||
public abstract class AbstractBuilder<T, S> {
|
||||
|
||||
static CommunityService communityService;
|
||||
static CollectionService collectionService;
|
||||
@@ -55,11 +54,26 @@ public abstract class AbstractBuilder<T extends DSpaceObject> {
|
||||
static AuthorizeService authorizeService;
|
||||
static ResourcePolicyService resourcePolicyService;
|
||||
static IndexingService indexingService;
|
||||
static RegistrationDataService registrationDataService;
|
||||
static VersionHistoryService versionHistoryService;
|
||||
static ClaimedTaskService claimedTaskService;
|
||||
static InProgressUserService inProgressUserService;
|
||||
static PoolTaskService poolTaskService;
|
||||
static WorkflowItemRoleService workflowItemRoleService;
|
||||
static MetadataFieldService metadataFieldService;
|
||||
static MetadataSchemaService metadataSchemaService;
|
||||
static SiteService siteService;
|
||||
|
||||
protected Context context;
|
||||
|
||||
private static List<AbstractBuilder> builders = new LinkedList<>();
|
||||
/** log4j category */
|
||||
private static final Logger log = Logger.getLogger(AbstractBuilder.class);
|
||||
private static final Logger log = Logger.getLogger(AbstractDSpaceObjectBuilder.class);
|
||||
|
||||
protected AbstractBuilder(Context context){
|
||||
this.context = context;
|
||||
builders.add(this);
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
communityService = ContentServiceFactory.getInstance().getCommunityService();
|
||||
@@ -75,8 +89,21 @@ public abstract class AbstractBuilder<T extends DSpaceObject> {
|
||||
authorizeService = AuthorizeServiceFactory.getInstance().getAuthorizeService();
|
||||
resourcePolicyService = AuthorizeServiceFactory.getInstance().getResourcePolicyService();
|
||||
indexingService = DSpaceServicesFactory.getInstance().getServiceManager().getServiceByName(IndexingService.class.getName(),IndexingService.class);
|
||||
registrationDataService = EPersonServiceFactory.getInstance().getRegistrationDataService();
|
||||
versionHistoryService = VersionServiceFactory.getInstance().getVersionHistoryService();
|
||||
metadataFieldService = ContentServiceFactory.getInstance().getMetadataFieldService();
|
||||
metadataSchemaService = ContentServiceFactory.getInstance().getMetadataSchemaService();
|
||||
siteService = ContentServiceFactory.getInstance().getSiteService();
|
||||
|
||||
// Temporarily disabled
|
||||
// TODO find a way to be able to test the XML and "default" workflow at the same time
|
||||
//claimedTaskService = XmlWorkflowServiceFactoryImpl.getInstance().getClaimedTaskService();
|
||||
//inProgressUserService = XmlWorkflowServiceFactoryImpl.getInstance().getInProgressUserService();
|
||||
//poolTaskService = XmlWorkflowServiceFactoryImpl.getInstance().getPoolTaskService();
|
||||
//workflowItemRoleService = XmlWorkflowServiceFactoryImpl.getInstance().getWorkflowItemRoleService();
|
||||
}
|
||||
|
||||
|
||||
public static void destroy() {
|
||||
communityService = null;
|
||||
collectionService = null;
|
||||
@@ -90,70 +117,29 @@ public abstract class AbstractBuilder<T extends DSpaceObject> {
|
||||
authorizeService = null;
|
||||
resourcePolicyService = null;
|
||||
indexingService = null;
|
||||
bitstreamFormatService = null;
|
||||
registrationDataService = null;
|
||||
versionHistoryService = null;
|
||||
claimedTaskService = null;
|
||||
inProgressUserService = null;
|
||||
poolTaskService = null;
|
||||
workflowItemRoleService = null;
|
||||
metadataFieldService = null;
|
||||
metadataSchemaService = null;
|
||||
siteService = null;
|
||||
}
|
||||
|
||||
protected <B> B handleException(final Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
|
||||
protected abstract DSpaceObjectService<T> getDsoService();
|
||||
|
||||
protected <B extends AbstractBuilder<T>> B addMetadataValue(final T dso, final String schema, final String element, final String qualifier, final String value) {
|
||||
try {
|
||||
getDsoService().addMetadata(context, dso, schema, element, qualifier, Item.ANY, value);
|
||||
} catch (Exception e) {
|
||||
return handleException(e);
|
||||
}
|
||||
return (B) this;
|
||||
}
|
||||
|
||||
protected <B extends AbstractBuilder<T>> B setMetadataSingleValue(final T dso, final String schema, final String element, final String qualifier, final String value) {
|
||||
try {
|
||||
getDsoService().setMetadataSingleValue(context, dso, schema, element, qualifier, Item.ANY, value);
|
||||
} catch (Exception e) {
|
||||
return handleException(e);
|
||||
}
|
||||
|
||||
return (B) this;
|
||||
}
|
||||
|
||||
protected <B extends AbstractBuilder<T>> B setEmbargo(String embargoPeriod, DSpaceObject dso) {
|
||||
// add policy just for anonymous
|
||||
try {
|
||||
MutablePeriod period = PeriodFormat.getDefault().parseMutablePeriod(embargoPeriod);
|
||||
Date embargoDate = DateTime.now(DateTimeZone.UTC).plus(period).toDate();
|
||||
|
||||
return setOnlyReadPermission(dso, groupService.findByName(context, Group.ANONYMOUS), embargoDate);
|
||||
} catch (Exception e) {
|
||||
return handleException(e);
|
||||
public static void cleanupObjects() throws Exception {
|
||||
for (AbstractBuilder builder : builders) {
|
||||
builder.cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
protected <B extends AbstractBuilder<T>> B setOnlyReadPermission(DSpaceObject dso, Group group, Date startDate) {
|
||||
// add policy just for anonymous
|
||||
try {
|
||||
authorizeService.removeAllPolicies(context, dso);
|
||||
|
||||
ResourcePolicy rp = authorizeService.createOrModifyPolicy(null, context, null, group,
|
||||
null, startDate, Constants.READ, "Integration Test", dso);
|
||||
if (rp != null) {
|
||||
resourcePolicyService.update(context, rp);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return handleException(e);
|
||||
}
|
||||
return (B) this;
|
||||
}
|
||||
protected abstract void cleanup() throws Exception;
|
||||
|
||||
public abstract T build();
|
||||
|
||||
public void delete(T dso) throws SQLException, IOException, AuthorizeException {
|
||||
Context c = new Context();
|
||||
c.turnOffAuthorisationSystem();
|
||||
T attachedDso = c.reloadEntity(dso);
|
||||
if(attachedDso != null) {
|
||||
getDsoService().delete(c, attachedDso);
|
||||
}
|
||||
}
|
||||
public abstract void delete(T dso) throws Exception;
|
||||
|
||||
protected abstract S getService();
|
||||
}
|
||||
|
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* 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.builder;
|
||||
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.core.ReloadableEntity;
|
||||
import org.dspace.service.DSpaceCRUDService;
|
||||
|
||||
/**
|
||||
* @author Jonas Van Goolen - (jonas@atmire.com)
|
||||
*/
|
||||
public abstract class AbstractCRUDBuilder<T extends ReloadableEntity> extends AbstractBuilder<T, DSpaceCRUDService> {
|
||||
|
||||
protected AbstractCRUDBuilder(Context context){
|
||||
super(context);
|
||||
}
|
||||
|
||||
protected abstract DSpaceCRUDService getService();
|
||||
|
||||
public abstract T build();
|
||||
|
||||
public void delete(T dso) throws Exception {
|
||||
try(Context c = new Context()) {
|
||||
c.turnOffAuthorisationSystem();
|
||||
T attachedDso = c.reloadEntity(dso);
|
||||
if (attachedDso != null) {
|
||||
getService().delete(c, attachedDso);
|
||||
}
|
||||
c.complete();
|
||||
}
|
||||
|
||||
indexingService.commit();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,115 @@
|
||||
/**
|
||||
* 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.builder;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.authorize.ResourcePolicy;
|
||||
import org.dspace.content.DSpaceObject;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.content.service.DSpaceObjectService;
|
||||
import org.dspace.core.Constants;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.eperson.Group;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.joda.time.MutablePeriod;
|
||||
import org.joda.time.format.PeriodFormat;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Abstract builder to construct DSpace Objects
|
||||
*
|
||||
* @author Tom Desair (tom dot desair at atmire dot com)
|
||||
* @author Raf Ponsaerts (raf dot ponsaerts at atmire dot com)
|
||||
*/
|
||||
public abstract class AbstractDSpaceObjectBuilder<T extends DSpaceObject> extends AbstractBuilder<T, DSpaceObjectService> {
|
||||
|
||||
/* Log4j logger*/
|
||||
private static final Logger log = Logger.getLogger(AbstractDSpaceObjectBuilder.class);
|
||||
|
||||
protected AbstractDSpaceObjectBuilder(Context context){
|
||||
super(context);
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
protected abstract void cleanup() throws Exception;
|
||||
|
||||
|
||||
protected abstract DSpaceObjectService<T> getService();
|
||||
|
||||
|
||||
protected <B> B handleException(final Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
protected <B extends AbstractDSpaceObjectBuilder<T>> B addMetadataValue(final T dso, final String schema, final String element, final String qualifier, final String value) {
|
||||
try {
|
||||
getService().addMetadata(context, dso, schema, element, qualifier, Item.ANY, value);
|
||||
} catch (Exception e) {
|
||||
return handleException(e);
|
||||
}
|
||||
return (B) this;
|
||||
}
|
||||
|
||||
protected <B extends AbstractDSpaceObjectBuilder<T>> B setMetadataSingleValue(final T dso, final String schema, final String element, final String qualifier, final String value) {
|
||||
try {
|
||||
getService().setMetadataSingleValue(context, dso, schema, element, qualifier, Item.ANY, value);
|
||||
} catch (Exception e) {
|
||||
return handleException(e);
|
||||
}
|
||||
|
||||
return (B) this;
|
||||
}
|
||||
|
||||
protected <B extends AbstractDSpaceObjectBuilder<T>> B setEmbargo(String embargoPeriod, DSpaceObject dso) {
|
||||
// add policy just for anonymous
|
||||
try {
|
||||
MutablePeriod period = PeriodFormat.getDefault().parseMutablePeriod(embargoPeriod);
|
||||
Date embargoDate = DateTime.now(DateTimeZone.UTC).plus(period).toDate();
|
||||
|
||||
return setOnlyReadPermission(dso, groupService.findByName(context, Group.ANONYMOUS), embargoDate);
|
||||
} catch (Exception e) {
|
||||
return handleException(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected <B extends AbstractDSpaceObjectBuilder<T>> B setOnlyReadPermission(DSpaceObject dso, Group group, Date startDate) {
|
||||
// add policy just for anonymous
|
||||
try {
|
||||
authorizeService.removeAllPolicies(context, dso);
|
||||
|
||||
ResourcePolicy rp = authorizeService.createOrModifyPolicy(null, context, null, group,
|
||||
null, startDate, Constants.READ, "Integration Test", dso);
|
||||
if (rp != null) {
|
||||
resourcePolicyService.update(context, rp);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return handleException(e);
|
||||
}
|
||||
return (B) this;
|
||||
}
|
||||
|
||||
public abstract T build();
|
||||
|
||||
public void delete(T dso) throws Exception {
|
||||
|
||||
try(Context c = new Context()) {
|
||||
c.turnOffAuthorisationSystem();
|
||||
T attachedDso = c.reloadEntity(dso);
|
||||
if (attachedDso != null) {
|
||||
getService().delete(c, attachedDso);
|
||||
}
|
||||
c.complete();
|
||||
}
|
||||
|
||||
indexingService.commit();
|
||||
}
|
||||
}
|
@@ -7,11 +7,6 @@
|
||||
*/
|
||||
package org.dspace.app.rest.builder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.Bitstream;
|
||||
import org.dspace.content.BitstreamFormat;
|
||||
@@ -21,13 +16,15 @@ import org.dspace.content.service.DSpaceObjectService;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.eperson.Group;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Builder class to build bitstreams in test cases
|
||||
*
|
||||
* @author Tom Desair (tom dot desair at atmire dot com)
|
||||
* @author Raf Ponsaerts (raf dot ponsaerts at atmire dot com)
|
||||
*/
|
||||
public class BitstreamBuilder extends AbstractBuilder<Bitstream>{
|
||||
public class BitstreamBuilder extends AbstractDSpaceObjectBuilder<Bitstream> {
|
||||
|
||||
public static final String ORIGINAL = "ORIGINAL";
|
||||
|
||||
@@ -35,12 +32,13 @@ public class BitstreamBuilder extends AbstractBuilder<Bitstream>{
|
||||
private Item item;
|
||||
private Group readerGroup;
|
||||
|
||||
protected BitstreamBuilder() {
|
||||
protected BitstreamBuilder(Context context) {
|
||||
super(context);
|
||||
|
||||
}
|
||||
|
||||
public static BitstreamBuilder createBitstream(Context context, Item item, InputStream is) throws SQLException, AuthorizeException, IOException {
|
||||
BitstreamBuilder builder = new BitstreamBuilder();
|
||||
BitstreamBuilder builder = new BitstreamBuilder(context);
|
||||
return builder.create(context, item, is);
|
||||
}
|
||||
|
||||
@@ -66,8 +64,7 @@ public class BitstreamBuilder extends AbstractBuilder<Bitstream>{
|
||||
}
|
||||
|
||||
public BitstreamBuilder withMimeType(String mimeType) throws SQLException {
|
||||
BitstreamFormat bf = bitstreamFormatService
|
||||
.findByMIMEType(context, mimeType);
|
||||
BitstreamFormat bf = bitstreamFormatService.findByMIMEType(context, mimeType);
|
||||
|
||||
if (bf != null) {
|
||||
bitstream.setFormat(context, bf);
|
||||
@@ -124,7 +121,20 @@ public class BitstreamBuilder extends AbstractBuilder<Bitstream>{
|
||||
return bitstream;
|
||||
}
|
||||
|
||||
protected DSpaceObjectService<Bitstream> getDsoService() {
|
||||
protected void cleanup() throws Exception {
|
||||
delete(bitstream);
|
||||
|
||||
try(Context c = new Context()) {
|
||||
bitstream = c.reloadEntity(bitstream);
|
||||
c.turnOffAuthorisationSystem();
|
||||
if (bitstream != null) {
|
||||
bitstreamService.expunge(c, bitstream);
|
||||
}
|
||||
c.complete();
|
||||
}
|
||||
}
|
||||
|
||||
protected DSpaceObjectService<Bitstream> getService() {
|
||||
return bitstreamService;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
* 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.builder;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.BitstreamFormat;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.discovery.SearchServiceException;
|
||||
import org.dspace.service.DSpaceCRUDService;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Created by jonas - jonas@atmire.com on 04/12/17.
|
||||
*/
|
||||
public class BitstreamFormatBuilder extends AbstractCRUDBuilder<BitstreamFormat> {
|
||||
|
||||
/* Log4j logger*/
|
||||
private static final Logger log = Logger.getLogger(BitstreamFormatBuilder.class);
|
||||
|
||||
private BitstreamFormat bitstreamFormat;
|
||||
|
||||
protected BitstreamFormatBuilder(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void cleanup() throws Exception {
|
||||
delete(bitstreamFormat);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DSpaceCRUDService<BitstreamFormat> getService() {
|
||||
return bitstreamFormatService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BitstreamFormat build() {
|
||||
try{
|
||||
|
||||
bitstreamFormatService.update(context, bitstreamFormat);
|
||||
context.dispatchEvents();
|
||||
|
||||
indexingService.commit();
|
||||
} catch (SearchServiceException e) {
|
||||
log.error(e);
|
||||
} catch (SQLException e) {
|
||||
log.error(e);
|
||||
} catch (AuthorizeException e) {
|
||||
log.error(e);;
|
||||
}
|
||||
return bitstreamFormat;
|
||||
}
|
||||
|
||||
|
||||
public static BitstreamFormatBuilder createBitstreamFormat(Context context) throws SQLException, AuthorizeException {
|
||||
BitstreamFormatBuilder bitstreamFormatBuilder = new BitstreamFormatBuilder(context);
|
||||
return bitstreamFormatBuilder.create(context);
|
||||
}
|
||||
private BitstreamFormatBuilder create(Context context) throws SQLException, AuthorizeException {
|
||||
this.context = context;
|
||||
|
||||
bitstreamFormat = bitstreamFormatService.create(context);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public BitstreamFormatBuilder withMimeType(String mimeType){
|
||||
bitstreamFormat.setMIMEType(mimeType);
|
||||
return this;
|
||||
}
|
||||
|
||||
public BitstreamFormatBuilder withDescription(String description){
|
||||
bitstreamFormat.setDescription(description);
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
@@ -7,11 +7,20 @@
|
||||
*/
|
||||
package org.dspace.app.rest.builder;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.CharEncoding;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.Bitstream;
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.content.Community;
|
||||
import org.dspace.content.MetadataSchema;
|
||||
import org.dspace.content.service.DSpaceObjectService;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.discovery.SearchServiceException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Builder to construct Collection objects
|
||||
@@ -19,16 +28,17 @@ import org.dspace.core.Context;
|
||||
* @author Tom Desair (tom dot desair at atmire dot com)
|
||||
* @author Raf Ponsaerts (raf dot ponsaerts at atmire dot com)
|
||||
*/
|
||||
public class CollectionBuilder extends AbstractBuilder<Collection> {
|
||||
public class CollectionBuilder extends AbstractDSpaceObjectBuilder<Collection> {
|
||||
|
||||
private Collection collection;
|
||||
|
||||
protected CollectionBuilder() {
|
||||
protected CollectionBuilder(Context context) {
|
||||
super(context);
|
||||
|
||||
}
|
||||
|
||||
public static CollectionBuilder createCollection(final Context context, final Community parent) {
|
||||
CollectionBuilder builder = new CollectionBuilder();
|
||||
CollectionBuilder builder = new CollectionBuilder(context);
|
||||
return builder.create(context, parent);
|
||||
}
|
||||
|
||||
@@ -39,7 +49,6 @@ public class CollectionBuilder extends AbstractBuilder<Collection> {
|
||||
} catch (Exception e) {
|
||||
return handleException(e);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -47,6 +56,18 @@ public class CollectionBuilder extends AbstractBuilder<Collection> {
|
||||
return setMetadataSingleValue(collection, MetadataSchema.DC_SCHEMA, "title", null, name);
|
||||
}
|
||||
|
||||
public CollectionBuilder withLogo(final String content) throws AuthorizeException, IOException, SQLException {
|
||||
|
||||
InputStream is = IOUtils.toInputStream(content, CharEncoding.UTF_8);
|
||||
try {
|
||||
collectionService.setLogo(context, collection, is);
|
||||
return this;
|
||||
|
||||
} finally {
|
||||
is.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection build() {
|
||||
try {
|
||||
@@ -60,8 +81,12 @@ public class CollectionBuilder extends AbstractBuilder<Collection> {
|
||||
return collection;
|
||||
}
|
||||
|
||||
protected void cleanup() throws Exception {
|
||||
delete(collection);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DSpaceObjectService<Collection> getDsoService() {
|
||||
protected DSpaceObjectService<Collection> getService() {
|
||||
return collectionService;
|
||||
}
|
||||
}
|
||||
|
@@ -7,27 +7,34 @@
|
||||
*/
|
||||
package org.dspace.app.rest.builder;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.CharEncoding;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.Community;
|
||||
import org.dspace.content.MetadataSchema;
|
||||
import org.dspace.content.service.DSpaceObjectService;
|
||||
import org.dspace.core.Context;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Builder to construct Community objects
|
||||
*
|
||||
* @author Tom Desair (tom dot desair at atmire dot com)
|
||||
* @author Raf Ponsaerts (raf dot ponsaerts at atmire dot com)
|
||||
*/
|
||||
public class CommunityBuilder extends AbstractBuilder<Community> {
|
||||
public class CommunityBuilder extends AbstractDSpaceObjectBuilder<Community> {
|
||||
|
||||
private Community community;
|
||||
|
||||
protected CommunityBuilder() {
|
||||
|
||||
protected CommunityBuilder(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public static CommunityBuilder createCommunity(final Context context) {
|
||||
CommunityBuilder builder = new CommunityBuilder();
|
||||
CommunityBuilder builder = new CommunityBuilder(context);
|
||||
return builder.create(context);
|
||||
}
|
||||
|
||||
@@ -36,7 +43,7 @@ public class CommunityBuilder extends AbstractBuilder<Community> {
|
||||
}
|
||||
|
||||
public static CommunityBuilder createSubCommunity(final Context context, final Community parent) {
|
||||
CommunityBuilder builder = new CommunityBuilder();
|
||||
CommunityBuilder builder = new CommunityBuilder(context);
|
||||
return builder.createSub(context, parent);
|
||||
}
|
||||
|
||||
@@ -56,6 +63,13 @@ public class CommunityBuilder extends AbstractBuilder<Community> {
|
||||
return setMetadataSingleValue(community, MetadataSchema.DC_SCHEMA, "title", null, communityName);
|
||||
}
|
||||
|
||||
public CommunityBuilder withLogo(String content) throws AuthorizeException, IOException, SQLException {
|
||||
try(InputStream is = IOUtils.toInputStream(content, CharEncoding.UTF_8)) {
|
||||
communityService.setLogo(context, community, is);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Community build() {
|
||||
try {
|
||||
@@ -70,8 +84,12 @@ public class CommunityBuilder extends AbstractBuilder<Community> {
|
||||
return community;
|
||||
}
|
||||
|
||||
protected void cleanup() throws Exception {
|
||||
delete(community);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DSpaceObjectService<Community> getDsoService() {
|
||||
protected DSpaceObjectService<Community> getService() {
|
||||
return communityService;
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* 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.builder;
|
||||
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.service.DSpaceObjectService;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.discovery.SearchServiceException;
|
||||
import org.dspace.eperson.EPerson;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class EPersonBuilder extends AbstractDSpaceObjectBuilder<EPerson> {
|
||||
|
||||
private EPerson ePerson;
|
||||
|
||||
protected EPersonBuilder(Context context){
|
||||
super(context);
|
||||
}
|
||||
|
||||
protected void cleanup() throws Exception {
|
||||
delete(ePerson);
|
||||
}
|
||||
|
||||
protected DSpaceObjectService<EPerson> getService() {
|
||||
return ePersonService;
|
||||
}
|
||||
|
||||
public EPerson build() {
|
||||
try {
|
||||
ePersonService.update(context, ePerson);
|
||||
indexingService.commit();
|
||||
} catch (SearchServiceException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} catch (AuthorizeException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return ePerson;
|
||||
}
|
||||
|
||||
public static EPersonBuilder createEPerson(Context context){
|
||||
EPersonBuilder ePersonBuilder = new EPersonBuilder(context);
|
||||
return ePersonBuilder.create();
|
||||
}
|
||||
private EPersonBuilder create() {
|
||||
try {
|
||||
ePerson = ePersonService.create(context);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} catch (AuthorizeException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public EPersonBuilder withNameInMetadata(String firstName, String lastName) throws SQLException {
|
||||
ePerson.setFirstName(context, firstName);
|
||||
ePerson.setLastName(context, lastName);
|
||||
return this;
|
||||
}
|
||||
|
||||
public EPersonBuilder withEmail(String name) {
|
||||
ePerson.setEmail(name);
|
||||
return this;
|
||||
}
|
||||
}
|
@@ -18,16 +18,21 @@ import org.dspace.eperson.Group;
|
||||
* @author Tom Desair (tom dot desair at atmire dot com)
|
||||
* @author Raf Ponsaerts (raf dot ponsaerts at atmire dot com)
|
||||
*/
|
||||
public class GroupBuilder extends AbstractBuilder<Group> {
|
||||
public class GroupBuilder extends AbstractDSpaceObjectBuilder<Group> {
|
||||
|
||||
private Group group;
|
||||
|
||||
protected GroupBuilder() {
|
||||
protected GroupBuilder(Context context) {
|
||||
super(context);
|
||||
|
||||
}
|
||||
|
||||
protected void cleanup() throws Exception {
|
||||
delete(group);
|
||||
}
|
||||
|
||||
public static GroupBuilder createGroup(final Context context) {
|
||||
GroupBuilder builder = new GroupBuilder();
|
||||
GroupBuilder builder = new GroupBuilder(context);
|
||||
return builder.create(context);
|
||||
}
|
||||
|
||||
@@ -42,7 +47,7 @@ public class GroupBuilder extends AbstractBuilder<Group> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DSpaceObjectService<Group> getDsoService() {
|
||||
protected DSpaceObjectService<Group> getService() {
|
||||
return groupService;
|
||||
}
|
||||
|
||||
@@ -78,8 +83,4 @@ public class GroupBuilder extends AbstractBuilder<Group> {
|
||||
return this;
|
||||
}
|
||||
|
||||
public static AbstractBuilder<Group> cleaner() {
|
||||
return new GroupBuilder();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -22,17 +22,18 @@ import org.dspace.eperson.Group;
|
||||
* @author Tom Desair (tom dot desair at atmire dot com)
|
||||
* @author Raf Ponsaerts (raf dot ponsaerts at atmire dot com)
|
||||
*/
|
||||
public class ItemBuilder extends AbstractBuilder<Item> {
|
||||
public class ItemBuilder extends AbstractDSpaceObjectBuilder<Item> {
|
||||
|
||||
private WorkspaceItem workspaceItem;
|
||||
private Item item;
|
||||
private Group readerGroup = null;
|
||||
|
||||
protected ItemBuilder() {
|
||||
|
||||
protected ItemBuilder(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public static ItemBuilder createItem(final Context context, final Collection col) {
|
||||
ItemBuilder builder = new ItemBuilder();
|
||||
ItemBuilder builder = new ItemBuilder(context);
|
||||
return builder.create(context, col);
|
||||
}
|
||||
|
||||
@@ -41,6 +42,7 @@ public class ItemBuilder extends AbstractBuilder<Item> {
|
||||
|
||||
try {
|
||||
workspaceItem = workspaceItemService.create(context, col, false);
|
||||
item = workspaceItem.getItem();
|
||||
} catch (Exception e) {
|
||||
return handleException(e);
|
||||
}
|
||||
@@ -49,28 +51,28 @@ public class ItemBuilder extends AbstractBuilder<Item> {
|
||||
}
|
||||
|
||||
public ItemBuilder withTitle(final String title) {
|
||||
return setMetadataSingleValue(workspaceItem.getItem(), MetadataSchema.DC_SCHEMA, "title", null, title);
|
||||
return setMetadataSingleValue(item, MetadataSchema.DC_SCHEMA, "title", null, title);
|
||||
}
|
||||
|
||||
public ItemBuilder withIssueDate(final String issueDate) {
|
||||
return addMetadataValue(workspaceItem.getItem(), MetadataSchema.DC_SCHEMA, "date", "issued", new DCDate(issueDate).toString());
|
||||
return addMetadataValue(item, MetadataSchema.DC_SCHEMA, "date", "issued", new DCDate(issueDate).toString());
|
||||
}
|
||||
|
||||
public ItemBuilder withAuthor(final String authorName) {
|
||||
return addMetadataValue(workspaceItem.getItem(), MetadataSchema.DC_SCHEMA, "contributor", "author", authorName);
|
||||
return addMetadataValue(item, MetadataSchema.DC_SCHEMA, "contributor", "author", authorName);
|
||||
}
|
||||
|
||||
public ItemBuilder withSubject(final String subject) {
|
||||
return addMetadataValue(workspaceItem.getItem(), MetadataSchema.DC_SCHEMA, "subject", null, subject);
|
||||
return addMetadataValue(item, MetadataSchema.DC_SCHEMA, "subject", null, subject);
|
||||
}
|
||||
|
||||
public ItemBuilder makePrivate() {
|
||||
workspaceItem.getItem().setDiscoverable(false);
|
||||
item.setDiscoverable(false);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder withEmbargoPeriod(String embargoPeriod) {
|
||||
return setEmbargo(embargoPeriod, workspaceItem.getItem());
|
||||
return setEmbargo(embargoPeriod, item);
|
||||
}
|
||||
|
||||
public ItemBuilder withReaderGroup(Group group) {
|
||||
@@ -81,7 +83,7 @@ public class ItemBuilder extends AbstractBuilder<Item> {
|
||||
@Override
|
||||
public Item build() {
|
||||
try {
|
||||
Item item = installItemService.installItem(context, workspaceItem);
|
||||
installItemService.installItem(context, workspaceItem);
|
||||
itemService.update(context, item);
|
||||
|
||||
//Check if we need to make this item private. This has to be done after item install.
|
||||
@@ -98,8 +100,12 @@ public class ItemBuilder extends AbstractBuilder<Item> {
|
||||
}
|
||||
}
|
||||
|
||||
protected void cleanup() throws Exception {
|
||||
delete(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DSpaceObjectService<Item> getDsoService() {
|
||||
protected DSpaceObjectService<Item> getService() {
|
||||
return itemService;
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,93 @@
|
||||
/**
|
||||
* 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.builder;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.MetadataField;
|
||||
import org.dspace.content.NonUniqueMetadataException;
|
||||
import org.dspace.content.service.MetadataFieldService;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.discovery.SearchServiceException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class MetadataFieldBuilder extends AbstractBuilder<MetadataField, MetadataFieldService> {
|
||||
|
||||
/* Log4j logger*/
|
||||
private static final Logger log = Logger.getLogger(MetadataFieldBuilder.class);
|
||||
|
||||
private MetadataField metadataField;
|
||||
|
||||
protected MetadataFieldBuilder(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MetadataFieldService getService() {
|
||||
return metadataFieldService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void cleanup() throws Exception {
|
||||
delete(metadataField);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetadataField build() {
|
||||
try{
|
||||
|
||||
metadataFieldService.update(context, metadataField);
|
||||
context.dispatchEvents();
|
||||
|
||||
indexingService.commit();
|
||||
} catch (SearchServiceException e) {
|
||||
log.error(e);
|
||||
} catch (SQLException e) {
|
||||
log.error(e);
|
||||
} catch (AuthorizeException e) {
|
||||
log.error(e);;
|
||||
} catch (NonUniqueMetadataException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return metadataField;
|
||||
}
|
||||
|
||||
public void delete(MetadataField dso) throws Exception {
|
||||
try(Context c = new Context()) {
|
||||
c.turnOffAuthorisationSystem();
|
||||
MetadataField attachedDso = c.reloadEntity(dso);
|
||||
if (attachedDso != null) {
|
||||
getService().delete(c, attachedDso);
|
||||
}
|
||||
c.complete();
|
||||
}
|
||||
|
||||
indexingService.commit();
|
||||
}
|
||||
|
||||
|
||||
public static MetadataFieldBuilder createMetadataField(Context context, String element, String qualifier, String scopeNote) throws SQLException, AuthorizeException {
|
||||
MetadataFieldBuilder metadataFieldBuilder = new MetadataFieldBuilder(context);
|
||||
return metadataFieldBuilder.create(context, element, qualifier, scopeNote);
|
||||
}
|
||||
private MetadataFieldBuilder create(Context context, String element, String qualifier, String scopeNote) throws SQLException, AuthorizeException {
|
||||
this.context = context;
|
||||
|
||||
try {
|
||||
metadataField = metadataFieldService.create(context, metadataSchemaService.find(context, "dc"), element, qualifier,scopeNote);
|
||||
} catch (NonUniqueMetadataException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* 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.builder;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.MetadataSchema;
|
||||
import org.dspace.content.NonUniqueMetadataException;
|
||||
import org.dspace.content.service.MetadataSchemaService;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.discovery.SearchServiceException;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class MetadataSchemaBuilder extends AbstractBuilder<MetadataSchema, MetadataSchemaService> {
|
||||
|
||||
/* Log4j logger*/
|
||||
private static final Logger log = Logger.getLogger(MetadataSchemaBuilder.class);
|
||||
|
||||
private MetadataSchema metadataSchema;
|
||||
|
||||
protected MetadataSchemaBuilder(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MetadataSchemaService getService() {
|
||||
return metadataSchemaService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void cleanup() throws Exception {
|
||||
delete(metadataSchema);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetadataSchema build() {
|
||||
try{
|
||||
|
||||
metadataSchemaService.update(context, metadataSchema);
|
||||
context.dispatchEvents();
|
||||
|
||||
indexingService.commit();
|
||||
} catch (SearchServiceException e) {
|
||||
log.error(e);
|
||||
} catch (SQLException e) {
|
||||
log.error(e);
|
||||
} catch (AuthorizeException e) {
|
||||
log.error(e);;
|
||||
} catch (NonUniqueMetadataException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return metadataSchema;
|
||||
}
|
||||
|
||||
public void delete(MetadataSchema dso) throws Exception {
|
||||
try(Context c = new Context()) {
|
||||
c.turnOffAuthorisationSystem();
|
||||
MetadataSchema attachedDso = c.reloadEntity(dso);
|
||||
if (attachedDso != null) {
|
||||
getService().delete(c, attachedDso);
|
||||
}
|
||||
c.complete();
|
||||
}
|
||||
|
||||
indexingService.commit();
|
||||
}
|
||||
|
||||
|
||||
public static MetadataSchemaBuilder createMetadataSchema(Context context, String name, String namespace) throws SQLException, AuthorizeException {
|
||||
MetadataSchemaBuilder metadataSchemaBuilder = new MetadataSchemaBuilder(context);
|
||||
return metadataSchemaBuilder.create(context, name, namespace);
|
||||
}
|
||||
private MetadataSchemaBuilder create(Context context, String name, String namespace) throws SQLException, AuthorizeException {
|
||||
this.context = context;
|
||||
|
||||
try {
|
||||
metadataSchema = metadataSchemaService.create(context, name, namespace);
|
||||
} catch (NonUniqueMetadataException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* 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.builder;
|
||||
|
||||
import org.dspace.content.Site;
|
||||
import org.dspace.content.service.DSpaceObjectService;
|
||||
import org.dspace.core.Context;
|
||||
|
||||
public class SiteBuilder extends AbstractDSpaceObjectBuilder<Site> {
|
||||
|
||||
private Site site;
|
||||
|
||||
protected SiteBuilder(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void cleanup() throws Exception {
|
||||
//Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DSpaceObjectService<Site> getService() {
|
||||
return siteService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Site build() {
|
||||
try {
|
||||
siteService.update(context, site);
|
||||
|
||||
context.dispatchEvents();
|
||||
|
||||
indexingService.commit();
|
||||
return site;
|
||||
} catch (Exception e) {
|
||||
return handleException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static SiteBuilder createSite(final Context context) {
|
||||
SiteBuilder builder = new SiteBuilder(context);
|
||||
return builder.create(context);
|
||||
}
|
||||
|
||||
private SiteBuilder create(final Context context) {
|
||||
this.context = context;
|
||||
|
||||
try {
|
||||
site = siteService.createSite(context);
|
||||
} catch (Exception e) {
|
||||
return handleException(e);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* 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.matcher;
|
||||
|
||||
import org.hamcrest.Matcher;
|
||||
|
||||
import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
/**
|
||||
* @author Jonas Van Goolen - (jonas@atmire.com)
|
||||
*/
|
||||
public class BitstreamFormatMatcher {
|
||||
|
||||
public static Matcher<? super Object> matchBitstreamFormat(String mimetype, String description) {
|
||||
return allOf(
|
||||
hasJsonPath("$.mimetype", is(mimetype)),
|
||||
hasJsonPath("$.description", is(description)),
|
||||
hasJsonPath("$.type", is("bitstreamformat"))
|
||||
);
|
||||
}
|
||||
|
||||
public static Matcher<? super Object> matchBitstreamFormatMimeType(String mimetype) {
|
||||
return allOf(
|
||||
hasJsonPath("$.mimetype", is(mimetype)),
|
||||
hasJsonPath("$.type", is("bitstreamformat"))
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* 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.matcher;
|
||||
|
||||
import org.dspace.content.Bitstream;
|
||||
import org.hamcrest.Matcher;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
public class BitstreamMatcher {
|
||||
|
||||
public static Matcher<? super Object> matchBitstreamEntry(Bitstream bitstream) {
|
||||
return allOf(
|
||||
//Check core metadata (the JSON Path expression evaluates to a collection so we have to use contains)
|
||||
hasJsonPath("$.uuid", is(bitstream.getID().toString())),
|
||||
hasJsonPath("$.name", is(bitstream.getName())),
|
||||
hasJsonPath("$.bundleName", is("ORIGINAL")),
|
||||
hasJsonPath("$.metadata", containsInAnyOrder(
|
||||
BitstreamMetadataMatcher.matchTitle(bitstream.getName()),
|
||||
BitstreamMetadataMatcher.matchDescription(bitstream.getDescription())
|
||||
)),
|
||||
hasJsonPath("$.sizeBytes", is((int) bitstream.getSize())),
|
||||
hasJsonPath("$.checkSum", matchChecksum()),
|
||||
hasJsonPath("$._embedded.format", matchFormat()),
|
||||
//Check links
|
||||
matchBitstreamLinks(bitstream.getID())
|
||||
);
|
||||
}
|
||||
|
||||
private static Matcher<? super Object> matchBitstreamLinks(UUID uuid) {
|
||||
return allOf(
|
||||
hasJsonPath("$._links.format.href", containsString("/api/core/bitstreams/" + uuid + "/format")),
|
||||
hasJsonPath("$._links.self.href", containsString("/api/core/bitstreams/"+uuid)),
|
||||
hasJsonPath("$._links.content.href", containsString("/api/core/bitstreams/"+uuid+"/content"))
|
||||
);
|
||||
}
|
||||
|
||||
private static Matcher<? super Object> matchChecksum(){
|
||||
return allOf(
|
||||
hasJsonPath("$.checkSumAlgorithm", not(empty())),
|
||||
hasJsonPath("$.value", not(empty()))
|
||||
);
|
||||
}
|
||||
|
||||
private static Matcher<? super Object> matchFormat(){
|
||||
return allOf(
|
||||
hasJsonPath("$.mimetype", not(empty())),
|
||||
hasJsonPath("$.type", is("bitstreamformat"))
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* 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.matcher;
|
||||
|
||||
import org.hamcrest.Matcher;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class BitstreamMetadataMatcher {
|
||||
|
||||
public static Matcher<? super Object> matchTitle(String title) {
|
||||
return allOf(
|
||||
hasJsonPath("$.key", is("dc.title")),
|
||||
hasJsonPath("$.value", is(title))
|
||||
);
|
||||
}
|
||||
|
||||
public static Matcher<? super Object> matchDescription(String description) {
|
||||
return allOf(
|
||||
hasJsonPath("$.key", is("dc.description")),
|
||||
hasJsonPath("$.value", is(description))
|
||||
);
|
||||
}
|
||||
}
|
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* 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.matcher;
|
||||
|
||||
import org.hamcrest.Matcher;
|
||||
import org.hamcrest.Matchers;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class CollectionMatcher {
|
||||
|
||||
public static Matcher<? super Object> matchCollectionEntry(String name, UUID uuid, String handle) {
|
||||
return allOf(
|
||||
hasJsonPath("$.uuid", is(uuid.toString())),
|
||||
hasJsonPath("$.name", is(name)),
|
||||
hasJsonPath("$.handle", is(handle)),
|
||||
hasJsonPath("$.type", is("collection")),
|
||||
hasJsonPath("$.metadata", Matchers.contains(
|
||||
CollectionMetadataMatcher.matchTitle(name)
|
||||
)),
|
||||
matchLinks(uuid),
|
||||
matchLogo()
|
||||
);
|
||||
}
|
||||
|
||||
private static Matcher<? super Object> matchLogo() {
|
||||
return allOf(
|
||||
hasJsonPath("$._embedded.logo", Matchers.not(Matchers.empty()))
|
||||
);
|
||||
}
|
||||
|
||||
public static Matcher<? super Object> matchLinks(UUID uuid){
|
||||
return allOf(
|
||||
hasJsonPath("$._links.logo.href", containsString("api/core/collections/" + uuid.toString() + "/logo")),
|
||||
hasJsonPath("$._links.self.href", containsString("api/core/collections/" + uuid.toString()))
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* 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.matcher;
|
||||
|
||||
import org.hamcrest.Matcher;
|
||||
|
||||
import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
|
||||
public class CollectionMetadataMatcher {
|
||||
|
||||
public static Matcher<? super Object> matchTitle(String title){
|
||||
return allOf(
|
||||
hasJsonPath("$.key", is("dc.title")),
|
||||
hasJsonPath("$.value", is(title))
|
||||
);
|
||||
}
|
||||
}
|
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* 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.matcher;
|
||||
|
||||
import org.hamcrest.Matcher;
|
||||
import org.hamcrest.Matchers;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class CommunityMatcher {
|
||||
|
||||
|
||||
public static Matcher<? super Object> matchCommunityEntry(String name, UUID uuid, String handle) {
|
||||
return allOf(
|
||||
hasJsonPath("$.uuid", is(uuid.toString())),
|
||||
hasJsonPath("$.name", is(name)),
|
||||
hasJsonPath("$.handle", is(handle)),
|
||||
hasJsonPath("$.type", is("community")),
|
||||
hasJsonPath("$.metadata", Matchers.contains(
|
||||
CommunityMetadataMatcher.matchTitle(name)
|
||||
)),
|
||||
hasJsonPath("$._embedded.collections", Matchers.not(Matchers.empty())),
|
||||
hasJsonPath("$._embedded.logo", Matchers.not(Matchers.empty())),
|
||||
matchLinks(uuid)
|
||||
);
|
||||
}
|
||||
|
||||
public static Matcher<? super Object> matchLinks(UUID uuid){
|
||||
return allOf(
|
||||
hasJsonPath("$._links.collections.href", Matchers.containsString("/api/core/communities/" + uuid.toString() + "/collections")),
|
||||
hasJsonPath("$._links.logo.href", Matchers.containsString("/api/core/communities/" + uuid.toString() + "/logo")),
|
||||
hasJsonPath("$._links.self.href", Matchers.containsString("/api/core/communities/" + uuid.toString()))
|
||||
);
|
||||
}
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* 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.matcher;
|
||||
|
||||
import org.hamcrest.Matcher;
|
||||
|
||||
import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class CommunityMetadataMatcher {
|
||||
|
||||
public static Matcher<? super Object> matchTitle(String title){
|
||||
return allOf(
|
||||
hasJsonPath("$.key", is("dc.title")),
|
||||
hasJsonPath("$.value", is(title))
|
||||
);
|
||||
}
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* 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.matcher;
|
||||
|
||||
import org.dspace.eperson.EPerson;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.hamcrest.Matchers;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
public class EPersonMatcher {
|
||||
|
||||
public static Matcher<? super Object> matchEPersonEntry(EPerson ePerson) {
|
||||
return allOf(
|
||||
hasJsonPath("$.uuid", is(ePerson.getID().toString())),
|
||||
hasJsonPath("$.name", is(ePerson.getName())),
|
||||
hasJsonPath("$.type", is("eperson")),
|
||||
hasJsonPath("$.canLogIn", not(empty())),
|
||||
hasJsonPath("$._links.self.href", containsString("/api/eperson/epersons/" + ePerson.getID().toString())),
|
||||
hasJsonPath("$.metadata", Matchers.containsInAnyOrder(
|
||||
EPersonMetadataMatcher.matchFirstName(ePerson.getFirstName()),
|
||||
EPersonMetadataMatcher.matchLastName(ePerson.getLastName())
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public static Matcher<? super Object> matchDefaultTestEPerson() {
|
||||
return allOf(
|
||||
hasJsonPath("$.type", is("eperson"))
|
||||
);
|
||||
}
|
||||
}
|
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* 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.matcher;
|
||||
|
||||
import org.hamcrest.Matcher;
|
||||
import org.hamcrest.Matchers;
|
||||
|
||||
import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.hamcrest.Matchers.empty;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class EPersonMetadataMatcher {
|
||||
|
||||
public static Matcher<? super Object> matchFirstName(String firstName){
|
||||
return allOf(
|
||||
hasJsonPath("$.key", is("eperson.firstname")),
|
||||
hasJsonPath("$.value", is(firstName))
|
||||
);
|
||||
}
|
||||
|
||||
public static Matcher<? super Object> matchLastName(String lastName){
|
||||
return allOf(
|
||||
hasJsonPath("$.key", is("eperson.lastname")),
|
||||
hasJsonPath("$.value", is(lastName))
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* 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.matcher;
|
||||
|
||||
import org.hamcrest.Matcher;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class GroupMatcher {
|
||||
|
||||
public static Matcher<? super Object> matchGroupEntry(UUID uuid, String name) {
|
||||
return allOf(
|
||||
hasJsonPath("$.uuid", is(uuid.toString())),
|
||||
hasJsonPath("$.name", is(name)),
|
||||
hasJsonPath("$.type", is("group")),
|
||||
hasJsonPath("$._links.self.href", containsString("/api/eperson/groups/" + uuid.toString()))
|
||||
);
|
||||
}
|
||||
|
||||
public static Matcher<? super Object> matchGroupWithName(String name) {
|
||||
return allOf(
|
||||
hasJsonPath("$.name", is(name)),
|
||||
hasJsonPath("$.type", is("group"))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* 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.matcher;
|
||||
|
||||
import org.dspace.content.MetadataField;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.hamcrest.Matchers;
|
||||
|
||||
import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class MetadataFieldMatcher {
|
||||
|
||||
public static Matcher<? super Object> matchMetadataField(){
|
||||
return allOf(
|
||||
hasJsonPath("$.element", Matchers.not(Matchers.empty())),
|
||||
hasJsonPath("$.qualifier", Matchers.not(Matchers.empty())),
|
||||
hasJsonPath("$.type", is("metadatafield")),
|
||||
hasJsonPath("$._embedded.schema", Matchers.not(Matchers.empty())),
|
||||
hasJsonPath("$._links.schema.href", Matchers.containsString("/api/core/metadatafields")),
|
||||
hasJsonPath("$._links.self.href", Matchers.containsString("/api/core/metadatafields"))
|
||||
);
|
||||
}
|
||||
|
||||
public static Matcher<? super Object> matchMetadataField(MetadataField metadataField){
|
||||
return allOf(
|
||||
hasJsonPath("$.element", is(metadataField.getElement())),
|
||||
hasJsonPath("$.qualifier", is(metadataField.getQualifier())),
|
||||
hasJsonPath("$.type", is("metadatafield")),
|
||||
hasJsonPath("$._embedded.schema", Matchers.not(Matchers.empty())),
|
||||
hasJsonPath("$._links.schema.href", Matchers.containsString("/api/core/metadatafields")),
|
||||
hasJsonPath("$._links.self.href", Matchers.containsString("/api/core/metadatafields"))
|
||||
);
|
||||
}
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* 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.matcher;
|
||||
|
||||
import org.dspace.content.MetadataSchema;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.hamcrest.Matchers;
|
||||
|
||||
import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class MetadataschemaMatcher {
|
||||
|
||||
public static Matcher<? super Object> matchEntry(){
|
||||
return allOf(
|
||||
hasJsonPath("$.prefix", Matchers.not(Matchers.empty())),
|
||||
hasJsonPath("$.namespace", Matchers.not(Matchers.empty())),
|
||||
hasJsonPath("$.type", is("metadataschema")),
|
||||
hasJsonPath("$._links.self.href", Matchers.containsString("/api/core/metadataschemas"))
|
||||
);
|
||||
}
|
||||
|
||||
public static Matcher<? super Object> matchEntry(MetadataSchema metadataSchema){
|
||||
return allOf(
|
||||
hasJsonPath("$.prefix", is(metadataSchema.getName())),
|
||||
hasJsonPath("$.namespace", is(metadataSchema.getNamespace())),
|
||||
hasJsonPath("$.type", is("metadataschema")),
|
||||
hasJsonPath("$._links.self.href", Matchers.containsString("/api/core/metadataschemas"))
|
||||
);
|
||||
}
|
||||
}
|
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* 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.matcher;
|
||||
|
||||
import org.dspace.content.Site;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.hamcrest.Matchers;
|
||||
|
||||
import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class SiteMatcher {
|
||||
|
||||
public static Matcher<? super Object> matchEntry(Site site){
|
||||
return allOf(
|
||||
hasJsonPath("$.uuid", is(site.getID().toString())),
|
||||
hasJsonPath("$.name", is(site.getName())),
|
||||
hasJsonPath("$.type", is("site")),
|
||||
hasJsonPath("$._links.self.href", containsString("/api/core/sites/" + site.getID()))
|
||||
|
||||
);
|
||||
}
|
||||
}
|
@@ -25,7 +25,8 @@ import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
|
||||
/**
|
||||
* @author Atmire NV (info at atmire dot com)
|
||||
* @author Frederic Van Reet (frederic dot vanreet at atmire dot com)
|
||||
* @author Tom Desair (tom dot desair at atmire dot com)
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class EPersonRestAuthenticationProviderTest {
|
||||
|
@@ -30,7 +30,8 @@ import org.mockito.Mockito;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
/**
|
||||
* @author Atmire NV (info at atmire dot com)
|
||||
* @author Frederic Van Reet (frederic dot vanreet at atmire dot com)
|
||||
* @author Tom Desair (tom dot desair at atmire dot com)
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class EPersonClaimProviderTest {
|
||||
|
@@ -38,7 +38,8 @@ import org.springframework.security.crypto.keygen.KeyGenerators;
|
||||
import org.springframework.security.crypto.keygen.StringKeyGenerator;
|
||||
|
||||
/**
|
||||
* @author Atmire NV (info at atmire dot com)
|
||||
* @author Frederic Van Reet (frederic dot vanreet at atmire dot com)
|
||||
* @author Tom Desair (tom dot desair at atmire dot com)
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class JWTTokenHandlerTest {
|
||||
|
@@ -29,7 +29,8 @@ import org.mockito.Mockito;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
/**
|
||||
* @author Atmire NV (info at atmire dot com)
|
||||
* @author Frederic Van Reet (frederic dot vanreet at atmire dot com)
|
||||
* @author Tom Desair (tom dot desair at atmire dot com)
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class SpecialGroupClaimProviderTest {
|
||||
|
@@ -7,7 +7,12 @@
|
||||
*/
|
||||
package org.dspace.app.rest.test;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.app.rest.builder.AbstractBuilder;
|
||||
import org.dspace.servicemanager.DSpaceKernelImpl;
|
||||
import org.dspace.servicemanager.DSpaceKernelInit;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
@@ -15,12 +20,7 @@ import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.app.rest.builder.AbstractBuilder;
|
||||
import org.dspace.servicemanager.DSpaceKernelImpl;
|
||||
import org.dspace.servicemanager.DSpaceKernelInit;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* Abstract Test class copied from DSpace API
|
||||
|
@@ -7,14 +7,10 @@
|
||||
*/
|
||||
package org.dspace.app.rest.test;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.app.rest.builder.AbstractBuilder;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.Community;
|
||||
import org.dspace.content.factory.ContentServiceFactory;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.core.I18nUtil;
|
||||
import org.dspace.eperson.EPerson;
|
||||
@@ -25,6 +21,10 @@ import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* Abstract Test class that will initialize the in-memory database
|
||||
*/
|
||||
@@ -146,16 +146,13 @@ public class AbstractIntegrationTestWithDatabase extends AbstractDSpaceIntegrati
|
||||
public void destroy() throws Exception {
|
||||
// Cleanup our global context object
|
||||
try {
|
||||
AbstractBuilder.cleanupObjects();
|
||||
if(context == null || !context.isValid()){
|
||||
context = new Context();
|
||||
}
|
||||
parentCommunity = context.reloadEntity(parentCommunity);
|
||||
eperson = context.reloadEntity(eperson);
|
||||
|
||||
context.turnOffAuthorisationSystem();
|
||||
if(parentCommunity != null) {
|
||||
ContentServiceFactory.getInstance().getCommunityService().delete(context, parentCommunity);
|
||||
}
|
||||
if(eperson != null) {
|
||||
EPersonServiceFactory.getInstance().getEPersonService().delete(context, eperson);
|
||||
}
|
||||
|
Reference in New Issue
Block a user