Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OAM-191: added integration test #55

Merged
merged 2 commits into from
Jun 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.notNullValue;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto;

import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import javax.transaction.Transactional;
import org.junit.After;
Expand All @@ -33,13 +37,17 @@
import org.mockito.Mock;
import org.mockito.Mockito;
import org.openlmis.stockmanagement.BaseIntegrationTest;
import org.openlmis.stockmanagement.domain.card.StockCard;
import org.openlmis.stockmanagement.domain.event.StockEvent;
import org.openlmis.stockmanagement.domain.event.StockEventLineItem;
import org.openlmis.stockmanagement.domain.reason.ReasonCategory;
import org.openlmis.stockmanagement.domain.reason.ReasonType;
import org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason;
import org.openlmis.stockmanagement.domain.sourcedestination.Node;
import org.openlmis.stockmanagement.domain.sourcedestination.Organization;
import org.openlmis.stockmanagement.dto.PhysicalInventoryDto;
import org.openlmis.stockmanagement.dto.StockEventDto;
import org.openlmis.stockmanagement.dto.StockEventLineItemDto;
import org.openlmis.stockmanagement.repository.CalculatedStockOnHandRepository;
import org.openlmis.stockmanagement.repository.NodeRepository;
import org.openlmis.stockmanagement.repository.OrganizationRepository;
Expand All @@ -61,14 +69,12 @@
@Transactional
public class StockEventProcessorIntegrationTest extends BaseIntegrationTest {

@MockBean
StockEventNotificationProcessor stockEventNotificationProcessor;
@MockBean
private StockEventValidationsService stockEventValidationsService;

@MockBean
private PhysicalInventoryService physicalInventoryService;

@MockBean StockEventNotificationProcessor stockEventNotificationProcessor;

@Autowired
private StockEventProcessor stockEventProcessor;

Expand Down Expand Up @@ -175,7 +181,7 @@ public void shouldNotSaveEventsIfAnythingGoesWrongInValidationsService()
}

@Test
public void shouldSaveEventAndLineItemsAndCallNotificationsWhenValidationServicePasses()
public void shouldSaveEventAndLineItemsAndCallNotificationsWhenValidationServicePasses()
throws Exception {
StockEventDto stockEventDto = createStockEventDto();
stockEventDto.getLineItems().get(0).setReasonId(reason.getId());
Expand Down Expand Up @@ -213,6 +219,40 @@ public void shouldSubmitPhysicalInventoryWhenEventIsAboutPhysicalInventory()
.submitPhysicalInventory(any(PhysicalInventoryDto.class), any(UUID.class));
}

@Test
public void shouldSaveUnitOfOrderableIdOnProcessingStockEvent() {
//given
StockEventDto stockEventDto = createStockEventDto();
stockEventDto.setUserId(userId);
stockEventDto.setActive(true);
StockEventLineItemDto eventLineItemDto = stockEventDto.getLineItems().get(0);
eventLineItemDto.setReasonId(null);
eventLineItemDto.setSourceId(null);
eventLineItemDto.setDestinationId(null);
UUID unitOfOrderableId = eventLineItemDto.getUnitOfOrderableId();

//when
UUID eventId = stockEventProcessor.process(stockEventDto);

//then
Optional<StockEvent> stockEventOptional = stockEventsRepository.findById(eventId);
assertThat(stockEventOptional.isPresent(), is(true));
StockEvent stockEvent = stockEventOptional.get();
List<StockEventLineItem> lineItems = stockEvent.getLineItems();
assertThat(lineItems, hasSize(1));
assertThat(lineItems.get(0).getUnitOfOrderableId(),
is(unitOfOrderableId));

StockCard card = stockCardRepository.findByProgramIdAndFacilityIdAndOrderableIdAndLotId(
stockEventDto.getProgramId(),
stockEventDto.getFacilityId(),
eventLineItemDto.getOrderableId(),
eventLineItemDto.getLotId()
);
assertThat(card, notNullValue());
assertThat(card.getUnitOfOrderableId(), is(unitOfOrderableId));
}

private void assertSize(long cardSize, long eventSize, long lineItemSize) {
assertThat(stockCardRepository.count(), is(cardSize));
assertThat(stockEventsRepository.count(), is(eventSize));
Expand Down
Loading