Search in sources :

Example 6 with JsonUser

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());
}
Also used : JsonUser(org.hisp.dhis.webapi.json.domain.JsonUser) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest) Test(org.junit.jupiter.api.Test)

Example 7 with JsonUser

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());
}
Also used : JsonUser(org.hisp.dhis.webapi.json.domain.JsonUser) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest) Test(org.junit.jupiter.api.Test)

Example 8 with JsonUser

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());
}
Also used : JsonUser(org.hisp.dhis.webapi.json.domain.JsonUser) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest) Test(org.junit.jupiter.api.Test)

Example 9 with JsonUser

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());
}
Also used : JsonUser(org.hisp.dhis.webapi.json.domain.JsonUser) User(org.hisp.dhis.user.User) JsonUser(org.hisp.dhis.webapi.json.domain.JsonUser) UserAuthorityGroup(org.hisp.dhis.user.UserAuthorityGroup) JsonResponse(org.hisp.dhis.jsontree.JsonResponse) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest) Test(org.junit.jupiter.api.Test)

Example 10 with JsonUser

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());
}
Also used : JsonUser(org.hisp.dhis.webapi.json.domain.JsonUser) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest) Test(org.junit.jupiter.api.Test)

Aggregations

JsonUser (org.hisp.dhis.webapi.json.domain.JsonUser)15 Test (org.junit.jupiter.api.Test)15 DhisControllerConvenienceTest (org.hisp.dhis.webapi.DhisControllerConvenienceTest)9 DhisControllerWithApiTokenAuthTest (org.hisp.dhis.webapi.DhisControllerWithApiTokenAuthTest)5 ApiToken (org.hisp.dhis.security.apikey.ApiToken)3 User (org.hisp.dhis.user.User)3 JsonResponse (org.hisp.dhis.jsontree.JsonResponse)2 JsonArray (org.hisp.dhis.jsontree.JsonArray)1 UserAuthorityGroup (org.hisp.dhis.user.UserAuthorityGroup)1 DhisControllerWithJwtTokenAuthTest (org.hisp.dhis.webapi.DhisControllerWithJwtTokenAuthTest)1 SomeUserId (org.hisp.dhis.webapi.snippets.SomeUserId)1