epugh commented on code in PR #4183:
URL: https://github.com/apache/solr/pull/4183#discussion_r2879543767


##########
solr/core/src/test/org/apache/solr/handler/V2ApiIntegrationTest.java:
##########
@@ -257,6 +261,35 @@ public void testSelect() throws Exception {
     assertEquals(0, ((SolrDocumentList) 
v2Response.getResponse().get("response")).getNumFound());
   }
 
+  @Test
+  public void testV2ApiErrorHandling() throws Exception {
+    final var deleteRequest = new 
CollectionsApi.DeleteCollection("collection-does-not-exist");
+
+    // Test with "Http" client
+    final String baseUrl = 
cluster.getJettySolrRunner(0).getBaseUrl().toString();
+    try (var httpClient = new HttpJettySolrClient.Builder(baseUrl).build()) {
+      final var ex =
+          expectThrows(RemoteSolrException.class, () -> 
deleteRequest.process(httpClient));
+      assertRSECodeAndMessage(ex, 400, "Could not find collection", 
"collection-does-not-exist");
+    }
+
+    // Test with "Cloud" client
+    final var ex =
+        expectThrows(
+            RemoteSolrException.class, () -> 
deleteRequest.process(cluster.getSolrClient()));
+    assertRSECodeAndMessage(ex, 400, "Could not find collection", 
"collection-does-not-exist");
+  }
+
+  private void assertRSECodeAndMessage(
+      RemoteSolrException rse, int expectedCode, String... 
expectedMessagePices) {

Review Comment:
   ding ding, I found a typo...   time to pick up the pieces.   heh heh.



##########
solr/core/src/test/org/apache/solr/handler/V2ApiIntegrationTest.java:
##########
@@ -257,6 +261,35 @@ public void testSelect() throws Exception {
     assertEquals(0, ((SolrDocumentList) 
v2Response.getResponse().get("response")).getNumFound());
   }
 
+  @Test
+  public void testV2ApiErrorHandling() throws Exception {
+    final var deleteRequest = new 
CollectionsApi.DeleteCollection("collection-does-not-exist");
+
+    // Test with "Http" client
+    final String baseUrl = 
cluster.getJettySolrRunner(0).getBaseUrl().toString();
+    try (var httpClient = new HttpJettySolrClient.Builder(baseUrl).build()) {
+      final var ex =
+          expectThrows(RemoteSolrException.class, () -> 
deleteRequest.process(httpClient));
+      assertRSECodeAndMessage(ex, 400, "Could not find collection", 
"collection-does-not-exist");
+    }
+
+    // Test with "Cloud" client
+    final var ex =
+        expectThrows(
+            RemoteSolrException.class, () -> 
deleteRequest.process(cluster.getSolrClient()));
+    assertRSECodeAndMessage(ex, 400, "Could not find collection", 
"collection-does-not-exist");
+  }
+
+  private void assertRSECodeAndMessage(

Review Comment:
   is there any value in testing here the other ways of making a query like 
GenericSolrRequest?   That it alos throws a 400?



##########
solr/solrj/src/test/org/apache/solr/client/solrj/response/json/JacksonDataBindResponseParserTest.java:
##########
@@ -0,0 +1,127 @@
+/*
+ * 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.solr.client.solrj.response.json;
+
+import static org.hamcrest.Matchers.instanceOf;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.solr.SolrTestCase;
+import org.apache.solr.client.api.model.SolrJerseyResponse;
+import org.apache.solr.common.util.NamedList;
+import org.junit.Test;
+
+/** Unit tests for {@link JacksonDataBindResponseParser} */
+public class JacksonDataBindResponseParserTest extends SolrTestCase {
+
+  @Test
+  public void testSuccessfulResponseHasNoErrorKey() throws IOException {
+    final var parser = new 
JacksonDataBindResponseParser<>(SolrJerseyResponse.class);
+    final var json = "{\"responseHeader\":{\"status\":0,\"QTime\":5}}";
+
+    final NamedList<Object> result = parser.processResponse(toStream(json), 
null);
+
+    assertNotNull(result.get("response"));
+    assertThat(result.get("response"), instanceOf(SolrJerseyResponse.class));
+    assertNull("No 'error' key expected on success", result.get("error"));
+  }
+
+  @Test
+  public void testErrorResponseSurfacesErrorAtTopLevel() throws IOException {
+    final var parser = new 
JacksonDataBindResponseParser<>(SolrJerseyResponse.class);
+    final var json =
+        "{"

Review Comment:
   I've been enjoying use the triple "double quotes" to not have all this 
string escaping and make reading multiline JSON easier.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to