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