Search in sources :

Example 1 with CronologyTripDTO

use of eu.europa.ec.fisheries.ers.service.dto.fishingtrip.CronologyTripDTO in project UVMS-ActivityModule-APP by UnionVMS.

the class FishingTripServiceBeanTest method getCronologyOfFishingTrip_OnlyCurrentAndSelected.

@Test
@SneakyThrows
public void getCronologyOfFishingTrip_OnlyCurrentAndSelected() {
    // Mock the Dao
    doReturn(getVesselIdentifiers()).when(vesselIdentifiersDao).getLatestVesselIdByTrip(any(String.class));
    FishingTripIdentifierEntity fishingTripIdentifierEntity = getCurrentTrip();
    doReturn(fishingTripIdentifierEntity).when(fishingTripIdentifierDao).getCurrentTrip(any(String.class), any(String.class));
    List<FishingTripIdentifierEntity> previousTrips = getPreviousTrips(5);
    doReturn(previousTrips).when(fishingTripIdentifierDao).getPreviousTrips(any(String.class), any(String.class), any(String.class), any(Integer.class));
    List<FishingTripIdentifierEntity> nextTrips = getNextTrips(5);
    doReturn(nextTrips).when(fishingTripIdentifierDao).getNextTrips(any(String.class), any(String.class), any(String.class), any(Integer.class));
    // Trigger
    String selectedTrip = "selected Trip";
    CronologyTripDTO cronology = fishingTripService.getCronologyOfFishingTrip(selectedTrip, 1);
    assertEquals(selectedTrip, cronology.getSelectedTrip());
    assertEquals(fishingTripIdentifierEntity.getTripId(), cronology.getCurrentTrip());
    assertEquals(0, cronology.getPreviousTrips().size());
    assertEquals(0, cronology.getNextTrips().size());
}
Also used : FishingTripIdentifierEntity(eu.europa.ec.fisheries.ers.fa.entities.FishingTripIdentifierEntity) CronologyTripDTO(eu.europa.ec.fisheries.ers.service.dto.fishingtrip.CronologyTripDTO) Test(org.junit.Test) SneakyThrows(lombok.SneakyThrows)

Example 2 with CronologyTripDTO

use of eu.europa.ec.fisheries.ers.service.dto.fishingtrip.CronologyTripDTO in project UVMS-ActivityModule-APP by UnionVMS.

the class FishingTripServiceBeanTest method getCronologyOfFishingTrip_OnlyPrevious.

@Test
@SneakyThrows
public void getCronologyOfFishingTrip_OnlyPrevious() {
    // Mock the Dao
    doReturn(getVesselIdentifiers()).when(vesselIdentifiersDao).getLatestVesselIdByTrip(any(String.class));
    FishingTripIdentifierEntity fishingTripIdentifierEntity = getCurrentTrip();
    doReturn(fishingTripIdentifierEntity).when(fishingTripIdentifierDao).getCurrentTrip(any(String.class), any(String.class));
    List<FishingTripIdentifierEntity> previousTrips = getPreviousTrips(2);
    doReturn(previousTrips).when(fishingTripIdentifierDao).getPreviousTrips(any(String.class), any(String.class), any(String.class), any(Integer.class));
    List<FishingTripIdentifierEntity> nextTrips = getNextTrips(2);
    doReturn(nextTrips).when(fishingTripIdentifierDao).getNextTrips(any(String.class), any(String.class), any(String.class), any(Integer.class));
    // Trigger
    String selectedTrip = "selected Trip";
    CronologyTripDTO cronology = fishingTripService.getCronologyOfFishingTrip(selectedTrip, 2);
    assertEquals(selectedTrip, cronology.getSelectedTrip());
    assertEquals(fishingTripIdentifierEntity.getTripId(), cronology.getCurrentTrip());
    List<String> previousIds = getIds(previousTrips);
    assertEquals(previousIds.subList(1, previousIds.size()), cronology.getPreviousTrips());
}
Also used : FishingTripIdentifierEntity(eu.europa.ec.fisheries.ers.fa.entities.FishingTripIdentifierEntity) CronologyTripDTO(eu.europa.ec.fisheries.ers.service.dto.fishingtrip.CronologyTripDTO) Test(org.junit.Test) SneakyThrows(lombok.SneakyThrows)

Example 3 with CronologyTripDTO

use of eu.europa.ec.fisheries.ers.service.dto.fishingtrip.CronologyTripDTO in project UVMS-ActivityModule-APP by UnionVMS.

the class FishingTripServiceBeanTest method getCronologyOfFishingTrip_All.

@Test
@SneakyThrows
public void getCronologyOfFishingTrip_All() {
    // Mock the Dao
    doReturn(getVesselIdentifiers()).when(vesselIdentifiersDao).getLatestVesselIdByTrip(any(String.class));
    FishingTripIdentifierEntity fishingTripIdentifierEntity = getCurrentTrip();
    doReturn(fishingTripIdentifierEntity).when(fishingTripIdentifierDao).getCurrentTrip(any(String.class), any(String.class));
    List<FishingTripIdentifierEntity> previousTrips = getPreviousTrips(10);
    doReturn(previousTrips).when(fishingTripIdentifierDao).getPreviousTrips(any(String.class), any(String.class), any(String.class), any(Integer.class));
    List<FishingTripIdentifierEntity> nextTrips = getNextTrips(10);
    doReturn(nextTrips).when(fishingTripIdentifierDao).getNextTrips(any(String.class), any(String.class), any(String.class), any(Integer.class));
    // Trigger
    String selectedTrip = "selected Trip";
    CronologyTripDTO cronology = fishingTripService.getCronologyOfFishingTrip(selectedTrip, 0);
    assertEquals(selectedTrip, cronology.getSelectedTrip());
    assertEquals(fishingTripIdentifierEntity.getTripId(), cronology.getCurrentTrip());
    List<String> previousIds = getIds(previousTrips);
    assertEquals(previousIds, cronology.getPreviousTrips());
    List<String> nextIds = getIds(nextTrips);
    assertEquals(nextIds, cronology.getNextTrips());
}
Also used : FishingTripIdentifierEntity(eu.europa.ec.fisheries.ers.fa.entities.FishingTripIdentifierEntity) CronologyTripDTO(eu.europa.ec.fisheries.ers.service.dto.fishingtrip.CronologyTripDTO) Test(org.junit.Test) SneakyThrows(lombok.SneakyThrows)

Example 4 with CronologyTripDTO

use of eu.europa.ec.fisheries.ers.service.dto.fishingtrip.CronologyTripDTO in project UVMS-ActivityModule-APP by UnionVMS.

the class FishingTripServiceBean method getCronologyOfFishingTrip.

/**
 * {@inheritDoc}
 */
@Override
public CronologyTripDTO getCronologyOfFishingTrip(String tripId, Integer count) throws ServiceException {
    // Find the latest Vessel for the Trip for finding the trip of that vessel
    List<VesselIdentifierEntity> latestVesselIdentifiers = vesselIdentifierDao.getLatestVesselIdByTrip(tripId);
    CronologyTripDTO cronologyTripDTO = new CronologyTripDTO();
    cronologyTripDTO.setCurrentTrip(getCurrentTrip(latestVesselIdentifiers));
    cronologyTripDTO.setSelectedTrip(tripId);
    List<String> previousTrips = new ArrayList<>(getPreviousTrips(tripId, count, latestVesselIdentifiers));
    List<String> nextTrips = new ArrayList<>(getNextTrips(tripId, count, latestVesselIdentifiers));
    Map<String, Integer> countMap = calculateTripCounts(count, previousTrips.size(), nextTrips.size());
    log.info("Number of previous record to find : " + countMap.get(PREVIOUS));
    log.info("Number of next record to find : " + countMap.get(NEXT));
    cronologyTripDTO.setPreviousTrips(previousTrips.subList(previousTrips.size() - countMap.get(PREVIOUS), previousTrips.size()));
    cronologyTripDTO.setNextTrips(nextTrips.subList(0, countMap.get(NEXT)));
    return cronologyTripDTO;
}
Also used : BigInteger(java.math.BigInteger) VesselIdentifierEntity(eu.europa.ec.fisheries.ers.fa.entities.VesselIdentifierEntity) ArrayList(java.util.ArrayList) CronologyTripDTO(eu.europa.ec.fisheries.ers.service.dto.fishingtrip.CronologyTripDTO)

Example 5 with CronologyTripDTO

use of eu.europa.ec.fisheries.ers.service.dto.fishingtrip.CronologyTripDTO in project UVMS-ActivityModule-APP by UnionVMS.

the class FishingTripServiceBeanTest method getCronologyOfFishingTrip_limitedRecordsFound.

@Test
@SneakyThrows
public void getCronologyOfFishingTrip_limitedRecordsFound() {
    // Mock the Dao
    doReturn(getVesselIdentifiers()).when(vesselIdentifiersDao).getLatestVesselIdByTrip(any(String.class));
    FishingTripIdentifierEntity fishingTripIdentifierEntity = getCurrentTrip();
    doReturn(fishingTripIdentifierEntity).when(fishingTripIdentifierDao).getCurrentTrip(any(String.class), any(String.class));
    List<FishingTripIdentifierEntity> previousTrips = getPreviousTrips(5);
    doReturn(previousTrips).when(fishingTripIdentifierDao).getPreviousTrips(any(String.class), any(String.class), any(String.class), any(Integer.class));
    List<FishingTripIdentifierEntity> nextTrips = getNextTrips(5);
    doReturn(nextTrips).when(fishingTripIdentifierDao).getNextTrips(any(String.class), any(String.class), any(String.class), any(Integer.class));
    // Trigger
    String selectedTrip = "selected Trip";
    CronologyTripDTO cronology = fishingTripService.getCronologyOfFishingTrip(selectedTrip, 5);
    // Assert
    assertEquals(selectedTrip, cronology.getSelectedTrip());
    assertEquals(fishingTripIdentifierEntity.getTripId(), cronology.getCurrentTrip());
    List<String> previousIds = getIds(previousTrips);
    assertEquals(previousIds.subList(3, previousIds.size()), cronology.getPreviousTrips());
    List<String> nextIds = getIds(nextTrips);
    assertEquals(nextIds.subList(0, 2), cronology.getNextTrips());
}
Also used : FishingTripIdentifierEntity(eu.europa.ec.fisheries.ers.fa.entities.FishingTripIdentifierEntity) CronologyTripDTO(eu.europa.ec.fisheries.ers.service.dto.fishingtrip.CronologyTripDTO) Test(org.junit.Test) SneakyThrows(lombok.SneakyThrows)

Aggregations

CronologyTripDTO (eu.europa.ec.fisheries.ers.service.dto.fishingtrip.CronologyTripDTO)5 FishingTripIdentifierEntity (eu.europa.ec.fisheries.ers.fa.entities.FishingTripIdentifierEntity)4 SneakyThrows (lombok.SneakyThrows)4 Test (org.junit.Test)4 VesselIdentifierEntity (eu.europa.ec.fisheries.ers.fa.entities.VesselIdentifierEntity)1 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1