diff --git a/dspace-api/src/main/java/org/dspace/core/Context.java b/dspace-api/src/main/java/org/dspace/core/Context.java
index 313cb241f6..c7c564f180 100644
--- a/dspace-api/src/main/java/org/dspace/core/Context.java
+++ b/dspace-api/src/main/java/org/dspace/core/Context.java
@@ -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 false
if this
diff --git a/dspace-api/src/test/java/org/dspace/core/ContextTest.java b/dspace-api/src/test/java/org/dspace/core/ContextTest.java
index 3109dfbf24..4748760130 100644
--- a/dspace-api/src/test/java/org/dspace/core/ContextTest.java
+++ b/dspace-api/src/test/java/org/dspace/core/ContextTest.java
@@ -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.
diff --git a/dspace-services/src/main/java/org/dspace/services/sessions/StatelessRequestServiceImpl.java b/dspace-services/src/main/java/org/dspace/services/sessions/StatelessRequestServiceImpl.java
index cf68e2d4f5..051d154c8f 100644
--- a/dspace-services/src/main/java/org/dspace/services/sessions/StatelessRequestServiceImpl.java
+++ b/dspace-services/src/main/java/org/dspace/services/sessions/StatelessRequestServiceImpl.java
@@ -44,7 +44,7 @@ import org.springframework.beans.factory.annotation.Required;
*
*
* @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 {
diff --git a/dspace-spring-rest/src/main/java/org/dspace/app/rest/AuthenticationRestController.java b/dspace-spring-rest/src/main/java/org/dspace/app/rest/AuthenticationRestController.java
index 18c4918abb..0822fb23b7 100644
--- a/dspace-spring-rest/src/main/java/org/dspace/app/rest/AuthenticationRestController.java
+++ b/dspace-spring-rest/src/main/java/org/dspace/app/rest/AuthenticationRestController.java
@@ -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
diff --git a/dspace-spring-rest/src/main/java/org/dspace/app/rest/model/AuthnRest.java b/dspace-spring-rest/src/main/java/org/dspace/app/rest/model/AuthnRest.java
index 9ae3c5cee7..fc50d80b5b 100644
--- a/dspace-spring-rest/src/main/java/org/dspace/app/rest/model/AuthnRest.java
+++ b/dspace-spring-rest/src/main/java/org/dspace/app/rest/model/AuthnRest.java
@@ -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{
diff --git a/dspace-spring-rest/src/main/java/org/dspace/app/rest/model/hateoas/AuthenticationStatusResource.java b/dspace-spring-rest/src/main/java/org/dspace/app/rest/model/hateoas/AuthenticationStatusResource.java
index ad08095f0e..5d64200fc2 100644
--- a/dspace-spring-rest/src/main/java/org/dspace/app/rest/model/hateoas/AuthenticationStatusResource.java
+++ b/dspace-spring-rest/src/main/java/org/dspace/app/rest/model/hateoas/AuthenticationStatusResource.java
@@ -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 {
diff --git a/dspace-spring-rest/src/main/java/org/dspace/app/rest/model/hateoas/AuthnResource.java b/dspace-spring-rest/src/main/java/org/dspace/app/rest/model/hateoas/AuthnResource.java
index 1d8c54169e..eebbbdf2b1 100644
--- a/dspace-spring-rest/src/main/java/org/dspace/app/rest/model/hateoas/AuthnResource.java
+++ b/dspace-spring-rest/src/main/java/org/dspace/app/rest/model/hateoas/AuthnResource.java
@@ -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 {
diff --git a/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/CustomLogoutHandler.java b/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/CustomLogoutHandler.java
index 15066bb03e..51c6b72826 100644
--- a/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/CustomLogoutHandler.java
+++ b/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/CustomLogoutHandler.java
@@ -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 {
diff --git a/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/DSpaceAuthentication.java b/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/DSpaceAuthentication.java
index 794f8f29db..5ec36f1d9e 100644
--- a/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/DSpaceAuthentication.java
+++ b/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/DSpaceAuthentication.java
@@ -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 {
diff --git a/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/EPersonRestAuthenticationProvider.java b/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/EPersonRestAuthenticationProvider.java
index 98987f5e75..e97af3cfc5 100644
--- a/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/EPersonRestAuthenticationProvider.java
+++ b/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/EPersonRestAuthenticationProvider.java
@@ -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{
diff --git a/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/RestAuthenticationService.java b/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/RestAuthenticationService.java
index 1b3665ca20..558aca9d74 100644
--- a/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/RestAuthenticationService.java
+++ b/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/RestAuthenticationService.java
@@ -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 {
diff --git a/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/StatelessAuthenticationFilter.java b/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/StatelessAuthenticationFilter.java
index 7d820a7058..3c8f93933b 100644
--- a/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/StatelessAuthenticationFilter.java
+++ b/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/StatelessAuthenticationFilter.java
@@ -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{
diff --git a/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/StatelessLoginFilter.java b/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/StatelessLoginFilter.java
index 825150878c..0eb5f15123 100644
--- a/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/StatelessLoginFilter.java
+++ b/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/StatelessLoginFilter.java
@@ -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 {
diff --git a/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/WebSecurityConfiguration.java b/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/WebSecurityConfiguration.java
index 06fe29659f..a1d71d0341 100644
--- a/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/WebSecurityConfiguration.java
+++ b/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/WebSecurityConfiguration.java
@@ -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
diff --git a/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/jwt/EPersonClaimProvider.java b/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/jwt/EPersonClaimProvider.java
index 148b6acce4..d2067ed460 100644
--- a/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/jwt/EPersonClaimProvider.java
+++ b/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/jwt/EPersonClaimProvider.java
@@ -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{
diff --git a/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/jwt/JWTClaimProvider.java b/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/jwt/JWTClaimProvider.java
index f1b10dc784..0f89721953 100644
--- a/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/jwt/JWTClaimProvider.java
+++ b/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/jwt/JWTClaimProvider.java
@@ -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 {
diff --git a/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/jwt/JWTTokenHandler.java b/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/jwt/JWTTokenHandler.java
index 2bf26ebaf4..8e36cb6fe5 100644
--- a/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/jwt/JWTTokenHandler.java
+++ b/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/jwt/JWTTokenHandler.java
@@ -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 {
diff --git a/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/jwt/JWTTokenRestAuthenticationServiceImpl.java b/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/jwt/JWTTokenRestAuthenticationServiceImpl.java
index 393e8e1750..7f286b7388 100644
--- a/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/jwt/JWTTokenRestAuthenticationServiceImpl.java
+++ b/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/jwt/JWTTokenRestAuthenticationServiceImpl.java
@@ -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 {
diff --git a/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/jwt/SpecialGroupClaimProvider.java b/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/jwt/SpecialGroupClaimProvider.java
index ed24dde85d..ef583c7dd8 100644
--- a/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/jwt/SpecialGroupClaimProvider.java
+++ b/dspace-spring-rest/src/main/java/org/dspace/app/rest/security/jwt/SpecialGroupClaimProvider.java
@@ -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 {
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/AuthenticationRestControllerIT.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/AuthenticationRestControllerIT.java
index 2f42057998..7ceba1b100 100644
--- a/dspace-spring-rest/src/test/java/org/dspace/app/rest/AuthenticationRestControllerIT.java
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/AuthenticationRestControllerIT.java
@@ -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 {
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/BitstreamContentRestControllerIT.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/BitstreamContentRestControllerIT.java
index 5dcd3fed01..e00b262f4e 100644
--- a/dspace-spring-rest/src/test/java/org/dspace/app/rest/BitstreamContentRestControllerIT.java
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/BitstreamContentRestControllerIT.java
@@ -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);
}
}
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/BitstreamFormatRestRepositoryIT.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/BitstreamFormatRestRepositoryIT.java
new file mode 100644
index 0000000000..ce79ee2c0c
--- /dev/null
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/BitstreamFormatRestRepositoryIT.java
@@ -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())))
+ ;
+ }
+}
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/BitstreamRestRepositoryIT.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/BitstreamRestRepositoryIT.java
new file mode 100644
index 0000000000..8f45ea8629
--- /dev/null
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/BitstreamRestRepositoryIT.java
@@ -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())
+ ;
+
+ }
+
+}
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/BrowsesResourceControllerIT.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/BrowsesResourceControllerIT.java
index f1950ed0d0..c8e73da639 100644
--- a/dspace-spring-rest/src/test/java/org/dspace/app/rest/BrowsesResourceControllerIT.java
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/BrowsesResourceControllerIT.java
@@ -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
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/CollectionRestRepositoryIT.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/CollectionRestRepositoryIT.java
new file mode 100644
index 0000000000..a290faa88f
--- /dev/null
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/CollectionRestRepositoryIT.java
@@ -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());
+ }
+
+}
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/CommunityRestRepositoryIT.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/CommunityRestRepositoryIT.java
new file mode 100644
index 0000000000..bec3ea8645
--- /dev/null
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/CommunityRestRepositoryIT.java
@@ -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());
+ }
+}
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/EPersonRestRepositoryIT.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/EPersonRestRepositoryIT.java
new file mode 100644
index 0000000000..c4e3ecb4be
--- /dev/null
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/EPersonRestRepositoryIT.java
@@ -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());
+
+ }
+}
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/GroupRestRepositoryIT.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/GroupRestRepositoryIT.java
new file mode 100644
index 0000000000..5d4584f17f
--- /dev/null
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/GroupRestRepositoryIT.java
@@ -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())
+ ;
+ }
+
+}
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/ItemRestRepositoryIT.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/ItemRestRepositoryIT.java
new file mode 100644
index 0000000000..66bab2f6d4
--- /dev/null
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/ItemRestRepositoryIT.java
@@ -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());
+ ;
+ }
+
+}
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/MetadatafieldRestRepositoryIT.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/MetadatafieldRestRepositoryIT.java
new file mode 100644
index 0000000000..3fb69d355f
--- /dev/null
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/MetadatafieldRestRepositoryIT.java
@@ -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)));
+ }
+}
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/MetadataschemaRestRepositoryIT.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/MetadataschemaRestRepositoryIT.java
new file mode 100644
index 0000000000..99f3edc17d
--- /dev/null
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/MetadataschemaRestRepositoryIT.java
@@ -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)
+ )));
+ }
+}
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/RootRestResourceControllerIT.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/RootRestResourceControllerIT.java
index b46ae8833d..2688115649 100644
--- a/dspace-spring-rest/src/test/java/org/dspace/app/rest/RootRestResourceControllerIT.java
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/RootRestResourceControllerIT.java
@@ -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 {
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/SiteRestRepositoryIT.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/SiteRestRepositoryIT.java
new file mode 100644
index 0000000000..9330d74c34
--- /dev/null
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/SiteRestRepositoryIT.java
@@ -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());
+
+ }
+}
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/AbstractBuilder.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/AbstractBuilder.java
index 39d4c7c153..c93860ecf3 100644
--- a/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/AbstractBuilder.java
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/AbstractBuilder.java
@@ -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 {
+public abstract class AbstractBuilder {
static CommunityService communityService;
static CollectionService collectionService;
@@ -55,11 +54,26 @@ public abstract class AbstractBuilder {
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 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 {
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 {
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 handleException(final Exception e) {
- log.error(e.getMessage(), e);
- return null;
- }
-
- protected abstract DSpaceObjectService getDsoService();
-
- protected > 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 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 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 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();
}
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/AbstractCRUDBuilder.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/AbstractCRUDBuilder.java
new file mode 100644
index 0000000000..7090e113bf
--- /dev/null
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/AbstractCRUDBuilder.java
@@ -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 extends AbstractBuilder {
+
+ 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();
+ }
+
+}
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/AbstractDSpaceObjectBuilder.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/AbstractDSpaceObjectBuilder.java
new file mode 100644
index 0000000000..10bbd416b5
--- /dev/null
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/AbstractDSpaceObjectBuilder.java
@@ -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 extends AbstractBuilder {
+
+ /* 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 getService();
+
+
+ protected B handleException(final Exception e) {
+ log.error(e.getMessage(), e);
+ return null;
+ }
+
+
+ protected > 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 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 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 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();
+ }
+}
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/BitstreamBuilder.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/BitstreamBuilder.java
index ae16d37a6c..f23e0d4b8f 100644
--- a/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/BitstreamBuilder.java
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/BitstreamBuilder.java
@@ -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{
+public class BitstreamBuilder extends AbstractDSpaceObjectBuilder {
public static final String ORIGINAL = "ORIGINAL";
@@ -35,12 +32,13 @@ public class BitstreamBuilder extends AbstractBuilder{
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{
}
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{
return bitstream;
}
- protected DSpaceObjectService 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 getService() {
return bitstreamService;
}
-}
+}
\ No newline at end of file
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/BitstreamFormatBuilder.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/BitstreamFormatBuilder.java
new file mode 100644
index 0000000000..3f84cbd9ec
--- /dev/null
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/BitstreamFormatBuilder.java
@@ -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 {
+
+ /* 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 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;
+ }
+
+}
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/CollectionBuilder.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/CollectionBuilder.java
index 81d3b416fc..1d8192d009 100644
--- a/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/CollectionBuilder.java
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/CollectionBuilder.java
@@ -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 {
+public class CollectionBuilder extends AbstractDSpaceObjectBuilder {
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 {
} catch (Exception e) {
return handleException(e);
}
-
return this;
}
@@ -47,6 +56,18 @@ public class CollectionBuilder extends AbstractBuilder {
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 {
return collection;
}
+ protected void cleanup() throws Exception {
+ delete(collection);
+ }
+
@Override
- protected DSpaceObjectService getDsoService() {
+ protected DSpaceObjectService getService() {
return collectionService;
}
}
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/CommunityBuilder.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/CommunityBuilder.java
index 5ab4f2ac8e..6a33d0af09 100644
--- a/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/CommunityBuilder.java
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/CommunityBuilder.java
@@ -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 {
+public class CommunityBuilder extends AbstractDSpaceObjectBuilder {
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 {
}
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 {
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 {
return community;
}
+ protected void cleanup() throws Exception {
+ delete(community);
+ }
+
@Override
- protected DSpaceObjectService getDsoService() {
+ protected DSpaceObjectService getService() {
return communityService;
}
}
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/EPersonBuilder.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/EPersonBuilder.java
new file mode 100644
index 0000000000..f3e5c55a00
--- /dev/null
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/EPersonBuilder.java
@@ -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 {
+
+ private EPerson ePerson;
+
+ protected EPersonBuilder(Context context){
+ super(context);
+ }
+
+ protected void cleanup() throws Exception {
+ delete(ePerson);
+ }
+
+ protected DSpaceObjectService 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;
+ }
+}
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/GroupBuilder.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/GroupBuilder.java
index fadcf697e8..e35ad5ad3a 100644
--- a/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/GroupBuilder.java
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/GroupBuilder.java
@@ -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 {
+public class GroupBuilder extends AbstractDSpaceObjectBuilder {
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 {
}
@Override
- protected DSpaceObjectService getDsoService() {
+ protected DSpaceObjectService getService() {
return groupService;
}
@@ -78,8 +83,4 @@ public class GroupBuilder extends AbstractBuilder {
return this;
}
- public static AbstractBuilder cleaner() {
- return new GroupBuilder();
- }
-
}
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/ItemBuilder.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/ItemBuilder.java
index 7c06d8d3e5..3efcddd148 100644
--- a/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/ItemBuilder.java
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/ItemBuilder.java
@@ -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- {
+public class ItemBuilder extends AbstractDSpaceObjectBuilder
- {
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
- {
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
- {
}
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
- {
@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
- {
}
}
+ protected void cleanup() throws Exception {
+ delete(item);
+ }
+
@Override
- protected DSpaceObjectService
- getDsoService() {
+ protected DSpaceObjectService
- getService() {
return itemService;
}
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/MetadataFieldBuilder.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/MetadataFieldBuilder.java
new file mode 100644
index 0000000000..f26c72e3cc
--- /dev/null
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/MetadataFieldBuilder.java
@@ -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 {
+
+ /* 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;
+ }
+}
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/MetadataSchemaBuilder.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/MetadataSchemaBuilder.java
new file mode 100644
index 0000000000..68c4a7b45c
--- /dev/null
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/MetadataSchemaBuilder.java
@@ -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 {
+
+ /* 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;
+ }
+}
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/SiteBuilder.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/SiteBuilder.java
new file mode 100644
index 0000000000..3747675253
--- /dev/null
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/SiteBuilder.java
@@ -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 {
+
+ private Site site;
+
+ protected SiteBuilder(Context context) {
+ super(context);
+ }
+
+ @Override
+ protected void cleanup() throws Exception {
+ //Do nothing
+ }
+
+ @Override
+ protected DSpaceObjectService 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;
+ }
+}
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/BitstreamFormatMatcher.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/BitstreamFormatMatcher.java
new file mode 100644
index 0000000000..af5f633d2c
--- /dev/null
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/BitstreamFormatMatcher.java
@@ -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"))
+ );
+ }
+
+}
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/BitstreamMatcher.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/BitstreamMatcher.java
new file mode 100644
index 0000000000..0fa3263c50
--- /dev/null
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/BitstreamMatcher.java
@@ -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"))
+ );
+ }
+
+}
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/BitstreamMetadataMatcher.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/BitstreamMetadataMatcher.java
new file mode 100644
index 0000000000..4f53b4904e
--- /dev/null
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/BitstreamMetadataMatcher.java
@@ -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))
+ );
+ }
+}
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/CollectionMatcher.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/CollectionMatcher.java
new file mode 100644
index 0000000000..9cdb2003d3
--- /dev/null
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/CollectionMatcher.java
@@ -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()))
+ );
+ }
+
+}
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/CollectionMetadataMatcher.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/CollectionMetadataMatcher.java
new file mode 100644
index 0000000000..31e3bf758a
--- /dev/null
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/CollectionMetadataMatcher.java
@@ -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))
+ );
+ }
+}
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/CommunityMatcher.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/CommunityMatcher.java
new file mode 100644
index 0000000000..2be2020430
--- /dev/null
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/CommunityMatcher.java
@@ -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()))
+ );
+ }
+}
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/CommunityMetadataMatcher.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/CommunityMetadataMatcher.java
new file mode 100644
index 0000000000..d46c50798f
--- /dev/null
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/CommunityMetadataMatcher.java
@@ -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))
+ );
+ }
+}
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/EPersonMatcher.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/EPersonMatcher.java
new file mode 100644
index 0000000000..4c0c51c83f
--- /dev/null
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/EPersonMatcher.java
@@ -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"))
+ );
+ }
+}
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/EPersonMetadataMatcher.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/EPersonMetadataMatcher.java
new file mode 100644
index 0000000000..eacb840927
--- /dev/null
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/EPersonMetadataMatcher.java
@@ -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))
+ );
+ }
+
+}
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/GroupMatcher.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/GroupMatcher.java
new file mode 100644
index 0000000000..f77a9a5a7c
--- /dev/null
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/GroupMatcher.java
@@ -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"))
+ );
+ }
+
+
+}
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/MetadataFieldMatcher.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/MetadataFieldMatcher.java
new file mode 100644
index 0000000000..3834f4d741
--- /dev/null
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/MetadataFieldMatcher.java
@@ -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"))
+ );
+ }
+}
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/MetadataschemaMatcher.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/MetadataschemaMatcher.java
new file mode 100644
index 0000000000..6ba7b3318c
--- /dev/null
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/MetadataschemaMatcher.java
@@ -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"))
+ );
+ }
+}
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/SiteMatcher.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/SiteMatcher.java
new file mode 100644
index 0000000000..e21de1aef2
--- /dev/null
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/SiteMatcher.java
@@ -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()))
+
+ );
+ }
+}
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/security/EPersonRestAuthenticationProviderTest.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/security/EPersonRestAuthenticationProviderTest.java
index eba17371de..bedd5fc59a 100644
--- a/dspace-spring-rest/src/test/java/org/dspace/app/rest/security/EPersonRestAuthenticationProviderTest.java
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/security/EPersonRestAuthenticationProviderTest.java
@@ -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 {
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/security/jwt/EPersonClaimProviderTest.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/security/jwt/EPersonClaimProviderTest.java
index 4fd58fc2fc..10b4be654f 100644
--- a/dspace-spring-rest/src/test/java/org/dspace/app/rest/security/jwt/EPersonClaimProviderTest.java
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/security/jwt/EPersonClaimProviderTest.java
@@ -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 {
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/security/jwt/JWTTokenHandlerTest.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/security/jwt/JWTTokenHandlerTest.java
index 789dfafc88..3289edee1e 100644
--- a/dspace-spring-rest/src/test/java/org/dspace/app/rest/security/jwt/JWTTokenHandlerTest.java
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/security/jwt/JWTTokenHandlerTest.java
@@ -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 {
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/security/jwt/SpecialGroupClaimProviderTest.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/security/jwt/SpecialGroupClaimProviderTest.java
index a4d9130fd4..16ef24d5d4 100644
--- a/dspace-spring-rest/src/test/java/org/dspace/app/rest/security/jwt/SpecialGroupClaimProviderTest.java
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/security/jwt/SpecialGroupClaimProviderTest.java
@@ -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 {
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/test/AbstractDSpaceIntegrationTest.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/test/AbstractDSpaceIntegrationTest.java
index 6a896b201a..aea4d19d4f 100644
--- a/dspace-spring-rest/src/test/java/org/dspace/app/rest/test/AbstractDSpaceIntegrationTest.java
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/test/AbstractDSpaceIntegrationTest.java
@@ -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
diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/test/AbstractIntegrationTestWithDatabase.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/test/AbstractIntegrationTestWithDatabase.java
index 1d825dcb84..bf6a571643 100644
--- a/dspace-spring-rest/src/test/java/org/dspace/app/rest/test/AbstractIntegrationTestWithDatabase.java
+++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/test/AbstractIntegrationTestWithDatabase.java
@@ -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);
}