use of com.github.springtestdbunit.annotation.ExpectedDatabase in project ArachneCentralAPI by OHDSI.
the class UserControllerTests method testSuggest.
@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetup(value = "/data/user/users-for-suggestion.xml")
@ExpectedDatabase(value = "/data/user/users-for-suggestion.xml", assertionMode = NON_STRICT)
public void testSuggest() throws Exception {
final String query = "fir";
final Long studyId = 1L;
MvcResult mvcResult = mvc.perform(get("/api/v1/user-management/users/suggest?target=STUDY&query=" + query + "&id=" + studyId)).andExpect(OK_STATUS).andExpect(jsonPath("$").isArray()).andExpect(jsonPath("$", hasSize(3))).andReturn();
JSONArray suggested = new JSONArray(mvcResult.getResponse().getContentAsString());
List<Object> list = new ArrayList<>();
for (int i = 0; i < suggested.length(); i++) {
list.add(suggested.getJSONObject(i).get("id"));
}
// suggested user ids
Assert.assertTrue(list.contains(UserIdUtils.idToUuid(3L)));
Assert.assertTrue(list.contains(UserIdUtils.idToUuid(6L)));
Assert.assertTrue(list.contains(UserIdUtils.idToUuid(7L)));
}
use of com.github.springtestdbunit.annotation.ExpectedDatabase in project ArachneCentralAPI by OHDSI.
the class UserControllerTests method testDeletePublicationFromUser.
@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetup("/data/user/admin-user-with-publication-for-deleting.xml")
@ExpectedDatabase(value = "/data/user/admin-user.xml", assertionMode = NON_STRICT)
public void testDeletePublicationFromUser() throws Exception {
Integer publicationId = 1;
MvcResult mvcResult = mvc.perform(delete("/api/v1/user-management/users/publications/" + publicationId)).andExpect(jsonPath("$.result.publications").isEmpty()).andReturn();
JSONAssert.assertEquals(ADMIN_JSON_OBJECT, getGeneral(mvcResult), false);
}
use of com.github.springtestdbunit.annotation.ExpectedDatabase in project ArachneCentralAPI by OHDSI.
the class UserControllerTests method testLinkToUser.
@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetup("/data/user/admin-user.xml")
@ExpectedDatabase(value = "/data/user/admin-user-with-link.xml", assertionMode = NON_STRICT)
public void testLinkToUser() throws Exception {
UserLinkDTO link = getUserLinkDTO();
MvcResult mvcResult = mvc.perform(post("/api/v1/user-management/users/links").contentType(APPLICATION_JSON).content(objectMapper.writeValueAsString(link))).andExpect(NO_ERROR_CODE).andExpect(OK_STATUS).andExpect(jsonPath("$.result.links").isNotEmpty()).andExpect(jsonPath("$.result.links").isArray()).andExpect(jsonPath("$.result.links", hasSize(1))).andReturn();
JSONAssert.assertEquals(ADMIN_JSON_OBJECT, getGeneral(mvcResult), FALSE);
JSONArray links = (JSONArray) getResultJSONObject(mvcResult).get("links");
JSONAssert.assertEquals(USER_LINK, (JSONObject) links.get(0), FALSE);
}
use of com.github.springtestdbunit.annotation.ExpectedDatabase in project ArachneCentralAPI by OHDSI.
the class UserControllerTests method testGetProfile.
@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetup("/data/user/enabled-user.xml")
@ExpectedDatabase(value = "/data/user/enabled-user.xml", assertionMode = NON_STRICT)
public void testGetProfile() throws Exception {
MvcResult mvcResult = mvc.perform(get("/api/v1/user-management/users/" + USER_2_UUID + "/profile")).andExpect(NO_ERROR_CODE).andExpect(OK_STATUS).andReturn();
JSONAssert.assertEquals(USER_JSON_OBJECT, getGeneral(mvcResult), false);
}
use of com.github.springtestdbunit.annotation.ExpectedDatabase in project ArachneCentralAPI by OHDSI.
the class UserControllerTests method testRemoveLinkFromUser.
@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetup("/data/user/admin-user-with-link-for-deleting.xml")
@ExpectedDatabase(value = "/data/user/admin-user.xml", assertionMode = NON_STRICT)
public void testRemoveLinkFromUser() throws Exception {
final Integer linkId = 1;
MvcResult mvcResult = mvc.perform(delete("/api/v1/user-management/users/links/" + linkId)).andExpect(NO_ERROR_CODE).andExpect(OK_STATUS).andExpect(jsonPath("$.result.skills").isEmpty()).andReturn();
JSONAssert.assertEquals(ADMIN_JSON_OBJECT, getGeneral(mvcResult), FALSE);
}
Aggregations