diff --git a/examples/ip-intelligence/console/src/main/java/fiftyone/ipintelligence/examples/console/GettingStartedCloud.java b/examples/ip-intelligence/console/src/main/java/fiftyone/ipintelligence/examples/console/GettingStartedCloud.java index a1c67e0eb..5251af6a3 100644 --- a/examples/ip-intelligence/console/src/main/java/fiftyone/ipintelligence/examples/console/GettingStartedCloud.java +++ b/examples/ip-intelligence/console/src/main/java/fiftyone/ipintelligence/examples/console/GettingStartedCloud.java @@ -54,7 +54,9 @@ import fiftyone.ipintelligence.shared.IPIntelligenceData; import fiftyone.ipintelligence.shared.testhelpers.KeyUtils; import fiftyone.pipeline.core.data.FlowData; +import fiftyone.pipeline.core.data.IWeightedValue; import fiftyone.pipeline.core.flowelements.Pipeline; +import fiftyone.pipeline.engines.data.AspectPropertyValue; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -64,12 +66,9 @@ import java.util.Map; import static fiftyone.common.testhelpers.LogbackHelper.configureLogback; -import static fiftyone.ipintelligence.examples.shared.PropertyHelper.asFloatProperty; -import static fiftyone.ipintelligence.examples.shared.PropertyHelper.asIPAddressProperty; -import static fiftyone.ipintelligence.examples.shared.PropertyHelper.asIntegerProperty; -import static fiftyone.ipintelligence.examples.shared.PropertyHelper.asStringProperty; -import static fiftyone.ipintelligence.examples.shared.PropertyHelper.asWktStringProperty; +import static fiftyone.ipintelligence.examples.shared.PropertyHelper.asWeightedString; import static fiftyone.ipintelligence.examples.shared.PropertyHelper.tryGet; +import static fiftyone.ipintelligence.examples.shared.PropertyHelper.weightedValues; import static fiftyone.pipeline.util.FileFinder.getFilePath; /** @@ -205,24 +204,51 @@ private static void analyzeEvidence(Map evidence, /* Display the results of the lookup, which are called IP Intelligence properties. See the property dictionary at https://51degrees.com/developers/property-dictionary?utm_source=code&utm_medium=example&utm_campaign=51degrees-java&utm_content=console-src-main-java-fiftyone-ipintelligence-examples-console-gettingstartedcloud.java&utm_term=property-dictionary for details of all available properties. */ - writer.println("\tRegisteredName: " + asStringProperty(tryGet(ipData::getRegisteredName))); - writer.println("\tRegisteredOwner: " + asStringProperty(tryGet(ipData::getRegisteredOwner))); - writer.println("\tRegisteredCountry: " + asStringProperty(tryGet(ipData::getRegisteredCountry))); - writer.println("\tIpRangeStart: " + asIPAddressProperty(tryGet(ipData::getIpRangeStart))); - writer.println("\tIpRangeEnd: " + asIPAddressProperty(tryGet(ipData::getIpRangeEnd))); - writer.println("\tCountry: " + asStringProperty(tryGet(ipData::getCountry))); - writer.println("\tCountryCode: " + asStringProperty(tryGet(ipData::getCountryCode))); - writer.println("\tCountryCode3: " + asStringProperty(tryGet(ipData::getCountryCode3))); - writer.println("\tRegion: " + asStringProperty(tryGet(ipData::getRegion))); - writer.println("\tState: " + asStringProperty(tryGet(ipData::getState))); - writer.println("\tTown: " + asStringProperty(tryGet(ipData::getTown))); - writer.println("\tLatitude: " + asFloatProperty(tryGet(ipData::getLatitude))); - writer.println("\tLongitude: " + asFloatProperty(tryGet(ipData::getLongitude))); - writer.println("\tAreas: " + asWktStringProperty(tryGet(ipData::getAreas))); - writer.println("\tAccuracyRadiusMin: " + asIntegerProperty(tryGet(ipData::getAccuracyRadiusMin))); - writer.println("\tTimeZoneOffset: " + asIntegerProperty(tryGet(ipData::getTimeZoneOffset))); + writeValue(writer, "RegisteredName", tryGet(ipData::getRegisteredName)); + writeValue(writer, "RegisteredOwner", tryGet(ipData::getRegisteredOwner)); + writeValue(writer, "RegisteredCountry", tryGet(ipData::getRegisteredCountry)); + writeValue(writer, "IpRangeStart", tryGet(ipData::getIpRangeStart)); + writeValue(writer, "IpRangeEnd", tryGet(ipData::getIpRangeEnd)); + writeValue(writer, "Country", tryGet(ipData::getCountry)); + writeValue(writer, "CountryCode", tryGet(ipData::getCountryCode)); + writeValue(writer, "CountryCode3", tryGet(ipData::getCountryCode3)); + writeValue(writer, "Region", tryGet(ipData::getRegion)); + writeValue(writer, "State", tryGet(ipData::getState)); + writeValue(writer, "Town", tryGet(ipData::getTown)); + writeValue(writer, "Latitude", tryGet(ipData::getLatitude)); + writeValue(writer, "Longitude", tryGet(ipData::getLongitude)); + writeValue(writer, "Areas", tryGet(ipData::getAreas)); + writeValue(writer, "AccuracyRadiusMin", tryGet(ipData::getAccuracyRadiusMin)); + writeValue(writer, "TimeZoneOffset", tryGet(ipData::getTimeZoneOffset)); } writer.println(); writer.flush(); } + + /** + * Writes each value of a property with its weighting, or why it has no + * value. + */ + private static void writeValue(PrintWriter writer, + String property, + AspectPropertyValue result) { + if (result.hasValue() == false) { + writer.println("\t" + property + ": " + asWeightedString(result)); + return; + } + /* IP Intelligence properties return weighted values. Each value comes + with a weighting between 0 and 1, which says how much of the IP range + the value applies to, and a property with a single answer returns it + with a weighting of 1. */ + StringBuilder line = new StringBuilder(); + for (IWeightedValue weighted : weightedValues(result)) { + if (line.length() > 0) { + line.append(", "); + } + line.append(asWeightedString( + weighted.getValue(), + weighted.getWeighting())); + } + writer.println("\t" + property + ": " + line); + } } diff --git a/examples/ip-intelligence/console/src/main/java/fiftyone/ipintelligence/examples/console/GettingStartedOnPrem.java b/examples/ip-intelligence/console/src/main/java/fiftyone/ipintelligence/examples/console/GettingStartedOnPrem.java index df87c9b75..6cf2f321f 100644 --- a/examples/ip-intelligence/console/src/main/java/fiftyone/ipintelligence/examples/console/GettingStartedOnPrem.java +++ b/examples/ip-intelligence/console/src/main/java/fiftyone/ipintelligence/examples/console/GettingStartedOnPrem.java @@ -68,6 +68,8 @@ import static fiftyone.common.testhelpers.LogbackHelper.configureLogback; import static fiftyone.ipintelligence.examples.shared.PropertyHelper.asString; +import static fiftyone.ipintelligence.examples.shared.PropertyHelper.asWeightedString; +import static fiftyone.ipintelligence.examples.shared.PropertyHelper.weightedValues; import static fiftyone.pipeline.util.FileFinder.getFilePath; import static fiftyone.ipintelligence.examples.shared.DataFileHelper.LITE_DATA_FILE_REL_PATH; @@ -272,7 +274,22 @@ private static boolean writeValue(PrintWriter writer, if (DataFileHelper.hasProperty(engine, property)) { AspectPropertyValue value = (AspectPropertyValue) ipData.get(property); - writer.println("\t" + property + ": " + asString(value)); + if (value.hasValue() == false) { + writer.println("\t" + property + ": " + asString(value)); + return false; + } + // Each value comes with a weighting between 0 and 1, which says + // how much of the IP range the value applies to. + StringBuilder line = new StringBuilder(); + for (IWeightedValue weighted : weightedValues(value)) { + if (line.length() > 0) { + line.append(", "); + } + line.append(asWeightedString( + weighted.getValue(), + weighted.getWeighting())); + } + writer.println("\t" + property + ": " + line); return false; } writer.println("\t" + property + ": " + DataFileHelper.NEEDS_ENTERPRISE); diff --git a/examples/ip-intelligence/console/src/test/java/fiftyone/ipintelligence/examples/console/WeightingShownTest.java b/examples/ip-intelligence/console/src/test/java/fiftyone/ipintelligence/examples/console/WeightingShownTest.java new file mode 100644 index 000000000..d6d762a58 --- /dev/null +++ b/examples/ip-intelligence/console/src/test/java/fiftyone/ipintelligence/examples/console/WeightingShownTest.java @@ -0,0 +1,70 @@ +/* ********************************************************************* + * This Original Work is copyright of 51 Degrees Mobile Experts Limited. + * Copyright 2026 51 Degrees Mobile Experts Limited, Davidson House, + * Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU. + * + * This Original Work is licensed under the European Union Public Licence + * (EUPL) v.1.2 and is subject to its terms as set out below. + * + * If a copy of the EUPL was not distributed with this file, You can obtain + * one at https://opensource.org/licenses/EUPL-1.2. + * + * The 'Compatible Licences' set out in the Appendix to the EUPL (as may be + * amended by the European Commission) shall be deemed incompatible for + * the purposes of the Work and the provisions of the compatibility + * clause in Article 5 of the EUPL shall not apply. + * + * If using the Work as, or as part of, a network application, by + * including the attribution notice(s) required under Article 5 of the EUPL + * in the end user terms of the application under an appropriate heading, + * such notice(s) shall fulfill the requirements of that article. + * ********************************************************************* */ + +package fiftyone.ipintelligence.examples.console; + +import org.junit.Test; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +import static org.junit.Assert.assertTrue; + +/** + * "Examples MUST demonstrate accessing both the value and its associated + * weighting" (ip-intelligence-specification/required-examples.md line 107). + * The getting started examples are where a developer first reads how to get + * a result, so their own code reads each value with its weighting, rather + * than leaving it to code in another file the developer does not see. + */ +public class WeightingShownTest { + + private static String source(String name) throws IOException { + Path path = Paths.get("src", "main", "java", "fiftyone", + "ipintelligence", "examples", "console", name + ".java"); + return new String(Files.readAllBytes(path), StandardCharsets.UTF_8); + } + + private static void assertShowsWeighting(String name) throws IOException { + String source = source(name); + assertTrue(name + " does not read a weighting", + source.contains(".getWeighting()")); + assertTrue(name + " does not read the weighted value", + source.contains("weightedValues(") && + source.contains(".getValue()")); + } + + @Test + public void gettingStartedOnPrem_ShowsValueAndWeighting() + throws IOException { + assertShowsWeighting("GettingStartedOnPrem"); + } + + @Test + public void gettingStartedCloud_ShowsValueAndWeighting() + throws IOException { + assertShowsWeighting("GettingStartedCloud"); + } +} diff --git a/examples/ip-intelligence/shared/src/main/java/fiftyone/ipintelligence/examples/shared/PropertyHelper.java b/examples/ip-intelligence/shared/src/main/java/fiftyone/ipintelligence/examples/shared/PropertyHelper.java index 7fa1aae6a..41ba0c5cc 100644 --- a/examples/ip-intelligence/shared/src/main/java/fiftyone/ipintelligence/examples/shared/PropertyHelper.java +++ b/examples/ip-intelligence/shared/src/main/java/fiftyone/ipintelligence/examples/shared/PropertyHelper.java @@ -23,6 +23,7 @@ package fiftyone.ipintelligence.examples.shared; import fiftyone.pipeline.core.data.IWeightedValue; +import fiftyone.pipeline.core.data.WeightedValue; import fiftyone.pipeline.core.data.WktString; import fiftyone.pipeline.engines.data.AspectPropertyValue; import fiftyone.pipeline.engines.data.AspectPropertyValueDefault; @@ -31,6 +32,7 @@ import org.slf4j.LoggerFactory; import java.net.InetAddress; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Locale; @@ -80,11 +82,8 @@ private static String unwrapValue(Object value) { // weighting the data gives it, which is 1 for // a property with one answer. IWeightedValue weighted = (IWeightedValue) item; - Object inner = weighted.getValue(); - return String.format( - Locale.ROOT, - "%s (weighting %.2f)", - toDisplayString(inner), + return asWeightedString( + weighted.getValue(), weighted.getWeighting()); } return toDisplayString(item); @@ -223,6 +222,75 @@ public static String asString(AspectPropertyValue value) { return "Unknown. " + value.getNoValueMessage(); } + /** + * The raw weighting of a value that is the only answer, which is a + * weighting of 1. + */ + private static final int FULL_WEIGHTING = 65535; + + /** + * Get each value of an IP Intelligence property with its weighting. IP + * Intelligence properties return weighted values, and a property with a + * single answer returns it with a weighting of 1. Due to Java generics + * type erasure, the on-premise engine returns + * List<IWeightedValue<T>> even when the declared type is T, so + * a value that is not such a list is given here with a weighting of 1. + * @param property the property value, may be null + * @return the weighted values, or an empty list when there is no value + */ + public static List> weightedValues( + AspectPropertyValue property) { + List> result = new ArrayList<>(); + if (property == null || property.hasValue() == false) { + return result; + } + Object value = property.getValue(); + if (value instanceof List) { + for (Object item : (List) value) { + if (item instanceof IWeightedValue) { + result.add((IWeightedValue) item); + } else { + result.add(new WeightedValue<>(FULL_WEIGHTING, item)); + } + } + } else { + result.add(new WeightedValue<>(FULL_WEIGHTING, value)); + } + return result; + } + + /** + * Write a value with its weighting, for example "gb (weighting 1.00)". + * Every weighting the examples print is written this way. + * @param value the value, may be null + * @param weighting the weighting, between 0 and 1 + * @return the value followed by its weighting + */ + public static String asWeightedString(Object value, float weighting) { + return String.format( + Locale.ROOT, + "%s (weighting %.2f)", + toDisplayString(value), + weighting); + } + + /** + * Write each value of an IP Intelligence property with its weighting, + * for example "gb (weighting 1.00)", or why there is no value. + * @param property the property value, may be null + * @return the values with their weightings, joined with ", " + */ + public static String asWeightedString(AspectPropertyValue property) { + if (property == null || property.hasValue() == false) { + return reportNoValue(property); + } + return weightedValues(property).stream() + .map(weighted -> asWeightedString( + weighted.getValue(), + weighted.getWeighting())) + .collect(Collectors.joining(", ")); + } + /** * Helper to get the first raw value of an IP Intelligence property. * Due to Java generics type erasure, the on-premise engine may return diff --git a/examples/ip-intelligence/shared/src/test/java/fiftyone/ipintelligence/examples/shared/PropertyHelperWeightingTests.java b/examples/ip-intelligence/shared/src/test/java/fiftyone/ipintelligence/examples/shared/PropertyHelperWeightingTests.java new file mode 100644 index 000000000..b8f93d5d6 --- /dev/null +++ b/examples/ip-intelligence/shared/src/test/java/fiftyone/ipintelligence/examples/shared/PropertyHelperWeightingTests.java @@ -0,0 +1,111 @@ +/* ********************************************************************* + * This Original Work is copyright of 51 Degrees Mobile Experts Limited. + * Copyright 2026 51 Degrees Mobile Experts Limited, Davidson House, + * Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU. + * + * This Original Work is licensed under the European Union Public Licence + * (EUPL) v.1.2 and is subject to its terms as set out below. + * + * If a copy of the EUPL was not distributed with this file, You can obtain + * one at https://opensource.org/licenses/EUPL-1.2. + * + * The 'Compatible Licences' set out in the Appendix to the EUPL (as may be + * amended by the European Commission) shall be deemed incompatible for + * the purposes of the Work and the provisions of the compatibility + * clause in Article 5 of the EUPL shall not apply. + * + * If using the Work as, or as part of, a network application, by + * including the attribution notice(s) required under Article 5 of the EUPL + * in the end user terms of the application under an appropriate heading, + * such notice(s) shall fulfill the requirements of that article. + * ********************************************************************* */ + +package fiftyone.ipintelligence.examples.shared; + +import fiftyone.pipeline.core.data.IWeightedValue; +import fiftyone.pipeline.engines.data.AspectPropertyValue; +import fiftyone.pipeline.engines.data.AspectPropertyValueDefault; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * "Examples MUST demonstrate accessing both the value and its associated + * weighting" (ip-intelligence-specification/required-examples.md line 107). + * The examples read each value of a property with its weighting through + * {@link PropertyHelper#weightedValues}. + */ +public class PropertyHelperWeightingTests { + + private static IWeightedValue weighted( + final int rawWeighting, + final Object value) { + return new IWeightedValue() { + @Override + public int getRawWeighting() { + return rawWeighting; + } + + @Override + public Object getValue() { + return value; + } + }; + } + + @SuppressWarnings({"unchecked", "rawtypes"}) + @Test + public void weightedValues_ListOfWeightedValues_KeepsEachWeighting() { + List> list = new ArrayList<>(); + list.add(weighted(49151, "gb")); + list.add(weighted(16384, "ie")); + AspectPropertyValue property = + new AspectPropertyValueDefault(list); + + List> values = + PropertyHelper.weightedValues(property); + + assertEquals(2, values.size()); + assertEquals("gb", values.get(0).getValue()); + assertEquals(49151 / 65535f, values.get(0).getWeighting(), 0.0001); + assertEquals("ie", values.get(1).getValue()); + assertEquals(16384 / 65535f, values.get(1).getWeighting(), 0.0001); + } + + /** + * "a property with a single answer returns it with a weighting of 1" + * (required-examples.md line 107) + */ + @Test + public void weightedValues_SingleValue_HasWeightingOfOne() { + AspectPropertyValue property = + new AspectPropertyValueDefault<>("gb"); + + List> values = + PropertyHelper.weightedValues(property); + + assertEquals(1, values.size()); + assertEquals("gb", values.get(0).getValue()); + assertEquals(1f, values.get(0).getWeighting(), 0.0001); + } + + @Test + public void weightedValues_NoValue_IsEmpty() { + assertTrue(PropertyHelper.weightedValues( + new AspectPropertyValueDefault()).isEmpty()); + assertTrue(PropertyHelper.weightedValues(null).isEmpty()); + } + + @SuppressWarnings({"unchecked", "rawtypes"}) + @Test + public void asWeightedString_ShowsValueAndWeighting() { + List> list = new ArrayList<>(); + list.add(weighted(65535, "gb")); + assertEquals("gb (weighting 1.00)", PropertyHelper.asWeightedString( + new AspectPropertyValueDefault(list))); + } +} diff --git a/pipeline/pipeline.engines/src/main/java/fiftyone/pipeline/engines/services/DataUpdateServiceDefault.java b/pipeline/pipeline.engines/src/main/java/fiftyone/pipeline/engines/services/DataUpdateServiceDefault.java index 5a1647c0c..303452a28 100644 --- a/pipeline/pipeline.engines/src/main/java/fiftyone/pipeline/engines/services/DataUpdateServiceDefault.java +++ b/pipeline/pipeline.engines/src/main/java/fiftyone/pipeline/engines/services/DataUpdateServiceDefault.java @@ -1344,8 +1344,8 @@ private AutoUpdateStatus checkForUpdateFromUrl( } return result; } catch (Throwable e) { - logger.error("Exception thrown", e); - return AutoUpdateStatus.AUTO_UPDATE_REFRESH_FAILED; + logUnhandledError(dataFile, e); + return AutoUpdateStatus.AUTO_UPDATE_UNKNOWN_ERROR; } finally { // Make sure the temp files are cleaned up try { diff --git a/pipeline/pipeline.engines/src/test/java/fiftyone/pipeline/engines/services/DataUpdateServiceLoggingTests.java b/pipeline/pipeline.engines/src/test/java/fiftyone/pipeline/engines/services/DataUpdateServiceLoggingTests.java index be0ce9ca1..6f94e3e57 100644 --- a/pipeline/pipeline.engines/src/test/java/fiftyone/pipeline/engines/services/DataUpdateServiceLoggingTests.java +++ b/pipeline/pipeline.engines/src/test/java/fiftyone/pipeline/engines/services/DataUpdateServiceLoggingTests.java @@ -513,6 +513,40 @@ public void UpdateFromMemory_FileCannotBeWritten_WarnsAndRefreshes() verify(engine).refreshData(anyString(), any(byte[].class)); } + /** + * An error of any other kind is logged at Error with the Errors table's + * last message and the error attached, and gives + * AUTO_UPDATE_UNKNOWN_ERROR. + */ + @Test + public void UnexpectedError_LogsTheLastRow() { + AspectEngineDataFileDefault file = newDataFile(false, false, false); + // The engine's copy is the data file itself, so the file on disk is + // not newer and the URL is checked. + file.setTempDataFilePath(dataFile.getAbsolutePath()); + final IllegalStateException broke = + new IllegalStateException("formatter broke"); + file.getConfiguration().setUrlFormatter(d -> { + throw broke; + }); + + assertEquals("AUTO_UPDATE_UNKNOWN_ERROR", + dataUpdate.checkForUpdate(engine).name()); + + for (ILoggingEvent event : appender.list) { + if (event.getLevel() == Level.ERROR && + event.getFormattedMessage().equals("An unhandled error " + + "occurred while checking for automatic updates for " + + "engine '" + engineType + "'") && + event.getThrowableProxy() != null && + "formatter broke".equals( + event.getThrowableProxy().getMessage())) { + return; + } + } + fail("No unhandled error entry in " + logged(Level.ERROR)); + } + /** * The MD5 hash of the bytes as lower case hexadecimal. */ diff --git a/pipeline/pipeline.javascriptbuilder/src/main/java/fiftyone/pipeline/javascriptbuilder/flowelements/JavaScriptBuilderElement.java b/pipeline/pipeline.javascriptbuilder/src/main/java/fiftyone/pipeline/javascriptbuilder/flowelements/JavaScriptBuilderElement.java index 50336ad68..3f3c6ee1a 100644 --- a/pipeline/pipeline.javascriptbuilder/src/main/java/fiftyone/pipeline/javascriptbuilder/flowelements/JavaScriptBuilderElement.java +++ b/pipeline/pipeline.javascriptbuilder/src/main/java/fiftyone/pipeline/javascriptbuilder/flowelements/JavaScriptBuilderElement.java @@ -495,11 +495,14 @@ private Map getParameters(FlowData data) throws UnsupportedEncod .getEvidence() .asKeyMap(); + // The prefix with its separator, so that a key such as "querystring" + // is not taken for a query parameter. + String queryPrefix = EVIDENCE_QUERY_PREFIX + EVIDENCE_SEPERATOR; for(Map.Entry entry : queryEvidence.entrySet()){ // Evidence keys ignore case, so the prefix and the excluded // keys are matched whatever the case the key was added in. if(entry.getKey().regionMatches(true, 0, - EVIDENCE_QUERY_PREFIX, 0, EVIDENCE_QUERY_PREFIX.length()) && + queryPrefix, 0, queryPrefix.length()) && EXCLUDED_PARAMETERS.contains( entry.getKey().toLowerCase(Locale.ROOT)) == false){ String key = entry.getKey().substring(entry.getKey().indexOf(EVIDENCE_SEPERATOR) + 1); diff --git a/pipeline/pipeline.javascriptbuilder/src/test/java/fiftyone/pipeline/javascriptbuilder/JavaScriptUrlTests.java b/pipeline/pipeline.javascriptbuilder/src/test/java/fiftyone/pipeline/javascriptbuilder/JavaScriptUrlTests.java index 2a822ee4a..5540c29ae 100644 --- a/pipeline/pipeline.javascriptbuilder/src/test/java/fiftyone/pipeline/javascriptbuilder/JavaScriptUrlTests.java +++ b/pipeline/pipeline.javascriptbuilder/src/test/java/fiftyone/pipeline/javascriptbuilder/JavaScriptUrlTests.java @@ -186,6 +186,47 @@ public void Parameters_QueryPrefixInAnyCase() throws Exception { "The session id is in the parameters: " + parameters); } + /** + * Only a key whose prefix is "query" followed by the separator is a + * query parameter, so a key such as "queryx.field" is left out. + */ + @Test + public void Parameters_PrefixWithoutSeparator_IsLeftOut() + throws Exception { + JavaScriptBuilderElement jsElement = + new JavaScriptBuilderElementBuilder(loggerFactory) + .setEndpoint("/json") + .setHost("example.com") + .setProtocol("https") + .setMinify(false) + .build(); + String javaScript; + try (Pipeline pipeline = new PipelineBuilder(loggerFactory) + .addFlowElement(new SequenceElementBuilder(loggerFactory).build()) + .addFlowElement(new JsonBuilderElementBuilder(loggerFactory).build()) + .addFlowElement(jsElement) + .build(); + FlowData flowData = pipeline.createFlowData()) { + flowData.addEvidence("query.kept", "yes"); + flowData.addEvidence("queryx.field", "not-a-query"); + flowData.process(); + javaScript = flowData.getFromElement(jsElement).getJavaScript(); + } + String parameters = null; + for (String line : javaScript.split("\\r?\\n")) { + if (line.toLowerCase().contains("parameters =") + && line.contains("{")) { + parameters = line; + break; + } + } + assertNotNull(parameters, "No parameters object in the script."); + assertTrue(parameters.contains("\"kept\":\"yes\""), + "query.kept is not in the parameters: " + parameters); + assertFalse(parameters.contains("not-a-query"), + "queryx.field is in the parameters: " + parameters); + } + /** * A context root still sits between the host and the endpoint, and the * URL still carries no query string.