You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by no...@apache.org on 2023/08/16 13:17:06 UTC
[solr] branch jira/solr16939 updated: added test
This is an automated email from the ASF dual-hosted git repository.
noble pushed a commit to branch jira/solr16939
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/jira/solr16939 by this push:
new d60e7afcb6c added test
d60e7afcb6c is described below
commit d60e7afcb6c1581b084f8ef08b01ef9d5279d231
Author: noblepaul <no...@gmail.com>
AuthorDate: Wed Aug 16 23:16:57 2023 +1000
added test
---
.../org/apache/solr/util/TestCborDataFormat.java | 55 ++++++++++++++++++++++
1 file changed, 55 insertions(+)
diff --git a/solr/core/src/test/org/apache/solr/util/TestCborDataFormat.java b/solr/core/src/test/org/apache/solr/util/TestCborDataFormat.java
index 90b61853bfb..d41e7afc4e6 100644
--- a/solr/core/src/test/org/apache/solr/util/TestCborDataFormat.java
+++ b/solr/core/src/test/org/apache/solr/util/TestCborDataFormat.java
@@ -27,6 +27,8 @@ import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.io.StringWriter;
+import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
@@ -44,9 +46,11 @@ import org.apache.solr.client.solrj.request.RequestWriter;
import org.apache.solr.client.solrj.request.UpdateRequest;
import org.apache.solr.cloud.MiniSolrCloudCluster;
import org.apache.solr.cloud.SolrCloudTestCase;
+import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.params.MapSolrParams;
import org.apache.solr.common.util.JavaBinCodec;
import org.apache.solr.common.util.NamedList;
+import org.apache.solr.common.util.SolrJSONWriter;
import org.apache.solr.common.util.Utils;
import org.apache.solr.handler.loader.CborLoader;
import org.apache.solr.response.XMLResponseWriter;
@@ -227,4 +231,55 @@ public class TestCborDataFormat extends SolrCloudTestCase {
jsonGenerator.close();
return baos.toByteArray();
}
+
+ public void testNestedDocs() throws IOException {
+ String json =
+ "[{ \"id\": \"P11!prod\",\n"
+ + " \"name_s\": \"Swingline Stapler\",\n"
+ + " \"type_s\": \"PRODUCT\",\n"
+ + " \"description_t\": \"The Cadillac of office staplers ...\",\n"
+ + " \"skus\": [\n"
+ + " { \"id\": \"P11!S21\",\n"
+ + " \"type_s\": \"SKU\",\n"
+ + " \"color_s\": \"RED\",\n"
+ + " \"price_i\": 42,\n"
+ + " \"manuals\": [\n"
+ + " { \"id\": \"P11!D41\",\n"
+ + " \"type_s\": \"MANUAL\",\n"
+ + " \"name_s\": \"Red Swingline Brochure\",\n"
+ + " \"pages_i\":1,\n"
+ + " \"content_t\": \"...\"\n"
+ + " } ]\n"
+ + " },\n"
+ + " { \"id\": \"P11!S31\",\n"
+ + " \"type_s\": \"SKU\",\n"
+ + " \"color_s\": \"BLACK\",\n"
+ + " \"price_i\": 3\n"
+ + " },\n"
+ + " { \"id\": \"P11!D51\",\n"
+ + " \"type_s\": \"MANUAL\",\n"
+ + " \"name_s\": \"Quick Reference Guide\",\n"
+ + " \"pages_i\":1,\n"
+ + " \"content_t\": \"How to use your stapler ...\"\n"
+ + " },\n"
+ + " { \"id\": \"P11!D61\",\n"
+ + " \"type_s\": \"MANUAL\",\n"
+ + " \"name_s\": \"Warranty Details\",\n"
+ + " \"pages_i\":42,\n"
+ + " \"content_t\": \"... lifetime guarantee ...\"\n"
+ + " }\n"
+ + " ]\n"
+ + "} ]";
+ byte[] bytes = serializeToCbor(json.getBytes(StandardCharsets.UTF_8));
+ SolrInputDocument[] d = new SolrInputDocument[1];
+ new CborLoader(null, doc -> d[0] = doc).stream(new ByteArrayInputStream(bytes));
+ StringWriter sw = new StringWriter();
+ try (SolrJSONWriter jsonWriter = new SolrJSONWriter(sw)) {
+ jsonWriter.writeObj(d[0]);
+ }
+ Object rootDoc = Utils.fromJSONString(sw.toString());
+ @SuppressWarnings("unchecked")
+ List<Object> l = (List<Object>) Utils.fromJSONString(json);
+ assertEquals(rootDoc, l.get(0));
+ }
}