HibernateReservedValueStore extends HibernateGenericStore<ReservedValue> implements ReservedValueStore { @Override public List<ReservedValue> reserveValuesJpa( ReservedValue reservedValue, List<String> values ) { List<ReservedValue> toAdd = getGeneratedValues( reservedValue, values ); toAdd.forEach( rv -> save( rv ) ); return toAdd; } HibernateReservedValueStore( SessionFactory sessionFactory, JdbcTemplate jdbcTemplate,
        ApplicationEventPublisher publisher, BatchHandlerFactory batchHandlerFactory ); @Override List<ReservedValue> reserveValues( ReservedValue reservedValue,
        List<String> values ); @Override List<ReservedValue> reserveValuesJpa( ReservedValue reservedValue, List<String> values ); @Override List<ReservedValue> getIfReservedValues( ReservedValue reservedValue,
        List<String> values ); @Override int getNumberOfUsedValues( ReservedValue reservedValue ); @Override void removeExpiredReservations(); @Override boolean useReservedValue( String ownerUID, String value ); @Override void deleteReservedValueByUid( String uid ); @Override boolean isReserved( String ownerObject, String ownerUID, String value );  }
@Test public void reserveValuesSingleValue() { int count = reservedValueStore.getCount(); ReservedValue rv = getFreeReservedValue(); List<ReservedValue> res = reservedValueStore.reserveValuesJpa( rv, Lists.newArrayList( rv.getValue() ) ); assertEquals( 1, res.size() ); assertEquals(reservedValueStore.getCount(), count + 1); }
@Test public void reserveValuesMultipleValues() { int count = reservedValueStore.getCount(); ArrayList<String> values = new ArrayList<>(); int n = 10; for ( int i = 0; i < n; i++ ) { values.add( String.format( "%03d", counter++ ) ); } List<ReservedValue> res = reservedValueStore.reserveValuesJpa( getFreeReservedValue(), values ); assertEquals( n, res.size() ); assertEquals( ( count + n ), reservedValueStore.getCount() ); }
@Test public void reserveValuesSingleValueAlreadyReserved() { int count = reservedValueStore.getCount(); List<ReservedValue> res = reservedValueStore .reserveValuesJpa( reservedValueA, Lists.newArrayList( reservedValueA.getValue() ) ); assertEquals( 0, res.size() ); assertEquals( count, reservedValueStore.getCount() ); }
@Test public void reserveValuesSingleValueAlreadyUsed() { int count = reservedValueStore.getCount(); List<ReservedValue> res = reservedValueStore .reserveValuesJpa( reservedValueA, Lists.newArrayList( reservedValueA.getValue() ) ); assertEquals( 0, res.size() ); assertEquals( count, reservedValueStore.getCount() ); }
@Test public void reserveValuesMultipleValuesAlreadyReservedAndUsed() { int count = reservedValueStore.getCount(); List<ReservedValue> res = reservedValueStore .reserveValuesJpa( reservedValueA, Lists.newArrayList( "001", "002", "003", "004" ) ); assertEquals( 1, count ); assertEquals( 3, res.size() ); assertEquals( ( count + 3 ), reservedValueStore.getCount() ); }