Skip to content

Commit

Permalink
fix: add compare UUID with UUID string
Browse files Browse the repository at this point in the history
  • Loading branch information
halber committed Oct 25, 2023
1 parent 5282a49 commit 559342a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,14 @@ default int comparePropertyValues(RoutingContext routingContext, Object leadingP
try {
// Example UUID: xxxxxxxx-xxxx-Bxxx-Axxx-xxxxxxxxxxxx
// The order is determined by 3 most significant bit of A
return ((UUID) leadingPropertyValue1).compareTo((UUID) propertyValue2);
if (propertyValue2 instanceof UUID) {
return ((UUID) leadingPropertyValue1).compareTo((UUID) propertyValue2);
} else if (propertyValue2 instanceof String) {
return ((UUID) leadingPropertyValue1).compareTo(UUID.fromString((String) propertyValue2));
}
throw createAndLogException(routingContext, EDM_GUID_JAVA_TYPES, leadingPropertyValue1,
propertyValue2,
propertyName);
} catch (Exception e) {
errorLog(routingContext, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@
import static java.nio.charset.StandardCharsets.UTF_8;

import java.util.Arrays;
import java.util.UUID;
import java.util.stream.Stream;

import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import io.vertx.ext.web.RoutingContext;

class EntityComparisonTest {
private final EntityComparison testEntityComparisonImplementation = new EntityComparison() {};
Expand Down Expand Up @@ -60,4 +69,24 @@ void instanceOfExpectedTypeTest() {
assertThat(testEntityComparisonImplementation.instanceOfExpectedType(EDM_BINARY_JAVA_TYPES, byteArrayToBeTested,
byteArrayToBeTested)).isTrue();
}

static Stream<Arguments> comparePropertyValuesParameters() {
UUID uuid1 = UUID.fromString("1386d8da-4cb4-4fee-97ef-5a24d6a41b34");
UUID uuid2 = UUID.fromString("74affcbf-1c66-4903-9cf3-685f511c93b0");

return Stream.of(
Arguments.of(null, uuid1, uuid1, EdmPrimitiveTypeKind.Guid, "ID", 0),
Arguments.of(null, uuid1, uuid1.toString(), EdmPrimitiveTypeKind.Guid, "ID", 0),
Arguments.of(null, uuid1, uuid2, EdmPrimitiveTypeKind.Guid, "ID", -1),
Arguments.of(null, uuid2, uuid1.toString(), EdmPrimitiveTypeKind.Guid, "ID", 1));
}

@ParameterizedTest(name = "{index}: compare {3} result should be {5}")
@MethodSource("comparePropertyValuesParameters")
@DisplayName("Test to compare entity properties of unknown concrete Java types (Object).")
void comparePropertyValues(RoutingContext routingContext, Object leadingPropertyValue1, Object propertyValue2,
EdmPrimitiveTypeKind propertyTypeKind, String propertyName, int expected) {
assertThat(testEntityComparisonImplementation.comparePropertyValues(routingContext, leadingPropertyValue1,
propertyValue2, propertyTypeKind, propertyName)).isEqualTo(expected);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,7 @@ void orderByShouldThrowMeaningfulErrorTest() throws ParseException {
calendar1.setTimeInMillis(date1.getTime());
Entity entity1 = new Entity() //
.addProperty(new Property(null, "name", ValueType.PRIMITIVE, "entity1"))
.addProperty(new Property(null, "testGuidProperty", ValueType.PRIMITIVE,
UUID.fromString("A7CF6C58-31FF-4B12-9670-F4FD80B2E82D").toString()))
.addProperty(new Property(null, "testGuidProperty", ValueType.PRIMITIVE, "NotAUuidButAString"))
.addProperty(new Property(null, "testStringProperty", ValueType.PRIMITIVE, Integer.valueOf(1337)))
.addProperty(new Property(null, "testNumberProperty", ValueType.PRIMITIVE, 111))
.addProperty(new Property(null, "testDateProperty", ValueType.PRIMITIVE, date1))
Expand Down

0 comments on commit 559342a

Please sign in to comment.