use of org.hisp.dhis.reservedvalue.ReservedValue in project dhis2-core by dhis2.
the class HibernateReservedValueStoreTest method shouldRemoveAlreadyUsedReservedValues.
@Test
void shouldRemoveAlreadyUsedReservedValues() {
ReservedValue rv = reservedValue.value(prog001).build();
reservedValueStore.save(rv);
OrganisationUnit ou = createOrganisationUnit("OU");
organisationUnitStore.save(ou);
TrackedEntityInstance tei = createTrackedEntityInstance(ou);
trackedEntityInstanceStore.save(tei);
TrackedEntityAttribute tea = createTrackedEntityAttribute('Y');
tea.setUid(teaUid);
trackedEntityAttributeStore.save(tea);
TrackedEntityAttributeValue teav = createTrackedEntityAttributeValue('Z', tei, tea);
teav.setValue(prog001);
trackedEntityAttributeValueStore.save(teav);
reservedValueStore.removeUsedOrExpiredReservations();
assertFalse(reservedValueStore.isReserved(Objects.TRACKEDENTITYATTRIBUTE.name(), teaUid, prog001));
assertEquals(0, reservedValueStore.getCount());
}
use of org.hisp.dhis.reservedvalue.ReservedValue in project dhis2-core by dhis2.
the class HibernateReservedValueStoreTest method reserveValuesMultipleValuesAlreadyReservedAndUsed.
@Test
void reserveValuesMultipleValuesAlreadyReservedAndUsed() {
ReservedValue rv = reservedValue.value(prog001).build();
reservedValueStore.save(rv);
int count = reservedValueStore.getCount();
List<ReservedValue> res = reservedValueStore.reserveValuesJpa(rv, Lists.newArrayList("002", "003", "004"));
assertEquals(1, count);
assertEquals(3, res.size());
assertEquals((count + 3), reservedValueStore.getCount());
}
use of org.hisp.dhis.reservedvalue.ReservedValue in project dhis2-core by dhis2.
the class HibernateReservedValueStoreTest method removeExpiredReservations.
@Test
void removeExpiredReservations() {
Calendar pastDate = Calendar.getInstance();
pastDate.add(Calendar.DATE, -1);
reservedValue.expiryDate(pastDate.getTime());
ReservedValue rv = reservedValue.value(prog001).build();
reservedValueStore.reserveValuesJpa(rv, Lists.newArrayList(rv.getValue()));
assertTrue(reservedValueStore.isReserved(Objects.TRACKEDENTITYATTRIBUTE.name(), teaUid, prog001));
reservedValueStore.removeUsedOrExpiredReservations();
assertFalse(reservedValueStore.getAll().contains(rv));
}
use of org.hisp.dhis.reservedvalue.ReservedValue in project dhis2-core by dhis2.
the class HibernateReservedValueStoreTest method shouldRemoveAlreadyUsedOrExpiredReservedValues.
@Test
void shouldRemoveAlreadyUsedOrExpiredReservedValues() {
// expired value
Calendar pastDate = Calendar.getInstance();
pastDate.add(Calendar.DATE, -1);
reservedValueStore.reserveValuesJpa(reservedValue.expiryDate(pastDate.getTime()).value(prog002).build(), Lists.newArrayList(prog002));
// used value
OrganisationUnit ou = createOrganisationUnit("OU");
organisationUnitStore.save(ou);
TrackedEntityInstance tei = createTrackedEntityInstance(ou);
trackedEntityInstanceStore.save(tei);
TrackedEntityAttribute tea = createTrackedEntityAttribute('Y');
tea.setUid(teaUid);
trackedEntityAttributeStore.save(tea);
TrackedEntityAttributeValue teav = createTrackedEntityAttributeValue('Z', tei, tea);
teav.setValue(prog001);
trackedEntityAttributeValueStore.save(teav);
ReservedValue rv = reservedValue.value(prog001).build();
reservedValueStore.save(rv);
reservedValueStore.removeUsedOrExpiredReservations();
assertFalse(reservedValueStore.isReserved(Objects.TRACKEDENTITYATTRIBUTE.name(), teaUid, prog001));
assertFalse(reservedValueStore.isReserved(Objects.TRACKEDENTITYATTRIBUTE.name(), teaUid, prog002));
assertEquals(0, reservedValueStore.getCount());
}
use of org.hisp.dhis.reservedvalue.ReservedValue in project dhis2-core by dhis2.
the class HibernateReservedValueStoreTest method isReservedShouldBeFalse.
@Test
void isReservedShouldBeFalse() {
ReservedValue rv = reservedValue.value(prog001).build();
reservedValueStore.save(rv);
assertFalse(reservedValueStore.isReserved(rv.getOwnerObject(), rv.getOwnerUid(), "100"));
}
Aggregations