Skip to content

Commit

Permalink
HSEARCH-3099 Test indexNullAs positive cases in mapper pojo
Browse files Browse the repository at this point in the history
  • Loading branch information
fax4ever committed Apr 19, 2019
1 parent 6a7b262 commit d1e41e9
Show file tree
Hide file tree
Showing 45 changed files with 940 additions and 16 deletions.
Expand Up @@ -51,6 +51,7 @@
@RunWith(Parameterized.class)
public class FieldDefaultBridgeIT<V, F> {
private static final String FIELD_NAME = DefaultValueBridgeExpectations.TYPE_WITH_VALUE_BRIDGE_FIELD_NAME;
private static final String FIELD_INDEXNULLAS_NAME = DefaultValueBridgeExpectations.TYPE_WITH_VALUE_BRIDGE_FIELD_INDEXNULLAS_NAME;

@Parameterized.Parameters(name = "{0}")
public static Object[] types() {
Expand Down Expand Up @@ -82,14 +83,22 @@ public void setup() {
Capture<StubIndexSchemaNode> schemaCapture1 = Capture.newInstance();
Capture<StubIndexSchemaNode> schemaCapture2 = Capture.newInstance();
backendMock.expectSchema(
DefaultValueBridgeExpectations.TYPE_WITH_VALUE_BRIDGE_1_INDEX_NAME,
b -> b.field( FIELD_NAME, expectations.getIndexFieldJavaType() ),
schemaCapture1
DefaultValueBridgeExpectations.TYPE_WITH_VALUE_BRIDGE_1_INDEX_NAME, b -> {
b.field( FIELD_NAME, expectations.getIndexFieldJavaType() );

if ( expectations.isNullTranslatedAsNull() ) {
b.field( FIELD_INDEXNULLAS_NAME, expectations.getIndexFieldJavaType(), f -> f.indexNullAs( expectations.getNullAsValueBridge1() ) );
}
}, schemaCapture1
);
backendMock.expectSchema(
DefaultValueBridgeExpectations.TYPE_WITH_VALUE_BRIDGE_2_INDEX_NAME,
b -> b.field( FIELD_NAME, expectations.getIndexFieldJavaType() ),
schemaCapture2
DefaultValueBridgeExpectations.TYPE_WITH_VALUE_BRIDGE_2_INDEX_NAME, b -> {
b.field( FIELD_NAME, expectations.getIndexFieldJavaType() );

if ( expectations.isNullTranslatedAsNull() ) {
b.field( FIELD_INDEXNULLAS_NAME, expectations.getIndexFieldJavaType(), f -> f.indexNullAs( expectations.getNullAsValueBridge2() ) );
}
}, schemaCapture2
);
mapping = setupHelper.withBackendMock( backendMock )
.setup( expectations.getTypeWithValueBridge1(), expectations.getTypeWithValueBridge2() );
Expand All @@ -113,10 +122,14 @@ public void indexing() {
);
id = 0;
for ( F expectedFieldValue : getDocumentFieldValues() ) {
expectationSetter.add(
String.valueOf( id ),
b -> b.field( FIELD_NAME, expectedFieldValue )
);
expectationSetter.add( String.valueOf( id ), b -> {
b.field( FIELD_NAME, expectedFieldValue );

if ( expectations.isNullTranslatedAsNull() ) {
// Stub backend is not supposed to use 'indexNullAs' option
b.field( FIELD_INDEXNULLAS_NAME, null );
}
} );
++id;
}
expectationSetter.preparedThenExecuted();
Expand Down
Expand Up @@ -69,34 +69,60 @@ public Object instantiateTypeWithValueBridge1(int identifier, BigDecimal propert
public Class<?> getTypeWithValueBridge2() {
return TypeWithValueBridge2.class;
}

@Override
public BigDecimal getNullAsValueBridge1() {
return BigDecimal.ZERO;
}

@Override
public BigDecimal getNullAsValueBridge2() {
return BigDecimal.valueOf( 42571524, 231254 );
}
} );
}

@Indexed(index = DefaultValueBridgeExpectations.TYPE_WITH_VALUE_BRIDGE_1_INDEX_NAME)
public static class TypeWithValueBridge1 {
Integer id;
BigDecimal myProperty;
BigDecimal indexNullAsProperty;

@DocumentId
public Integer getId() {
return id;
}

@GenericField
public BigDecimal getMyProperty() {
return myProperty;
}

@GenericField(indexNullAs = "0")
public BigDecimal getIndexNullAsProperty() {
return indexNullAsProperty;
}
}

@Indexed(index = DefaultValueBridgeExpectations.TYPE_WITH_VALUE_BRIDGE_2_INDEX_NAME)
public static class TypeWithValueBridge2 {
Integer id;
BigDecimal myProperty;
BigDecimal indexNullAsProperty;

@DocumentId
public Integer getId() {
return id;
}

@GenericField
public BigDecimal getMyProperty() {
return myProperty;
}

@GenericField(indexNullAs = "4.2571524E-231247")
public BigDecimal getIndexNullAsProperty() {
return indexNullAsProperty;
}
}
}
Expand Up @@ -97,13 +97,23 @@ public Object instantiateTypeWithValueBridge1(int identifier, BigInteger propert
public Class<?> getTypeWithValueBridge2() {
return TypeWithValueBridge2.class;
}

@Override
public BigInteger getNullAsValueBridge1() {
return BigInteger.ZERO;
}

@Override
public BigInteger getNullAsValueBridge2() {
return BigInteger.valueOf( -10301 );
}
} );
}

@Indexed(index = DefaultIdentifierBridgeExpectations.TYPE_WITH_IDENTIFIER_BRIDGE_1_INDEX_NAME)
public static class TypeWithIdentifierBridge1 {

BigInteger id;

@DocumentId
public BigInteger getId() {
return id;
Expand All @@ -112,8 +122,8 @@ public BigInteger getId() {
}
@Indexed(index = DefaultIdentifierBridgeExpectations.TYPE_WITH_IDENTIFIER_BRIDGE_2_INDEX_NAME)
public static class TypeWithIdentifierBridge2 {

BigInteger id;

@DocumentId
public BigInteger getId() {
return id;
Expand All @@ -122,9 +132,10 @@ public BigInteger getId() {
}
@Indexed(index = DefaultValueBridgeExpectations.TYPE_WITH_VALUE_BRIDGE_1_INDEX_NAME)
public static class TypeWithValueBridge1 {

Integer id;
BigInteger myProperty;
BigInteger indexNullAsProperty;

@DocumentId
public Integer getId() {
return id;
Expand All @@ -135,12 +146,17 @@ public BigInteger getMyProperty() {
return myProperty;
}

@GenericField(indexNullAs = "0")
public BigInteger getIndexNullAsProperty() {
return indexNullAsProperty;
}
}
@Indexed(index = DefaultValueBridgeExpectations.TYPE_WITH_VALUE_BRIDGE_2_INDEX_NAME)
public static class TypeWithValueBridge2 {

Integer id;
BigInteger myProperty;
BigInteger indexNullAsProperty;

@DocumentId
public Integer getId() {
return id;
Expand All @@ -151,6 +167,10 @@ public BigInteger getMyProperty() {
return myProperty;
}

@GenericField(indexNullAs = "-10301")
public BigInteger getIndexNullAsProperty() {
return indexNullAsProperty;
}
}

private List<BigInteger> takeBigIntegerSequence() {
Expand Down
Expand Up @@ -67,34 +67,60 @@ public Object instantiateTypeWithValueBridge1(int identifier, Boolean propertyVa
public Class<?> getTypeWithValueBridge2() {
return TypeWithValueBridge2.class;
}

@Override
public Boolean getNullAsValueBridge1() {
return Boolean.FALSE;
}

@Override
public Boolean getNullAsValueBridge2() {
return Boolean.TRUE;
}
} );
}

@Indexed(index = DefaultValueBridgeExpectations.TYPE_WITH_VALUE_BRIDGE_1_INDEX_NAME)
public static class TypeWithValueBridge1 {
Integer id;
Boolean myProperty;
Boolean indexNullAsProperty;

@DocumentId
public Integer getId() {
return id;
}

@GenericField
public Boolean getMyProperty() {
return myProperty;
}

@GenericField(indexNullAs = "false")
public Boolean getIndexNullAsProperty() {
return indexNullAsProperty;
}
}

@Indexed(index = DefaultValueBridgeExpectations.TYPE_WITH_VALUE_BRIDGE_2_INDEX_NAME)
public static class TypeWithValueBridge2 {
Integer id;
Boolean myProperty;
Boolean indexNullAsProperty;

@DocumentId
public Integer getId() {
return id;
}

@GenericField
public Boolean getMyProperty() {
return myProperty;
}

@GenericField(indexNullAs = "true")
public Boolean getIndexNullAsProperty() {
return indexNullAsProperty;
}
}
}
Expand Up @@ -67,34 +67,60 @@ public Object instantiateTypeWithValueBridge1(int identifier, Byte propertyValue
public Class<?> getTypeWithValueBridge2() {
return TypeWithValueBridge2.class;
}

@Override
public Byte getNullAsValueBridge1() {
return (byte)0;
}

@Override
public Byte getNullAsValueBridge2() {
return (byte)-64;
}
} );
}

@Indexed(index = DefaultValueBridgeExpectations.TYPE_WITH_VALUE_BRIDGE_1_INDEX_NAME)
public static class TypeWithValueBridge1 {
Integer id;
Byte myProperty;
Byte indexNullAsProperty;

@DocumentId
public int getId() {
return id;
}

@GenericField
public Byte getMyProperty() {
return myProperty;
}

@GenericField(indexNullAs = "0")
public Byte getIndexNullAsProperty() {
return indexNullAsProperty;
}
}

@Indexed(index = DefaultValueBridgeExpectations.TYPE_WITH_VALUE_BRIDGE_2_INDEX_NAME)
public static class TypeWithValueBridge2 {
Integer id;
Byte myProperty;
Byte indexNullAsProperty;

@DocumentId
public int getId() {
return id;
}

@GenericField
public Byte getMyProperty() {
return myProperty;
}

@GenericField(indexNullAs = "-64")
public Byte getIndexNullAsProperty() {
return indexNullAsProperty;
}
}
}
Expand Up @@ -67,34 +67,60 @@ public Object instantiateTypeWithValueBridge1(int identifier, Character property
public Class<?> getTypeWithValueBridge2() {
return TypeWithValueBridge2.class;
}

@Override
public String getNullAsValueBridge1() {
return "7";
}

@Override
public String getNullAsValueBridge2() {
return "F";
}
} );
}

@Indexed(index = DefaultValueBridgeExpectations.TYPE_WITH_VALUE_BRIDGE_1_INDEX_NAME)
public static class TypeWithValueBridge1 {
Integer id;
Character myProperty;
Character indexNullAsProperty;

@DocumentId
public Integer getId() {
return id;
}

@GenericField
public Character getMyProperty() {
return myProperty;
}

@GenericField(indexNullAs = "7")
public Character getIndexNullAsProperty() {
return indexNullAsProperty;
}
}

@Indexed(index = DefaultValueBridgeExpectations.TYPE_WITH_VALUE_BRIDGE_2_INDEX_NAME)
public static class TypeWithValueBridge2 {
Integer id;
Character myProperty;
Character indexNullAsProperty;

@DocumentId
public Integer getId() {
return id;
}

@GenericField
public Character getMyProperty() {
return myProperty;
}

@GenericField(indexNullAs = "F")
public Character getIndexNullAsProperty() {
return indexNullAsProperty;
}
}
}

0 comments on commit d1e41e9

Please sign in to comment.