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());
}
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);
}
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());
}
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;
}
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();
}
Aggregations