Skip to content

Commit

Permalink
HSEARCH-4142 Test convertToSource with default identifier bridges
Browse files Browse the repository at this point in the history
  • Loading branch information
fax4ever committed Mar 1, 2021
1 parent 7b3e945 commit 69503b5
Showing 1 changed file with 23 additions and 0 deletions.
Expand Up @@ -16,6 +16,7 @@
import java.util.Optional;

import org.hibernate.search.engine.backend.types.converter.runtime.spi.FromDocumentIdentifierValueConvertContext;
import org.hibernate.search.engine.backend.types.converter.runtime.spi.FromDocumentIdentifierValueConvertContextImpl;
import org.hibernate.search.engine.backend.types.converter.runtime.spi.ToDocumentIdentifierValueConvertContext;
import org.hibernate.search.engine.backend.types.converter.runtime.spi.ToDocumentIdentifierValueConvertContextImpl;
import org.hibernate.search.engine.backend.types.converter.spi.DocumentIdentifierValueConverter;
Expand Down Expand Up @@ -219,6 +220,28 @@ public void dslToIndexConverter() {
.isInstanceOf( RuntimeException.class );
}

// Test behavior that backends expect from our bridges when using the identifier projections
@Test
public void convertToSource() {
// This cast may be unsafe, but only if something is deeply wrong, and then an exception will be thrown below
@SuppressWarnings("unchecked")
DocumentIdentifierValueConverter<I> documentIdentifierValueConverter =
(DocumentIdentifierValueConverter<I>) index1RootSchemaNode.getIdDslConverter();

// convert must behave appropriately on valid input
try ( SearchSession searchSession = mapping.createSession() ) {
FromDocumentIdentifierValueConvertContextImpl convertContext =
new FromDocumentIdentifierValueConvertContextImpl(
BridgeTestUtils.toBackendSessionContext( searchSession ) );

Iterator<I> entityIdentifierIterator = expectations.getEntityIdentifierValues().iterator();
for ( String documentId : expectations.getDocumentIdentifierValues() ) {
assertThat( documentIdentifierValueConverter.convertToSource( documentId, convertContext ) )
.isEqualTo( entityIdentifierIterator.next() );
}
}
}

private static class IncompatibleDocumentIdentifierValueConverter
implements DocumentIdentifierValueConverter<Object> {
@Override
Expand Down

0 comments on commit 69503b5

Please sign in to comment.