Search in sources :

Example 1 with ValidReasonAssignmentDto

use of org.openlmis.stockmanagement.dto.ValidReasonAssignmentDto in project openlmis-stockmanagement by OpenLMIS.

the class ValidReasonAssignmentDtoBuilderTest method shouldBuildDtoWithProperServiceUrls.

@Test
public void shouldBuildDtoWithProperServiceUrls() {
    ValidReasonAssignment assignment = new ValidReasonAssignmentDataBuilder().build();
    ValidReasonAssignmentDto dto = dtoBuilder.build(assignment);
    assertValidReasonAssignmentDto(assignment, dto);
}
Also used : ValidReasonAssignmentDataBuilder(org.openlmis.stockmanagement.testutils.ValidReasonAssignmentDataBuilder) ValidReasonAssignment(org.openlmis.stockmanagement.domain.reason.ValidReasonAssignment) ValidReasonAssignmentDto(org.openlmis.stockmanagement.dto.ValidReasonAssignmentDto) Test(org.junit.Test)

Example 2 with ValidReasonAssignmentDto

use of org.openlmis.stockmanagement.dto.ValidReasonAssignmentDto in project openlmis-stockmanagement by OpenLMIS.

the class ValidReasonAssignmentControllerIntegrationTest method getValidReasonAssignmentByProgramAndFacilityTypeAndReasonType.

@Test
public void getValidReasonAssignmentByProgramAndFacilityTypeAndReasonType() throws Exception {
    // given
    UUID programId = UUID.randomUUID();
    UUID facilityTypeId = UUID.randomUUID();
    ValidReasonAssignmentDto firstAssignment = mockedValidReasonAssignment(UUID.randomUUID(), ReasonType.DEBIT);
    ValidReasonAssignmentDto secondAssignment = mockedValidReasonAssignment(UUID.randomUUID(), ReasonType.CREDIT);
    when(validReasonAssignmentService.search(programId, facilityTypeId, Arrays.asList("CREDIT", "DEBIT"))).thenReturn(Arrays.asList(ValidReasonAssignment.newInstance(firstAssignment), ValidReasonAssignment.newInstance(secondAssignment)));
    // when
    ResultActions resultActions = mvc.perform(get(VALID_REASON_API).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).param(PROGRAM, programId.toString()).param(FACILITY_TYPE, facilityTypeId.toString()).param(REASON_TYPE, "CREDIT").param(REASON_TYPE, "DEBIT"));
    // then
    verifyZeroInteractions(permissionService);
    resultActions.andExpect(status().isOk()).andExpect(jsonPath("$", hasSize(2)));
}
Also used : ValidReasonAssignmentDto(org.openlmis.stockmanagement.dto.ValidReasonAssignmentDto) ResultActions(org.springframework.test.web.servlet.ResultActions) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Example 3 with ValidReasonAssignmentDto

use of org.openlmis.stockmanagement.dto.ValidReasonAssignmentDto in project openlmis-stockmanagement by OpenLMIS.

the class ValidReasonAssignmentControllerIntegrationTest method shouldAssignReasonToProgramFacilityTypeAndSetAsShownByDefault.

@Test
public void shouldAssignReasonToProgramFacilityTypeAndSetAsShownByDefault() throws Exception {
    // given
    UUID reasonId = UUID.randomUUID();
    ValidReasonAssignmentDto assignment = mockedValidReasonAssignment(reasonId, ReasonType.DEBIT);
    // when
    ResultActions resultActions = mvc.perform(post(VALID_REASON_API).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).contentType(MediaType.APPLICATION_JSON).content(objectToJsonString(assignment)));
    // then
    ArgumentCaptor<ValidReasonAssignment> assignmentCaptor = forClass(ValidReasonAssignment.class);
    resultActions.andDo(print()).andExpect(status().isCreated());
    verify(reasonAssignmentRepository, times(1)).save(assignmentCaptor.capture());
    assertThat(assignmentCaptor.getValue().getReason().getId(), is(reasonId));
    assertThat(assignmentCaptor.getValue().getHidden(), is(false));
    verify(programFacilityTypeExistenceService, times(1)).checkProgramAndFacilityTypeExist(assignment.getProgramId(), assignment.getFacilityTypeId());
    verify(permissionService, times(1)).canManageReasons();
}
Also used : ValidReasonAssignmentDto(org.openlmis.stockmanagement.dto.ValidReasonAssignmentDto) ValidReasonAssignment(org.openlmis.stockmanagement.domain.reason.ValidReasonAssignment) ResultActions(org.springframework.test.web.servlet.ResultActions) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Example 4 with ValidReasonAssignmentDto

use of org.openlmis.stockmanagement.dto.ValidReasonAssignmentDto in project openlmis-stockmanagement by OpenLMIS.

the class ValidReasonAssignmentControllerIntegrationTest method mockedValidReasonAssignment.

private ValidReasonAssignmentDto mockedValidReasonAssignment(UUID reasonId, ReasonType reasonType) {
    StockCardLineItemReason reason = new StockCardLineItemReason();
    reason.setId(reasonId);
    reason.setReasonType(reasonType);
    ValidReasonAssignmentDto assignment = new ValidReasonAssignmentDto();
    assignment.setReason(reason);
    assignment.setProgramId(reasonId);
    assignment.setFacilityTypeId(reasonId);
    when(reasonRepository.exists(assignment.getReason().getId())).thenReturn(true);
    return assignment;
}
Also used : StockCardLineItemReason(org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason) ValidReasonAssignmentDto(org.openlmis.stockmanagement.dto.ValidReasonAssignmentDto)

Example 5 with ValidReasonAssignmentDto

use of org.openlmis.stockmanagement.dto.ValidReasonAssignmentDto in project openlmis-stockmanagement by OpenLMIS.

the class ValidReasonAssignmentDtoBuilder method export.

private ValidReasonAssignmentDto export(ValidReasonAssignment reasonAssignment) {
    ValidReasonAssignmentDto dto = new ValidReasonAssignmentDto();
    dto.setServiceUrl(serviceUrl);
    reasonAssignment.export(dto);
    return dto;
}
Also used : ValidReasonAssignmentDto(org.openlmis.stockmanagement.dto.ValidReasonAssignmentDto)

Aggregations

ValidReasonAssignmentDto (org.openlmis.stockmanagement.dto.ValidReasonAssignmentDto)12 Test (org.junit.Test)9 ValidReasonAssignment (org.openlmis.stockmanagement.domain.reason.ValidReasonAssignment)8 ResultActions (org.springframework.test.web.servlet.ResultActions)5 UUID (java.util.UUID)4 UUID.randomUUID (java.util.UUID.randomUUID)3 StockCardLineItemReason (org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason)2 ValidReasonAssignmentDataBuilder (org.openlmis.stockmanagement.testutils.ValidReasonAssignmentDataBuilder)2 ResponseEntity (org.springframework.http.ResponseEntity)1