Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AsyncElementAsserter not working async #11989

Open
DamnClin opened this issue Feb 25, 2025 · 0 comments
Open

AsyncElementAsserter not working async #11989

DamnClin opened this issue Feb 25, 2025 · 0 comments

Comments

@DamnClin
Copy link
Collaborator

AsyncElementAsserter is not really working in async mode since we load the elment to check at build instead of evaluation.

Simple fix:

class AsyncElementAsserter implements ElementAsserter<AsyncResponseAsserter> {

  private final String jsonPath;
  private final Duration maxTime;
  private final AsyncResponseAsserter responseAsserter;

  AsyncElementAsserter(AsyncResponseAsserter responseAsserter, String jsonPath, Duration maxTime) {
    this.responseAsserter = responseAsserter;
    this.jsonPath = jsonPath;
    this.maxTime = maxTime;
  }

  @Override
  public AsyncElementAsserter withValues(Collection<String> values) {
    Awaiter.await(maxTime, () -> assertions().withValues(values));

    return this;
  }

  @Override
  public AsyncElementAsserter withElementsCount(int count) {
    Awaiter.await(maxTime, () -> assertions().withElementsCount(count));

    return this;
  }

  @Override
  public AsyncElementAsserter withMoreThanElementsCount(int count) {
    Awaiter.await(maxTime, () -> assertions().withMoreThanElementsCount(count));

    return this;
  }

  @Override
  public AsyncElementAsserter withValue(Object value) {
    Awaiter.await(maxTime, () -> assertions().withValue(value));

    return this;
  }

  @Override
  public <Data> AsyncElementAsserter containingExactly(List<Map<String, Data>> responses) {
    Awaiter.await(maxTime, () -> assertions().containingExactly(responses));

    return this;
  }

  @Override
  public <Data> AsyncElementAsserter containing(Map<String, Data> response) {
    Awaiter.await(maxTime, () -> assertions().containing(response));

    return this;
  }

  @Override
  public <Data> AsyncElementAsserter containing(List<Map<String, Data>> responses) {
    Awaiter.await(maxTime, () -> assertions().containing(responses));

    return this;
  }

  private ElementAssertions assertions() {
    return new ElementAssertions(jsonPath);
  }

  @Override
  public AsyncResponseAsserter and() {
    return responseAsserter;
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant