Search in sources :

Example 6 with JsonIdentifiableObject

use of org.hisp.dhis.webapi.json.domain.JsonIdentifiableObject in project dhis2-core by dhis2.

the class BulkPatchSharingControllerTest method testApplyPatches.

@Test
void testApplyPatches() throws IOException {
    assertStatus(HttpStatus.CREATED, POST("/users", createUser("usera", userAId)));
    assertStatus(HttpStatus.CREATED, POST("/users", createUser("userb", userBId)));
    userCId = assertStatus(HttpStatus.CREATED, POST("/users", createUser("userc")));
    assertStatus(HttpStatus.CREATED, POST("/dataSets", jsonMapper.writeValueAsString(createDataSet('A', dsIdA, userCId))));
    assertStatus(HttpStatus.CREATED, POST("/dataElements", jsonMapper.writeValueAsString(createDataElement('A', deAId, userCId))));
    assertStatus(HttpStatus.CREATED, POST("/dataElements", jsonMapper.writeValueAsString(createDataElement('B', deBId, userCId))));
    assertStatus(HttpStatus.OK, PATCH("/metadata/sharing", "patch/bulk_sharing_patches.json"));
    JsonIdentifiableObject savedDeA = GET("/dataElements/{uid}", deAId).content(HttpStatus.OK).as(JsonIdentifiableObject.class);
    JsonIdentifiableObject savedDeB = GET("/dataElements/{uid}", deBId).content(HttpStatus.OK).as(JsonIdentifiableObject.class);
    JsonIdentifiableObject savedDsA = GET("/dataSets/{uid}", dsIdA).content(HttpStatus.OK).as(JsonIdentifiableObject.class);
    assertEquals(2, savedDeA.getSharing().getUsers().size());
    assertEquals(2, savedDeB.getSharing().getUsers().size());
    assertEquals(2, savedDsA.getSharing().getUsers().size());
    assertNotNull(savedDeA.getSharing().getUsers().get(userAId));
    assertNotNull(savedDeB.getSharing().getUsers().get(userAId));
    assertNotNull(savedDsA.getSharing().getUsers().get(userAId));
    assertNotNull(savedDeA.getSharing().getUsers().get(userBId));
    assertNotNull(savedDeB.getSharing().getUsers().get(userBId));
    assertNotNull(savedDsA.getSharing().getUsers().get(userBId));
}
Also used : JsonIdentifiableObject(org.hisp.dhis.webapi.json.domain.JsonIdentifiableObject) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest) Test(org.junit.jupiter.api.Test)

Example 7 with JsonIdentifiableObject

use of org.hisp.dhis.webapi.json.domain.JsonIdentifiableObject in project dhis2-core by dhis2.

the class BulkPatchSharingControllerTest method testApplyPatchOk.

@Test
void testApplyPatchOk() throws IOException {
    assertStatus(HttpStatus.CREATED, POST("/users", createUser("usera", userAId)));
    assertStatus(HttpStatus.CREATED, POST("/users", createUser("userb", userBId)));
    userCId = assertStatus(HttpStatus.CREATED, POST("/users", createUser("userc")));
    assertStatus(HttpStatus.CREATED, POST("/dataElements", jsonMapper.writeValueAsString(createDataElement('A', deAId, userCId))));
    assertStatus(HttpStatus.CREATED, POST("/dataElements", jsonMapper.writeValueAsString(createDataElement('B', deBId, userCId))));
    assertStatus(HttpStatus.OK, PATCH("/dataElements/sharing", "patch/bulk_sharing_patch.json"));
    JsonIdentifiableObject saveDeA = GET("/dataElements/{uid}", deAId).content(HttpStatus.OK).as(JsonIdentifiableObject.class);
    JsonIdentifiableObject saveDeB = GET("/dataElements/{uid}", deBId).content(HttpStatus.OK).as(JsonIdentifiableObject.class);
    assertEquals(2, saveDeA.getSharing().getUsers().size());
    assertEquals(2, saveDeB.getSharing().getUsers().size());
}
Also used : JsonIdentifiableObject(org.hisp.dhis.webapi.json.domain.JsonIdentifiableObject) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest) Test(org.junit.jupiter.api.Test)

Example 8 with JsonIdentifiableObject

use of org.hisp.dhis.webapi.json.domain.JsonIdentifiableObject in project dhis2-core by dhis2.

the class SharingControllerTest method testPutSharing.

@Test
void testPutSharing() {
    String groupId = assertStatus(HttpStatus.CREATED, POST("/userGroups", "{'name':'test'}"));
    JsonIdentifiableObject group = GET("/userGroups/{id}", groupId).content().as(JsonIdentifiableObject.class);
    assertWebMessage("OK", 200, "OK", "Access control set", PUT("/sharing?type=userGroup&id=" + groupId, group.getSharing().node().getDeclaration()).content(HttpStatus.OK));
}
Also used : JsonIdentifiableObject(org.hisp.dhis.webapi.json.domain.JsonIdentifiableObject) Test(org.junit.jupiter.api.Test) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest)

Example 9 with JsonIdentifiableObject

use of org.hisp.dhis.webapi.json.domain.JsonIdentifiableObject in project dhis2-core by dhis2.

the class SharingControllerTest method testPostSharing.

@Test
void testPostSharing() {
    String groupId = assertStatus(HttpStatus.CREATED, POST("/userGroups", "{'name':'test'}"));
    JsonIdentifiableObject group = GET("/userGroups/{id}", groupId).content().as(JsonIdentifiableObject.class);
    assertWebMessage("OK", 200, "OK", "Access control set", POST("/sharing?type=userGroup&id=" + groupId, group.getSharing().node().getDeclaration()).content(HttpStatus.OK));
}
Also used : JsonIdentifiableObject(org.hisp.dhis.webapi.json.domain.JsonIdentifiableObject) Test(org.junit.jupiter.api.Test) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest)

Aggregations

DhisControllerConvenienceTest (org.hisp.dhis.webapi.DhisControllerConvenienceTest)9 JsonIdentifiableObject (org.hisp.dhis.webapi.json.domain.JsonIdentifiableObject)9 Test (org.junit.jupiter.api.Test)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 GeoJsonObject (org.geojson.GeoJsonObject)1 Polygon (org.geojson.Polygon)1 JsonNode (org.hisp.dhis.jsontree.JsonNode)1 JsonAttributeValue (org.hisp.dhis.webapi.json.domain.JsonAttributeValue)1