gortiz commented on code in PR #15277:
URL: https://github.com/apache/pinot/pull/15277#discussion_r2005649218


##########
pinot-integration-test-base/src/test/java/org/apache/pinot/integration/tests/QueryAssert.java:
##########
@@ -0,0 +1,159 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.integration.tests;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import java.util.Locale;
+import org.apache.pinot.spi.exception.QueryErrorCode;
+import org.assertj.core.api.AbstractAssert;
+import org.assertj.core.api.AbstractSoftAssertions;
+
+/// A custom AssertJ assertion class for query responses that provides a 
fluent API for asserting on query responses.
+///
+/// The current implementation is partial and we should be adding more methods 
to support more use cases as more tests
+/// are migrated to this class instead of TestNG's Assert class.
+public class QueryAssert extends AbstractAssert<QueryAssert, JsonNode> {
+  public QueryAssert(JsonNode jsonNode) {
+    super(jsonNode, QueryAssert.class);
+  }
+
+  public static QueryAssert assertThat(JsonNode actual) {
+    return new QueryAssert(actual);
+  }
+
+  public QueryAssert hasNoExceptions() {
+    isNotNull();
+    if (actual.has("exceptions") && !actual.get("exceptions").isEmpty()) {
+      failWithMessage("Expected no exceptions but found <%s>", 
actual.get("exceptions"));
+    }
+    return this;
+  }
+
+  /// Obtains the first exception in the query response, returning it as a 
[QueryErrorAssert] object.
+  ///
+  /// It fails if there are no exceptions in the query response.
+  public QueryErrorAssert firstException() {
+    isNotNull();
+    if (!actual.has("exceptions")) {
+      failWithMessage("No exceptions found in query response");
+    }
+    JsonNode exceptions = actual.get("exceptions");
+    if (exceptions.isEmpty()) {
+      failWithMessage("No exceptions found in query response");
+    }
+    return new QueryErrorAssert(actual.get("exceptions").get(0));
+  }
+
+
+  /// Obtains the first exception in the query response, returning it as a 
[QueryErrorAssert.Soft] object.
+  ///
+  /// It fails if there are no exceptions in the query response.
+  ///
+  /// Unlike [#firstException], this method returns a [QueryErrorAssert.Soft] 
object, which allows for multiple
+  /// assertions to be made before failing.
+  ///
+  /// See [Soft Assertions in AssertJ 
docs](https://assertj.github.io/doc/#assertj-core-soft-assertions)
+  public QueryErrorAssert.Soft softFirstException() {

Review Comment:
   When only one condition is needed (then soft assertions are ok, but require 
more code to be used because they need to be closed) or when one condition only 
make sense if the next one is true (ie an assert verifies that something is not 
null and the next one uses it as a not null value).
   
   There are some cases in this PR



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to