[DS-3762] added extra clauses for the EPerson matcher

This commit is contained in:
Raf Ponsaerts
2017-12-01 16:08:28 +01:00
committed by Tom Desair
parent 70529b154c
commit f4b6b5d480
3 changed files with 46 additions and 14 deletions

View File

@@ -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())));

View File

@@ -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())
))
);
}

View File

@@ -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))
);
}
}