Search in sources :

Example 1 with DraftValidation

use of se.inera.intyg.webcert.web.service.utkast.dto.DraftValidation in project webcert by sklintyg.

the class UtkastServiceImplTest method testValidateValidDraftWithWarningsIncludesWarningsInResponse.

@Test
public void testValidateValidDraftWithWarningsIncludesWarningsInResponse() throws ModuleException, ModuleNotFoundException {
    when(moduleRegistry.getModuleApi(anyString())).thenReturn(mockModuleApi);
    when(mockModuleApi.validateDraft(anyString())).thenReturn(buildValidationResponse());
    DraftValidation validationResult = draftService.validateDraft(INTYG_ID, INTYG_TYPE, utkast.getModel());
    assertEquals(1, validationResult.getWarnings().size());
    assertEquals(0, validationResult.getMessages().size());
}
Also used : DraftValidation(se.inera.intyg.webcert.web.service.utkast.dto.DraftValidation) Test(org.junit.Test)

Example 2 with DraftValidation

use of se.inera.intyg.webcert.web.service.utkast.dto.DraftValidation in project webcert by sklintyg.

the class UtkastServiceImplTest method testValidateDraft.

@Test
public void testValidateDraft() throws Exception {
    ValidationMessage valMsg = new ValidationMessage("a", "field.somewhere", ValidationMessageType.OTHER, "This is soooo wrong!");
    ValidateDraftResponse validationResponse = new ValidateDraftResponse(ValidationStatus.INVALID, Collections.singletonList(valMsg));
    when(moduleRegistry.getModuleApi(INTYG_TYPE)).thenReturn(mockModuleApi);
    when(mockModuleApi.validateDraft(INTYG_JSON)).thenReturn(validationResponse);
    DraftValidation res = draftService.validateDraft(INTYG_ID, INTYG_TYPE, INTYG_JSON);
    assertNotNull(res);
    assertFalse(res.isDraftValid());
    assertEquals(1, res.getMessages().size());
    verify(mockModuleApi).validateDraft(INTYG_JSON);
}
Also used : ValidationMessage(se.inera.intyg.common.support.modules.support.api.dto.ValidationMessage) DraftValidation(se.inera.intyg.webcert.web.service.utkast.dto.DraftValidation) ValidateDraftResponse(se.inera.intyg.common.support.modules.support.api.dto.ValidateDraftResponse) Test(org.junit.Test)

Example 3 with DraftValidation

use of se.inera.intyg.webcert.web.service.utkast.dto.DraftValidation in project webcert by sklintyg.

the class UtkastModuleApiControllerTest method testValidateDraftWithWarningsArePropagatedToCaller.

@Test
public void testValidateDraftWithWarningsArePropagatedToCaller() {
    String intygTyp = "fk7263";
    String intygId = "intyg1";
    String draftAsJson = "test";
    byte[] payload = draftAsJson.getBytes();
    setupUser(AuthoritiesConstants.PRIVILEGE_SKRIVA_INTYG, intygTyp, false, AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST);
    DraftValidation draftValidation = buildDraftValidation();
    draftValidation.addWarning(new DraftValidationMessage("category", "field", ValidationMessageType.WARN, "this.is.a.message", "dy.nam.ic.key"));
    when(utkastService.validateDraft(intygId, intygTyp, draftAsJson)).thenReturn(draftValidation);
    Response response = moduleApiController.validateDraft(intygTyp, intygId, payload);
    DraftValidation entity = (DraftValidation) response.getEntity();
    verify(utkastService).validateDraft(intygId, intygTyp, draftAsJson);
    assertEquals(OK.getStatusCode(), response.getStatus());
    assertEquals(ValidationStatus.VALID, entity.getStatus());
    assertEquals(0, entity.getMessages().size());
    assertEquals(1, entity.getWarnings().size());
}
Also used : Response(javax.ws.rs.core.Response) SaveDraftResponse(se.inera.intyg.webcert.web.service.utkast.dto.SaveDraftResponse) DraftValidation(se.inera.intyg.webcert.web.service.utkast.dto.DraftValidation) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DraftValidationMessage(se.inera.intyg.webcert.web.service.utkast.dto.DraftValidationMessage) Test(org.junit.Test)

Example 4 with DraftValidation

use of se.inera.intyg.webcert.web.service.utkast.dto.DraftValidation in project webcert by sklintyg.

the class UtkastModuleApiControllerTest method buildDraftValidation.

private DraftValidation buildDraftValidation() {
    DraftValidation validation = new DraftValidation();
    validation.setMessages(new ArrayList<>());
    validation.setStatus(ValidationStatus.VALID);
    return validation;
}
Also used : DraftValidation(se.inera.intyg.webcert.web.service.utkast.dto.DraftValidation)

Example 5 with DraftValidation

use of se.inera.intyg.webcert.web.service.utkast.dto.DraftValidation in project webcert by sklintyg.

the class UtkastModuleApiController method validateDraft.

/**
 * Validate the supplied draft certificate.
 *
 * @param intygsId The id of the certificate.
 * @param payload  Object holding the certificate and its current status.
 */
@POST
@Path("/{intygsTyp}/{intygsId}/validate")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
public Response validateDraft(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String intygsId, byte[] payload) {
    authoritiesValidator.given(getWebCertUserService().getUser(), intygsTyp).features(AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST).privilege(AuthoritiesConstants.PRIVILEGE_SKRIVA_INTYG).orThrow();
    LOG.debug("Validating utkast with id '{}'", intygsId);
    String draftAsJson = fromBytesToString(payload);
    LOG.debug("---- intyg : " + draftAsJson);
    DraftValidation validateResponse = utkastService.validateDraft(intygsId, intygsTyp, draftAsJson);
    LOG.debug("Utkast validation on '{}' is {}", intygsId, validateResponse.isDraftValid() ? "valid" : "invalid");
    return Response.ok().entity(validateResponse).build();
}
Also used : DraftValidation(se.inera.intyg.webcert.web.service.utkast.dto.DraftValidation) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Aggregations

DraftValidation (se.inera.intyg.webcert.web.service.utkast.dto.DraftValidation)5 Test (org.junit.Test)3 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Response (javax.ws.rs.core.Response)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 ValidateDraftResponse (se.inera.intyg.common.support.modules.support.api.dto.ValidateDraftResponse)1 ValidationMessage (se.inera.intyg.common.support.modules.support.api.dto.ValidationMessage)1 DraftValidationMessage (se.inera.intyg.webcert.web.service.utkast.dto.DraftValidationMessage)1 SaveDraftResponse (se.inera.intyg.webcert.web.service.utkast.dto.SaveDraftResponse)1