Skip to content

Commit

Permalink
Fix test issues after master merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Raf-atmire committed Apr 16, 2020
1 parent dd00ab2 commit 802e641
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ public void findAllTest() throws Exception {
.andExpect(status().isOk())
.andExpect(content().contentType(contentType))
.andExpect(jsonPath("$._embedded.collections", Matchers.containsInAnyOrder(
CollectionMatcher.matchCollectionEntryFullProjection(col1.getName(), col1.getID(),
CollectionMatcher.matchCollectionEntrySpecificEmbedProjection(col1.getName(), col1.getID(),
col1.getHandle()),
CollectionMatcher.matchCollectionEntryFullProjection(col2.getName(), col2.getID(),
CollectionMatcher.matchCollectionEntrySpecificEmbedProjection(col2.getName(), col2.getID(),
col2.getHandle())
)));
}
Expand Down Expand Up @@ -225,12 +225,12 @@ public void findAllPaginationTest() throws Exception {
.andExpect(status().isOk())
.andExpect(content().contentType(contentType))
.andExpect(jsonPath("$._embedded.collections", Matchers.contains(
CollectionMatcher.matchCollectionEntryFullProjection(col1.getName(), col1.getID(),
CollectionMatcher.matchCollectionEntrySpecificEmbedProjection(col1.getName(), col1.getID(),
col1.getHandle())
)))
.andExpect(jsonPath("$._embedded.collections", Matchers.not(
Matchers.contains(
CollectionMatcher.matchCollectionEntryFullProjection(col2.getName(), col2.getID(),
CollectionMatcher.matchCollectionEntrySpecificEmbedProjection(col2.getName(), col2.getID(),
col2.getHandle())
)
)));
Expand All @@ -243,12 +243,12 @@ public void findAllPaginationTest() throws Exception {
.andExpect(status().isOk())
.andExpect(content().contentType(contentType))
.andExpect(jsonPath("$._embedded.collections", Matchers.contains(
CollectionMatcher.matchCollectionEntryFullProjection(col2.getName(), col2.getID(),
CollectionMatcher.matchCollectionEntrySpecificEmbedProjection(col2.getName(), col2.getID(),
col2.getHandle())
)))
.andExpect(jsonPath("$._embedded.collections", Matchers.not(
Matchers.contains(
CollectionMatcher.matchCollectionEntryFullProjection(col1.getName(), col1.getID(),
CollectionMatcher.matchCollectionEntrySpecificEmbedProjection(col1.getName(), col1.getID(),
col1.getHandle())
)
)));
Expand Down Expand Up @@ -283,7 +283,7 @@ public void findOneCollectionTest() throws Exception {

.andExpect(status().isOk())
.andExpect(content().contentType(contentType))
.andExpect(jsonPath("$", CollectionMatcher.matchFullEmbeds()))
.andExpect(jsonPath("$", CollectionMatcher.matchSpecificEmbeds()))
.andExpect(jsonPath("$", CollectionMatcher.matchCollectionEntry(
col1.getName(), col1.getID(), col1.getHandle())));

Expand Down Expand Up @@ -418,12 +418,12 @@ public void findOneCollectionRelsTest() throws Exception {
.andExpect(status().isOk())
.andExpect(content().contentType(contentType))
.andExpect(jsonPath("$", is(
CollectionMatcher.matchCollectionEntryFullProjection(col1.getName(), col1.getID(),
CollectionMatcher.matchCollectionEntrySpecificEmbedProjection(col1.getName(), col1.getID(),
col1.getHandle())
)))
.andExpect(jsonPath("$", Matchers.not(
is(
CollectionMatcher.matchCollectionEntryFullProjection(col2.getName(), col2.getID(),
CollectionMatcher.matchCollectionEntrySpecificEmbedProjection(col2.getName(), col2.getID(),
col2.getHandle())
)))
)
Expand Down Expand Up @@ -567,12 +567,12 @@ public void findCollectionWithParentCommunity() throws Exception {
.andExpect(status().isOk())
.andExpect(content().contentType(contentType))
.andExpect(jsonPath("$", is(
CollectionMatcher.matchCollectionEntryFullProjection(col1.getName(), col1.getID(),
CollectionMatcher.matchCollectionEntrySpecificEmbedProjection(col1.getName(), col1.getID(),
col1.getHandle())
)))
.andExpect(jsonPath("$", Matchers.not(
is(
CollectionMatcher.matchCollectionEntryFullProjection(col2.getName(), col2.getID(),
CollectionMatcher.matchCollectionEntrySpecificEmbedProjection(col2.getName(), col2.getID(),
col2.getHandle())
))));
}
Expand All @@ -598,7 +598,7 @@ public void updateTest() throws Exception {
.andExpect(status().isOk())
.andExpect(content().contentType(contentType))
.andExpect(jsonPath("$", Matchers.is(
CollectionMatcher.matchCollectionEntryFullProjection(col1.getName(), col1.getID(),
CollectionMatcher.matchCollectionEntrySpecificEmbedProjection(col1.getName(), col1.getID(),
col1.getHandle())
)))
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/collections")))
Expand Down Expand Up @@ -627,8 +627,8 @@ public void updateTest() throws Exception {
.andExpect(status().isOk())
.andExpect(content().contentType(contentType))
.andExpect(jsonPath("$", Matchers.is(
CollectionMatcher.matchCollectionEntryFullProjection("Electronic theses and dissertations",
col1.getID(), col1.getHandle())
CollectionMatcher.matchCollectionEntrySpecificEmbedProjection(
"Electronic theses and dissertations", col1.getID(), col1.getHandle())
)))
.andExpect(jsonPath("$._links.self.href",
Matchers.containsString("/api/core/collections")))
Expand Down Expand Up @@ -670,7 +670,7 @@ public void deleteTest() throws Exception {
.andExpect(status().isOk())
.andExpect(content().contentType(contentType))
.andExpect(jsonPath("$", Matchers.is(
CollectionMatcher.matchCollectionEntryFullProjection(col1.getName(), col1.getID(),
CollectionMatcher.matchCollectionEntrySpecificEmbedProjection(col1.getName(), col1.getID(),
col1.getHandle())
)))
.andExpect(jsonPath("$._links.self.href",
Expand Down Expand Up @@ -716,7 +716,7 @@ public void deleteTestUnAuthorized() throws Exception {
.andExpect(status().isOk())
.andExpect(content().contentType(contentType))
.andExpect(jsonPath("$", Matchers.is(
CollectionMatcher.matchCollectionEntryFullProjection(col1.getName(), col1.getID(),
CollectionMatcher.matchCollectionEntrySpecificEmbedProjection(col1.getName(), col1.getID(),
col1.getHandle())
)))
.andExpect(jsonPath("$._links.self.href",
Expand Down Expand Up @@ -765,7 +765,7 @@ public void createTest() throws Exception {

.andExpect(status().isCreated())
.andExpect(content().contentType(contentType))
.andExpect(jsonPath("$", CollectionMatcher.matchFullEmbeds()))
.andExpect(jsonPath("$", CollectionMatcher.matchSpecificEmbeds()))
.andExpect(jsonPath("$", Matchers.allOf(
hasJsonPath("$.id", not(empty())),
hasJsonPath("$.uuid", not(empty())),
Expand Down Expand Up @@ -940,7 +940,7 @@ public void deleteCollectionEpersonWithDeleteRightsTest() throws Exception {
.andExpect(status().isOk())
.andExpect(content().contentType(contentType))
.andExpect(jsonPath("$", Matchers.is(
CollectionMatcher.matchCollectionEntryFullProjection(col1.getName(), col1.getID(),
CollectionMatcher.matchCollectionEntrySpecificEmbedProjection(col1.getName(), col1.getID(),
col1.getHandle())
)))
.andExpect(jsonPath("$._links.self.href",
Expand Down Expand Up @@ -978,7 +978,7 @@ public void updateCollectionEpersonWithWriteRightsTest() throws Exception {
.andExpect(status().isOk())
.andExpect(content().contentType(contentType))
.andExpect(jsonPath("$", Matchers.is(
CollectionMatcher.matchCollectionEntryFullProjection(col1.getName(), col1.getID(),
CollectionMatcher.matchCollectionEntrySpecificEmbedProjection(col1.getName(), col1.getID(),
col1.getHandle())
)))
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/collections")))
Expand Down Expand Up @@ -1010,8 +1010,8 @@ public void updateCollectionEpersonWithWriteRightsTest() throws Exception {
.andExpect(status().isOk())
.andExpect(content().contentType(contentType))
.andExpect(jsonPath("$", Matchers.is(
CollectionMatcher.matchCollectionEntryFullProjection("Electronic theses and dissertations",
col1.getID(), col1.getHandle())
CollectionMatcher.matchCollectionEntrySpecificEmbedProjection(
"Electronic theses and dissertations", col1.getID(), col1.getHandle())
)))
.andExpect(jsonPath("$._links.self.href",
Matchers.containsString("/api/core/collections")))
Expand Down Expand Up @@ -1152,9 +1152,9 @@ public void findAllCollectionsWithMultilanguageTitlesTest() throws Exception {
.andExpect(status().isOk())
.andExpect(content().contentType(contentType))
.andExpect(jsonPath("$._embedded.collections", Matchers.containsInAnyOrder(
CollectionMatcher.matchCollectionEntryFullProjection(col1.getName(), col1.getID(),
CollectionMatcher.matchCollectionEntrySpecificEmbedProjection(col1.getName(), col1.getID(),
col1.getHandle()),
CollectionMatcher.matchCollectionEntryFullProjection(col2.getName(), col2.getID(),
CollectionMatcher.matchCollectionEntrySpecificEmbedProjection(col2.getName(), col2.getID(),
col2.getHandle())
)))
.andExpect(jsonPath("$.page", PageMatcher.pageEntryWithTotalPagesAndElements(0, 20,
Expand Down Expand Up @@ -1307,10 +1307,8 @@ public void testHiddenMetadataForAonymousUser() throws Exception {
context.restoreAuthSystemState();


getClient().perform(get("/api/core/collections/" + col1.getID())
.param("projection", "full"))
getClient().perform(get("/api/core/collections/" + col1.getID()))
.andExpect(status().isOk())
.andExpect(jsonPath("$", CollectionMatcher.matchFullEmbeds()))
.andExpect(jsonPath("$", CollectionMatcher.matchProperties(col1.getName(),
col1.getID(),
col1.getHandle())))
Expand Down Expand Up @@ -1338,10 +1336,8 @@ public void testHiddenMetadataForAdminUser() throws Exception {

String token = getAuthToken(admin.getEmail(), password);

getClient(token).perform(get("/api/core/collections/" + col1.getID())
.param("projection", "full"))
getClient(token).perform(get("/api/core/collections/" + col1.getID()))
.andExpect(status().isOk())
.andExpect(jsonPath("$", CollectionMatcher.matchFullEmbeds()))
.andExpect(jsonPath("$", CollectionMatcher.matchProperties(col1.getName(),
col1.getID(),
col1.getHandle())))
Expand Down Expand Up @@ -1373,10 +1369,8 @@ public void testHiddenMetadataForUserWithWriteRights() throws Exception {

String token = getAuthToken(eperson.getEmail(), password);

getClient(token).perform(get("/api/core/collections/" + col1.getID())
.param("projection", "full"))
getClient(token).perform(get("/api/core/collections/" + col1.getID()))
.andExpect(status().isOk())
.andExpect(jsonPath("$", CollectionMatcher.matchFullEmbeds()))
.andExpect(jsonPath("$", CollectionMatcher.matchProperties(col1.getName(),
col1.getID(),
col1.getHandle())))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2576,10 +2576,8 @@ public void testHiddenMetadataForAnonymousUser() throws Exception {
context.restoreAuthSystemState();


getClient().perform(get("/api/core/items/" + item.getID())
.param("projection", "full"))
getClient().perform(get("/api/core/items/" + item.getID()))
.andExpect(status().isOk())
.andExpect(jsonPath("$", ItemMatcher.matchFullEmbeds()))
.andExpect(jsonPath("$", ItemMatcher.matchItemProperties(item)))
.andExpect(jsonPath("$.metadata", matchMetadata("dc.title", "Public item 1")))
.andExpect(jsonPath("$.metadata", matchMetadataDoesNotExist("dc.description.provenance")));
Expand All @@ -2603,10 +2601,8 @@ public void testHiddenMetadataForAdminUser() throws Exception {

String token = getAuthToken(admin.getEmail(), password);

getClient(token).perform(get("/api/core/items/" + item.getID())
.param("projection", "full"))
getClient(token).perform(get("/api/core/items/" + item.getID()))
.andExpect(status().isOk())
.andExpect(jsonPath("$", ItemMatcher.matchFullEmbeds()))
.andExpect(jsonPath("$", ItemMatcher.matchItemProperties(item)))
.andExpect(jsonPath("$.metadata", matchMetadata("dc.title", "Public item 1")))
.andExpect(jsonPath("$.metadata", matchMetadata("dc.description.provenance", "Provenance data")));
Expand Down Expand Up @@ -2637,10 +2633,8 @@ public void testHiddenMetadataForUserWithWriteRights() throws Exception {

String token = getAuthToken(eperson.getEmail(), password);

getClient(token).perform(get("/api/core/items/" + item.getID())
.param("projection", "full"))
getClient(token).perform(get("/api/core/items/" + item.getID()))
.andExpect(status().isOk())
.andExpect(jsonPath("$", ItemMatcher.matchFullEmbeds()))
.andExpect(jsonPath("$", ItemMatcher.matchItemProperties(item)))
.andExpect(jsonPath("$.metadata", matchMetadata("dc.title", "Public item 1")))
.andExpect(jsonPath("$.metadata", matchMetadataDoesNotExist("dc.description.provenance")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ public static Matcher<? super Object> matchCollectionEntryFullProjection(String
);
}

public static Matcher<? super Object> matchCollectionEntrySpecificEmbedProjection(String name, UUID uuid,
String handle) {
return matchCollectionEntrySpecificEmbedProjection(name, uuid, handle, null);

}

public static Matcher<? super Object> matchCollectionEntrySpecificEmbedProjection(String name, UUID uuid,
String handle, Bitstream logo) {
return allOf(
matchProperties(name, uuid, handle),
matchLinks(uuid),
matchLogo(logo),
matchSpecificEmbeds()
);
}

public static Matcher<? super Object> matchProperties(String name, UUID uuid, String handle) {
return allOf(
hasJsonPath("$.uuid", is(uuid.toString())),
Expand All @@ -70,7 +86,11 @@ public static Matcher<? super Object> matchFullEmbeds() {
"license",
"logo",
"parentCommunity",
"mappedItems[]"
"mappedItems[]",
"adminGroup",
"submittersGroup",
"itemReadGroup",
"bitstreamReadGroup"
);
}

Expand Down Expand Up @@ -119,4 +139,12 @@ public static Matcher<? super Object> matchCollection(Collection collection) {
hasJsonPath("$.type", is("collection")),
hasJsonPath("$.handle", is(collection.getHandle())));
}

/**
* Gets a matcher for all expected embeds when the embeds parameter is requested.
*/
public static Matcher<? super Object> matchSpecificEmbeds() {
return matchEmbeds(getEmbedsParameter().split(",")
);
}
}

0 comments on commit 802e641

Please sign in to comment.