Skip to content

Commit

Permalink
docs: prove that count endpoint works with distinct results
Browse files Browse the repository at this point in the history
  • Loading branch information
bbortt committed Oct 22, 2024
1 parent 924ee02 commit 886c697
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions simulator-docs/src/main/asciidoc/rest-api.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ For each listed resource, the following operations are supported:
* Listing all entries with a `GET` request to the root URI.
** Pagination and filtering are supported.
* Counting all entries with a `GET /count` endpoint.
** Note that the `?distinct=true` query parameter is required to count unique results.
* Retrieving a single resource using the `GET /{id}` endpoint.

All REST resources adhere to this pattern, with exceptions noted in subsequent sections.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.citrusframework.testng.spring.TestNGCitrusSpringSupport;
import org.citrusframework.xml.XsdSchemaRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
Expand All @@ -49,10 +50,18 @@ public class SimulatorRestIT extends TestNGCitrusSpringSupport {

private final String defaultResponse = "<DefaultResponse>This is a default response!</DefaultResponse>";

/**
* Test Http REST client configured to access the API
*/
@Autowired
@Qualifier("apiClient")
private HttpClient apiClient;

/**
* Test Http REST client
*/
@Autowired
@Qualifier("simulatorClient")
private HttpClient simulatorClient;

/**
Expand Down Expand Up @@ -263,6 +272,17 @@ public void testSimulationFailingExpectantly() {
$(http().client(simulatorClient)
.receive()
.response(HttpStatus.OK));

// Make sure we receive exactly one record using "count" resources
$(http().client(apiClient)
.send()
.get("scenario-executions/count?headers=citrus_endpoint_uri~/services/rest/simulator/fail&scenarioName.contains=Fail&status.equals=2&distinct=true"));

$(http().client(apiClient)
.receive()
.response(HttpStatus.OK)
.getMessageBuilderSupport()
.body("1"));
}

/**
Expand Down Expand Up @@ -319,6 +339,13 @@ public HttpClient simulatorClient() {
.build();
}

@Bean
public HttpClient apiClient() {
return CitrusEndpoints.http().client()
.requestUrl(String.format("http://localhost:%s/api", 8080))
.build();
}

@Bean
@ConditionalOnProperty(name = "simulator.mode", havingValue = "embedded")
public BeforeSuite startEmbeddedSimulator() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.citrusframework.simulator.service;

import static java.util.Objects.nonNull;
import static org.springframework.data.domain.Pageable.unpaged;

import jakarta.persistence.EntityManager;
import jakarta.persistence.TypedQuery;
Expand Down Expand Up @@ -68,7 +69,10 @@ static <R> TypedQuery<Long> newSelectIdBySpecificationQuery(Class<R> entityClass
criteriaQuery = orderByPageSort(page, root, criteriaBuilder, criteriaQuery);

TypedQuery<Long> query = entityManager.createQuery(criteriaQuery);
query = selectPage(page, query);

if (!unpaged().equals(page)) {
query = selectPage(page, query);
}

return query;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ private Specification<ScenarioExecution> buildMessageHeaderValueSpecification(Lo

private static SetJoin<Message, MessageHeader> joinMessageHeaders(Root<ScenarioExecution> root) {
return root.join(ScenarioExecution_.scenarioMessages, JoinType.LEFT)
.join(Message_.headers);
.join(Message_.headers, JoinType.LEFT);
}

private static Path<String> joinMessageHeadersAndGetValue(Root<ScenarioExecution> root) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ void getNonExistingScenarioExecution() throws Exception {

@Nested
class CorrectTimeOnScenarioExecution {

public static final TemporalUnitLessThanOffset LESS_THAN_5_SECONDS = new TemporalUnitLessThanOffset(5, SECONDS);

@Autowired
Expand Down

0 comments on commit 886c697

Please sign in to comment.