mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-08 02:24:18 +00:00
Add IT for eperson search methods
This commit is contained in:
@@ -30,7 +30,7 @@ public class EPersonRestRepositoryIT extends AbstractControllerIntegrationTest {
|
|||||||
|
|
||||||
EPerson newUser = EPersonBuilder.createEPerson(context)
|
EPerson newUser = EPersonBuilder.createEPerson(context)
|
||||||
.withNameInMetadata("John", "Doe")
|
.withNameInMetadata("John", "Doe")
|
||||||
.withEmail("Johndoe@gmail.com")
|
.withEmail("Johndoe@fake-email.com")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
String authToken = getAuthToken(admin.getEmail(), password);
|
String authToken = getAuthToken(admin.getEmail(), password);
|
||||||
@@ -53,7 +53,7 @@ public class EPersonRestRepositoryIT extends AbstractControllerIntegrationTest {
|
|||||||
|
|
||||||
EPerson newUser = EPersonBuilder.createEPerson(context)
|
EPerson newUser = EPersonBuilder.createEPerson(context)
|
||||||
.withNameInMetadata("John", "Doe")
|
.withNameInMetadata("John", "Doe")
|
||||||
.withEmail("Johndoe@gmail.com")
|
.withEmail("Johndoe@fake-email.com")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
getClient().perform(get("/api/eperson/eperson"))
|
getClient().perform(get("/api/eperson/eperson"))
|
||||||
@@ -66,7 +66,7 @@ public class EPersonRestRepositoryIT extends AbstractControllerIntegrationTest {
|
|||||||
|
|
||||||
EPerson newUser = EPersonBuilder.createEPerson(context)
|
EPerson newUser = EPersonBuilder.createEPerson(context)
|
||||||
.withNameInMetadata("John", "Doe")
|
.withNameInMetadata("John", "Doe")
|
||||||
.withEmail("Johndoe@gmail.com")
|
.withEmail("Johndoe@fake-email.com")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
String authToken = getAuthToken(eperson.getEmail(), password);
|
String authToken = getAuthToken(eperson.getEmail(), password);
|
||||||
@@ -80,7 +80,7 @@ public class EPersonRestRepositoryIT extends AbstractControllerIntegrationTest {
|
|||||||
|
|
||||||
EPerson ePerson = EPersonBuilder.createEPerson(context)
|
EPerson ePerson = EPersonBuilder.createEPerson(context)
|
||||||
.withNameInMetadata("John", "Doe")
|
.withNameInMetadata("John", "Doe")
|
||||||
.withEmail("Johndoe@gmail.com")
|
.withEmail("Johndoe@fake-email.com")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
String authToken = getAuthToken(admin.getEmail(), password);
|
String authToken = getAuthToken(admin.getEmail(), password);
|
||||||
@@ -123,12 +123,12 @@ public class EPersonRestRepositoryIT extends AbstractControllerIntegrationTest {
|
|||||||
|
|
||||||
EPerson ePerson = EPersonBuilder.createEPerson(context)
|
EPerson ePerson = EPersonBuilder.createEPerson(context)
|
||||||
.withNameInMetadata("John", "Doe")
|
.withNameInMetadata("John", "Doe")
|
||||||
.withEmail("Johndoe@gmail.com")
|
.withEmail("Johndoe@fake-email.com")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
EPerson ePerson2 = EPersonBuilder.createEPerson(context)
|
EPerson ePerson2 = EPersonBuilder.createEPerson(context)
|
||||||
.withNameInMetadata("Jane", "Smith")
|
.withNameInMetadata("Jane", "Smith")
|
||||||
.withEmail("janesmith@gmail.com")
|
.withEmail("janesmith@fake-email.com")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
String authToken = getAuthToken(admin.getEmail(), password);
|
String authToken = getAuthToken(admin.getEmail(), password);
|
||||||
@@ -152,12 +152,12 @@ public class EPersonRestRepositoryIT extends AbstractControllerIntegrationTest {
|
|||||||
|
|
||||||
EPerson ePerson = EPersonBuilder.createEPerson(context)
|
EPerson ePerson = EPersonBuilder.createEPerson(context)
|
||||||
.withNameInMetadata("John", "Doe")
|
.withNameInMetadata("John", "Doe")
|
||||||
.withEmail("Johndoe@gmail.com")
|
.withEmail("Johndoe@fake-email.com")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
EPerson ePerson2 = EPersonBuilder.createEPerson(context)
|
EPerson ePerson2 = EPersonBuilder.createEPerson(context)
|
||||||
.withNameInMetadata("Jane", "Smith")
|
.withNameInMetadata("Jane", "Smith")
|
||||||
.withEmail("janesmith@gmail.com")
|
.withEmail("janesmith@fake-email.com")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
String authToken = getAuthToken(admin.getEmail(), password);
|
String authToken = getAuthToken(admin.getEmail(), password);
|
||||||
@@ -183,12 +183,12 @@ public class EPersonRestRepositoryIT extends AbstractControllerIntegrationTest {
|
|||||||
|
|
||||||
EPerson ePerson = EPersonBuilder.createEPerson(context)
|
EPerson ePerson = EPersonBuilder.createEPerson(context)
|
||||||
.withNameInMetadata("John", "Doe")
|
.withNameInMetadata("John", "Doe")
|
||||||
.withEmail("Johndoe@gmail.com")
|
.withEmail("Johndoe@fake-email.com")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
EPerson ePerson2 = EPersonBuilder.createEPerson(context)
|
EPerson ePerson2 = EPersonBuilder.createEPerson(context)
|
||||||
.withNameInMetadata("Jane", "Smith")
|
.withNameInMetadata("Jane", "Smith")
|
||||||
.withEmail("janesmith@gmail.com")
|
.withEmail("janesmith@fake-email.com")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
String authToken = getAuthToken(admin.getEmail(), password);
|
String authToken = getAuthToken(admin.getEmail(), password);
|
||||||
@@ -196,4 +196,140 @@ public class EPersonRestRepositoryIT extends AbstractControllerIntegrationTest {
|
|||||||
.andExpect(status().isNotFound());
|
.andExpect(status().isNotFound());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void searchMethodsExist() throws Exception {
|
||||||
|
String authToken = getAuthToken(admin.getEmail(), password);
|
||||||
|
getClient(authToken).perform(get("/api/eperson/epersons"))
|
||||||
|
.andExpect(jsonPath("$._links.search.href", Matchers.notNullValue()));
|
||||||
|
|
||||||
|
getClient(authToken).perform(get("/api/eperson/epersons/search"))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(content().contentType(contentType))
|
||||||
|
.andExpect(jsonPath("$._links.byEmail", Matchers.notNullValue()))
|
||||||
|
.andExpect(jsonPath("$._links.byName", Matchers.notNullValue()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findByEmail() throws Exception {
|
||||||
|
context.turnOffAuthorisationSystem();
|
||||||
|
|
||||||
|
EPerson ePerson = EPersonBuilder.createEPerson(context)
|
||||||
|
.withNameInMetadata("John", "Doe")
|
||||||
|
.withEmail("Johndoe@fake-email.com")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
// create a second eperson to put the previous one in a no special position (is not the first as we have default
|
||||||
|
// epersons is not the latest created)
|
||||||
|
EPerson ePerson2 = EPersonBuilder.createEPerson(context)
|
||||||
|
.withNameInMetadata("Jane", "Smith")
|
||||||
|
.withEmail("janesmith@fake-email.com")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
String authToken = getAuthToken(admin.getEmail(), password);
|
||||||
|
getClient(authToken).perform(get("/api/eperson/epersons/search/byEmail")
|
||||||
|
.param("email", ePerson.getEmail()))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(content().contentType(contentType))
|
||||||
|
.andExpect(jsonPath("$", is(
|
||||||
|
EPersonMatcher.matchEPersonEntry(ePerson)
|
||||||
|
)));
|
||||||
|
|
||||||
|
// it must be case-insensitive
|
||||||
|
getClient(authToken).perform(get("/api/eperson/epersons/search/byEmail")
|
||||||
|
.param("email", ePerson.getEmail().toUpperCase()))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(content().contentType(contentType))
|
||||||
|
.andExpect(jsonPath("$", is(
|
||||||
|
EPersonMatcher.matchEPersonEntry(ePerson)
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findByEmailUndefined() throws Exception {
|
||||||
|
String authToken = getAuthToken(admin.getEmail(), password);
|
||||||
|
getClient(authToken).perform(get("/api/eperson/epersons/search/byEmail")
|
||||||
|
.param("email", "undefined@undefined.com"))
|
||||||
|
.andExpect(status().isNotFound());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findByEmailUnprocessable() throws Exception {
|
||||||
|
String authToken = getAuthToken(admin.getEmail(), password);
|
||||||
|
getClient(authToken).perform(get("/api/eperson/epersons/search/byEmail"))
|
||||||
|
.andExpect(status().isUnprocessableEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findByName() throws Exception {
|
||||||
|
context.turnOffAuthorisationSystem();
|
||||||
|
EPerson ePerson = EPersonBuilder.createEPerson(context)
|
||||||
|
.withNameInMetadata("John", "Doe")
|
||||||
|
.withEmail("Johndoe@fake-email.com")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
EPerson ePerson2 = EPersonBuilder.createEPerson(context)
|
||||||
|
.withNameInMetadata("Jane", "Smith")
|
||||||
|
.withEmail("janesmith@fake-email.com")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
EPerson ePerson3 = EPersonBuilder.createEPerson(context)
|
||||||
|
.withNameInMetadata("Tom", "Doe")
|
||||||
|
.withEmail("tomdoe@fake-email.com")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
EPerson ePerson4 = EPersonBuilder.createEPerson(context)
|
||||||
|
.withNameInMetadata("Dirk", "Doe-Postfix")
|
||||||
|
.withEmail("dirkdoepostfix@fake-email.com")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
EPerson ePerson5 = EPersonBuilder.createEPerson(context)
|
||||||
|
.withNameInMetadata("Harry", "Prefix-Doe")
|
||||||
|
.withEmail("harrydoeprefix@fake-email.com")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
String authToken = getAuthToken(admin.getEmail(), password);
|
||||||
|
getClient(authToken).perform(get("/api/eperson/epersons/search/byName")
|
||||||
|
.param("q", ePerson.getLastName()))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(content().contentType(contentType))
|
||||||
|
.andExpect(jsonPath("$._embedded.epersons", Matchers.containsInAnyOrder(
|
||||||
|
EPersonMatcher.matchEPersonEntry(ePerson),
|
||||||
|
EPersonMatcher.matchEPersonEntry(ePerson3),
|
||||||
|
EPersonMatcher.matchEPersonEntry(ePerson4),
|
||||||
|
EPersonMatcher.matchEPersonEntry(ePerson5)
|
||||||
|
)))
|
||||||
|
.andExpect(jsonPath("$.page.totalElements", is(4)));
|
||||||
|
|
||||||
|
// it must be case insensitive
|
||||||
|
getClient(authToken).perform(get("/api/eperson/epersons/search/byName")
|
||||||
|
.param("q", ePerson.getLastName().toLowerCase()))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(content().contentType(contentType))
|
||||||
|
.andExpect(jsonPath("$._embedded.epersons", Matchers.containsInAnyOrder(
|
||||||
|
EPersonMatcher.matchEPersonEntry(ePerson),
|
||||||
|
EPersonMatcher.matchEPersonEntry(ePerson3),
|
||||||
|
EPersonMatcher.matchEPersonEntry(ePerson4),
|
||||||
|
EPersonMatcher.matchEPersonEntry(ePerson5)
|
||||||
|
)))
|
||||||
|
.andExpect(jsonPath("$.page.totalElements", is(4)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findByNameUndefined() throws Exception {
|
||||||
|
String authToken = getAuthToken(admin.getEmail(), password);
|
||||||
|
getClient(authToken).perform(get("/api/eperson/epersons/search/byName")
|
||||||
|
.param("q", "Doe, John"))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(content().contentType(contentType))
|
||||||
|
.andExpect(jsonPath("$.page.totalElements", is(0)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findByNameUnprocessable() throws Exception {
|
||||||
|
String authToken = getAuthToken(admin.getEmail(), password);
|
||||||
|
getClient(authToken).perform(get("/api/eperson/epersons/search/byName"))
|
||||||
|
.andExpect(status().isUnprocessableEntity());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user