use of org.openlmis.stockmanagement.domain.reason.ValidReasonAssignment in project openlmis-stockmanagement by OpenLMIS.
the class ValidReasonAssignmentRepositoryIntegrationTest method shouldThrowExceptionWhenSaveDuplicatedValidReason.
@Test(expected = PersistenceException.class)
public void shouldThrowExceptionWhenSaveDuplicatedValidReason() throws Exception {
ValidReasonAssignment validReasonAssignment = generateInstance();
repository.save(validReasonAssignment);
ValidReasonAssignment duplicateValidReason = new ValidReasonAssignment(PROGRAM_ID, FACILITY_TYPE_ID, false, validReasonAssignment.getReason());
repository.save(duplicateValidReason);
entityManager.flush();
}
use of org.openlmis.stockmanagement.domain.reason.ValidReasonAssignment in project openlmis-stockmanagement by OpenLMIS.
the class PhysicalInventoryAdjustmentReasonsValidatorTest method setUp.
@Before
public void setUp() throws Exception {
super.setUp();
setContext(stockEventDto);
when(validReasonRepository.findByProgramIdAndFacilityTypeIdAndReasonId(any(UUID.class), any(UUID.class), any(UUID.class))).thenReturn(new ValidReasonAssignment());
stubFacilityType();
when(stockEventDto.isPhysicalInventory()).thenReturn(true);
}
use of org.openlmis.stockmanagement.domain.reason.ValidReasonAssignment in project openlmis-stockmanagement by OpenLMIS.
the class ValidReasonAssignmentControllerIntegrationTest method shouldSetValidReasonAsHiddenWhenHiddenIsTrue.
@Test
public void shouldSetValidReasonAsHiddenWhenHiddenIsTrue() throws Exception {
// given1
ValidReasonAssignmentDto assignment = mockedValidReasonAssignment(UUID.randomUUID(), ReasonType.DEBIT);
assignment.setHidden(true);
// 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().getHidden(), is(true));
}
use of org.openlmis.stockmanagement.domain.reason.ValidReasonAssignment in project openlmis-stockmanagement by OpenLMIS.
the class ValidReasonAssignmentControllerIntegrationTest method shouldIgnoreAssignmentIdWhenRequestBodySpecifiedIt.
@Test
public void shouldIgnoreAssignmentIdWhenRequestBodySpecifiedIt() throws Exception {
// given
ValidReasonAssignmentDto assignment = mockedValidReasonAssignment(UUID.randomUUID(), ReasonType.DEBIT);
assignment.setId(UUID.randomUUID());
// when
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);
verify(reasonAssignmentRepository, times(1)).save(assignmentCaptor.capture());
assertNotEquals(assignment.getId(), assignmentCaptor.getValue().getId());
}
use of org.openlmis.stockmanagement.domain.reason.ValidReasonAssignment in project openlmis-stockmanagement by OpenLMIS.
the class ValidReasonAssignmentControllerIntegrationTest method shouldNotAssignSameReasonTwice.
@Test
public void shouldNotAssignSameReasonTwice() throws Exception {
// given
UUID reasonId = UUID.randomUUID();
StockCardLineItemReason reason = new StockCardLineItemReason();
reason.setId(reasonId);
ValidReasonAssignmentDto assignment = new ValidReasonAssignmentDto();
assignment.setReason(reason);
assignment.setProgramId(UUID.randomUUID());
assignment.setFacilityTypeId(UUID.randomUUID());
when(reasonRepository.exists(reasonId)).thenReturn(true);
when(reasonAssignmentRepository.findByProgramIdAndFacilityTypeIdAndReasonId(assignment.getProgramId(), assignment.getFacilityTypeId(), reasonId)).thenReturn(new ValidReasonAssignment());
// 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().isOk());
verify(reasonAssignmentRepository, never()).save(any(ValidReasonAssignment.class));
}
Aggregations