Search in sources :

Example 21 with CopyIntygRequest

use of se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygRequest in project webcert by sklintyg.

the class IntygModuleApiControllerTest method testCreateUtkastFromTemplateInvalidPrivleges.

@Test(expected = AuthoritiesException.class)
public void testCreateUtkastFromTemplateInvalidPrivleges() {
    WebCertUser user = new WebCertUser();
    user.setOrigin("NORMAL");
    when(webcertUserService.getUser()).thenReturn(user);
    CopyIntygRequest copyRequest = new CopyIntygRequest();
    copyRequest.setPatientPersonnummer(createPnr("191212121212"));
    try {
        moduleApiController.createUtkastFromTemplate(copyRequest, CERTIFICATE_TYPE, CERTIFICATE_ID, CERTIFICATE_TYPE);
    } finally {
        verifyZeroInteractions(copyUtkastService);
    }
}
Also used : CopyIntygRequest(se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygRequest) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Example 22 with CopyIntygRequest

use of se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygRequest in project webcert by sklintyg.

the class IntygModuleApiControllerTest method testReplaceIntyg.

@Test
public void testReplaceIntyg() {
    final String personnummer = "191212121212";
    final String newIntygId = "newIntygId";
    CopyIntygRequest copyIntygRequest = new CopyIntygRequest();
    copyIntygRequest.setPatientPersonnummer(createPnr(personnummer));
    WebCertUser user = new WebCertUser();
    addFeatures(user, CERTIFICATE_TYPE, AuthoritiesConstants.FEATURE_FORNYA_INTYG);
    addPrivileges(user, CERTIFICATE_TYPE, AuthoritiesConstants.PRIVILEGE_ERSATTA_INTYG);
    user.setOrigin("NORMAL");
    ArgumentCaptor<CreateReplacementCopyRequest> captor = ArgumentCaptor.forClass(CreateReplacementCopyRequest.class);
    when(copyUtkastService.createReplacementCopy(captor.capture())).thenReturn(new CreateReplacementCopyResponse(CERTIFICATE_TYPE, newIntygId, CERTIFICATE_ID));
    when(webcertUserService.getUser()).thenReturn(user);
    Response response = moduleApiController.createReplacement(copyIntygRequest, CERTIFICATE_TYPE, CERTIFICATE_ID);
    verify(copyUtkastService).createReplacementCopy(any());
    verifyNoMoreInteractions(copyUtkastService);
    assertEquals(newIntygId, ((CopyIntygResponse) response.getEntity()).getIntygsUtkastId());
}
Also used : Response(javax.ws.rs.core.Response) CreateRenewalCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyResponse) CopyIntygResponse(se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygResponse) CreateUtkastFromTemplateResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateUtkastFromTemplateResponse) CreateReplacementCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyResponse) CreateCompletionCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateCompletionCopyResponse) CopyIntygRequest(se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygRequest) CreateReplacementCopyRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyRequest) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) CreateReplacementCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyResponse) Test(org.junit.Test)

Example 23 with CopyIntygRequest

use of se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygRequest in project webcert by sklintyg.

the class IntygModuleApiControllerIT method testReplaceIntyg.

@Test
public void testReplaceIntyg() {
    final String personnummer = "19121212-1212";
    RestAssured.sessionId = getAuthSession(DEFAULT_LAKARE);
    changeOriginTo("DJUPINTEGRATION");
    String intygsId = createSignedIntyg("lisjp", personnummer);
    CopyIntygRequest copyIntygRequest = new CopyIntygRequest();
    copyIntygRequest.setPatientPersonnummer(createPnr(personnummer));
    Map<String, String> pathParams = new HashMap<>();
    pathParams.put("intygsTyp", "lisjp");
    pathParams.put("intygsId", intygsId);
    final Response response = given().cookie("ROUTEID", BaseRestIntegrationTest.routeId).contentType(ContentType.JSON).and().pathParams(pathParams).and().body(copyIntygRequest).expect().statusCode(200).when().post("moduleapi/intyg/{intygsTyp}/{intygsId}/ersatt").then().body("intygsUtkastId", not(isEmptyString())).body("intygsUtkastId", not(equalTo(intygsId))).body("intygsTyp", equalTo("lisjp")).extract().response();
    JsonPath intygJson = new JsonPath(response.body().asString());
    String utkastId = intygJson.getString("intygsUtkastId");
    // Verify that the new draft has correct relations
    given().cookie("ROUTEID", BaseRestIntegrationTest.routeId).expect().statusCode(200).when().get(MODULEAPI_UTKAST_BASE + "/lisjp/" + utkastId).then().body("relations.parent.intygsId", equalTo(intygsId)).body("relations.parent.relationKod", equalTo(RelationKod.ERSATT.name()));
    // Verify the original certficate has a child relationship
    given().cookie("ROUTEID", BaseRestIntegrationTest.routeId).expect().statusCode(200).when().get("moduleapi/intyg/lisjp/" + intygsId).then().body("relations.latestChildRelations.replacedByUtkast.intygsId", equalTo(utkastId)).body("relations.latestChildRelations.replacedByUtkast.relationKod", equalTo(RelationKod.ERSATT.name()));
}
Also used : Response(com.jayway.restassured.response.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) CopyIntygRequest(se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygRequest) HashMap(java.util.HashMap) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) Matchers.containsString(org.hamcrest.Matchers.containsString) JsonPath(com.jayway.restassured.path.json.JsonPath) BaseRestIntegrationTest(se.inera.intyg.webcert.web.web.controller.integrationtest.BaseRestIntegrationTest) Test(org.junit.Test)

Example 24 with CopyIntygRequest

use of se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygRequest in project webcert by sklintyg.

the class IntygModuleApiControllerIT method testCreateUtkastFromTemplate.

@Test
public void testCreateUtkastFromTemplate() throws Exception {
    final String personnummer = "19121212-1212";
    RestAssured.sessionId = getAuthSession(DEFAULT_LAKARE);
    String dbIntyg = createDbIntyg(personnummer);
    CopyIntygRequest copyIntygRequest = new CopyIntygRequest();
    copyIntygRequest.setPatientPersonnummer(createPnr(personnummer));
    Map<String, String> pathParams = new HashMap<>();
    pathParams.put("intygsTyp", "db");
    pathParams.put("intygsId", dbIntyg);
    pathParams.put("newIntygsTyp", "doi");
    given().cookie("ROUTEID", BaseRestIntegrationTest.routeId).contentType(ContentType.JSON).and().pathParams(pathParams).and().body(copyIntygRequest).expect().statusCode(200).when().post("moduleapi/intyg/{intygsTyp}/{intygsId}/{newIntygsTyp}/create").then().body("intygsUtkastId", not(isEmptyString())).body("intygsUtkastId", not(equalTo(dbIntyg))).body("intygsTyp", equalTo("doi"));
}
Also used : CopyIntygRequest(se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygRequest) HashMap(java.util.HashMap) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) Matchers.containsString(org.hamcrest.Matchers.containsString) BaseRestIntegrationTest(se.inera.intyg.webcert.web.web.controller.integrationtest.BaseRestIntegrationTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)24 CopyIntygRequest (se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygRequest)24 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)15 HashMap (java.util.HashMap)8 Matchers.containsString (org.hamcrest.Matchers.containsString)8 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)8 BaseRestIntegrationTest (se.inera.intyg.webcert.web.web.controller.integrationtest.BaseRestIntegrationTest)8 Response (javax.ws.rs.core.Response)6 CreateCompletionCopyResponse (se.inera.intyg.webcert.web.service.utkast.dto.CreateCompletionCopyResponse)6 CreateRenewalCopyResponse (se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyResponse)6 CreateReplacementCopyResponse (se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyResponse)6 CreateUtkastFromTemplateResponse (se.inera.intyg.webcert.web.service.utkast.dto.CreateUtkastFromTemplateResponse)6 CopyIntygResponse (se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygResponse)6 IntegrationParameters (se.inera.intyg.webcert.web.web.controller.integration.dto.IntegrationParameters)4 CreateRenewalCopyRequest (se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyRequest)3 JsonPath (com.jayway.restassured.path.json.JsonPath)2 Response (com.jayway.restassured.response.Response)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 Personnummer (se.inera.intyg.schemas.contract.Personnummer)1 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)1