use of org.openlmis.stockmanagement.domain.reason.ValidReasonAssignment in project openlmis-stockmanagement by OpenLMIS.
the class ValidReasonAssignmentController method assignReason.
/**
* Assign a reason to program and facility type.
* If valid reason assignment ID is specified, ID will be ignored.
*
* @param assignmentDto valid reason assignment.
* @return the assigned reason and program and facility type.
*/
@RequestMapping(value = "/validReasons", method = POST)
public ResponseEntity<ValidReasonAssignmentDto> assignReason(@RequestBody ValidReasonAssignmentDto assignmentDto) {
permissionService.canManageReasons();
assignmentDto.setId(null);
ValidReasonAssignment assignment = ValidReasonAssignment.newInstance(assignmentDto);
checkIsValidRequest(assignment);
return findExistingOrSaveNew(assignment);
}
use of org.openlmis.stockmanagement.domain.reason.ValidReasonAssignment 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.domain.reason.ValidReasonAssignment 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.domain.reason.ValidReasonAssignment in project openlmis-stockmanagement by OpenLMIS.
the class ValidReasonAssignmentControllerIntegrationTest method getValidReasonAssignmentByProgramAndFacilityType.
@Test
public void getValidReasonAssignmentByProgramAndFacilityType() throws Exception {
// given
UUID programId = UUID.randomUUID();
UUID facilityTypeId = UUID.randomUUID();
when(validReasonAssignmentService.search(programId, facilityTypeId, null)).thenReturn(Collections.singletonList(new ValidReasonAssignment()));
// when
ResultActions resultActions = mvc.perform(get(VALID_REASON_API).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).param(PROGRAM, programId.toString()).param(FACILITY_TYPE, facilityTypeId.toString()));
// then
verifyZeroInteractions(permissionService);
resultActions.andExpect(status().isOk()).andExpect(jsonPath("$", hasSize(1)));
}
use of org.openlmis.stockmanagement.domain.reason.ValidReasonAssignment in project openlmis-stockmanagement by OpenLMIS.
the class ValidReasonAssignmentControllerIntegrationTest method shouldReturn400IfReasonNotExist.
@Test
public void shouldReturn400IfReasonNotExist() throws Exception {
// given
UUID reasonId = UUID.randomUUID();
StockCardLineItemReason reason = new StockCardLineItemReason();
reason.setId(reasonId);
when(reasonRepository.findOne(reasonId)).thenReturn(null);
ValidReasonAssignment assignment = new ValidReasonAssignment();
assignment.setReason(reason);
// when
ResultActions resultActions = mvc.perform(post(VALID_REASON_API).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).contentType(MediaType.APPLICATION_JSON).content(objectToJsonString(assignment)));
// then
resultActions.andExpect(status().isBadRequest());
verify(reasonAssignmentRepository, never()).save(any(ValidReasonAssignment.class));
}
Aggregations