Search in sources :

Example 6 with JsonMetadataProposal

use of org.hisp.dhis.webapi.controller.json.JsonMetadataProposal in project dhis2-core by dhis2.

the class MetadataWorkflowControllerTest method testMakeRemoveProposal.

@Test
void testMakeRemoveProposal() {
    String proposalId = postRemoveProposal(defaultTargetId);
    JsonMetadataProposal proposal = GET("/metadata/proposals/{uid}", proposalId).content().asObject(JsonMetadataProposal.class);
    assertEquals(MetadataProposalStatus.PROPOSED, proposal.getStatus());
    assertEquals(MetadataProposalType.REMOVE, proposal.getType());
    assertEquals(MetadataProposalTarget.ORGANISATION_UNIT, proposal.getTarget());
    assertEquals(defaultTargetId, proposal.getTargetId());
    assertNotNull(proposal.getCreated());
    assertNotNull(proposal.getCreatedBy());
    assertNull(proposal.getFinalisedBy());
    assertNull(proposal.getFinalised());
    assertNull(proposal.getComment());
    assertNull(proposal.getReason());
    assertTrue(proposal.getChange().isUndefined());
}
Also used : JsonMetadataProposal(org.hisp.dhis.webapi.controller.json.JsonMetadataProposal) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest) Test(org.junit.jupiter.api.Test)

Example 7 with JsonMetadataProposal

use of org.hisp.dhis.webapi.controller.json.JsonMetadataProposal in project dhis2-core by dhis2.

the class MetadataWorkflowControllerTest method testAcceptProposal_ConflictTargetAlreadyDeleted.

@Test
void testAcceptProposal_ConflictTargetAlreadyDeleted() {
    String proposalId = postRemoveProposal(defaultTargetId);
    assertStatus(HttpStatus.OK, DELETE("/organisationUnits/" + defaultTargetId));
    assertStatus(HttpStatus.CONFLICT, POST("/metadata/proposals/" + proposalId));
    JsonMetadataProposal proposal = GET("/metadata/proposals/{uid}", proposalId).content().asObject(JsonMetadataProposal.class);
    assertEquals(MetadataProposalStatus.NEEDS_UPDATE, proposal.getStatus());
    assertNotNull(proposal.getReason());
    assertWebMessage("Conflict", 409, "ERROR", "Proposal must be in status PROPOSED for this action", POST("/metadata/proposals/" + proposalId).content(HttpStatus.CONFLICT));
}
Also used : JsonMetadataProposal(org.hisp.dhis.webapi.controller.json.JsonMetadataProposal) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest) Test(org.junit.jupiter.api.Test)

Example 8 with JsonMetadataProposal

use of org.hisp.dhis.webapi.controller.json.JsonMetadataProposal in project dhis2-core by dhis2.

the class MetadataWorkflowControllerTest method testAcceptProposal_ConflictMissingAuthority.

@Test
void testAcceptProposal_ConflictMissingAuthority() {
    User guest = switchToNewUser("guest");
    String proposalId = postUpdateNameProposal(defaultTargetId, "New name");
    JsonWebMessage message = assertWebMessage("Conflict", 409, "WARNING", "One more more errors occurred, please see full details in import report.", POST("/metadata/proposals/" + proposalId).content(HttpStatus.CONFLICT));
    JsonErrorReport error = message.find(JsonErrorReport.class, report -> report.getErrorCode() == ErrorCode.E3001);
    JsonMetadataProposal proposal = GET("/metadata/proposals/" + proposalId).content().as(JsonMetadataProposal.class);
    assertEquals(String.format("E3001 User `guest guest [%s] (User)` is not allowed to update object `New name [%s] (OrganisationUnit)`.\n", guest.getUid(), defaultTargetId), proposal.getReason());
    // but the system could accept the proposal
    switchContextToUser(system);
    assertStatus(HttpStatus.OK, PUT("/metadata/proposals/" + proposalId));
    assertStatus(HttpStatus.OK, POST("/metadata/proposals/" + proposalId));
}
Also used : User(org.hisp.dhis.user.User) JsonWebMessage(org.hisp.dhis.webapi.json.domain.JsonWebMessage) JsonErrorReport(org.hisp.dhis.webapi.json.domain.JsonErrorReport) JsonMetadataProposal(org.hisp.dhis.webapi.controller.json.JsonMetadataProposal) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest) Test(org.junit.jupiter.api.Test)

Example 9 with JsonMetadataProposal

use of org.hisp.dhis.webapi.controller.json.JsonMetadataProposal in project dhis2-core by dhis2.

the class MetadataWorkflowControllerTest method testMakeAddProposal.

@Test
void testMakeAddProposal() {
    String proposalId = postAddProposal("My Unit", "OU1");
    JsonMetadataProposal proposal = GET("/metadata/proposals/{uid}", proposalId).content().asObject(JsonMetadataProposal.class);
    assertEquals(MetadataProposalStatus.PROPOSED, proposal.getStatus());
    assertEquals(MetadataProposalType.ADD, proposal.getType());
    assertEquals(MetadataProposalTarget.ORGANISATION_UNIT, proposal.getTarget());
    assertNull(proposal.getTargetId());
    assertNotNull(proposal.getCreated());
    assertNotNull(proposal.getCreatedBy());
    assertNull(proposal.getFinalisedBy());
    assertNull(proposal.getFinalised());
    assertEquals("We need it", proposal.getComment());
    assertNull(proposal.getReason());
    assertTrue(proposal.getChange().isObject());
}
Also used : JsonMetadataProposal(org.hisp.dhis.webapi.controller.json.JsonMetadataProposal) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest) Test(org.junit.jupiter.api.Test)

Example 10 with JsonMetadataProposal

use of org.hisp.dhis.webapi.controller.json.JsonMetadataProposal in project dhis2-core by dhis2.

the class MetadataWorkflowControllerTest method testRejectProposal.

@Test
void testRejectProposal() {
    String proposalId = postRemoveProposal(defaultTargetId);
    // reject
    assertStatus(HttpStatus.NO_CONTENT, DELETE("/metadata/proposals/" + proposalId));
    JsonMetadataProposal proposal = GET("/metadata/proposals/{uid}", proposalId).content().asObject(JsonMetadataProposal.class);
    assertEquals(MetadataProposalStatus.REJECTED, proposal.getStatus());
    assertNotNull(proposal.getFinalisedBy());
    assertNotNull(proposal.getFinalised());
}
Also used : JsonMetadataProposal(org.hisp.dhis.webapi.controller.json.JsonMetadataProposal) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest) Test(org.junit.jupiter.api.Test)

Aggregations

DhisControllerConvenienceTest (org.hisp.dhis.webapi.DhisControllerConvenienceTest)12 JsonMetadataProposal (org.hisp.dhis.webapi.controller.json.JsonMetadataProposal)12 Test (org.junit.jupiter.api.Test)12 JsonOrganisationUnit (org.hisp.dhis.webapi.json.domain.JsonOrganisationUnit)2 User (org.hisp.dhis.user.User)1 JsonErrorReport (org.hisp.dhis.webapi.json.domain.JsonErrorReport)1 JsonWebMessage (org.hisp.dhis.webapi.json.domain.JsonWebMessage)1