HibernateReservedValueStore extends HibernateGenericStore<ReservedValue> implements ReservedValueStore { @Override public List<ReservedValue> getIfReservedValues( ReservedValue reservedValue, List<String> values ) { String hql = "from ReservedValue rv where rv.ownerObject =:ownerObject and rv.ownerUid =:ownerUid " + "and rv.key =:key and rv.value in :values"; return getQuery( hql ) .setParameter( "ownerObject", reservedValue.getOwnerObject() ) .setParameter( "ownerUid", reservedValue.getOwnerUid() ) .setParameter( "key", reservedValue.getKey() ) .setParameter( "values", values ) .getResultList(); } 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 getIfReservedValuesReturnsReservedValue() { List<ReservedValue> res = reservedValueStore .getIfReservedValues( reservedValueA, Lists.newArrayList( reservedValueA.getValue() ) ); assertEquals( reservedValueA, res.get( 0 ) ); assertEquals( 1, res.size() ); }
@Test public void getIfReservedValuesReturnEmptyListWhenNotReserved() { List<ReservedValue> res = reservedValueStore .getIfReservedValues( getFreeReservedValue(), Lists.newArrayList( "999" ) ); assertEquals( 0, res.size() ); }
@Test public void getIfReservedValuesReturnOnlyReservedValuesWhenSendingMultipleValues() { List<ReservedValue> res = reservedValueStore .getIfReservedValues( reservedValueA, Lists.newArrayList( "001", "002", "003" ) ); assertEquals( reservedValueA, res.get( 0 ) ); assertEquals( 1, res.size() ); }