Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public ODataRequestCount(
@Nullable final String encodedQuery,
@Nonnull final ODataProtocol protocol )
{
super(servicePath, resourcePath.addSegment("$count"), encodedQuery, protocol);
super(servicePath, appendCountResourcePath(resourcePath), encodedQuery, protocol);
}

/**
Expand All @@ -74,8 +74,24 @@ public ODataRequestCount(
{
this(
servicePath,
resourcePath.addSegment(query.getEntityOrPropertyName()),
appendResourcePath(resourcePath, query.getEntityOrPropertyName()),
query.getEncodedQueryString(),
query.getProtocol());
}

@Nonnull
private static ODataResourcePath appendCountResourcePath( @Nonnull final ODataResourcePath resourcePath )
{
return appendResourcePath(resourcePath, "$count");
}

@Nonnull
private static
ODataResourcePath
appendResourcePath( @Nonnull final ODataResourcePath resourcePath, @Nonnull final String segment )
{
final ODataResourcePath appendedPath = new ODataResourcePath();
resourcePath.getSegments().forEach(s -> appendedPath.addSegment(s._1, s._2));
return appendedPath.addSegment(segment);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,14 @@ void testConstructorWithStructuredQuery()
assertThat(actual).isEqualTo(expected);
assertThat(actual.getQueryString()).isEqualTo(expected.getQueryString());
}

@Test
void testConstructorDoesNotMutateResourcePath()
{
final ODataResourcePath resourcePath = ODataResourcePath.of(ENTITY_NAME);

new ODataRequestCount(SERVICE_PATH, resourcePath, "", ODataProtocol.V4);

assertThat(resourcePath.toString()).isEqualTo("/" + ENTITY_NAME);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,19 @@ void testCountNestedTrip()
assertThat(count.getRelativeUri()).hasToString("/TripPinServiceRW/People('russellwhyte')/Trips/$count");
}

@Test
void testCountNestedTripToRequestIsStable()
{
final Person personByKey = Person.builder().userName("russellwhyte").build();
final CountRequestBuilder<Trip> countBuilder =
service.forEntity(personByKey).navigateTo(Person.TO_TRIPS).count();

assertThat(countBuilder.toRequest().getRelativeUri())
.hasToString("/TripPinServiceRW/People('russellwhyte')/Trips/$count");
assertThat(countBuilder.toRequest().getRelativeUri())
.hasToString("/TripPinServiceRW/People('russellwhyte')/Trips/$count");
}

@Test
void testGetByKeyNestedPlanItem()
{
Expand Down