mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
[DS-3762] added extra clauses for the EPerson matcher
This commit is contained in:

committed by
Tom Desair

parent
70529b154c
commit
f4b6b5d480
@@ -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())));
|
||||
|
@@ -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<? super Object> matchEPersonEntry(UUID uuid, String name) {
|
||||
public static Matcher<? super Object> 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())
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
|
@@ -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<? super Object> matchFirstName(String firstName){
|
||||
return allOf(
|
||||
hasJsonPath("$.key", is("eperson.firstname")),
|
||||
hasJsonPath("$.value", is(firstName))
|
||||
);
|
||||
}
|
||||
|
||||
public static Matcher<? super Object> matchLastName(String lastName){
|
||||
return allOf(
|
||||
hasJsonPath("$.key", is("eperson.lastname")),
|
||||
hasJsonPath("$.value", is(lastName))
|
||||
);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user