|
38 | 38 | import java.util.List; |
39 | 39 | import java.util.Set; |
40 | 40 |
|
| 41 | +import com.fasterxml.jackson.databind.JsonNode; |
| 42 | +import com.fasterxml.jackson.databind.ObjectMapper; |
41 | 43 | import org.junit.jupiter.api.AfterEach; |
42 | 44 | import org.junit.jupiter.api.BeforeEach; |
43 | 45 | import org.junit.jupiter.api.Disabled; |
@@ -772,11 +774,23 @@ public void testConvertConfigXmlToJson() throws Exception { |
772 | 774 | String xmlPath = Paths.get(getClass().getResource("/xml-configs/tika-config-simple.xml").toURI()).toString(); |
773 | 775 | String content = getParamOutContent("--convert-config-xml-to-json=" + xmlPath); |
774 | 776 |
|
775 | | - // stdout should contain the converted JSON (and only the JSON) |
776 | | - assertTrue(content.contains("\"parsers\""), "Expected JSON parsers section, got: " + content); |
777 | | - assertTrue(content.contains("pdf-parser"), "Expected pdf-parser in output, got: " + content); |
778 | | - assertTrue(content.contains("\"sortByPosition\" : true"), "Expected converted param, got: " + content); |
779 | | - assertTrue(content.trim().startsWith("{"), "Output should be pure JSON, got: " + content); |
| 777 | + // stdout should be pure JSON; parse and assert on structure, not formatting |
| 778 | + JsonNode root = new ObjectMapper().readTree(content.trim()); |
| 779 | + JsonNode parsers = root.get("parsers"); |
| 780 | + assertNotNull(parsers, "Expected parsers section, got: " + content); |
| 781 | + assertTrue(parsers.isArray() && parsers.size() > 0, "Expected non-empty parsers array, got: " + content); |
| 782 | + |
| 783 | + JsonNode pdfEntry = null; |
| 784 | + for (JsonNode entry : parsers) { |
| 785 | + if (entry.has("pdf-parser")) { |
| 786 | + pdfEntry = entry.get("pdf-parser"); |
| 787 | + break; |
| 788 | + } |
| 789 | + } |
| 790 | + assertNotNull(pdfEntry, "Expected pdf-parser entry, got: " + content); |
| 791 | + JsonNode sortByPosition = pdfEntry.findValue("sortByPosition"); |
| 792 | + assertNotNull(sortByPosition, "Expected sortByPosition under pdf-parser, got: " + content); |
| 793 | + assertTrue(sortByPosition.asBoolean(), "Expected sortByPosition=true, got: " + sortByPosition); |
780 | 794 | } |
781 | 795 |
|
782 | 796 | /** |
|
0 commit comments