janhoy commented on code in PR #4336:
URL: https://github.com/apache/solr/pull/4336#discussion_r3215361871


##########
solr/core/src/test/org/apache/solr/util/FileTypeMagicUtilTikaCorpusTest.java:
##########
@@ -0,0 +1,224 @@
+/*
+ * 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.util;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.ObjectOutputStream;
+import java.net.URI;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.common.util.SuppressForbidden;
+
+/**
+ * Manual regression test that downloads small binary sample files from Apache 
Tika's test corpus
+ * (Apache License 2.0) and verifies that {@link FileTypeMagicUtil} correctly 
identifies each MIME
+ * type it claims to handle.
+ *
+ * <p><b>This test is disabled by default.</b> It requires outbound network 
access and downloads
+ * several binary files at runtime. It is intended to be run manually in two 
situations:
+ *
+ * <ol>
+ *   <li><b>Adding a new format:</b> after extending {@link FileTypeMagicUtil} 
with a new magic-byte
+ *       detector, add a corresponding entry to the URL map below so future 
runs validate that real
+ *       files of that format are detected correctly.
+ *   <li><b>Regression validation:</b> when refactoring the detector, run this 
test to confirm that
+ *       real-world binary samples are still detected as expected.
+ * </ol>
+ *
+ * <p>To run this test, temporarily remove the {@code @Ignore} annotation and 
run:
+ *
+ * <pre>{@code
+ * ./gradlew :solr:core:test \
+ *     --tests "org.apache.solr.util.FileTypeMagicUtilTikaCorpusTest"
+ * }</pre>
+ *
+ * <p>Sample sources:
+ *
+ * <ul>
+ *   <li>Apache Tika test corpus (Apache 2.0): <a
+ *       
href="https://github.com/apache/tika/tree/main/tika-parsers";>tika-parsers</a>
+ *   <li>XZ Utils test files (public domain): <a
+ *       
href="https://github.com/tukaani-project/xz/tree/master/tests/files";>xz 
tests</a>
+ *   <li>TAR, shell script, and Java serialised object: generated in-test via 
JDK APIs (no public
+ *       corpus provides a reliably uncompressed TAR or a {@code .ser} file).
+ * </ul>
+ */
+// @Ignore("Corpus validation test — downloads external files at runtime. 
Remove @Ignore to run
+// manually.")
+public class FileTypeMagicUtilTikaCorpusTest extends SolrTestCaseJ4 {
+
+  private static final String TIKA_PKG =
+      "https://raw.githubusercontent.com/apache/tika/main/tika-parsers/";
+          + "tika-parsers-standard/tika-parsers-standard-modules/"
+          + "tika-parser-pkg-module/src/test/resources/test-documents/";
+
+  private static final String TIKA_CODE =
+      "https://raw.githubusercontent.com/apache/tika/main/tika-parsers/";
+          + "tika-parsers-standard/tika-parsers-standard-modules/"
+          + "tika-parser-code-module/src/test/resources/test-documents/";

Review Comment:
   Added this new test case which is `@Ignore`'d by default but can be run 
manually. It will download real binaries from the tika project and other 
locations and then test our detection on those.



-- 
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