diff --git a/full/src/test/java/apoc/load/LoadHtmlTest.java b/full/src/test/java/apoc/load/LoadHtmlTest.java index f8b4e6a622..e41909ea24 100644 --- a/full/src/test/java/apoc/load/LoadHtmlTest.java +++ b/full/src/test/java/apoc/load/LoadHtmlTest.java @@ -37,6 +37,7 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Stream; import org.apache.commons.lang.exception.ExceptionUtils; import org.junit.After; import org.junit.Assert; @@ -49,20 +50,30 @@ public class LoadHtmlTest { - protected static final String RESULT_QUERY_METADATA = ("{attributes={charset=UTF-8}, tagName=meta}, " - + "{attributes={name=ResourceLoaderDynamicStyles}, tagName=meta}, " - + "{attributes={name=generator, content=MediaWiki 1.32.0-wmf.18}, tagName=meta}, " - + "{attributes={name=referrer, content=origin}, tagName=meta}, " - + "{attributes={name=referrer, content=origin-when-crossorigin}, tagName=meta}, " - + "{attributes={name=referrer, content=origin-when-cross-origin}, tagName=meta}, " - + "{attributes={property=og:image, content=https://upload.wikimedia.org/wikipedia/en/e/ea/Aap_Kaa_Hak_titles.jpg}, tagName=meta}"); - - protected static final String RESULT_QUERY_H2 = - ("{text=Contents, tagName=h2}, " + "{text=Origins[edit], tagName=h2}, " - + "{text=Content[edit], tagName=h2}, " - + "{text=Legacy[edit], tagName=h2}, " - + "{text=References[edit], tagName=h2}, " - + "{text=Navigation menu, tagName=h2}"); + protected static final List> RESULT_QUERY_METADATA = asList( + map("tagName", "meta", "attributes", map("charset", "UTF-8")), + map("attributes", map("name", "ResourceLoaderDynamicStyles"), "tagName", "meta"), + map("attributes", map("name", "generator", "content", "MediaWiki 1.32.0-wmf.18"), "tagName", "meta"), + map("attributes", map("name", "referrer", "content", "origin"), "tagName", "meta"), + map("attributes", map("name", "referrer", "content", "origin-when-crossorigin"), "tagName", "meta"), + map("attributes", map("name", "referrer", "content", "origin-when-cross-origin"), "tagName", "meta"), + map( + "attributes", + map( + "property", + "og:image", + "content", + "https://upload.wikimedia.org/wikipedia/en/e/ea/Aap_Kaa_Hak_titles.jpg"), + "tagName", + "meta")); + + protected static final List> RESULT_QUERY_H2 = asList( + map("text", "Contents", "tagName", "h2"), + map("text", "Origins[edit]", "tagName", "h2"), + map("text", "Content[edit]", "tagName", "h2"), + map("text", "Legacy[edit]", "tagName", "h2"), + map("text", "References[edit]", "tagName", "h2"), + map("text", "Navigation menu", "tagName", "h2")); private static final String INVALID_PATH = new File("src/test/resources/wikipedia1.html").getName(); private static final String VALID_PATH = @@ -208,11 +219,7 @@ public void testQueryMetadata() { map("url", new File("src/test/resources/wikipedia.html").toURI().toString(), "query", query), result -> { Map row = result.next(); - assertEquals( - map("metadata", asList(RESULT_QUERY_METADATA)) - .toString() - .trim(), - row.get("value").toString().trim()); + assertEquals(map("metadata", RESULT_QUERY_METADATA), row.get("value")); assertFalse(result.hasNext()); }); } @@ -426,9 +433,7 @@ public void testQueryH2() { map("url", new File("src/test/resources/wikipedia.html").toURI().toString(), "query", query), result -> { Map row = result.next(); - assertEquals( - map("h2", asList(RESULT_QUERY_H2)).toString().trim(), - row.get("value").toString().trim()); + assertEquals(map("h2", RESULT_QUERY_H2), row.get("value")); assertFalse(result.hasNext()); }); } @@ -472,8 +477,9 @@ public void testHref() { public void testQueryWithFailsSilentlyWithList() { Map query = map("a", "a", "invalid", "invalid", "h6", "h6"); - String expectedH6 = - "[{attributes={id=correct}, text=test, tagName=h6}, {attributes={id=childIncorrect}, text=incorrecttest, tagName=h6}]"; + List> expectedH6 = asList( + map("attributes", map("id", "correct"), "text", "test", "tagName", "h6"), + map("attributes", map("id", "childIncorrect"), "text", "incorrecttest", "tagName", "h6")); testResult( db, @@ -485,7 +491,7 @@ public void testQueryWithFailsSilentlyWithList() { // number of tags in html file minus the incorrect tag assertEquals(107, ((List) value.get("a")).size()); assertEquals(Collections.emptyList(), value.get("invalid")); - assertEquals(expectedH6, value.get("h6").toString().trim()); + assertEquals(expectedH6, value.get("h6")); assertEquals(2, ((List) value.get(KEY_ERROR)).size()); assertFalse(result.hasNext()); }); @@ -495,8 +501,17 @@ public void testQueryWithFailsSilentlyWithList() { public void testQueryWithFailsSilentlyWithListAndChildren() { Map query = map("a", "a", "invalid", "invalid", "h6", "h6"); - String expectedH6 = - "[{children=[], attributes={id=correct}, text=test, tagName=h6}, {children=[], attributes={id=childIncorrect}, text=incorrect, tagName=h6}]"; + List> expectedH6 = asList( + map("children", asList(), "attributes", map("id", "correct"), "text", "test", "tagName", "h6"), + map( + "children", + asList(), + "attributes", + map("id", "childIncorrect"), + "text", + "incorrect", + "tagName", + "h6")); testResult( db, @@ -508,7 +523,7 @@ public void testQueryWithFailsSilentlyWithListAndChildren() { // number of tags in html file minus the incorrect tag assertEquals(107, ((List) value.get("a")).size()); assertEquals(Collections.emptyList(), value.get("invalid")); - assertEquals(expectedH6, value.get("h6").toString().trim()); + assertEquals(expectedH6, value.get("h6")); assertEquals(3, ((List) value.get(KEY_ERROR)).size()); assertFalse(result.hasNext()); }); @@ -638,12 +653,17 @@ public static void skipIfBrowserNotPresentOrCompatible(Runnable runnable) { try { runnable.run(); } catch (RuntimeException e) { + // The test don't fail if the current chrome/firefox version is incompatible or if the browser is not // installed + Stream notPresentOrIncompatible = Stream.of( + "cannot find Chrome binary", + "Cannot find firefox binary", + "Expected browser binary location", + "browser start-up failure", + "This version of ChromeDriver only supports Chrome version"); final String msg = e.getMessage(); - if (!msg.contains("cannot find Chrome binary") - && !msg.contains("Cannot find firefox binary") - && !msg.contains("This version of ChromeDriver only supports Chrome version")) { + if (notPresentOrIncompatible.noneMatch(msg::contains)) { throw e; } } diff --git a/full/src/test/java/apoc/load/LoadHtmlTestParameterized.java b/full/src/test/java/apoc/load/LoadHtmlTestParameterized.java index 1c493e75d3..7f0fdd3d2d 100644 --- a/full/src/test/java/apoc/load/LoadHtmlTestParameterized.java +++ b/full/src/test/java/apoc/load/LoadHtmlTestParameterized.java @@ -24,7 +24,6 @@ import static apoc.util.MapUtil.map; import static apoc.util.TestUtil.testResult; import static com.google.common.collect.Lists.newArrayList; -import static java.util.Arrays.asList; import static java.util.Collections.emptyMap; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -99,12 +98,8 @@ public void testQueryAll() { List> metadata = (List>) value.get("metadata"); List> h2 = (List>) value.get("h2"); - assertEquals( - asList(RESULT_QUERY_METADATA).toString().trim(), - metadata.toString().trim()); - assertEquals( - asList(RESULT_QUERY_H2).toString().trim(), - h2.toString().trim()); + assertEquals(RESULT_QUERY_METADATA, metadata); + assertEquals(RESULT_QUERY_H2, h2); }); }); } @@ -131,9 +126,7 @@ public void testQueryH2WithConfig() { config), result -> { Map row = result.next(); - assertEquals( - map("h2", asList(RESULT_QUERY_H2)).toString().trim(), - row.get("value").toString().trim()); + assertEquals(map("h2", RESULT_QUERY_H2), row.get("value")); assertFalse(result.hasNext()); }); });