From 729b8cc9a8151fea8a9730c13fdc401e5f86d7b6 Mon Sep 17 00:00:00 2001 From: Raf Ponsaerts Date: Wed, 29 Nov 2017 10:03:29 +0100 Subject: [PATCH 01/42] [DS-3762] added tests for the eperson endpoint and created the logic to automatically delete objects that were build with the provided builders --- .../app/rest/BrowsesResourceControllerIT.java | 7 +- .../app/rest/EPersonRestRepositoryIT.java | 90 +++++++++++++++++++ .../rest/RootRestResourceControllerIT.java | 3 +- .../app/rest/builder/AbstractBuilder.java | 48 ++++++++-- .../app/rest/builder/CollectionBuilder.java | 12 ++- .../app/rest/builder/CommunityBuilder.java | 15 ++-- .../app/rest/builder/EPersonBuilder.java | 66 ++++++++++++++ .../dspace/app/rest/builder/GroupBuilder.java | 12 ++- .../dspace/app/rest/builder/ItemBuilder.java | 29 +++--- .../matcher/BrowseEntryResourceMatcher.java | 3 +- .../app/rest/matcher/BrowseIndexMatcher.java | 3 +- .../app/rest/matcher/EPersonMatcher.java | 29 ++++++ .../dspace/app/rest/matcher/ItemMatcher.java | 3 +- .../AbstractControllerIntegrationTest.java | 2 +- .../AbstractIntegrationTestWithDatabase.java | 6 +- .../DSpaceKernelContextCustomizerFactory.java | 2 +- 16 files changed, 278 insertions(+), 52 deletions(-) create mode 100644 dspace-spring-rest/src/test/java/org/dspace/app/rest/EPersonRestRepositoryIT.java create mode 100644 dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/EPersonBuilder.java create mode 100644 dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/EPersonMatcher.java 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..6bef045dec 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,7 @@ 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 Tom Desair (tom dot desair at atmire dot com) - * @author Raf Ponsaerts (raf dot ponsaerts at atmire dot com) + * @author Atmire NV (info at atmire dot com) */ public class BrowsesResourceControllerIT extends AbstractControllerIntegrationTest { @@ -174,7 +173,7 @@ public class BrowsesResourceControllerIT extends AbstractControllerIntegrationTe //We expect the content type to be "application/hal+json;charset=UTF-8" .andExpect(content().contentType(contentType)) .andExpect(jsonPath("$.page.size", is(20))) - //Check that there are indeed 3 different subjects + //Check that there are indeed 8 different subjects .andExpect(jsonPath("$.page.totalElements", is(3))) //Check the embedded resources and that they're sorted alphabetically //Check that the subject matches as expected @@ -379,7 +378,7 @@ public class BrowsesResourceControllerIT extends AbstractControllerIntegrationTe ; //** CLEANUP ** - GroupBuilder.cleaner().delete(internalGroup); +// GroupBuilder.cleaner().delete(internalGroup); } @Test 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..9941ca4ba0 --- /dev/null +++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/EPersonRestRepositoryIT.java @@ -0,0 +1,90 @@ +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 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.getID(), ePerson.getEmail()), + EPersonMatcher.matchDefaultTestEPerson() + ))); + } + + @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("$", Matchers.is( + EPersonMatcher.matchEPersonEntry(ePerson2.getID(), ePerson2.getEmail()) + ))) + .andExpect(jsonPath("$", Matchers.not( + Matchers.is( + EPersonMatcher.matchEPersonEntry(ePerson.getID(), ePerson.getEmail()) + ) + ))); + + } + + @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("$", Matchers.is( + EPersonMatcher.matchEPersonEntry(ePerson2.getID(), ePerson2.getEmail()) + ))) + .andExpect(jsonPath("$", Matchers.not( + Matchers.is( + EPersonMatcher.matchEPersonEntry(ePerson.getID(), ePerson.getEmail()) + ) + ))) + .andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/eperson/epersons/" + ePerson2.getID()))); + } +} 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..dd08f4c258 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,7 @@ import org.junit.Test; /** * Integration test for the {@link RootRestResourceController} * - * @author Tom Desair (tom dot desair at atmire dot com) - * @author Raf Ponsaerts (raf dot ponsaerts at atmire dot com) + * @author Atmire NV (info at atmire dot com) */ public class RootRestResourceControllerIT extends AbstractControllerIntegrationTest { 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..ac8fb847dd 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 @@ -7,6 +7,12 @@ */ package org.dspace.app.rest.builder; +import java.io.IOException; +import java.sql.SQLException; +import java.util.Date; +import java.util.LinkedList; +import java.util.List; + import org.apache.log4j.Logger; import org.dspace.authorize.AuthorizeException; import org.dspace.authorize.ResourcePolicy; @@ -37,8 +43,7 @@ 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) + * @author Atmire NV (info at atmire dot com) */ public abstract class AbstractBuilder { @@ -58,9 +63,15 @@ public abstract class AbstractBuilder { protected Context context; + private static List builders = new LinkedList<>(); /** log4j category */ private static final Logger log = Logger.getLogger(AbstractBuilder.class); + protected AbstractBuilder(Context context){ + this.context = context; + builders.add(this); + } + public static void init() { communityService = ContentServiceFactory.getInstance().getCommunityService(); collectionService = ContentServiceFactory.getInstance().getCollectionService(); @@ -92,6 +103,17 @@ public abstract class AbstractBuilder { indexingService = null; } + public static void cleanupObjects() throws Exception { + for (AbstractBuilder builder : builders) { + + builder.cleanup(); + + } + } + + protected abstract void cleanup() throws Exception; + + protected B handleException(final Exception e) { log.error(e.getMessage(), e); return null; @@ -148,12 +170,22 @@ public abstract class AbstractBuilder { 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 void delete(T dso) throws Exception { + Context c = null; + try { + c = new Context(); + c.turnOffAuthorisationSystem(); + T attachedDso = c.reloadEntity(dso); + if (attachedDso != null) { + getDsoService().delete(c, attachedDso); + } + + } finally { + if(c != null) { + c.complete(); + } } + + indexingService.commit(); } } 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..c200b3f4f9 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 @@ -16,19 +16,19 @@ import org.dspace.core.Context; /** * Builder to construct Collection objects * - * @author Tom Desair (tom dot desair at atmire dot com) - * @author Raf Ponsaerts (raf dot ponsaerts at atmire dot com) + * @author Atmire NV (info at atmire dot com) */ public class CollectionBuilder extends AbstractBuilder { 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); } @@ -60,6 +60,10 @@ public class CollectionBuilder extends AbstractBuilder { return collection; } + protected void cleanup() throws Exception { + delete(collection); + } + @Override protected DSpaceObjectService getDsoService() { 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..f393177ad7 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 @@ -15,19 +15,18 @@ import org.dspace.core.Context; /** * 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) + * @author Atmire NV (info at atmire dot com) */ public class CommunityBuilder extends AbstractBuilder { 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 +35,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); } @@ -70,6 +69,10 @@ public class CommunityBuilder extends AbstractBuilder { return community; } + protected void cleanup() throws Exception { + delete(community); + } + @Override protected DSpaceObjectService getDsoService() { 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..f1ce5334eb --- /dev/null +++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/EPersonBuilder.java @@ -0,0 +1,66 @@ +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 AbstractBuilder { + + private EPerson ePerson; + + protected EPersonBuilder(Context context){ + super(context); + } + + protected void cleanup() throws Exception { + delete(ePerson); + } + + protected DSpaceObjectService getDsoService() { + 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..d19b5f8e6e 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 @@ -15,19 +15,23 @@ import org.dspace.eperson.Group; /** * Builder to construct Group objects * - * @author Tom Desair (tom dot desair at atmire dot com) - * @author Raf Ponsaerts (raf dot ponsaerts at atmire dot com) + * @author Atmire NV (info at atmire dot com) */ public class GroupBuilder extends AbstractBuilder { 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); } 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..52db38655a 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 @@ -19,20 +19,20 @@ import org.dspace.eperson.Group; /** * Builder to construct Item objects * - * @author Tom Desair (tom dot desair at atmire dot com) - * @author Raf Ponsaerts (raf dot ponsaerts at atmire dot com) + * @author Atmire NV (info at atmire dot com) */ public class ItemBuilder extends AbstractBuilder { 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 +41,7 @@ public class ItemBuilder extends AbstractBuilder { try { workspaceItem = workspaceItemService.create(context, col, false); + item = workspaceItem.getItem(); } catch (Exception e) { return handleException(e); } @@ -49,28 +50,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 +82,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,6 +99,10 @@ public class ItemBuilder extends AbstractBuilder { } } + protected void cleanup() throws Exception { + delete(item); + } + @Override protected DSpaceObjectService getDsoService() { return itemService; diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/BrowseEntryResourceMatcher.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/BrowseEntryResourceMatcher.java index 4c5e798fcd..0004f912e9 100644 --- a/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/BrowseEntryResourceMatcher.java +++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/BrowseEntryResourceMatcher.java @@ -18,8 +18,7 @@ import org.hamcrest.Matcher; /** * Class to match JSON browse entries in ITs * - * @author Tom Desair (tom dot desair at atmire dot com) - * @author Raf Ponsaerts (raf dot ponsaerts at atmire dot com) + * @author Atmire NV (info at atmire dot com) */ public class BrowseEntryResourceMatcher { public static Matcher matchBrowseEntry(String value, int expectedCount) { diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/BrowseIndexMatcher.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/BrowseIndexMatcher.java index f3fa51d761..63d6423351 100644 --- a/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/BrowseIndexMatcher.java +++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/BrowseIndexMatcher.java @@ -21,8 +21,7 @@ import org.hamcrest.Matchers; /** * Utility class to construct a Matcher for a browse index * - * @author Tom Desair (tom dot desair at atmire dot com) - * @author Raf Ponsaerts (raf dot ponsaerts at atmire dot com) + * @author Atmire NV (info at atmire dot com) */ public class BrowseIndexMatcher { 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..13a2116d97 --- /dev/null +++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/EPersonMatcher.java @@ -0,0 +1,29 @@ +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 EPersonMatcher { + + public static Matcher matchEPersonEntry(UUID uuid, String name) { + return allOf( + hasJsonPath("$.uuid", is(uuid.toString())), + hasJsonPath("$.name", is(name)), + hasJsonPath("$.type", is("eperson")), + hasJsonPath("$._links.self.href", containsString("/api/eperson/epersons/" + uuid.toString())) + ); + } + + + public static Matcher matchDefaultTestEPerson() { + return allOf( + hasJsonPath("$.type", is("eperson")) + ); + } +} diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/ItemMatcher.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/ItemMatcher.java index 106e20540d..747318a267 100644 --- a/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/ItemMatcher.java +++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/ItemMatcher.java @@ -21,8 +21,7 @@ import org.hamcrest.Matcher; /** * Utility class to construct a Matcher for an item * - * @author Tom Desair (tom dot desair at atmire dot com) - * @author Raf Ponsaerts (raf dot ponsaerts at atmire dot com) + * @author Atmire NV (info at atmire dot com) */ public class ItemMatcher { diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/test/AbstractControllerIntegrationTest.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/test/AbstractControllerIntegrationTest.java index 0091e99a2e..8ed060db53 100644 --- a/dspace-spring-rest/src/test/java/org/dspace/app/rest/test/AbstractControllerIntegrationTest.java +++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/test/AbstractControllerIntegrationTest.java @@ -48,7 +48,7 @@ import org.springframework.web.context.WebApplicationContext; * Abstract controller integration test class that will take care of setting up the * environment to run the integration test * - * @author Tom Desair (tom dot desair at atmire dot com) + * @author Atmire NV (info at atmire dot com) */ @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = {Application.class, ApplicationConfig.class, WebSecurityConfiguration.class}) 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..3e8292f8eb 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 @@ -12,6 +12,7 @@ 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; @@ -146,16 +147,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); } diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/test/DSpaceKernelContextCustomizerFactory.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/test/DSpaceKernelContextCustomizerFactory.java index 798070915a..d6754c2bd6 100644 --- a/dspace-spring-rest/src/test/java/org/dspace/app/rest/test/DSpaceKernelContextCustomizerFactory.java +++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/test/DSpaceKernelContextCustomizerFactory.java @@ -17,7 +17,7 @@ import org.springframework.test.context.ContextCustomizerFactory; /** * Context customizer factory to set the parent context of our Spring Boot application in TEST mode * - * @author Tom Desair (tom dot desair at atmire dot com) + * @author Atmire NV (info at atmire dot com) */ public class DSpaceKernelContextCustomizerFactory implements ContextCustomizerFactory { From f6d3568eaadb826b48dd86635996b3aef214ee72 Mon Sep 17 00:00:00 2001 From: Raf Ponsaerts Date: Wed, 29 Nov 2017 13:16:07 +0100 Subject: [PATCH 02/42] [DS-3762] added pagination test and license headers --- .../app/rest/EPersonRestRepositoryIT.java | 40 +++++++++++++++++++ .../app/rest/builder/EPersonBuilder.java | 7 ++++ .../app/rest/matcher/EPersonMatcher.java | 7 ++++ 3 files changed, 54 insertions(+) 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 index 9941ca4ba0..fddce17b63 100644 --- 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 @@ -1,3 +1,10 @@ +/** + * 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; @@ -32,6 +39,39 @@ public class EPersonRestRepositoryIT extends AbstractControllerIntegrationTest{ ))); } + @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.getID(), ePerson.getEmail()) + ) + ))); + + 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.getID(), ePerson.getEmail()) + ))); + } + + @Test public void findOneTest() throws Exception{ context.turnOffAuthorisationSystem(); 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 index f1ce5334eb..f20be6ee2c 100644 --- 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 @@ -1,3 +1,10 @@ +/** + * 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; 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 index 13a2116d97..b8df989757 100644 --- 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 @@ -1,3 +1,10 @@ +/** + * 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; From 00638f1b681c3c349574a347f6455b5332d05db2 Mon Sep 17 00:00:00 2001 From: Raf Ponsaerts Date: Wed, 29 Nov 2017 15:54:40 +0100 Subject: [PATCH 03/42] [DS-3762] wrote test for metadatafield endpoint --- .../rest/MetadatafieldRestRepositoryIT.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 dspace-spring-rest/src/test/java/org/dspace/app/rest/MetadatafieldRestRepositoryIT.java 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..a04e2ac42e --- /dev/null +++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/MetadatafieldRestRepositoryIT.java @@ -0,0 +1,33 @@ +/** + * 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.test.AbstractControllerIntegrationTest; +import org.hamcrest.Matchers; +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; + +public class MetadatafieldRestRepositoryIT extends AbstractControllerIntegrationTest { + + @Test + public void findAll() throws Exception{ + + getClient().perform(get("/api/core/metadatafields")) + .andExpect(status().isOk()) + .andExpect(content().contentType(contentType)) + .andExpect(jsonPath("$._embedded.metadatafields[0].type", Matchers.is("metadatafield"))) + .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"))); + } +} From e2ff7fa2e8e68c2d510d314586b018e37dda99cd Mon Sep 17 00:00:00 2001 From: Raf Ponsaerts Date: Tue, 28 Nov 2017 09:22:34 +0100 Subject: [PATCH 04/42] [DS-3762] wrote all possible, accepting, tests for the bitstreams endpoint. See comments for failures --- .../app/rest/BitstreamRestRepositoryIT.java | 208 ++++++++++++++++++ .../app/rest/builder/AbstractBuilder.java | 13 +- .../app/rest/builder/BitstreamBuilder.java | 5 +- .../app/rest/matcher/BitstreamMatcher.java | 40 ++++ 4 files changed, 261 insertions(+), 5 deletions(-) create mode 100644 dspace-spring-rest/src/test/java/org/dspace/app/rest/BitstreamRestRepositoryIT.java create mode 100644 dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/BitstreamMatcher.java 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..178c5e4ac1 --- /dev/null +++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/BitstreamRestRepositoryIT.java @@ -0,0 +1,208 @@ +/** + * 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.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.hamcrest.Matchers; +import org.junit.Test; + +import java.io.InputStream; + +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 { + + @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 = new CommunityBuilder().createCommunity(context) + .withName("Parent Community") + .build(); + Community child1 = new CommunityBuilder().createSubCommunity(context, parentCommunity) + .withName("Sub Community") + .build(); + Collection col1 = new CollectionBuilder().createCollection(context, child1).withName("Collection 1").build(); + + //2. One public items that is readable by Anonymous + Item publicItem1 = new 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") + .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") + .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.getName(), bitstream.getID()), + BitstreamMatcher.matchBitstreamEntry(bitstream1.getName(), bitstream1.getID()) + ))) + + ; + } + + @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 = new CommunityBuilder().createCommunity(context) + .withName("Parent Community") + .build(); + Community child1 = new CommunityBuilder().createSubCommunity(context, parentCommunity) + .withName("Sub Community") + .build(); + Collection col1 = new CollectionBuilder().createCollection(context, child1).withName("Collection 1").build(); + + //2. One public items that is readable by Anonymous + Item publicItem1 = new 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") + .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") + .withMimeType("text/plain") + .build(); + } + + getClient().perform(get("/api/core/bitstreams/"+bitstream.getID())) + .andExpect(status().isOk()) + .andExpect(content().contentType(contentType)) + .andExpect(jsonPath("$", BitstreamMatcher.matchBitstreamEntry(bitstream.getName(), bitstream.getID()))) + .andExpect(jsonPath("$", not(BitstreamMatcher.matchBitstreamEntry(bitstream1.getName(), bitstream1.getID())))) + ; + + } + + @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 = new CommunityBuilder().createCommunity(context) + .withName("Parent Community") + .build(); + Community child1 = new CommunityBuilder().createSubCommunity(context, parentCommunity) + .withName("Sub Community") + .build(); + Collection col1 = new CollectionBuilder().createCollection(context, child1).withName("Collection 1").build(); + + //2. One public items that is readable by Anonymous + Item publicItem1 = new 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") + .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") + .withMimeType("text/plain") + .build(); + } + + getClient().perform(get("/api/core/bitstreams/"+bitstream.getID()+"/format")) + .andExpect(status().isOk()) + .andExpect(content().contentType(contentType)) + ; + + + getClient().perform(get("/api/core/bitstreams/"+bitstream.getID()+"/self")) + .andExpect(status().isOk()) + ; + + + //TODO This test fails in the current code. Authorization error +// getClient().perform(get("/api/core/bitstreams/"+bitstream.getID()+"/content")) +// .andExpect(status().isOk()) +// ; + + } + + //TODO /api/core/bitstreams/search does not yet exist (404 error) +} 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 ac8fb847dd..61e630ff45 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 @@ -22,7 +22,15 @@ 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.content.service.BitstreamFormatService; +import org.dspace.content.service.BitstreamService; +import org.dspace.content.service.BundleService; +import org.dspace.content.service.CollectionService; +import org.dspace.content.service.CommunityService; +import org.dspace.content.service.DSpaceObjectService; +import org.dspace.content.service.InstallItemService; +import org.dspace.content.service.ItemService; +import org.dspace.content.service.WorkspaceItemService; import org.dspace.core.Constants; import org.dspace.core.Context; import org.dspace.discovery.IndexingService; @@ -60,6 +68,7 @@ public abstract class AbstractBuilder { static AuthorizeService authorizeService; static ResourcePolicyService resourcePolicyService; static IndexingService indexingService; + static BitstreamFormatService bitstreamFormatService; protected Context context; @@ -86,6 +95,7 @@ public abstract class AbstractBuilder { authorizeService = AuthorizeServiceFactory.getInstance().getAuthorizeService(); resourcePolicyService = AuthorizeServiceFactory.getInstance().getResourcePolicyService(); indexingService = DSpaceServicesFactory.getInstance().getServiceManager().getServiceByName(IndexingService.class.getName(),IndexingService.class); + bitstreamFormatService = ContentServiceFactory.getInstance().getBitstreamFormatService(); } public static void destroy() { @@ -101,6 +111,7 @@ public abstract class AbstractBuilder { authorizeService = null; resourcePolicyService = null; indexingService = null; + bitstreamFormatService = null; } public static void cleanupObjects() throws Exception { 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..5eb6c9ee15 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 @@ -23,9 +23,6 @@ import org.dspace.eperson.Group; /** * 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{ @@ -127,4 +124,4 @@ public class BitstreamBuilder extends AbstractBuilder{ protected DSpaceObjectService getDsoService() { return bitstreamService; } -} +} \ No newline at end of file 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..592d4d3e39 --- /dev/null +++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/BitstreamMatcher.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.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 BitstreamMatcher { + + public static Matcher matchBitstreamEntry(String name, UUID uuid) { + return allOf( + //Check core metadata (the JSON Path expression evaluates to a collection so we have to use contains) + hasJsonPath("$.uuid", is(uuid.toString())), + hasJsonPath("$.name", is(name)), + //Check links + matchBitstreamLinks(uuid) + ); + } + + private static Matcher 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")) + ); + } + + +} From 37a4e05b77635319a3b6d5557748663a90fdf392 Mon Sep 17 00:00:00 2001 From: Raf Ponsaerts Date: Wed, 29 Nov 2017 12:02:05 +0100 Subject: [PATCH 05/42] [DS-3762] added pagination test for bitstreams endpoint --- .../app/rest/BitstreamRestRepositoryIT.java | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) 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 index 178c5e4ac1..a5cd901faa 100644 --- 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 @@ -87,6 +87,82 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest ; } + @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 = new CommunityBuilder().createCommunity(context) + .withName("Parent Community") + .build(); + Community child1 = new CommunityBuilder().createSubCommunity(context, parentCommunity) + .withName("Sub Community") + .build(); + Collection col1 = new CollectionBuilder().createCollection(context, child1).withName("Collection 1").build(); + + //2. One public items that is readable by Anonymous + Item publicItem1 = new 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") + .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") + .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.getName(), bitstream.getID()) + ))) + .andExpect(jsonPath("$._embedded.bitstreams", Matchers.not( + Matchers.contains( + BitstreamMatcher.matchBitstreamEntry(bitstream1.getName(), bitstream1.getID()) + ) + ))) + + ; + + 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.getName(), bitstream1.getID()) + ))) + .andExpect(jsonPath("$._embedded.bitstreams", Matchers.not( + Matchers.contains( + BitstreamMatcher.matchBitstreamEntry(bitstream.getName(), bitstream.getID()) + ) + ))) + + ; + } + @Test public void findOneBitstreamTest() throws Exception { From 3c408de9c5296296353c513c6ea30c4a29a0da37 Mon Sep 17 00:00:00 2001 From: Raf Ponsaerts Date: Tue, 28 Nov 2017 10:57:10 +0100 Subject: [PATCH 06/42] [DS-3762] Wrote tests for the collection endpoint. /api/core/collections/search is not implemented yet and thus not tested --- .../app/rest/CollectionRestRepositoryIT.java | 133 ++++++++++++++++++ .../app/rest/builder/CollectionBuilder.java | 22 ++- .../app/rest/matcher/CollectionMatcher.java | 38 +++++ 3 files changed, 192 insertions(+), 1 deletion(-) create mode 100644 dspace-spring-rest/src/test/java/org/dspace/app/rest/CollectionRestRepositoryIT.java create mode 100644 dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/CollectionMatcher.java 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..f0b26eee67 --- /dev/null +++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/CollectionRestRepositoryIT.java @@ -0,0 +1,133 @@ +/** + * 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.content.Collection; +import org.dspace.content.Community; +import org.hamcrest.Matchers; +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; + +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 = new CommunityBuilder().createCommunity(context) + .withName("Parent Community") + .build(); + Community child1 = new CommunityBuilder().createSubCommunity(context, parentCommunity) + .withName("Sub Community") + .build(); + Community child2 = new CommunityBuilder().createSubCommunity(context, parentCommunity) + .withName("Sub Community Two") + .build(); + Collection col1 = new CollectionBuilder().createCollection(context, child1).withName("Collection 1").build(); + Collection col2 = new 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 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 = new CommunityBuilder().createCommunity(context) + .withName("Parent Community") + .build(); + Community child1 = new CommunityBuilder().createSubCommunity(context, parentCommunity) + .withName("Sub Community") + .build(); + Community child2 = new CommunityBuilder().createSubCommunity(context, parentCommunity) + .withName("Sub Community Two") + .build(); + Collection col1 = new CollectionBuilder().createCollection(context, child1).withName("Collection 1").build(); + Collection col2 = new 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("$", Matchers.is( + CollectionMatcher.matchCollectionEntry(col1.getName(), col1.getID(), col1.getHandle()) + ))) + .andExpect(jsonPath("$", Matchers.not( + Matchers.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 = new CommunityBuilder().createCommunity(context) + .withName("Parent Community") + .build(); + Community child1 = new CommunityBuilder().createSubCommunity(context, parentCommunity) + .withName("Sub Community") + .build(); + Community child2 = new CommunityBuilder().createSubCommunity(context, parentCommunity) + .withName("Sub Community Two") + .build(); + Collection col1 = new CollectionBuilder().createCollection(context, child1).withName("Collection 1").withLogo("TestingContentForLogo").build(); + Collection col2 = new 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("$", Matchers.is( + CollectionMatcher.matchCollectionEntry(col1.getName(), col1.getID(), col1.getHandle()) + ))) + .andExpect(jsonPath("$", Matchers.not( + Matchers.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"))) + ; + + } + + //TODO Search doesn't exist yet for this endpoint. Write tests when it does. +} 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 c200b3f4f9..07ae706e29 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 @@ -39,7 +48,6 @@ public class CollectionBuilder extends AbstractBuilder { } catch (Exception e) { return handleException(e); } - return this; } @@ -47,6 +55,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 { 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..d9775aaada --- /dev/null +++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/CollectionMatcher.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 CollectionMatcher { + + public static Matcher 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")), + matchLinks(uuid) + ); + } + + public static Matcher 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())) + ); + } + +} From 13c3da82f97c78a37785a4d8b878218d01c8c428 Mon Sep 17 00:00:00 2001 From: Raf Ponsaerts Date: Wed, 29 Nov 2017 13:00:03 +0100 Subject: [PATCH 07/42] [DS-3762] added pagination test for the collection endpoint --- .../app/rest/CollectionRestRepositoryIT.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) 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 index f0b26eee67..b98ea1e6ec 100644 --- 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 @@ -54,6 +54,56 @@ public class CollectionRestRepositoryIT extends AbstractControllerIntegrationTes ))); } + @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 = new CommunityBuilder().createCommunity(context) + .withName("Parent Community") + .build(); + Community child1 = new CommunityBuilder().createSubCommunity(context, parentCommunity) + .withName("Sub Community") + .build(); + Community child2 = new CommunityBuilder().createSubCommunity(context, parentCommunity) + .withName("Sub Community Two") + .build(); + Collection col1 = new CollectionBuilder().createCollection(context, child1).withName("Collection 1").build(); + Collection col2 = new 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 { From 043882d07936f2ad1d05b9afb5e1919618f42790 Mon Sep 17 00:00:00 2001 From: Raf Ponsaerts Date: Tue, 28 Nov 2017 13:44:58 +0100 Subject: [PATCH 08/42] [DS-3762] wrote tests for the community endpoint, the /api/core/communities/search is still missing as there is no implementation for it --- .../app/rest/CommunityRestRepositoryIT.java | 131 ++++++++++++++++++ .../app/rest/builder/CommunityBuilder.java | 15 ++ .../app/rest/matcher/CommunityMatcher.java | 40 ++++++ 3 files changed, 186 insertions(+) create mode 100644 dspace-spring-rest/src/test/java/org/dspace/app/rest/CommunityRestRepositoryIT.java create mode 100644 dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/CommunityMatcher.java 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..1413a4fd59 --- /dev/null +++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/CommunityRestRepositoryIT.java @@ -0,0 +1,131 @@ +/** + * 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.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; + +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 = new CommunityBuilder().createCommunity(context) + .withName("Parent Community") + .build(); + Community child1 = new CommunityBuilder().createSubCommunity(context, parentCommunity) + .withName("Sub Community") + .build(); + Collection col1 = new 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"))) + ; + } + + @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 = new CommunityBuilder().createCommunity(context) + .withName("Parent Community") + .build(); + Community child1 = new CommunityBuilder().createSubCommunity(context, parentCommunity) + .withName("Sub Community") + .build(); + Collection col1 = new 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 = new CommunityBuilder().createCommunity(context) + .withName("Parent Community") + .withLogo("ThisIsSomeDummyText") + .build(); + Community child1 = new CommunityBuilder().createSubCommunity(context, parentCommunity) + .withName("Sub Community") + .build(); + Collection col1 = new 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)); + } + + //TODO /api/core/communities/search does not yet exist, write tests when it does + +} 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 f393177ad7..da30d7ac32 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,11 +7,19 @@ */ 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.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 * @@ -55,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 { 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..adef65e8f7 --- /dev/null +++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/CommunityMatcher.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.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 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")), + matchLinks(uuid) + ); + } + + + public static Matcher 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())) + ); + } +} From dd3df70b0d3c8ab95552bf8f3d83dfde2ff1be4c Mon Sep 17 00:00:00 2001 From: Raf Ponsaerts Date: Wed, 29 Nov 2017 13:04:10 +0100 Subject: [PATCH 09/42] [DS-3762] added pagination test for the community endpoint --- .../app/rest/CommunityRestRepositoryIT.java | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) 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 index 1413a4fd59..87bf9924c0 100644 --- 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 @@ -49,6 +49,53 @@ public class CommunityRestRepositoryIT extends AbstractControllerIntegrationTest ; } + @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 = new CommunityBuilder().createCommunity(context) + .withName("Parent Community") + .build(); + Community child1 = new CommunityBuilder().createSubCommunity(context, parentCommunity) + .withName("Sub Community") + .build(); + Collection col1 = new 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"))) + ; + } + @Test public void findOneTest() throws Exception{ //We turn off the authorization system in order to create the structure as defined below From 6cfdcd3923f26fc88e455abaee3ce2e140587b9f Mon Sep 17 00:00:00 2001 From: Raf Ponsaerts Date: Wed, 29 Nov 2017 11:31:38 +0100 Subject: [PATCH 10/42] [DS-3762] wrote tests for the items endpoint --- .../dspace/app/rest/ItemRestRepositoryIT.java | 277 ++++++++++++++++++ .../app/rest/builder/BitstreamBuilder.java | 12 +- 2 files changed, 285 insertions(+), 4 deletions(-) create mode 100644 dspace-spring-rest/src/test/java/org/dspace/app/rest/ItemRestRepositoryIT.java 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..936f8d3afa --- /dev/null +++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/ItemRestRepositoryIT.java @@ -0,0 +1,277 @@ +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 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 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"))) + ; + } + + @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"))) + ; + } + + @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(); + + //TODO Add bitstream to publicitem1 + + //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()) + ; + } + +} 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 5eb6c9ee15..3d7f2ede93 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 @@ -32,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); } @@ -63,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); @@ -121,6 +121,10 @@ public class BitstreamBuilder extends AbstractBuilder{ return bitstream; } + protected void cleanup() throws Exception { + delete(bitstream); + } + protected DSpaceObjectService getDsoService() { return bitstreamService; } From d2a7824ebf04f496cb0b367ecb3d4e9520c3c623 Mon Sep 17 00:00:00 2001 From: Raf Ponsaerts Date: Wed, 29 Nov 2017 13:44:03 +0100 Subject: [PATCH 11/42] [DS-3762] added license headers --- .../java/org/dspace/app/rest/ItemRestRepositoryIT.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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 index 936f8d3afa..58fd8e647c 100644 --- 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 @@ -1,3 +1,10 @@ +/** + * 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; @@ -231,8 +238,6 @@ public class ItemRestRepositoryIT extends AbstractControllerIntegrationTest { .withSubject("AnotherTest").withSubject("TestingForMore").withSubject("ExtraEntry") .build(); - //TODO Add bitstream to publicitem1 - //Add a bitstream to an item String bitstreamContent = "ThisIsSomeDummyText"; Bitstream bitstream1 = null; From 364b940ac2d5c0fc15f580a3021d8f33422244a9 Mon Sep 17 00:00:00 2001 From: Tom Desair Date: Thu, 30 Nov 2017 13:31:29 +0100 Subject: [PATCH 12/42] DS-3762: Fixed and added bitstream tests --- .../main/java/org/dspace/core/Context.java | 9 +- .../app/rest/BitstreamRestRepositoryIT.java | 112 ++++++++++++++---- .../app/rest/CollectionRestRepositoryIT.java | 40 +++---- .../app/rest/CommunityRestRepositoryIT.java | 28 +++-- .../app/rest/builder/AbstractBuilder.java | 11 +- .../app/rest/builder/BitstreamBuilder.java | 9 ++ 6 files changed, 145 insertions(+), 64 deletions(-) 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 f8340353d1..b25b30306a 100644 --- a/dspace-api/src/main/java/org/dspace/core/Context.java +++ b/dspace-api/src/main/java/org/dspace/core/Context.java @@ -42,7 +42,7 @@ import java.util.*; * * @version $Revision$ */ -public class Context +public class Context implements AutoCloseable { private static final Logger log = Logger.getLogger(Context.class); @@ -564,6 +564,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-spring-rest/src/test/java/org/dspace/app/rest/BitstreamRestRepositoryIT.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/BitstreamRestRepositoryIT.java index a5cd901faa..d99251145e 100644 --- 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 @@ -19,11 +19,16 @@ 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 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; @@ -32,6 +37,9 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. 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 @@ -39,16 +47,16 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest //** GIVEN ** //1. A community-collection structure with one parent community with sub-community and one collection. - parentCommunity = new CommunityBuilder().createCommunity(context) + parentCommunity = CommunityBuilder.createCommunity(context) .withName("Parent Community") .build(); - Community child1 = new CommunityBuilder().createSubCommunity(context, parentCommunity) + Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity) .withName("Sub Community") .build(); - Collection col1 = new CollectionBuilder().createCollection(context, child1).withName("Collection 1").build(); + Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build(); //2. One public items that is readable by Anonymous - Item publicItem1 = new ItemBuilder().createItem(context, col1) + Item publicItem1 = ItemBuilder.createItem(context, col1) .withTitle("Test") .withIssueDate("2010-10-17") .withAuthor("Smith, Donald") @@ -79,7 +87,7 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest getClient().perform(get("/api/core/bitstreams/")) .andExpect(status().isOk()) .andExpect(content().contentType(contentType)) - .andExpect(jsonPath("$._embedded.bitstreams", Matchers.containsInAnyOrder( + .andExpect(jsonPath("$._embedded.bitstreams", containsInAnyOrder( BitstreamMatcher.matchBitstreamEntry(bitstream.getName(), bitstream.getID()), BitstreamMatcher.matchBitstreamEntry(bitstream1.getName(), bitstream1.getID()) ))) @@ -94,16 +102,16 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest //** GIVEN ** //1. A community-collection structure with one parent community with sub-community and one collection. - parentCommunity = new CommunityBuilder().createCommunity(context) + parentCommunity = CommunityBuilder.createCommunity(context) .withName("Parent Community") .build(); - Community child1 = new CommunityBuilder().createSubCommunity(context, parentCommunity) + Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity) .withName("Sub Community") .build(); - Collection col1 = new CollectionBuilder().createCollection(context, child1).withName("Collection 1").build(); + Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build(); //2. One public items that is readable by Anonymous - Item publicItem1 = new ItemBuilder().createItem(context, col1) + Item publicItem1 = ItemBuilder.createItem(context, col1) .withTitle("Test") .withIssueDate("2010-10-17") .withAuthor("Smith, Donald") @@ -135,11 +143,11 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest .param("size","1")) .andExpect(status().isOk()) .andExpect(content().contentType(contentType)) - .andExpect(jsonPath("$._embedded.bitstreams", Matchers.contains( + .andExpect(jsonPath("$._embedded.bitstreams", contains( BitstreamMatcher.matchBitstreamEntry(bitstream.getName(), bitstream.getID()) ))) .andExpect(jsonPath("$._embedded.bitstreams", Matchers.not( - Matchers.contains( + contains( BitstreamMatcher.matchBitstreamEntry(bitstream1.getName(), bitstream1.getID()) ) ))) @@ -151,11 +159,11 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest .param("page", "1")) .andExpect(status().isOk()) .andExpect(content().contentType(contentType)) - .andExpect(jsonPath("$._embedded.bitstreams", Matchers.contains( + .andExpect(jsonPath("$._embedded.bitstreams", contains( BitstreamMatcher.matchBitstreamEntry(bitstream1.getName(), bitstream1.getID()) ))) .andExpect(jsonPath("$._embedded.bitstreams", Matchers.not( - Matchers.contains( + contains( BitstreamMatcher.matchBitstreamEntry(bitstream.getName(), bitstream.getID()) ) ))) @@ -163,6 +171,66 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest ; } + //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.getName(), bitstream.getID()) + ))) + + ; + } + @Test public void findOneBitstreamTest() throws Exception { @@ -171,16 +239,16 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest //** GIVEN ** //1. A community-collection structure with one parent community with sub-community and one collection. - parentCommunity = new CommunityBuilder().createCommunity(context) + parentCommunity = CommunityBuilder.createCommunity(context) .withName("Parent Community") .build(); - Community child1 = new CommunityBuilder().createSubCommunity(context, parentCommunity) + Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity) .withName("Sub Community") .build(); - Collection col1 = new CollectionBuilder().createCollection(context, child1).withName("Collection 1").build(); + Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build(); //2. One public items that is readable by Anonymous - Item publicItem1 = new ItemBuilder().createItem(context, col1) + Item publicItem1 = ItemBuilder.createItem(context, col1) .withTitle("Test") .withIssueDate("2010-10-17") .withAuthor("Smith, Donald") @@ -225,16 +293,16 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest //** GIVEN ** //1. A community-collection structure with one parent community with sub-community and one collection. - parentCommunity = new CommunityBuilder().createCommunity(context) + parentCommunity = CommunityBuilder.createCommunity(context) .withName("Parent Community") .build(); - Community child1 = new CommunityBuilder().createSubCommunity(context, parentCommunity) + Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity) .withName("Sub Community") .build(); - Collection col1 = new CollectionBuilder().createCollection(context, child1).withName("Collection 1").build(); + Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build(); //2. One public items that is readable by Anonymous - Item publicItem1 = new ItemBuilder().createItem(context, col1) + Item publicItem1 = ItemBuilder.createItem(context, col1) .withTitle("Test") .withIssueDate("2010-10-17") .withAuthor("Smith, Donald") @@ -265,6 +333,7 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest getClient().perform(get("/api/core/bitstreams/"+bitstream.getID()+"/format")) .andExpect(status().isOk()) .andExpect(content().contentType(contentType)) + //TODO add matcher on bitstream format ; @@ -280,5 +349,4 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest } - //TODO /api/core/bitstreams/search does not yet exist (404 error) } 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 index b98ea1e6ec..0fb2d0da09 100644 --- 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 @@ -31,17 +31,17 @@ public class CollectionRestRepositoryIT extends AbstractControllerIntegrationTes context.turnOffAuthorisationSystem(); //** GIVEN ** //1. A community-collection structure with one parent community with sub-community and one collection. - parentCommunity = new CommunityBuilder().createCommunity(context) + parentCommunity = CommunityBuilder.createCommunity(context) .withName("Parent Community") .build(); - Community child1 = new CommunityBuilder().createSubCommunity(context, parentCommunity) + Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity) .withName("Sub Community") .build(); - Community child2 = new CommunityBuilder().createSubCommunity(context, parentCommunity) + Community child2 = CommunityBuilder.createSubCommunity(context, parentCommunity) .withName("Sub Community Two") .build(); - Collection col1 = new CollectionBuilder().createCollection(context, child1).withName("Collection 1").build(); - Collection col2 = new CollectionBuilder().createCollection(context, child2).withName("Collection 2").build(); + Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build(); + Collection col2 = CollectionBuilder.createCollection(context, child2).withName("Collection 2").build(); @@ -61,17 +61,17 @@ public class CollectionRestRepositoryIT extends AbstractControllerIntegrationTes context.turnOffAuthorisationSystem(); //** GIVEN ** //1. A community-collection structure with one parent community with sub-community and one collection. - parentCommunity = new CommunityBuilder().createCommunity(context) + parentCommunity = CommunityBuilder.createCommunity(context) .withName("Parent Community") .build(); - Community child1 = new CommunityBuilder().createSubCommunity(context, parentCommunity) + Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity) .withName("Sub Community") .build(); - Community child2 = new CommunityBuilder().createSubCommunity(context, parentCommunity) + Community child2 = CommunityBuilder.createSubCommunity(context, parentCommunity) .withName("Sub Community Two") .build(); - Collection col1 = new CollectionBuilder().createCollection(context, child1).withName("Collection 1").build(); - Collection col2 = new CollectionBuilder().createCollection(context, child2).withName("Collection 2").build(); + Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build(); + Collection col2 = CollectionBuilder.createCollection(context, child2).withName("Collection 2").build(); @@ -111,17 +111,17 @@ public class CollectionRestRepositoryIT extends AbstractControllerIntegrationTes context.turnOffAuthorisationSystem(); //** GIVEN ** //1. A community-collection structure with one parent community with sub-community and one collection. - parentCommunity = new CommunityBuilder().createCommunity(context) + parentCommunity = CommunityBuilder.createCommunity(context) .withName("Parent Community") .build(); - Community child1 = new CommunityBuilder().createSubCommunity(context, parentCommunity) + Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity) .withName("Sub Community") .build(); - Community child2 = new CommunityBuilder().createSubCommunity(context, parentCommunity) + Community child2 = CommunityBuilder.createSubCommunity(context, parentCommunity) .withName("Sub Community Two") .build(); - Collection col1 = new CollectionBuilder().createCollection(context, child1).withName("Collection 1").build(); - Collection col2 = new CollectionBuilder().createCollection(context, child2).withName("Collection 2").build(); + Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build(); + Collection col2 = CollectionBuilder.createCollection(context, child2).withName("Collection 2").build(); @@ -144,17 +144,17 @@ public class CollectionRestRepositoryIT extends AbstractControllerIntegrationTes context.turnOffAuthorisationSystem(); //** GIVEN ** //1. A community-collection structure with one parent community with sub-community and one collection. - parentCommunity = new CommunityBuilder().createCommunity(context) + parentCommunity = CommunityBuilder.createCommunity(context) .withName("Parent Community") .build(); - Community child1 = new CommunityBuilder().createSubCommunity(context, parentCommunity) + Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity) .withName("Sub Community") .build(); - Community child2 = new CommunityBuilder().createSubCommunity(context, parentCommunity) + Community child2 = CommunityBuilder.createSubCommunity(context, parentCommunity) .withName("Sub Community Two") .build(); - Collection col1 = new CollectionBuilder().createCollection(context, child1).withName("Collection 1").withLogo("TestingContentForLogo").build(); - Collection col2 = new CollectionBuilder().createCollection(context, child2).withName("Collection 2").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()) 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 index 87bf9924c0..79d628e540 100644 --- 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 @@ -30,13 +30,13 @@ public class CommunityRestRepositoryIT extends AbstractControllerIntegrationTest //** GIVEN ** //1. A community-collection structure with one parent community with sub-community and one collection. - parentCommunity = new CommunityBuilder().createCommunity(context) + parentCommunity = CommunityBuilder.createCommunity(context) .withName("Parent Community") .build(); - Community child1 = new CommunityBuilder().createSubCommunity(context, parentCommunity) + Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity) .withName("Sub Community") .build(); - Collection col1 = new CollectionBuilder().createCollection(context, child1).withName("Collection 1").build(); + Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build(); getClient().perform(get("/api/core/communities")) .andExpect(status().isOk()) @@ -56,13 +56,13 @@ public class CommunityRestRepositoryIT extends AbstractControllerIntegrationTest //** GIVEN ** //1. A community-collection structure with one parent community with sub-community and one collection. - parentCommunity = new CommunityBuilder().createCommunity(context) + parentCommunity = CommunityBuilder.createCommunity(context) .withName("Parent Community") .build(); - Community child1 = new CommunityBuilder().createSubCommunity(context, parentCommunity) + Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity) .withName("Sub Community") .build(); - Collection col1 = new CollectionBuilder().createCollection(context, child1).withName("Collection 1").build(); + Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build(); getClient().perform(get("/api/core/communities") .param("size", "1")) @@ -103,13 +103,13 @@ public class CommunityRestRepositoryIT extends AbstractControllerIntegrationTest //** GIVEN ** //1. A community-collection structure with one parent community with sub-community and one collection. - parentCommunity = new CommunityBuilder().createCommunity(context) + parentCommunity = CommunityBuilder.createCommunity(context) .withName("Parent Community") .build(); - Community child1 = new CommunityBuilder().createSubCommunity(context, parentCommunity) + Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity) .withName("Sub Community") .build(); - Collection col1 = new CollectionBuilder().createCollection(context, child1).withName("Collection 1").build(); + Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build(); getClient().perform(get("/api/core/communities/" + parentCommunity.getID().toString())) .andExpect(status().isOk()) @@ -133,14 +133,14 @@ public class CommunityRestRepositoryIT extends AbstractControllerIntegrationTest //** GIVEN ** //1. A community-collection structure with one parent community with sub-community and one collection. - parentCommunity = new CommunityBuilder().createCommunity(context) + parentCommunity = CommunityBuilder.createCommunity(context) .withName("Parent Community") .withLogo("ThisIsSomeDummyText") .build(); - Community child1 = new CommunityBuilder().createSubCommunity(context, parentCommunity) + Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity) .withName("Sub Community") .build(); - Collection col1 = new CollectionBuilder().createCollection(context, child1).withName("Collection 1").build(); + Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build(); getClient().perform(get("/api/core/communities/" + parentCommunity.getID().toString())) .andExpect(status().isOk()) @@ -173,6 +173,8 @@ public class CommunityRestRepositoryIT extends AbstractControllerIntegrationTest .andExpect(content().contentType(contentType)); } - //TODO /api/core/communities/search does not yet exist, write tests when it does + //TODO /api/core/communities/search/top + + //TODO /api/core/communities/search/subCommunities } 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 61e630ff45..2425a71b1f 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 @@ -182,19 +182,14 @@ public abstract class AbstractBuilder { public abstract T build(); public void delete(T dso) throws Exception { - Context c = null; - try { - c = new Context(); + + try(Context c = new Context()) { c.turnOffAuthorisationSystem(); T attachedDso = c.reloadEntity(dso); if (attachedDso != null) { getDsoService().delete(c, attachedDso); } - - } finally { - if(c != null) { - c.complete(); - } + 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 3d7f2ede93..f3ff7c12a0 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 @@ -123,6 +123,15 @@ public class BitstreamBuilder extends AbstractBuilder{ 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 getDsoService() { From e4b164dc9c45a550be2254b92fc6c1ce90915dc5 Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Fri, 1 Dec 2017 16:30:20 +0100 Subject: [PATCH 13/42] [DS-3762] Tests for api/eperson/groups endpoint --- .../app/rest/GroupRestRepositoryIT.java | 101 ++++++++++++++++++ .../dspace/app/rest/matcher/GroupMatcher.java | 31 ++++++ 2 files changed, 132 insertions(+) create mode 100644 dspace-spring-rest/src/test/java/org/dspace/app/rest/GroupRestRepositoryIT.java create mode 100644 dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/GroupMatcher.java 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..2b71b2813e --- /dev/null +++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/GroupRestRepositoryIT.java @@ -0,0 +1,101 @@ +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 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.*; + +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()))); + } + +} 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..a327614fcc --- /dev/null +++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/GroupMatcher.java @@ -0,0 +1,31 @@ +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 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 matchGroupWithName(String name) { + return allOf( + hasJsonPath("$.name", is(name)), + hasJsonPath("$.type", is("group")) + ); + } + + +} From 20a3b03b4f4b4946d91f934f70e5ace3905d8a28 Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Mon, 4 Dec 2017 09:21:30 +0100 Subject: [PATCH 14/42] [DS-3762] Commit before generalising AbstractBuilder to also include the "DSpaceCRUDService" --- .../rest/BitstreamFormatRestRepositoryIT.java | 57 ++++++++++++++ .../app/rest/GroupRestRepositoryIT.java | 1 + .../app/rest/builder/AbstractCRUDBuilder.java | 77 +++++++++++++++++++ .../rest/builder/BitstreamFormatBuilder.java | 77 +++++++++++++++++++ .../rest/matcher/BitstreamFormatMatcher.java | 22 ++++++ .../test/AbstractDSpaceIntegrationTest.java | 17 ++-- .../AbstractIntegrationTestWithDatabase.java | 11 +-- 7 files changed, 250 insertions(+), 12 deletions(-) create mode 100644 dspace-spring-rest/src/test/java/org/dspace/app/rest/BitstreamFormatRestRepositoryIT.java create mode 100644 dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/AbstractCRUDBuilder.java create mode 100644 dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/BitstreamFormatBuilder.java create mode 100644 dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/BitstreamFormatMatcher.java 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..da9ec546d3 --- /dev/null +++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/BitstreamFormatRestRepositoryIT.java @@ -0,0 +1,57 @@ +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.*; + + +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 + 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(1))) + .andExpect(jsonPath("$._embedded.bitstreamformats", Matchers.contains( + BitstreamFormatMatcher.matchBitstreamFormat(bitstreamFormat.getMIMEType(), bitstreamFormat.getDescription()) + ))) + ; + + } + + @Test + @Ignore + public void findOne() throws Exception { + getClient().perform(get("/api/core/bitstreamformats/1")) + .andExpect(status().isOk()) + .andExpect(content().contentType(contentType)) + .andExpect(jsonPath("$._links.self.href", startsWith(REST_SERVER_URL))) + .andExpect(jsonPath("$._links.self.href", endsWith("/api/core/bitstreamformats/1"))) + ; + } +} 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 index 2b71b2813e..6f981d9121 100644 --- 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 @@ -68,6 +68,7 @@ public class GroupRestRepositoryIT extends AbstractControllerIntegrationTest { //The status has to be 200 OK .andExpect(status().isOk()) .andExpect(content().contentType(contentType)) + .andExpect(jsonPath("$.page.totalElements", is(3))); } 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..742d5b902c --- /dev/null +++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/AbstractCRUDBuilder.java @@ -0,0 +1,77 @@ +package org.dspace.app.rest.builder; + +import org.apache.log4j.Logger; +import org.dspace.authorize.factory.AuthorizeServiceFactory; +import org.dspace.authorize.service.AuthorizeService; +import org.dspace.content.factory.ContentServiceFactory; +import org.dspace.content.service.BitstreamFormatService; +import org.dspace.core.Context; +import org.dspace.core.ReloadableEntity; +import org.dspace.discovery.IndexingService; +import org.dspace.service.DSpaceCRUDService; +import org.dspace.services.factory.DSpaceServicesFactory; + +import java.util.LinkedList; +import java.util.List; + +/** + * Created by jonas - jonas@atmire.com on 04/12/17. + */ +public abstract class AbstractCRUDBuilder { + + static AuthorizeService authorizeService; + static IndexingService indexingService; + static BitstreamFormatService bitstreamFormatService; + + private static List builders = new LinkedList<>(); + /** log4j category */ + private static final Logger log = Logger.getLogger(AbstractBuilder.class); + + protected Context context; + + + protected AbstractCRUDBuilder(Context context){ + this.context = context; + builders.add(this); + } + + public static void init() { + authorizeService = AuthorizeServiceFactory.getInstance().getAuthorizeService(); + indexingService = DSpaceServicesFactory.getInstance().getServiceManager().getServiceByName(IndexingService.class.getName(),IndexingService.class); + bitstreamFormatService = ContentServiceFactory.getInstance().getBitstreamFormatService(); + + } + + public static void destroy(){ + authorizeService = null; + indexingService= null; + bitstreamFormatService=null; + } + + + public static void cleanupObjects() throws Exception { + for (AbstractCRUDBuilder builder : builders) { + + builder.cleanup(); + } + } + protected abstract void cleanup() throws Exception; + + protected abstract DSpaceCRUDService getCRUDService(); + + 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) { + getCRUDService().delete(c, attachedDso); + } + c.complete(); + } + + indexingService.commit(); + } +} 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..7d823babb3 --- /dev/null +++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/BitstreamFormatBuilder.java @@ -0,0 +1,77 @@ +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 getCRUDService() { + 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/matcher/BitstreamFormatMatcher.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/BitstreamFormatMatcher.java new file mode 100644 index 0000000000..58007c70c6 --- /dev/null +++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/BitstreamFormatMatcher.java @@ -0,0 +1,22 @@ +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; + +/** + * Created by jonas - jonas@atmire.com on 01/12/17. + */ +public class BitstreamFormatMatcher { + + public static Matcher matchBitstreamFormat(String mimetype, String description) { + return allOf( + hasJsonPath("$.mimetype", is(mimetype)), + hasJsonPath("$.description", is(description)), + hasJsonPath("$.type", is("bitstreamformat")) + ); + } + +} 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..83e60873dc 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,13 @@ */ 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.app.rest.builder.AbstractCRUDBuilder; +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 +21,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 @@ -71,6 +72,7 @@ public class AbstractDSpaceIntegrationTest kernelImpl.start(getDspaceDir()); // init the kernel } AbstractBuilder.init(); + AbstractCRUDBuilder.init(); } catch (IOException ex) { @@ -90,6 +92,7 @@ public class AbstractDSpaceIntegrationTest testProps = null; AbstractBuilder.destroy(); + AbstractCRUDBuilder.destroy(); //Also clear out the kernel & nullify (so JUnit will clean it up) if (kernelImpl != null) { 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 3e8292f8eb..409299bf95 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,15 +7,11 @@ */ 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.app.rest.builder.AbstractCRUDBuilder; 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; @@ -26,6 +22,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 */ @@ -148,6 +148,7 @@ public class AbstractIntegrationTestWithDatabase extends AbstractDSpaceIntegrati // Cleanup our global context object try { AbstractBuilder.cleanupObjects(); + AbstractCRUDBuilder.cleanupObjects(); if(context == null || !context.isValid()){ context = new Context(); } From 1a6100bce1716d3fc93d41a6501f2aa44f631b5d Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Mon, 4 Dec 2017 09:59:24 +0100 Subject: [PATCH 15/42] [DS-3762] Additional testing, taking into account that "Unknown" needs to exist --- .../rest/BitstreamFormatRestRepositoryIT.java | 18 +++++++++++++++++- .../rest/matcher/BitstreamFormatMatcher.java | 7 +++++++ 2 files changed, 24 insertions(+), 1 deletion(-) 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 index da9ec546d3..c442bcd6d8 100644 --- 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 @@ -27,6 +27,22 @@ public class BitstreamFormatRestRepositoryIT extends AbstractControllerIntegrati } @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) @@ -36,7 +52,7 @@ public class BitstreamFormatRestRepositoryIT extends AbstractControllerIntegrati getClient().perform(get("/api/core/bitstreamformats")) .andExpect(status().isOk()) .andExpect(content().contentType(contentType)) - .andExpect(jsonPath("$.page.totalElements", is(1))) + .andExpect(jsonPath("$.page.totalElements", is(2))) .andExpect(jsonPath("$._embedded.bitstreamformats", Matchers.contains( BitstreamFormatMatcher.matchBitstreamFormat(bitstreamFormat.getMIMEType(), bitstreamFormat.getDescription()) ))) 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 index 58007c70c6..9ec05f77a3 100644 --- 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 @@ -19,4 +19,11 @@ public class BitstreamFormatMatcher { ); } + public static Matcher matchBitstreamFormatMimeType(String mimetype) { + return allOf( + hasJsonPath("$.mimetype", is(mimetype)), + hasJsonPath("$.type", is("bitstreamformat")) + ); + } + } From 7b002d93eb39467b80abaee6373ae7c07bfc746e Mon Sep 17 00:00:00 2001 From: Raf Ponsaerts Date: Fri, 1 Dec 2017 15:01:17 +0100 Subject: [PATCH 16/42] [DS-3762] added clauses to the bitstream matcher --- .../app/rest/BitstreamRestRepositoryIT.java | 38 +++++++++++-------- .../app/rest/matcher/BitstreamMatcher.java | 34 +++++++++++++---- .../matcher/BitstreamMetadataMatcher.java | 27 +++++++++++++ 3 files changed, 77 insertions(+), 22 deletions(-) create mode 100644 dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/BitstreamMetadataMatcher.java 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 index d99251145e..3142e317c3 100644 --- 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 @@ -70,6 +70,7 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest bitstream = BitstreamBuilder. createBitstream(context, publicItem1, is) .withName("Bitstream") + .withDescription("description") .withMimeType("text/plain") .build(); } @@ -80,6 +81,7 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest bitstream1 = BitstreamBuilder. createBitstream(context, publicItem1, is) .withName("Bitstream1") + .withDescription("description123") .withMimeType("text/plain") .build(); } @@ -87,9 +89,9 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest getClient().perform(get("/api/core/bitstreams/")) .andExpect(status().isOk()) .andExpect(content().contentType(contentType)) - .andExpect(jsonPath("$._embedded.bitstreams", containsInAnyOrder( - BitstreamMatcher.matchBitstreamEntry(bitstream.getName(), bitstream.getID()), - BitstreamMatcher.matchBitstreamEntry(bitstream1.getName(), bitstream1.getID()) + .andExpect(jsonPath("$._embedded.bitstreams", Matchers.containsInAnyOrder( + BitstreamMatcher.matchBitstreamEntry(bitstream), + BitstreamMatcher.matchBitstreamEntry(bitstream1) ))) ; @@ -125,6 +127,7 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest bitstream = BitstreamBuilder. createBitstream(context, publicItem1, is) .withName("Bitstream") + .withDescription("descr") .withMimeType("text/plain") .build(); } @@ -135,6 +138,7 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest bitstream1 = BitstreamBuilder. createBitstream(context, publicItem1, is) .withName("Bitstream1") + .withDescription("desscrip1") .withMimeType("text/plain") .build(); } @@ -143,14 +147,14 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest .param("size","1")) .andExpect(status().isOk()) .andExpect(content().contentType(contentType)) - .andExpect(jsonPath("$._embedded.bitstreams", contains( - BitstreamMatcher.matchBitstreamEntry(bitstream.getName(), bitstream.getID()) - ))) + .andExpect(jsonPath("$._embedded.bitstreams", Matchers.contains( + BitstreamMatcher.matchBitstreamEntry(bitstream)) + )) .andExpect(jsonPath("$._embedded.bitstreams", Matchers.not( - contains( - BitstreamMatcher.matchBitstreamEntry(bitstream1.getName(), bitstream1.getID()) + Matchers.contains( + BitstreamMatcher.matchBitstreamEntry(bitstream1)) ) - ))) + )) ; @@ -159,12 +163,12 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest .param("page", "1")) .andExpect(status().isOk()) .andExpect(content().contentType(contentType)) - .andExpect(jsonPath("$._embedded.bitstreams", contains( - BitstreamMatcher.matchBitstreamEntry(bitstream1.getName(), bitstream1.getID()) + .andExpect(jsonPath("$._embedded.bitstreams", Matchers.contains( + BitstreamMatcher.matchBitstreamEntry(bitstream1) ))) .andExpect(jsonPath("$._embedded.bitstreams", Matchers.not( - contains( - BitstreamMatcher.matchBitstreamEntry(bitstream.getName(), bitstream.getID()) + Matchers.contains( + BitstreamMatcher.matchBitstreamEntry(bitstream) ) ))) @@ -262,6 +266,7 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest bitstream = BitstreamBuilder. createBitstream(context, publicItem1, is) .withName("Bitstream") + .withDescription("Description") .withMimeType("text/plain") .build(); } @@ -272,6 +277,7 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest bitstream1 = BitstreamBuilder. createBitstream(context, publicItem1, is) .withName("Bitstream1") + .withDescription("Description1") .withMimeType("text/plain") .build(); } @@ -279,8 +285,8 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest getClient().perform(get("/api/core/bitstreams/"+bitstream.getID())) .andExpect(status().isOk()) .andExpect(content().contentType(contentType)) - .andExpect(jsonPath("$", BitstreamMatcher.matchBitstreamEntry(bitstream.getName(), bitstream.getID()))) - .andExpect(jsonPath("$", not(BitstreamMatcher.matchBitstreamEntry(bitstream1.getName(), bitstream1.getID())))) + .andExpect(jsonPath("$", BitstreamMatcher.matchBitstreamEntry(bitstream))) + .andExpect(jsonPath("$", not(BitstreamMatcher.matchBitstreamEntry(bitstream1)))) ; } @@ -316,6 +322,7 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest bitstream = BitstreamBuilder. createBitstream(context, publicItem1, is) .withName("Bitstream") + .withDescription("Description") .withMimeType("text/plain") .build(); } @@ -326,6 +333,7 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest bitstream1 = BitstreamBuilder. createBitstream(context, publicItem1, is) .withName("Bitstream1") + .withDescription("Description1234") .withMimeType("text/plain") .build(); } 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 index 592d4d3e39..0fa3263c50 100644 --- 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 @@ -7,24 +7,31 @@ */ 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.allOf; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.*; public class BitstreamMatcher { - public static Matcher matchBitstreamEntry(String name, UUID uuid) { + public static Matcher 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(uuid.toString())), - hasJsonPath("$.name", is(name)), + 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(uuid) + matchBitstreamLinks(bitstream.getID()) ); } @@ -36,5 +43,18 @@ public class BitstreamMatcher { ); } + private static Matcher matchChecksum(){ + return allOf( + hasJsonPath("$.checkSumAlgorithm", not(empty())), + hasJsonPath("$.value", not(empty())) + ); + } + + private static Matcher 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..5940531523 --- /dev/null +++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/BitstreamMetadataMatcher.java @@ -0,0 +1,27 @@ +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 matchTitle(String title) { + return allOf( + hasJsonPath("$.key", is("dc.title")), + hasJsonPath("$.value", is(title)) + ); + } + + public static Matcher matchDescription(String description) { + return allOf( + hasJsonPath("$.key", is("dc.description")), + hasJsonPath("$.value", is(description)) + ); + } +} From 81e91d7f54a8636de28e2522e2707a87785b628b Mon Sep 17 00:00:00 2001 From: Raf Ponsaerts Date: Fri, 1 Dec 2017 15:35:10 +0100 Subject: [PATCH 17/42] [DS-3762] added an extra clause in the collection matcher --- .../app/rest/matcher/CollectionMatcher.java | 4 ++++ .../rest/matcher/CollectionMetadataMatcher.java | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/CollectionMetadataMatcher.java 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 index d9775aaada..37c1d101a8 100644 --- 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 @@ -8,6 +8,7 @@ package org.dspace.app.rest.matcher; import org.hamcrest.Matcher; +import org.hamcrest.Matchers; import java.util.UUID; @@ -24,6 +25,9 @@ public class CollectionMatcher { hasJsonPath("$.name", is(name)), hasJsonPath("$.handle", is(handle)), hasJsonPath("$.type", is("collection")), + hasJsonPath("$.metadata", Matchers.contains( + CollectionMetadataMatcher.matchTitle(name) + )), matchLinks(uuid) ); } 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..ad6c90b2c9 --- /dev/null +++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/CollectionMetadataMatcher.java @@ -0,0 +1,17 @@ +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 matchTitle(String title){ + return allOf( + hasJsonPath("$.key", is("dc.title")), + hasJsonPath("$.value", is(title)) + ); + } +} From 033a734fb534d3854c6f8520156e769e62ef1253 Mon Sep 17 00:00:00 2001 From: Raf Ponsaerts Date: Mon, 4 Dec 2017 10:16:07 +0100 Subject: [PATCH 18/42] [DS-3762] finalized testing for the CollectionRestRepository --- .../org/dspace/app/rest/CollectionRestRepositoryIT.java | 3 +-- .../org/dspace/app/rest/matcher/CollectionMatcher.java | 9 ++++++++- 2 files changed, 9 insertions(+), 3 deletions(-) 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 index 0fb2d0da09..190c28f97e 100644 --- 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 @@ -14,6 +14,7 @@ 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 static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; @@ -178,6 +179,4 @@ public class CollectionRestRepositoryIT extends AbstractControllerIntegrationTes ; } - - //TODO Search doesn't exist yet for this endpoint. Write tests when it does. } 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 index 37c1d101a8..9cdb2003d3 100644 --- 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 @@ -28,7 +28,14 @@ public class CollectionMatcher { hasJsonPath("$.metadata", Matchers.contains( CollectionMetadataMatcher.matchTitle(name) )), - matchLinks(uuid) + matchLinks(uuid), + matchLogo() + ); + } + + private static Matcher matchLogo() { + return allOf( + hasJsonPath("$._embedded.logo", Matchers.not(Matchers.empty())) ); } From 759d987332fea4a1cc303029791a04c50b9e3607 Mon Sep 17 00:00:00 2001 From: Raf Ponsaerts Date: Fri, 1 Dec 2017 15:42:14 +0100 Subject: [PATCH 19/42] [DS-3762] added an extra clause on the dc.title metadata field for the communities --- .../app/rest/matcher/CommunityMatcher.java | 3 +++ .../rest/matcher/CommunityMetadataMatcher.java | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/CommunityMetadataMatcher.java 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 index adef65e8f7..e243d9a3cd 100644 --- 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 @@ -25,6 +25,9 @@ public class CommunityMatcher { hasJsonPath("$.name", is(name)), hasJsonPath("$.handle", is(handle)), hasJsonPath("$.type", is("community")), + hasJsonPath("$.metadata", Matchers.contains( + CommunityMetadataMatcher.matchTitle(name) + )), matchLinks(uuid) ); } 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..a14f59841a --- /dev/null +++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/CommunityMetadataMatcher.java @@ -0,0 +1,17 @@ +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 matchTitle(String title){ + return allOf( + hasJsonPath("$.key", is("dc.title")), + hasJsonPath("$.value", is(title)) + ); + } +} From e9b84572898996bb2480e4e29218b36029dea95e Mon Sep 17 00:00:00 2001 From: Raf Ponsaerts Date: Fri, 1 Dec 2017 16:35:24 +0100 Subject: [PATCH 20/42] [DS-3762] added a not empty check on the collections of the community --- .../test/java/org/dspace/app/rest/matcher/CommunityMatcher.java | 1 + 1 file changed, 1 insertion(+) 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 index e243d9a3cd..7651e0c374 100644 --- 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 @@ -28,6 +28,7 @@ public class CommunityMatcher { hasJsonPath("$.metadata", Matchers.contains( CommunityMetadataMatcher.matchTitle(name) )), + hasJsonPath("$._embedded.collections", Matchers.not(Matchers.empty())), matchLinks(uuid) ); } From 70529b154c8bbe2d12b8241859f413c0451b6b54 Mon Sep 17 00:00:00 2001 From: Raf Ponsaerts Date: Mon, 4 Dec 2017 11:12:00 +0100 Subject: [PATCH 21/42] [DS-3762] Finalized community endpoint tests, added test for /search/top and /search/subCommunities, though the latter one is on ignore --- .../app/rest/CommunityRestRepositoryIT.java | 106 +++++++++++++++++- .../app/rest/matcher/CommunityMatcher.java | 2 +- 2 files changed, 104 insertions(+), 4 deletions(-) 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 index 79d628e540..095cbe4f4e 100644 --- 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 @@ -14,13 +14,14 @@ 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 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 @@ -46,6 +47,8 @@ public class CommunityRestRepositoryIT extends AbstractControllerIntegrationTest 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))) ; } @@ -93,6 +96,8 @@ public class CommunityRestRepositoryIT extends AbstractControllerIntegrationTest ) ))) .andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/communities"))) + .andExpect(jsonPath("$.page.size", is(1))) + .andExpect(jsonPath("$.page.totalElements", is(2))) ; } @@ -173,8 +178,103 @@ public class CommunityRestRepositoryIT extends AbstractControllerIntegrationTest .andExpect(content().contentType(contentType)); } - //TODO /api/core/communities/search/top - //TODO /api/core/communities/search/subCommunities + @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 = new CommunityBuilder().createCommunity(context) + .withName("Parent Community") + .withLogo("ThisIsSomeDummyText") + .build(); + + Community parentCommunity2 = new CommunityBuilder().createCommunity(context) + .withName("Parent Community 2") + .withLogo("SomeTest") + .build(); + + Community child1 = new CommunityBuilder().createSubCommunity(context, parentCommunity) + .withName("Sub Community") + .build(); + + Community child12 = new CommunityBuilder().createSubCommunity(context, child1) + .withName("Sub Sub Community") + .build(); + Collection col1 = new 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 = new CommunityBuilder().createCommunity(context) + .withName("Parent Community") + .withLogo("ThisIsSomeDummyText") + .build(); + + Community parentCommunity2 = new CommunityBuilder().createCommunity(context) + .withName("Parent Community 2") + .withLogo("SomeTest") + .build(); + + Community child1 = new CommunityBuilder().createSubCommunity(context, parentCommunity) + .withName("Sub Community") + .build(); + + Community child12 = new CommunityBuilder().createSubCommunity(context, child1) + .withName("Sub Sub Community") + .build(); + + Community child2 = new CommunityBuilder().createSubCommunity(context, parentCommunity2) + .withName("Sub2 Community") + .build(); + + Collection col1 = new CollectionBuilder().createCollection(context, child1).withName("Collection 1").build(); + + getClient().perform(get("/api/core/communities/search/subCommunities")) + .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()), + CommunityMatcher.matchCommunityEntry(child2.getName(), child2.getID(), child2.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()) + )))) + .andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/communities/search/subCommunities"))) + .andExpect(jsonPath("$.page.size", is(20))) + .andExpect(jsonPath("$.page.totalElements", is(3))) + ; + } } 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 index 7651e0c374..2be2020430 100644 --- 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 @@ -29,11 +29,11 @@ public class CommunityMatcher { CommunityMetadataMatcher.matchTitle(name) )), hasJsonPath("$._embedded.collections", Matchers.not(Matchers.empty())), + hasJsonPath("$._embedded.logo", Matchers.not(Matchers.empty())), matchLinks(uuid) ); } - public static Matcher matchLinks(UUID uuid){ return allOf( hasJsonPath("$._links.collections.href", Matchers.containsString("/api/core/communities/" + uuid.toString() + "/collections")), From f4b6b5d4802e49c667e42155df880b5245e77433 Mon Sep 17 00:00:00 2001 From: Raf Ponsaerts Date: Fri, 1 Dec 2017 16:08:28 +0100 Subject: [PATCH 22/42] [DS-3762] added extra clauses for the EPerson matcher --- .../app/rest/EPersonRestRepositoryIT.java | 14 +++++----- .../app/rest/matcher/EPersonMatcher.java | 19 ++++++++----- .../rest/matcher/EPersonMetadataMatcher.java | 27 +++++++++++++++++++ 3 files changed, 46 insertions(+), 14 deletions(-) create mode 100644 dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/EPersonMetadataMatcher.java 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 index fddce17b63..7c1cd1299b 100644 --- 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 @@ -34,7 +34,7 @@ public class EPersonRestRepositoryIT extends AbstractControllerIntegrationTest{ .andExpect(status().isOk()) .andExpect(content().contentType(contentType)) .andExpect(jsonPath("$._embedded.epersons", Matchers.containsInAnyOrder( - EPersonMatcher.matchEPersonEntry(ePerson.getID(), ePerson.getEmail()), + EPersonMatcher.matchEPersonEntry(ePerson), EPersonMatcher.matchDefaultTestEPerson() ))); } @@ -57,7 +57,7 @@ public class EPersonRestRepositoryIT extends AbstractControllerIntegrationTest{ ))) .andExpect(jsonPath("$._embedded.epersons", Matchers.not( Matchers.contains( - EPersonMatcher.matchEPersonEntry(ePerson.getID(), ePerson.getEmail()) + EPersonMatcher.matchEPersonEntry(ePerson) ) ))); @@ -67,7 +67,7 @@ public class EPersonRestRepositoryIT extends AbstractControllerIntegrationTest{ .andExpect(status().isOk()) .andExpect(content().contentType(contentType)) .andExpect(jsonPath("$._embedded.epersons", Matchers.contains( - EPersonMatcher.matchEPersonEntry(ePerson.getID(), ePerson.getEmail()) + EPersonMatcher.matchEPersonEntry(ePerson) ))); } @@ -90,11 +90,11 @@ public class EPersonRestRepositoryIT extends AbstractControllerIntegrationTest{ .andExpect(status().isOk()) .andExpect(content().contentType(contentType)) .andExpect(jsonPath("$", Matchers.is( - EPersonMatcher.matchEPersonEntry(ePerson2.getID(), ePerson2.getEmail()) + EPersonMatcher.matchEPersonEntry(ePerson2) ))) .andExpect(jsonPath("$", Matchers.not( Matchers.is( - EPersonMatcher.matchEPersonEntry(ePerson.getID(), ePerson.getEmail()) + EPersonMatcher.matchEPersonEntry(ePerson) ) ))); @@ -118,11 +118,11 @@ public class EPersonRestRepositoryIT extends AbstractControllerIntegrationTest{ .andExpect(status().isOk()) .andExpect(content().contentType(contentType)) .andExpect(jsonPath("$", Matchers.is( - EPersonMatcher.matchEPersonEntry(ePerson2.getID(), ePerson2.getEmail()) + EPersonMatcher.matchEPersonEntry(ePerson2) ))) .andExpect(jsonPath("$", Matchers.not( Matchers.is( - EPersonMatcher.matchEPersonEntry(ePerson.getID(), ePerson.getEmail()) + EPersonMatcher.matchEPersonEntry(ePerson) ) ))) .andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/eperson/epersons/" + ePerson2.getID()))); 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 index b8df989757..4c0c51c83f 100644 --- 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 @@ -7,23 +7,28 @@ */ 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.allOf; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.*; public class EPersonMatcher { - public static Matcher matchEPersonEntry(UUID uuid, String name) { + public static Matcher matchEPersonEntry(EPerson ePerson) { return allOf( - hasJsonPath("$.uuid", is(uuid.toString())), - hasJsonPath("$.name", is(name)), + hasJsonPath("$.uuid", is(ePerson.getID().toString())), + hasJsonPath("$.name", is(ePerson.getName())), hasJsonPath("$.type", is("eperson")), - hasJsonPath("$._links.self.href", containsString("/api/eperson/epersons/" + uuid.toString())) + 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()) + )) ); } 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..bb235b2954 --- /dev/null +++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/EPersonMetadataMatcher.java @@ -0,0 +1,27 @@ +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 matchFirstName(String firstName){ + return allOf( + hasJsonPath("$.key", is("eperson.firstname")), + hasJsonPath("$.value", is(firstName)) + ); + } + + public static Matcher matchLastName(String lastName){ + return allOf( + hasJsonPath("$.key", is("eperson.lastname")), + hasJsonPath("$.value", is(lastName)) + ); + } + +} From 00d3e095fbb1341726e267104b235ca9031db17c Mon Sep 17 00:00:00 2001 From: Raf Ponsaerts Date: Fri, 1 Dec 2017 16:28:52 +0100 Subject: [PATCH 23/42] [DS-3762] added more clauses to the metadatafield tests --- .../rest/MetadatafieldRestRepositoryIT.java | 6 ++++- .../rest/matcher/MetadataFieldMatcher.java | 22 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/MetadataFieldMatcher.java 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 index a04e2ac42e..17effb1531 100644 --- 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 @@ -7,6 +7,7 @@ */ package org.dspace.app.rest; +import org.dspace.app.rest.matcher.MetadataFieldMatcher; import org.dspace.app.rest.test.AbstractControllerIntegrationTest; import org.hamcrest.Matchers; import org.junit.Test; @@ -24,10 +25,13 @@ public class MetadatafieldRestRepositoryIT extends AbstractControllerIntegration getClient().perform(get("/api/core/metadatafields")) .andExpect(status().isOk()) .andExpect(content().contentType(contentType)) - .andExpect(jsonPath("$._embedded.metadatafields[0].type", Matchers.is("metadatafield"))) + .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"))); + } } 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..8cd4df6fca --- /dev/null +++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/MetadataFieldMatcher.java @@ -0,0 +1,22 @@ +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.is; + +public class MetadataFieldMatcher { + + public static Matcher 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")) + ); + } +} From 06cae1627e18f569999032372beabca547475f98 Mon Sep 17 00:00:00 2001 From: Raf Ponsaerts Date: Mon, 4 Dec 2017 11:23:12 +0100 Subject: [PATCH 24/42] [DS-3762] finalized Eperson tests --- .../app/rest/EPersonRestRepositoryIT.java | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) 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 index 7c1cd1299b..f3f33f5311 100644 --- 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 @@ -14,6 +14,7 @@ import org.dspace.eperson.EPerson; import org.hamcrest.Matchers; import org.junit.Test; +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; @@ -36,7 +37,10 @@ public class EPersonRestRepositoryIT extends AbstractControllerIntegrationTest{ .andExpect(jsonPath("$._embedded.epersons", Matchers.containsInAnyOrder( EPersonMatcher.matchEPersonEntry(ePerson), EPersonMatcher.matchDefaultTestEPerson() - ))); + ))) + .andExpect(jsonPath("$.page.size", is(20))) + .andExpect(jsonPath("$.page.totalElements", is(2))) + ; } @Test @@ -59,7 +63,10 @@ public class EPersonRestRepositoryIT extends AbstractControllerIntegrationTest{ 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") @@ -68,7 +75,10 @@ public class EPersonRestRepositoryIT extends AbstractControllerIntegrationTest{ .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))) + ; } @@ -89,11 +99,11 @@ public class EPersonRestRepositoryIT extends AbstractControllerIntegrationTest{ getClient().perform(get("/api/eperson/epersons/" + ePerson2.getID())) .andExpect(status().isOk()) .andExpect(content().contentType(contentType)) - .andExpect(jsonPath("$", Matchers.is( + .andExpect(jsonPath("$", is( EPersonMatcher.matchEPersonEntry(ePerson2) ))) .andExpect(jsonPath("$", Matchers.not( - Matchers.is( + is( EPersonMatcher.matchEPersonEntry(ePerson) ) ))); @@ -117,11 +127,11 @@ public class EPersonRestRepositoryIT extends AbstractControllerIntegrationTest{ getClient().perform(get("/api/eperson/epersons/" + ePerson2.getID())) .andExpect(status().isOk()) .andExpect(content().contentType(contentType)) - .andExpect(jsonPath("$", Matchers.is( + .andExpect(jsonPath("$", is( EPersonMatcher.matchEPersonEntry(ePerson2) ))) .andExpect(jsonPath("$", Matchers.not( - Matchers.is( + is( EPersonMatcher.matchEPersonEntry(ePerson) ) ))) From 63a62b9c360c304853c0178a1c3e51fbd1a39d14 Mon Sep 17 00:00:00 2001 From: Raf Ponsaerts Date: Mon, 4 Dec 2017 11:41:34 +0100 Subject: [PATCH 25/42] [DS-3762] added a page check to the metadatafield, finalized the metadatafield endpoint tests --- .../org/dspace/app/rest/MetadatafieldRestRepositoryIT.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 index 17effb1531..a4a6b26023 100644 --- 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 @@ -16,6 +16,7 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder 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 { @@ -31,7 +32,8 @@ public class MetadatafieldRestRepositoryIT extends AbstractControllerIntegration .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("$._links.last.href", Matchers.containsString("/api/core/metadatafields"))) + .andExpect(jsonPath("$.page.size", is(20))); } } From f90772cb4a49e9edbc7dac4aaf4eea50cdab3411 Mon Sep 17 00:00:00 2001 From: Raf Ponsaerts Date: Mon, 4 Dec 2017 11:33:20 +0100 Subject: [PATCH 26/42] [DS-3762] added page checks to the item tests, finalized the ItemRestRepository tests --- .../test/java/org/dspace/app/rest/ItemRestRepositoryIT.java | 5 +++++ 1 file changed, 5 insertions(+) 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 index 58fd8e647c..570407d259 100644 --- 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 @@ -28,6 +28,7 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder 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 { @@ -77,6 +78,8 @@ public class ItemRestRepositoryIT extends AbstractControllerIntegrationTest { 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))) ; } @@ -146,6 +149,8 @@ public class ItemRestRepositoryIT extends AbstractControllerIntegrationTest { ) ))) .andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/items"))) + .andExpect(jsonPath("$.page.size", is(2))) + .andExpect(jsonPath("$.page.totalElements", is(3))) ; } From 9a1ab3e9f6ea79325548b0222fa51343278ee2c3 Mon Sep 17 00:00:00 2001 From: Raf Ponsaerts Date: Fri, 1 Dec 2017 16:57:08 +0100 Subject: [PATCH 27/42] [DS-3762] added tests for metadataschemas and added license headers for previous test classes --- .../rest/MetadataschemaRestRepositoryIT.java | 33 +++++++++++++++++++ .../rest/matcher/EPersonMetadataMatcher.java | 7 ++++ .../rest/matcher/MetadataFieldMatcher.java | 7 ++++ .../rest/matcher/MetadataschemaMatcher.java | 26 +++++++++++++++ 4 files changed, 73 insertions(+) create mode 100644 dspace-spring-rest/src/test/java/org/dspace/app/rest/MetadataschemaRestRepositoryIT.java create mode 100644 dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/MetadataschemaMatcher.java 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..7cb2d2c05b --- /dev/null +++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/MetadataschemaRestRepositoryIT.java @@ -0,0 +1,33 @@ +/** + * 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.matcher.MetadataschemaMatcher; +import org.dspace.app.rest.test.AbstractControllerIntegrationTest; +import org.hamcrest.Matchers; +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; + +public class MetadataschemaRestRepositoryIT extends AbstractControllerIntegrationTest { + + @Test + public void findAll() throws Exception{ + + 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"))); + } +} 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 index bb235b2954..eacb840927 100644 --- 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 @@ -1,3 +1,10 @@ +/** + * 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; 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 index 8cd4df6fca..909f328235 100644 --- 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 @@ -1,3 +1,10 @@ +/** + * 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; 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..ddb7ad7895 --- /dev/null +++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/MetadataschemaMatcher.java @@ -0,0 +1,26 @@ +/** + * 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.is; + +public class MetadataschemaMatcher { + + public static Matcher matchEntry(){ + return allOf( + hasJsonPath("$.prefix", Matchers.not(Matchers.empty())), + hasJsonPath("$.type", is("metadataschema")), + hasJsonPath("$._links.self.href", Matchers.containsString("/api/core/metadataschemas")) + ); + } +} From 907501c28097ae8e7d6795940b1b41f2c84673ed Mon Sep 17 00:00:00 2001 From: Raf Ponsaerts Date: Mon, 4 Dec 2017 09:26:37 +0100 Subject: [PATCH 28/42] [DS-3762] added clause in the metadataschemamatcher and added a new, ignored, test --- .../app/rest/MetadataschemaRestRepositoryIT.java | 11 +++++++++++ .../app/rest/matcher/MetadataschemaMatcher.java | 1 + 2 files changed, 12 insertions(+) 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 index 7cb2d2c05b..56ccf454ad 100644 --- 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 @@ -10,6 +10,7 @@ package org.dspace.app.rest; import org.dspace.app.rest.matcher.MetadataschemaMatcher; import org.dspace.app.rest.test.AbstractControllerIntegrationTest; import org.hamcrest.Matchers; +import org.junit.Ignore; import org.junit.Test; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; @@ -30,4 +31,14 @@ public class MetadataschemaRestRepositoryIT extends AbstractControllerIntegratio ))) .andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/metadataschemas"))); } + + + //TODO This test fails, reactivate when endpoint is fixed + @Test + @Ignore + public void findOne() throws Exception{ + + getClient().perform(get("/api/core/metadataschemas/1")) + .andExpect(status().isOk()); + } } 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 index ddb7ad7895..052be2e05a 100644 --- 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 @@ -19,6 +19,7 @@ public class MetadataschemaMatcher { public static Matcher 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")) ); From 078b71010ae396be81a341f16a049c4ae2ce83e7 Mon Sep 17 00:00:00 2001 From: Raf Ponsaerts Date: Mon, 4 Dec 2017 11:46:35 +0100 Subject: [PATCH 29/42] [DS-3762] added a page check to the metadataschemas endpoint and finalized the tests --- .../org/dspace/app/rest/MetadataschemaRestRepositoryIT.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 index 56ccf454ad..ff0be3570c 100644 --- 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 @@ -17,6 +17,7 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder 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 { @@ -29,7 +30,8 @@ public class MetadataschemaRestRepositoryIT extends AbstractControllerIntegratio .andExpect(jsonPath("$._embedded.metadataschemas", Matchers.hasItem( MetadataschemaMatcher.matchEntry() ))) - .andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/metadataschemas"))); + .andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/metadataschemas"))) + .andExpect(jsonPath("$.page.size", is(20))); } From eaaffd403bcb6cc7440beb9242ca16eed06b0784 Mon Sep 17 00:00:00 2001 From: Raf Ponsaerts Date: Mon, 4 Dec 2017 09:54:05 +0100 Subject: [PATCH 30/42] [DS-3762] made a test for site endpoint --- .../dspace/app/rest/SiteRestRepositoryIT.java | 36 +++++++++++++++++++ .../dspace/app/rest/matcher/SiteMatcher.java | 30 ++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 dspace-spring-rest/src/test/java/org/dspace/app/rest/SiteRestRepositoryIT.java create mode 100644 dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/SiteMatcher.java 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..cc8109808a --- /dev/null +++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/SiteRestRepositoryIT.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; + +import com.jayway.jsonpath.JsonPath; +import org.dspace.app.rest.matcher.SiteMatcher; +import org.dspace.app.rest.test.AbstractControllerIntegrationTest; +import org.hamcrest.Matchers; +import org.junit.Test; +import org.springframework.test.web.servlet.ResultActions; + +import java.util.List; + +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{ + + getClient().perform(get("/api/core/sites")) + .andExpect(status().isOk()) + .andExpect(jsonPath("$._embedded.sites[0]", SiteMatcher.matchEntry())) + .andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/sites"))) + .andExpect(jsonPath("$.page.size", is(20))); + + } +} 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..79cb5377a6 --- /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.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 matchEntry(){ + return allOf( + hasJsonPath("$.uuid", Matchers.not(Matchers.empty())), + hasJsonPath("$.name", Matchers.not(Matchers.empty())), + hasJsonPath("$.handle", Matchers.not(Matchers.empty())), + hasJsonPath("$.type", is("site")), + hasJsonPath("$._links.self.href", containsString("/api/core/sites/")) + + ); + } +} From 3c8533d607f3a55dcbc229d8b1a02d63c11275bd Mon Sep 17 00:00:00 2001 From: Raf Ponsaerts Date: Mon, 4 Dec 2017 13:38:37 +0100 Subject: [PATCH 31/42] [DS-3762] Merge of all the tests and fixed for the travis build --- .../dspace/app/rest/BitstreamFormatRestRepositoryIT.java | 7 +++++++ .../java/org/dspace/app/rest/GroupRestRepositoryIT.java | 7 +++++++ .../org/dspace/app/rest/builder/AbstractCRUDBuilder.java | 7 +++++++ .../dspace/app/rest/builder/BitstreamFormatBuilder.java | 7 +++++++ .../dspace/app/rest/matcher/BitstreamFormatMatcher.java | 7 +++++++ .../dspace/app/rest/matcher/BitstreamMetadataMatcher.java | 7 +++++++ .../dspace/app/rest/matcher/CollectionMetadataMatcher.java | 7 +++++++ .../dspace/app/rest/matcher/CommunityMetadataMatcher.java | 7 +++++++ .../java/org/dspace/app/rest/matcher/GroupMatcher.java | 7 +++++++ 9 files changed, 63 insertions(+) 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 index c442bcd6d8..234d6046a2 100644 --- 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 @@ -1,3 +1,10 @@ +/** + * 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; 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 index 6f981d9121..6aa9625759 100644 --- 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 @@ -1,3 +1,10 @@ +/** + * 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; 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 index 742d5b902c..c3b59a7f0b 100644 --- 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 @@ -1,3 +1,10 @@ +/** + * 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; 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 index 7d823babb3..2c4a98ae13 100644 --- 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 @@ -1,3 +1,10 @@ +/** + * 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; 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 index 9ec05f77a3..48e0158893 100644 --- 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 @@ -1,3 +1,10 @@ +/** + * 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; 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 index 5940531523..4f53b4904e 100644 --- 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 @@ -1,3 +1,10 @@ +/** + * 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; 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 index ad6c90b2c9..31e3bf758a 100644 --- 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 @@ -1,3 +1,10 @@ +/** + * 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; 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 index a14f59841a..d46c50798f 100644 --- 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 @@ -1,3 +1,10 @@ +/** + * 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; 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 index a327614fcc..f77a9a5a7c 100644 --- 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 @@ -1,3 +1,10 @@ +/** + * 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; From c97f8c432083bf95d04c83fbe80dad52dcd92053 Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Mon, 4 Dec 2017 13:56:41 +0100 Subject: [PATCH 32/42] [DS-3762] Refactoring for 1 generalised Builder --- .../rest/BitstreamFormatRestRepositoryIT.java | 3 + .../app/rest/GroupRestRepositoryIT.java | 4 + .../app/rest/builder/AbstractBuilder.java | 115 ++---------------- .../app/rest/builder/AbstractCRUDBuilder.java | 56 +-------- .../builder/AbstractDSpaceObjectBuilder.java | 114 +++++++++++++++++ .../app/rest/builder/BitstreamBuilder.java | 14 +-- .../rest/builder/BitstreamFormatBuilder.java | 2 +- .../app/rest/builder/CollectionBuilder.java | 4 +- .../app/rest/builder/CommunityBuilder.java | 5 +- .../app/rest/builder/EPersonBuilder.java | 4 +- .../dspace/app/rest/builder/GroupBuilder.java | 4 +- .../dspace/app/rest/builder/ItemBuilder.java | 4 +- .../test/AbstractDSpaceIntegrationTest.java | 3 - .../AbstractIntegrationTestWithDatabase.java | 2 - 14 files changed, 154 insertions(+), 180 deletions(-) create mode 100644 dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/AbstractDSpaceObjectBuilder.java 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 index 234d6046a2..7d5f60aec3 100644 --- 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 @@ -19,6 +19,9 @@ 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 { 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 index 6aa9625759..573aa51ccf 100644 --- 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 @@ -19,6 +19,10 @@ 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 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 2425a71b1f..9dc2218376 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 @@ -1,59 +1,29 @@ -/** - * 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 java.io.IOException; -import java.sql.SQLException; -import java.util.Date; -import java.util.LinkedList; -import java.util.List; - 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.BitstreamFormatService; -import org.dspace.content.service.BitstreamService; -import org.dspace.content.service.BundleService; -import org.dspace.content.service.CollectionService; -import org.dspace.content.service.CommunityService; -import org.dspace.content.service.DSpaceObjectService; -import org.dspace.content.service.InstallItemService; -import org.dspace.content.service.ItemService; -import org.dspace.content.service.WorkspaceItemService; -import org.dspace.core.Constants; +import org.dspace.content.service.*; 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.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 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 - * - * @author Atmire NV (info at atmire dot com) + * Created by jonas - jonas@atmire.com on 04/12/17. */ -public abstract class AbstractBuilder { +public abstract class AbstractBuilder { static CommunityService communityService; static CollectionService collectionService; @@ -74,7 +44,7 @@ public abstract class AbstractBuilder { 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; @@ -116,82 +86,15 @@ public abstract class AbstractBuilder { public static void cleanupObjects() throws Exception { for (AbstractBuilder builder : builders) { - builder.cleanup(); - } } protected abstract void cleanup() throws Exception; - - 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); - } - } - - 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 { + public abstract void delete(T dso) throws Exception; - try(Context c = new Context()) { - c.turnOffAuthorisationSystem(); - T attachedDso = c.reloadEntity(dso); - if (attachedDso != null) { - getDsoService().delete(c, attachedDso); - } - c.complete(); - } - - indexingService.commit(); - } + 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 index c3b59a7f0b..7090e113bf 100644 --- 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 @@ -7,78 +7,34 @@ */ package org.dspace.app.rest.builder; -import org.apache.log4j.Logger; -import org.dspace.authorize.factory.AuthorizeServiceFactory; -import org.dspace.authorize.service.AuthorizeService; -import org.dspace.content.factory.ContentServiceFactory; -import org.dspace.content.service.BitstreamFormatService; import org.dspace.core.Context; import org.dspace.core.ReloadableEntity; -import org.dspace.discovery.IndexingService; import org.dspace.service.DSpaceCRUDService; -import org.dspace.services.factory.DSpaceServicesFactory; - -import java.util.LinkedList; -import java.util.List; /** - * Created by jonas - jonas@atmire.com on 04/12/17. + * @author Jonas Van Goolen - (jonas@atmire.com) */ -public abstract class AbstractCRUDBuilder { - - static AuthorizeService authorizeService; - static IndexingService indexingService; - static BitstreamFormatService bitstreamFormatService; - - private static List builders = new LinkedList<>(); - /** log4j category */ - private static final Logger log = Logger.getLogger(AbstractBuilder.class); - - protected Context context; - +public abstract class AbstractCRUDBuilder extends AbstractBuilder { protected AbstractCRUDBuilder(Context context){ - this.context = context; - builders.add(this); + super(context); } - public static void init() { - authorizeService = AuthorizeServiceFactory.getInstance().getAuthorizeService(); - indexingService = DSpaceServicesFactory.getInstance().getServiceManager().getServiceByName(IndexingService.class.getName(),IndexingService.class); - bitstreamFormatService = ContentServiceFactory.getInstance().getBitstreamFormatService(); - - } - - public static void destroy(){ - authorizeService = null; - indexingService= null; - bitstreamFormatService=null; - } - - - public static void cleanupObjects() throws Exception { - for (AbstractCRUDBuilder builder : builders) { - - builder.cleanup(); - } - } - protected abstract void cleanup() throws Exception; - - protected abstract DSpaceCRUDService getCRUDService(); + 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) { - getCRUDService().delete(c, attachedDso); + 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..6d5f463cbb --- /dev/null +++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/AbstractDSpaceObjectBuilder.java @@ -0,0 +1,114 @@ +/** + * 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 Atmire NV (info 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 f3ff7c12a0..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,10 +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 */ -public class BitstreamBuilder extends AbstractBuilder{ +public class BitstreamBuilder extends AbstractDSpaceObjectBuilder { public static final String ORIGINAL = "ORIGINAL"; @@ -134,7 +134,7 @@ public class BitstreamBuilder extends AbstractBuilder{ } } - protected DSpaceObjectService getDsoService() { + 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 index 2c4a98ae13..3f84cbd9ec 100644 --- 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 @@ -36,7 +36,7 @@ public class BitstreamFormatBuilder extends AbstractCRUDBuilder } @Override - protected DSpaceCRUDService getCRUDService() { + protected DSpaceCRUDService getService() { return bitstreamFormatService; } 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 07ae706e29..f6eefb2bc4 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 @@ -27,7 +27,7 @@ import java.sql.SQLException; * * @author Atmire NV (info at atmire dot com) */ -public class CollectionBuilder extends AbstractBuilder { +public class CollectionBuilder extends AbstractDSpaceObjectBuilder { private Collection collection; @@ -85,7 +85,7 @@ public class CollectionBuilder extends AbstractBuilder { } @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 da30d7ac32..11bdbc85ba 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 @@ -10,7 +10,6 @@ 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.Community; import org.dspace.content.MetadataSchema; import org.dspace.content.service.DSpaceObjectService; @@ -25,7 +24,7 @@ import java.sql.SQLException; * * @author Atmire NV (info at atmire dot com) */ -public class CommunityBuilder extends AbstractBuilder { +public class CommunityBuilder extends AbstractDSpaceObjectBuilder { private Community community; @@ -89,7 +88,7 @@ public class CommunityBuilder extends AbstractBuilder { } @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 index f20be6ee2c..f3e5c55a00 100644 --- 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 @@ -15,7 +15,7 @@ import org.dspace.eperson.EPerson; import java.sql.SQLException; -public class EPersonBuilder extends AbstractBuilder { +public class EPersonBuilder extends AbstractDSpaceObjectBuilder { private EPerson ePerson; @@ -27,7 +27,7 @@ public class EPersonBuilder extends AbstractBuilder { delete(ePerson); } - protected DSpaceObjectService getDsoService() { + protected DSpaceObjectService getService() { return ePersonService; } 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 d19b5f8e6e..33125c3eb1 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 @@ -17,7 +17,7 @@ import org.dspace.eperson.Group; * * @author Atmire NV (info at atmire dot com) */ -public class GroupBuilder extends AbstractBuilder { +public class GroupBuilder extends AbstractDSpaceObjectBuilder { private Group group; @@ -46,7 +46,7 @@ public class GroupBuilder extends AbstractBuilder { } @Override - protected DSpaceObjectService getDsoService() { + protected DSpaceObjectService getService() { return groupService; } 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 52db38655a..a7d73ca787 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 @@ -21,7 +21,7 @@ import org.dspace.eperson.Group; * * @author Atmire NV (info at atmire dot com) */ -public class ItemBuilder extends AbstractBuilder { +public class ItemBuilder extends AbstractDSpaceObjectBuilder { private WorkspaceItem workspaceItem; private Item item; @@ -104,7 +104,7 @@ public class ItemBuilder extends AbstractBuilder { } @Override - protected DSpaceObjectService getDsoService() { + protected DSpaceObjectService getService() { return itemService; } 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 83e60873dc..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 @@ -9,7 +9,6 @@ package org.dspace.app.rest.test; import org.apache.log4j.Logger; import org.dspace.app.rest.builder.AbstractBuilder; -import org.dspace.app.rest.builder.AbstractCRUDBuilder; import org.dspace.servicemanager.DSpaceKernelImpl; import org.dspace.servicemanager.DSpaceKernelInit; import org.junit.AfterClass; @@ -72,7 +71,6 @@ public class AbstractDSpaceIntegrationTest kernelImpl.start(getDspaceDir()); // init the kernel } AbstractBuilder.init(); - AbstractCRUDBuilder.init(); } catch (IOException ex) { @@ -92,7 +90,6 @@ public class AbstractDSpaceIntegrationTest testProps = null; AbstractBuilder.destroy(); - AbstractCRUDBuilder.destroy(); //Also clear out the kernel & nullify (so JUnit will clean it up) if (kernelImpl != null) { 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 409299bf95..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 @@ -9,7 +9,6 @@ package org.dspace.app.rest.test; import org.apache.log4j.Logger; import org.dspace.app.rest.builder.AbstractBuilder; -import org.dspace.app.rest.builder.AbstractCRUDBuilder; import org.dspace.authorize.AuthorizeException; import org.dspace.content.Community; import org.dspace.core.Context; @@ -148,7 +147,6 @@ public class AbstractIntegrationTestWithDatabase extends AbstractDSpaceIntegrati // Cleanup our global context object try { AbstractBuilder.cleanupObjects(); - AbstractCRUDBuilder.cleanupObjects(); if(context == null || !context.isValid()){ context = new Context(); } From 50c8e08da659a0de9fc817370cf5a843c6734e1e Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Mon, 4 Dec 2017 14:53:12 +0100 Subject: [PATCH 33/42] [DS-3762] Author update, + CRUDService implementation pre-loading --- .../app/rest/builder/AbstractBuilder.java | 31 ++++++++++++++++++- .../rest/matcher/BitstreamFormatMatcher.java | 2 +- 2 files changed, 31 insertions(+), 2 deletions(-) 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 9dc2218376..aaaa0b7b6a 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 @@ -11,7 +11,14 @@ import org.dspace.discovery.IndexingService; 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.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; @@ -21,7 +28,7 @@ import java.sql.SQLException; import java.util.Date; /** - * Created by jonas - jonas@atmire.com on 04/12/17. + * @author Jonas Van Goolen - (jonas@atmire.com) */ public abstract class AbstractBuilder { @@ -39,6 +46,12 @@ public abstract class AbstractBuilder { static ResourcePolicyService resourcePolicyService; static IndexingService indexingService; static BitstreamFormatService bitstreamFormatService; + static RegistrationDataService registrationDataService; + static VersionHistoryService versionHistoryService; + static ClaimedTaskService claimedTaskService; + static InProgressUserService inProgressUserService; + static PoolTaskService poolTaskService; + static WorkflowItemRoleService workflowItemRoleService; protected Context context; @@ -66,8 +79,18 @@ public abstract class AbstractBuilder { resourcePolicyService = AuthorizeServiceFactory.getInstance().getResourcePolicyService(); indexingService = DSpaceServicesFactory.getInstance().getServiceManager().getServiceByName(IndexingService.class.getName(),IndexingService.class); bitstreamFormatService = ContentServiceFactory.getInstance().getBitstreamFormatService(); + registrationDataService = EPersonServiceFactory.getInstance().getRegistrationDataService(); + versionHistoryService = VersionServiceFactory.getInstance().getVersionHistoryService(); + + // 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; @@ -82,6 +105,12 @@ public abstract class AbstractBuilder { resourcePolicyService = null; indexingService = null; bitstreamFormatService = null; + registrationDataService = null; + versionHistoryService = null; + claimedTaskService = null; + inProgressUserService = null; + poolTaskService = null; + workflowItemRoleService = null; } public static void cleanupObjects() throws Exception { 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 index 48e0158893..af5f633d2c 100644 --- 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 @@ -14,7 +14,7 @@ import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.is; /** - * Created by jonas - jonas@atmire.com on 01/12/17. + * @author Jonas Van Goolen - (jonas@atmire.com) */ public class BitstreamFormatMatcher { From fa1f2993c89086c59511a431c6eece8e47ebd5cd Mon Sep 17 00:00:00 2001 From: Raf Ponsaerts Date: Mon, 4 Dec 2017 17:12:46 +0100 Subject: [PATCH 34/42] [DS-3762] Added extra tests using the new builders --- .../content/service/MetadataFieldService.java | 3 +- .../app/rest/BitstreamRestRepositoryIT.java | 7 +- .../app/rest/CollectionRestRepositoryIT.java | 57 ++++++++++++ .../rest/MetadatafieldRestRepositoryIT.java | 23 +++++ .../rest/MetadataschemaRestRepositoryIT.java | 15 ++- .../dspace/app/rest/SiteRestRepositoryIT.java | 32 ++++++- .../app/rest/builder/AbstractBuilder.java | 16 ++++ .../rest/builder/MetadataFieldBuilder.java | 93 +++++++++++++++++++ .../rest/builder/MetadataSchemaBuilder.java | 89 ++++++++++++++++++ .../dspace/app/rest/builder/SiteBuilder.java | 62 +++++++++++++ .../rest/matcher/MetadataFieldMatcher.java | 12 +++ .../rest/matcher/MetadataschemaMatcher.java | 10 ++ .../dspace/app/rest/matcher/SiteMatcher.java | 10 +- 13 files changed, 413 insertions(+), 16 deletions(-) create mode 100644 dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/MetadataFieldBuilder.java create mode 100644 dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/MetadataSchemaBuilder.java create mode 100644 dspace-spring-rest/src/test/java/org/dspace/app/rest/builder/SiteBuilder.java diff --git a/dspace-api/src/main/java/org/dspace/content/service/MetadataFieldService.java b/dspace-api/src/main/java/org/dspace/content/service/MetadataFieldService.java index b94092d9d1..215b82b3eb 100644 --- a/dspace-api/src/main/java/org/dspace/content/service/MetadataFieldService.java +++ b/dspace-api/src/main/java/org/dspace/content/service/MetadataFieldService.java @@ -12,6 +12,7 @@ import org.dspace.content.MetadataField; import org.dspace.content.MetadataSchema; import org.dspace.content.NonUniqueMetadataException; import org.dspace.core.Context; +import org.dspace.service.DSpaceCRUDService; import java.io.IOException; import java.sql.SQLException; @@ -23,7 +24,7 @@ import java.util.List; * * @author kevinvandevelde at atmire.com */ -public interface MetadataFieldService { +public interface MetadataFieldService{ /** * Creates a new metadata field. 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 index 3142e317c3..ee99281dcf 100644 --- 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 @@ -351,9 +351,10 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest //TODO This test fails in the current code. Authorization error -// getClient().perform(get("/api/core/bitstreams/"+bitstream.getID()+"/content")) -// .andExpect(status().isOk()) -// ; + getClient().perform(get("/api/core/bitstreams/"+bitstream.getID()+"/content")) + .andExpect(status().isOk()) + .andExpect(content().string("ThisIsSomeDummyText")) + ; } 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 index 190c28f97e..a9f3aebb31 100644 --- 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 @@ -179,4 +179,61 @@ public class CollectionRestRepositoryIT extends AbstractControllerIntegrationTes ; } + + + //TODO Populate the two tests when we know how to populate these endpoints + + @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)); + } + + + @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)); + } + } 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 index a4a6b26023..61136b6c2b 100644 --- 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 @@ -7,9 +7,12 @@ */ package org.dspace.app.rest; +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.hamcrest.Matchers; +import org.junit.Ignore; import org.junit.Test; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; @@ -23,6 +26,9 @@ public class MetadatafieldRestRepositoryIT extends AbstractControllerIntegration @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)) @@ -36,4 +42,21 @@ public class MetadatafieldRestRepositoryIT extends AbstractControllerIntegration .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 index ff0be3570c..99f3edc17d 100644 --- 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 @@ -7,8 +7,10 @@ */ 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; @@ -24,6 +26,9 @@ public class MetadataschemaRestRepositoryIT extends AbstractControllerIntegratio @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)) @@ -40,7 +45,13 @@ public class MetadataschemaRestRepositoryIT extends AbstractControllerIntegratio @Ignore public void findOne() throws Exception{ - getClient().perform(get("/api/core/metadataschemas/1")) - .andExpect(status().isOk()); + 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/SiteRestRepositoryIT.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/SiteRestRepositoryIT.java index cc8109808a..d4ced979cb 100644 --- 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 @@ -7,14 +7,12 @@ */ package org.dspace.app.rest; -import com.jayway.jsonpath.JsonPath; +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 org.springframework.test.web.servlet.ResultActions; - -import java.util.List; import static org.hamcrest.Matchers.is; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; @@ -26,11 +24,35 @@ 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())) + .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"))); + + } } 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 aaaa0b7b6a..6706d0a3d2 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 @@ -1,3 +1,10 @@ +/** + * 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; @@ -52,6 +59,9 @@ public abstract class AbstractBuilder { static InProgressUserService inProgressUserService; static PoolTaskService poolTaskService; static WorkflowItemRoleService workflowItemRoleService; + static MetadataFieldService metadataFieldService; + static MetadataSchemaService metadataSchemaService; + static SiteService siteService; protected Context context; @@ -81,6 +91,9 @@ public abstract class AbstractBuilder { bitstreamFormatService = ContentServiceFactory.getInstance().getBitstreamFormatService(); 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 @@ -111,6 +124,9 @@ public abstract class AbstractBuilder { inProgressUserService = null; poolTaskService = null; workflowItemRoleService = null; + metadataFieldService = null; + metadataSchemaService = null; + siteService = null; } public static void cleanupObjects() throws Exception { 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/MetadataFieldMatcher.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/MetadataFieldMatcher.java index 909f328235..3834f4d741 100644 --- 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 @@ -7,6 +7,7 @@ */ package org.dspace.app.rest.matcher; +import org.dspace.content.MetadataField; import org.hamcrest.Matcher; import org.hamcrest.Matchers; @@ -26,4 +27,15 @@ public class MetadataFieldMatcher { hasJsonPath("$._links.self.href", Matchers.containsString("/api/core/metadatafields")) ); } + + public static Matcher 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 index 052be2e05a..6ba7b3318c 100644 --- 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 @@ -7,6 +7,7 @@ */ package org.dspace.app.rest.matcher; +import org.dspace.content.MetadataSchema; import org.hamcrest.Matcher; import org.hamcrest.Matchers; @@ -24,4 +25,13 @@ public class MetadataschemaMatcher { hasJsonPath("$._links.self.href", Matchers.containsString("/api/core/metadataschemas")) ); } + + public static Matcher 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 index 79cb5377a6..e21de1aef2 100644 --- 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 @@ -7,6 +7,7 @@ */ package org.dspace.app.rest.matcher; +import org.dspace.content.Site; import org.hamcrest.Matcher; import org.hamcrest.Matchers; @@ -17,13 +18,12 @@ import static org.hamcrest.Matchers.is; public class SiteMatcher { - public static Matcher matchEntry(){ + public static Matcher matchEntry(Site site){ return allOf( - hasJsonPath("$.uuid", Matchers.not(Matchers.empty())), - hasJsonPath("$.name", Matchers.not(Matchers.empty())), - hasJsonPath("$.handle", Matchers.not(Matchers.empty())), + hasJsonPath("$.uuid", is(site.getID().toString())), + hasJsonPath("$.name", is(site.getName())), hasJsonPath("$.type", is("site")), - hasJsonPath("$._links.self.href", containsString("/api/core/sites/")) + hasJsonPath("$._links.self.href", containsString("/api/core/sites/" + site.getID())) ); } From 37016e6e9c1f4dfa98bad3079f698b8094598d87 Mon Sep 17 00:00:00 2001 From: Raf Ponsaerts Date: Tue, 5 Dec 2017 10:51:54 +0100 Subject: [PATCH 35/42] [DS-3762] Added tests on every endpoint that a findOne lookup with a wrong UUID fails with a 404 error message --- .../app/rest/BitstreamRestRepositoryIT.java | 26 ++++++++++++++ .../app/rest/CollectionRestRepositoryIT.java | 35 ++++++++++++++++--- .../app/rest/CommunityRestRepositoryIT.java | 24 +++++++++++++ .../app/rest/EPersonRestRepositoryIT.java | 22 ++++++++++++ .../app/rest/GroupRestRepositoryIT.java | 19 ++++++++++ .../dspace/app/rest/ItemRestRepositoryIT.java | 23 ++++++++++++ .../rest/MetadatafieldRestRepositoryIT.java | 34 ++++++++++++++++++ .../dspace/app/rest/SiteRestRepositoryIT.java | 14 ++++++++ 8 files changed, 193 insertions(+), 4 deletions(-) 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 index ee99281dcf..da47f9298b 100644 --- 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 @@ -26,6 +26,7 @@ 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; @@ -358,4 +359,29 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest } + + + @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(); + + //TODO This test fails in the current code. Authorization error + getClient().perform(get("/api/core/bitstreams/"+ UUID.randomUUID())) + .andExpect(status().isNotFound()) + ; + + } + } 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 index a9f3aebb31..23e31502c4 100644 --- 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 @@ -11,12 +11,18 @@ 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.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; @@ -202,8 +208,6 @@ public class CollectionRestRepositoryIT extends AbstractControllerIntegrationTes 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)); @@ -229,11 +233,34 @@ public class CollectionRestRepositoryIT extends AbstractControllerIntegrationTes 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)); } + @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 index 095cbe4f4e..6b2d9a627c 100644 --- 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 @@ -16,6 +16,9 @@ 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; @@ -277,4 +280,25 @@ public class CommunityRestRepositoryIT extends AbstractControllerIntegrationTest .andExpect(jsonPath("$.page.totalElements", is(3))) ; } + + + + + @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 index f3f33f5311..c4e3ecb4be 100644 --- 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 @@ -14,6 +14,8 @@ 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; @@ -137,4 +139,24 @@ public class EPersonRestRepositoryIT extends AbstractControllerIntegrationTest{ ))) .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 index 573aa51ccf..5d4584f17f 100644 --- 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 @@ -14,6 +14,8 @@ 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; @@ -110,4 +112,21 @@ public class GroupRestRepositoryIT extends AbstractControllerIntegrationTest { .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 index 570407d259..66bab2f6d4 100644 --- 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 @@ -23,6 +23,7 @@ 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; @@ -284,4 +285,26 @@ public class ItemRestRepositoryIT extends AbstractControllerIntegrationTest { ; } + + + @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 index 61136b6c2b..02847ffdc4 100644 --- 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 @@ -11,10 +11,16 @@ 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.Mockito; +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; @@ -23,6 +29,7 @@ import static org.hamcrest.Matchers.is; public class MetadatafieldRestRepositoryIT extends AbstractControllerIntegrationTest { + @Test public void findAll() throws Exception{ @@ -59,4 +66,31 @@ public class MetadatafieldRestRepositoryIT extends AbstractControllerIntegration .andExpect(jsonPath("$.page.size", is(20))); } + + + @Test + public void findAllSqlException() throws Exception{ + + + context.turnOffAuthorisationSystem(); + MetadataField metadataField = MetadataFieldBuilder.createMetadataField(context, "AnElement", "AQualifier", "AScopeNote").build(); + + MetadataFieldService metadataFieldService = org.mockito.Mockito.mock(MetadataFieldService.class); + + when(metadataFieldService.findAll(Mockito.any(Context.class))).thenThrow(new SQLException()); + + + 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))); + } } 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 index d4ced979cb..9330d74c34 100644 --- 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 @@ -14,6 +14,8 @@ 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; @@ -55,4 +57,16 @@ public class SiteRestRepositoryIT extends AbstractControllerIntegrationTest { .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()); + + } } From e070c2bd79aaf99048e92a52bcd94ad44cf1f479 Mon Sep 17 00:00:00 2001 From: Raf Ponsaerts Date: Tue, 5 Dec 2017 14:07:12 +0100 Subject: [PATCH 36/42] [DS-3762] made the findAuthorized tests to assert that no values get returned --- .../app/rest/CollectionRestRepositoryIT.java | 24 ++++++++------ .../rest/MetadatafieldRestRepositoryIT.java | 32 +++---------------- 2 files changed, 20 insertions(+), 36 deletions(-) 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 index 23e31502c4..a290faa88f 100644 --- 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 @@ -23,6 +23,8 @@ 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; @@ -135,11 +137,11 @@ public class CollectionRestRepositoryIT extends AbstractControllerIntegrationTes getClient().perform(get("/api/core/collections/" + col1.getID())) .andExpect(status().isOk()) .andExpect(content().contentType(contentType)) - .andExpect(jsonPath("$", Matchers.is( + .andExpect(jsonPath("$", is( CollectionMatcher.matchCollectionEntry(col1.getName(), col1.getID(), col1.getHandle()) ))) .andExpect(jsonPath("$", Matchers.not( - Matchers.is( + is( CollectionMatcher.matchCollectionEntry(col2.getName(), col2.getID(), col2.getHandle()) )))); } @@ -166,11 +168,11 @@ public class CollectionRestRepositoryIT extends AbstractControllerIntegrationTes getClient().perform(get("/api/core/collections/" + col1.getID())) .andExpect(status().isOk()) .andExpect(content().contentType(contentType)) - .andExpect(jsonPath("$", Matchers.is( + .andExpect(jsonPath("$", is( CollectionMatcher.matchCollectionEntry(col1.getName(), col1.getID(), col1.getHandle()) ))) .andExpect(jsonPath("$", Matchers.not( - Matchers.is( + is( CollectionMatcher.matchCollectionEntry(col2.getName(), col2.getID(), col2.getHandle()) ))) ) @@ -186,9 +188,7 @@ public class CollectionRestRepositoryIT extends AbstractControllerIntegrationTes } - - //TODO Populate the two tests when we know how to populate these endpoints - + @Test public void findAuthorizedTest() throws Exception { @@ -210,7 +210,11 @@ public class CollectionRestRepositoryIT extends AbstractControllerIntegrationTes getClient().perform(get("/api/core/collections/search/findAuthorized")) .andExpect(status().isOk()) - .andExpect(content().contentType(contentType)); + .andExpect(content().contentType(contentType)) + .andExpect(jsonPath("$.page.totalElements", is(0))) + .andExpect(jsonPath("$._embedded").doesNotExist()) + ; + } @@ -235,7 +239,9 @@ public class CollectionRestRepositoryIT extends AbstractControllerIntegrationTes getClient().perform(get("/api/core/collections/search/findAuthorizedByCommunity")) .andExpect(status().isOk()) - .andExpect(content().contentType(contentType)); + .andExpect(content().contentType(contentType)) + .andExpect(jsonPath("$.page.totalElements", is(0))) + .andExpect(jsonPath("$._embedded").doesNotExist()); } @Test 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 index 02847ffdc4..3fb69d355f 100644 --- 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 @@ -7,6 +7,9 @@ */ 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; @@ -16,7 +19,9 @@ 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; @@ -66,31 +71,4 @@ public class MetadatafieldRestRepositoryIT extends AbstractControllerIntegration .andExpect(jsonPath("$.page.size", is(20))); } - - - @Test - public void findAllSqlException() throws Exception{ - - - context.turnOffAuthorisationSystem(); - MetadataField metadataField = MetadataFieldBuilder.createMetadataField(context, "AnElement", "AQualifier", "AScopeNote").build(); - - MetadataFieldService metadataFieldService = org.mockito.Mockito.mock(MetadataFieldService.class); - - when(metadataFieldService.findAll(Mockito.any(Context.class))).thenThrow(new SQLException()); - - - 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))); - } } From a47886780460b4f6b42b550a95a8ae8dd6647403 Mon Sep 17 00:00:00 2001 From: Tom Desair Date: Tue, 5 Dec 2017 15:10:57 +0100 Subject: [PATCH 37/42] [DS-3762] Adjust tests to new Builder API --- .../BitstreamContentRestControllerIT.java | 3 --- .../app/rest/BitstreamRestRepositoryIT.java | 9 +++----- .../app/rest/CommunityRestRepositoryIT.java | 22 +++++++++---------- .../app/rest/builder/AbstractBuilder.java | 4 ++-- .../dspace/app/rest/builder/GroupBuilder.java | 4 ---- 5 files changed, 16 insertions(+), 26 deletions(-) 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/BitstreamRestRepositoryIT.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/BitstreamRestRepositoryIT.java index da47f9298b..8f45ea8629 100644 --- 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 @@ -13,6 +13,7 @@ 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; @@ -230,7 +231,7 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest .andExpect(status().isOk()) .andExpect(content().contentType(contentType)) .andExpect(jsonPath("$._embedded.bitstreams", contains( - BitstreamMatcher.matchBitstreamEntry(bitstream.getName(), bitstream.getID()) + BitstreamMatcher.matchBitstreamEntry(bitstream) ))) ; @@ -342,7 +343,7 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest getClient().perform(get("/api/core/bitstreams/"+bitstream.getID()+"/format")) .andExpect(status().isOk()) .andExpect(content().contentType(contentType)) - //TODO add matcher on bitstream format + .andExpect(jsonPath("$", BitstreamFormatMatcher.matchBitstreamFormatMimeType("text/plain"))) ; @@ -351,7 +352,6 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest ; - //TODO This test fails in the current code. Authorization error getClient().perform(get("/api/core/bitstreams/"+bitstream.getID()+"/content")) .andExpect(status().isOk()) .andExpect(content().string("ThisIsSomeDummyText")) @@ -359,8 +359,6 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest } - - @Test public void findOneWrongUUID() throws Exception { @@ -377,7 +375,6 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest .build(); Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build(); - //TODO This test fails in the current code. Authorization error getClient().perform(get("/api/core/bitstreams/"+ 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 index 6b2d9a627c..8ed69498d0 100644 --- 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 @@ -190,24 +190,24 @@ public class CommunityRestRepositoryIT extends AbstractControllerIntegrationTest //** GIVEN ** //1. A community-collection structure with one parent community with sub-community and one collection. - parentCommunity = new CommunityBuilder().createCommunity(context) + parentCommunity = CommunityBuilder.createCommunity(context) .withName("Parent Community") .withLogo("ThisIsSomeDummyText") .build(); - Community parentCommunity2 = new CommunityBuilder().createCommunity(context) + Community parentCommunity2 = CommunityBuilder.createCommunity(context) .withName("Parent Community 2") .withLogo("SomeTest") .build(); - Community child1 = new CommunityBuilder().createSubCommunity(context, parentCommunity) + Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity) .withName("Sub Community") .build(); - Community child12 = new CommunityBuilder().createSubCommunity(context, child1) + Community child12 = CommunityBuilder.createSubCommunity(context, child1) .withName("Sub Sub Community") .build(); - Collection col1 = new CollectionBuilder().createCollection(context, child1).withName("Collection 1").build(); + Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build(); getClient().perform(get("/api/core/communities/search/top")) @@ -239,29 +239,29 @@ public class CommunityRestRepositoryIT extends AbstractControllerIntegrationTest //** GIVEN ** //1. A community-collection structure with one parent community with sub-community and one collection. - parentCommunity = new CommunityBuilder().createCommunity(context) + parentCommunity = CommunityBuilder.createCommunity(context) .withName("Parent Community") .withLogo("ThisIsSomeDummyText") .build(); - Community parentCommunity2 = new CommunityBuilder().createCommunity(context) + Community parentCommunity2 = CommunityBuilder.createCommunity(context) .withName("Parent Community 2") .withLogo("SomeTest") .build(); - Community child1 = new CommunityBuilder().createSubCommunity(context, parentCommunity) + Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity) .withName("Sub Community") .build(); - Community child12 = new CommunityBuilder().createSubCommunity(context, child1) + Community child12 = CommunityBuilder.createSubCommunity(context, child1) .withName("Sub Sub Community") .build(); - Community child2 = new CommunityBuilder().createSubCommunity(context, parentCommunity2) + Community child2 = CommunityBuilder.createSubCommunity(context, parentCommunity2) .withName("Sub2 Community") .build(); - Collection col1 = new CollectionBuilder().createCollection(context, child1).withName("Collection 1").build(); + Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build(); getClient().perform(get("/api/core/communities/search/subCommunities")) .andExpect(status().isOk()) 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 6706d0a3d2..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 @@ -35,6 +35,8 @@ import java.sql.SQLException; import java.util.Date; /** + * Abstract builder class that holds references to all available services + * * @author Jonas Van Goolen - (jonas@atmire.com) */ public abstract class AbstractBuilder { @@ -52,7 +54,6 @@ public abstract class AbstractBuilder { static AuthorizeService authorizeService; static ResourcePolicyService resourcePolicyService; static IndexingService indexingService; - static BitstreamFormatService bitstreamFormatService; static RegistrationDataService registrationDataService; static VersionHistoryService versionHistoryService; static ClaimedTaskService claimedTaskService; @@ -88,7 +89,6 @@ public abstract class AbstractBuilder { authorizeService = AuthorizeServiceFactory.getInstance().getAuthorizeService(); resourcePolicyService = AuthorizeServiceFactory.getInstance().getResourcePolicyService(); indexingService = DSpaceServicesFactory.getInstance().getServiceManager().getServiceByName(IndexingService.class.getName(),IndexingService.class); - bitstreamFormatService = ContentServiceFactory.getInstance().getBitstreamFormatService(); registrationDataService = EPersonServiceFactory.getInstance().getRegistrationDataService(); versionHistoryService = VersionServiceFactory.getInstance().getVersionHistoryService(); metadataFieldService = ContentServiceFactory.getInstance().getMetadataFieldService(); 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 33125c3eb1..bbfd4805ab 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 @@ -82,8 +82,4 @@ public class GroupBuilder extends AbstractDSpaceObjectBuilder { return this; } - public static AbstractBuilder cleaner() { - return new GroupBuilder(); - } - } From 1dde73f55b4ece136bbf72bdeb4617c79fd51daa Mon Sep 17 00:00:00 2001 From: Tom Desair Date: Tue, 5 Dec 2017 15:30:25 +0100 Subject: [PATCH 38/42] DS-3762: Correct @author tag --- .../dspace/services/sessions/StatelessRequestServiceImpl.java | 2 +- .../java/org/dspace/app/rest/AuthenticationRestController.java | 3 ++- .../src/main/java/org/dspace/app/rest/model/AuthnRest.java | 3 ++- .../app/rest/model/hateoas/AuthenticationStatusResource.java | 3 ++- .../java/org/dspace/app/rest/model/hateoas/AuthnResource.java | 3 ++- .../java/org/dspace/app/rest/security/CustomLogoutHandler.java | 3 ++- .../org/dspace/app/rest/security/DSpaceAuthentication.java | 3 ++- .../app/rest/security/EPersonRestAuthenticationProvider.java | 3 ++- .../dspace/app/rest/security/RestAuthenticationService.java | 3 ++- .../app/rest/security/StatelessAuthenticationFilter.java | 3 ++- .../org/dspace/app/rest/security/StatelessLoginFilter.java | 3 ++- .../org/dspace/app/rest/security/WebSecurityConfiguration.java | 3 ++- .../org/dspace/app/rest/security/jwt/EPersonClaimProvider.java | 3 ++- .../org/dspace/app/rest/security/jwt/JWTClaimProvider.java | 3 ++- .../java/org/dspace/app/rest/security/jwt/JWTTokenHandler.java | 3 ++- .../security/jwt/JWTTokenRestAuthenticationServiceImpl.java | 3 ++- .../app/rest/security/jwt/SpecialGroupClaimProvider.java | 3 ++- .../org/dspace/app/rest/AuthenticationRestControllerIT.java | 3 ++- .../java/org/dspace/app/rest/BrowsesResourceControllerIT.java | 3 ++- .../java/org/dspace/app/rest/RootRestResourceControllerIT.java | 3 ++- .../dspace/app/rest/builder/AbstractDSpaceObjectBuilder.java | 3 ++- .../java/org/dspace/app/rest/builder/CollectionBuilder.java | 3 ++- .../java/org/dspace/app/rest/builder/CommunityBuilder.java | 3 ++- .../test/java/org/dspace/app/rest/builder/GroupBuilder.java | 3 ++- .../src/test/java/org/dspace/app/rest/builder/ItemBuilder.java | 3 ++- .../dspace/app/rest/matcher/BrowseEntryResourceMatcher.java | 3 ++- .../java/org/dspace/app/rest/matcher/BrowseIndexMatcher.java | 3 ++- .../src/test/java/org/dspace/app/rest/matcher/ItemMatcher.java | 3 ++- .../rest/security/EPersonRestAuthenticationProviderTest.java | 3 ++- .../dspace/app/rest/security/jwt/EPersonClaimProviderTest.java | 3 ++- .../org/dspace/app/rest/security/jwt/JWTTokenHandlerTest.java | 3 ++- .../app/rest/security/jwt/SpecialGroupClaimProviderTest.java | 3 ++- .../app/rest/test/AbstractControllerIntegrationTest.java | 2 +- .../app/rest/test/DSpaceKernelContextCustomizerFactory.java | 2 +- 34 files changed, 65 insertions(+), 34 deletions(-) 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/BrowsesResourceControllerIT.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/BrowsesResourceControllerIT.java index 6bef045dec..02d6fd2955 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,7 +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 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 BrowsesResourceControllerIT extends AbstractControllerIntegrationTest { 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 dd08f4c258..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,7 +17,8 @@ import org.junit.Test; /** * Integration test for the {@link RootRestResourceController} * - * @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 RootRestResourceControllerIT extends AbstractControllerIntegrationTest { 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 index 6d5f463cbb..10bbd416b5 100644 --- 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 @@ -25,7 +25,8 @@ import java.util.Date; /** * Abstract builder to construct DSpace Objects * - * @author Atmire NV (info 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 abstract class AbstractDSpaceObjectBuilder extends AbstractBuilder { 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 f6eefb2bc4..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 @@ -25,7 +25,8 @@ import java.sql.SQLException; /** * Builder to construct Collection objects * - * @author Atmire NV (info 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 CollectionBuilder extends AbstractDSpaceObjectBuilder { 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 11bdbc85ba..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 @@ -22,7 +22,8 @@ import java.sql.SQLException; /** * Builder to construct Community objects * - * @author Atmire NV (info 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 CommunityBuilder extends AbstractDSpaceObjectBuilder { 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 bbfd4805ab..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 @@ -15,7 +15,8 @@ import org.dspace.eperson.Group; /** * Builder to construct Group objects * - * @author Atmire NV (info 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 GroupBuilder extends AbstractDSpaceObjectBuilder { 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 a7d73ca787..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 @@ -19,7 +19,8 @@ import org.dspace.eperson.Group; /** * Builder to construct Item objects * - * @author Atmire NV (info 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 ItemBuilder extends AbstractDSpaceObjectBuilder { diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/BrowseEntryResourceMatcher.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/BrowseEntryResourceMatcher.java index 0004f912e9..4c5e798fcd 100644 --- a/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/BrowseEntryResourceMatcher.java +++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/BrowseEntryResourceMatcher.java @@ -18,7 +18,8 @@ import org.hamcrest.Matcher; /** * Class to match JSON browse entries in ITs * - * @author Atmire NV (info 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 BrowseEntryResourceMatcher { public static Matcher matchBrowseEntry(String value, int expectedCount) { diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/BrowseIndexMatcher.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/BrowseIndexMatcher.java index 63d6423351..f3fa51d761 100644 --- a/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/BrowseIndexMatcher.java +++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/BrowseIndexMatcher.java @@ -21,7 +21,8 @@ import org.hamcrest.Matchers; /** * Utility class to construct a Matcher for a browse index * - * @author Atmire NV (info 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 BrowseIndexMatcher { diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/ItemMatcher.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/ItemMatcher.java index 747318a267..106e20540d 100644 --- a/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/ItemMatcher.java +++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/matcher/ItemMatcher.java @@ -21,7 +21,8 @@ import org.hamcrest.Matcher; /** * Utility class to construct a Matcher for an item * - * @author Atmire NV (info 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 ItemMatcher { 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/AbstractControllerIntegrationTest.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/test/AbstractControllerIntegrationTest.java index 8ed060db53..0091e99a2e 100644 --- a/dspace-spring-rest/src/test/java/org/dspace/app/rest/test/AbstractControllerIntegrationTest.java +++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/test/AbstractControllerIntegrationTest.java @@ -48,7 +48,7 @@ import org.springframework.web.context.WebApplicationContext; * Abstract controller integration test class that will take care of setting up the * environment to run the integration test * - * @author Atmire NV (info at atmire dot com) + * @author Tom Desair (tom dot desair at atmire dot com) */ @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = {Application.class, ApplicationConfig.class, WebSecurityConfiguration.class}) diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/test/DSpaceKernelContextCustomizerFactory.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/test/DSpaceKernelContextCustomizerFactory.java index d6754c2bd6..798070915a 100644 --- a/dspace-spring-rest/src/test/java/org/dspace/app/rest/test/DSpaceKernelContextCustomizerFactory.java +++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/test/DSpaceKernelContextCustomizerFactory.java @@ -17,7 +17,7 @@ import org.springframework.test.context.ContextCustomizerFactory; /** * Context customizer factory to set the parent context of our Spring Boot application in TEST mode * - * @author Atmire NV (info at atmire dot com) + * @author Tom Desair (tom dot desair at atmire dot com) */ public class DSpaceKernelContextCustomizerFactory implements ContextCustomizerFactory { From f4c07c947d56bc89e6f298a989bb5fee2e3b8f92 Mon Sep 17 00:00:00 2001 From: Raf Ponsaerts Date: Tue, 5 Dec 2017 17:21:00 +0100 Subject: [PATCH 39/42] [DS-3762] cleaned up unneccesary code and comments --- .../org/dspace/content/service/MetadataFieldService.java | 3 +-- .../org/dspace/app/rest/BrowsesResourceControllerIT.java | 5 +---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/dspace-api/src/main/java/org/dspace/content/service/MetadataFieldService.java b/dspace-api/src/main/java/org/dspace/content/service/MetadataFieldService.java index 215b82b3eb..b94092d9d1 100644 --- a/dspace-api/src/main/java/org/dspace/content/service/MetadataFieldService.java +++ b/dspace-api/src/main/java/org/dspace/content/service/MetadataFieldService.java @@ -12,7 +12,6 @@ import org.dspace.content.MetadataField; import org.dspace.content.MetadataSchema; import org.dspace.content.NonUniqueMetadataException; import org.dspace.core.Context; -import org.dspace.service.DSpaceCRUDService; import java.io.IOException; import java.sql.SQLException; @@ -24,7 +23,7 @@ import java.util.List; * * @author kevinvandevelde at atmire.com */ -public interface MetadataFieldService{ +public interface MetadataFieldService { /** * Creates a new metadata field. 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 02d6fd2955..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 @@ -174,7 +174,7 @@ public class BrowsesResourceControllerIT extends AbstractControllerIntegrationTe //We expect the content type to be "application/hal+json;charset=UTF-8" .andExpect(content().contentType(contentType)) .andExpect(jsonPath("$.page.size", is(20))) - //Check that there are indeed 8 different subjects + //Check that there are indeed 3 different subjects .andExpect(jsonPath("$.page.totalElements", is(3))) //Check the embedded resources and that they're sorted alphabetically //Check that the subject matches as expected @@ -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 From 2d537abd7e343f92671db7b168daa43146713e06 Mon Sep 17 00:00:00 2001 From: Tom Desair Date: Wed, 6 Dec 2017 00:47:50 +0100 Subject: [PATCH 40/42] DS-3762: Added test for Context.close() in try-with-resources block --- .../java/org/dspace/core/ContextTest.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) 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 00cade17df..dc1f4be16a 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. From e61e6e7a1ea334b79aae112993ec1257efe0bff0 Mon Sep 17 00:00:00 2001 From: Raf Ponsaerts Date: Mon, 11 Dec 2017 14:20:45 +0100 Subject: [PATCH 41/42] [DS-3762] implemented changes --- .../app/rest/BitstreamFormatRestRepositoryIT.java | 13 +++++++++++-- .../dspace/app/rest/CommunityRestRepositoryIT.java | 9 ++++----- 2 files changed, 15 insertions(+), 7 deletions(-) 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 index 7d5f60aec3..ce79ee2c0c 100644 --- 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 @@ -73,11 +73,20 @@ public class BitstreamFormatRestRepositoryIT extends AbstractControllerIntegrati @Test @Ignore public void findOne() throws Exception { - getClient().perform(get("/api/core/bitstreamformats/1")) + 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/1"))) + .andExpect(jsonPath("$._links.self.href", endsWith("/api/core/bitstreamformats/"+bitstreamFormat.getID()))) ; } } 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 index 8ed69498d0..df07fb9dd5 100644 --- 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 @@ -231,7 +231,6 @@ public class CommunityRestRepositoryIT extends AbstractControllerIntegrationTest //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 @@ -263,17 +262,17 @@ public class CommunityRestRepositoryIT extends AbstractControllerIntegrationTest Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build(); - getClient().perform(get("/api/core/communities/search/subCommunities")) + 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()), - CommunityMatcher.matchCommunityEntry(child2.getName(), child2.getID(), child2.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(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))) From 1271eb2a3a3e08c140f41ef3c3b23b7b33588115 Mon Sep 17 00:00:00 2001 From: Raf Ponsaerts Date: Mon, 11 Dec 2017 14:41:33 +0100 Subject: [PATCH 42/42] [DS-3762] implemented requested changes --- .../app/rest/CommunityRestRepositoryIT.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) 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 index df07fb9dd5..bec3ea8645 100644 --- 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 @@ -231,6 +231,7 @@ public class CommunityRestRepositoryIT extends AbstractControllerIntegrationTest //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 @@ -280,7 +281,44 @@ public class CommunityRestRepositoryIT extends AbstractControllerIntegrationTest ; } + //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