use of org.hisp.dhis.webapi.json.domain.JsonUser in project dhis2-core by dhis2.
the class AbstractCrudControllerTest method testGetObjectProperty.
@Test
void testGetObjectProperty() {
// response will look like: { "surname": <name> }
JsonUser userProperty = GET("/users/{id}/surname", run(SomeUserId::new)).content(HttpStatus.OK).as(JsonUser.class);
assertEquals("admin", userProperty.getSurname());
assertEquals(1, userProperty.size());
}
use of org.hisp.dhis.webapi.json.domain.JsonUser in project dhis2-core by dhis2.
the class AbstractCrudControllerTest method testPutJsonObject_accountExpiry_PutNoChange.
@Test
void testPutJsonObject_accountExpiry_PutNoChange() {
String userId = switchToNewUser("someUser").getUid();
switchToSuperuser();
JsonUser user = GET("/users/{id}", userId).content().as(JsonUser.class);
assertStatus(HttpStatus.OK, PUT("/users/{id}", userId, Body(user.toString())));
assertNull(GET("/users/{id}", userId).content().as(JsonUser.class).getAccountExpiry());
}
use of org.hisp.dhis.webapi.json.domain.JsonUser in project dhis2-core by dhis2.
the class AbstractCrudControllerTest method testPutJsonObject_accountExpiry_NaN.
@Test
void testPutJsonObject_accountExpiry_NaN() {
String userId = switchToNewUser("someUser").getUid();
switchToSuperuser();
JsonUser user = GET("/users/{id}", userId).content().as(JsonUser.class);
String body = user.node().addMember("accountExpiry", "\"NaN\"").toString();
assertEquals("Invalid date format 'NaN', only ISO format or UNIX Epoch timestamp is supported.", PUT("/users/{id}", userId, Body(body)).error().getMessage());
}
use of org.hisp.dhis.webapi.json.domain.JsonUser in project dhis2-core by dhis2.
the class AbstractCrudControllerTest method testUpdateObjectProperty.
@Test
void testUpdateObjectProperty() {
String peter = "{'name': 'Peter', 'firstName':'Peter', 'surname':'Pan', 'username':'peter47'}";
String peterUserId = assertStatus(HttpStatus.CREATED, POST("/users", peter));
JsonResponse roles = GET("/userRoles?fields=id").content();
String roleId = roles.getArray("userRoles").getObject(0).getString("id").string();
assertStatus(HttpStatus.NO_CONTENT, POST("/userRoles/" + roleId + "/users/" + peterUserId));
JsonUser oldPeter = GET("/users/{id}", peterUserId).content().as(JsonUser.class);
assertEquals("Peter", oldPeter.getFirstName());
assertEquals(1, oldPeter.getArray("userRoles").size());
List<User> allUsers2 = userService.getAllUsers();
Set<UserAuthorityGroup> g1 = allUsers2.get(0).getUserAuthorityGroups();
Set<UserAuthorityGroup> g2 = allUsers2.get(1).getUserAuthorityGroups();
assertStatus(HttpStatus.NO_CONTENT, PATCH("/users/" + peterUserId + "/firstName", Body("{'firstName': 'Fry'}"), ContentType(MediaType.APPLICATION_JSON)));
List<User> allUsers3 = userService.getAllUsers();
Set<UserAuthorityGroup> g3 = allUsers3.get(0).getUserAuthorityGroups();
Set<UserAuthorityGroup> g4 = allUsers3.get(1).getUserAuthorityGroups();
JsonUser newPeter = GET("/users/{id}", peterUserId).content().as(JsonUser.class);
assertEquals("Fry", newPeter.getFirstName());
// are user roles still there?
assertEquals(1, newPeter.getArray("userRoles").size());
}
use of org.hisp.dhis.webapi.json.domain.JsonUser in project dhis2-core by dhis2.
the class AbstractCrudControllerTest method testPutJsonObject_accountExpiry.
@Test
void testPutJsonObject_accountExpiry() {
String userId = switchToNewUser("someUser").getUid();
switchToSuperuser();
JsonUser user = GET("/users/{id}", userId).content().as(JsonUser.class);
assertStatus(HttpStatus.OK, PUT("/users/{id}", userId, Body(user.node().addMember("accountExpiry", "null").toString())));
assertNull(GET("/users/{id}", userId).content().as(JsonUser.class).getAccountExpiry());
}
Aggregations