diff --git a/location/geo-location.shell.examples/src/main/java/fiftyone/geolocation/examples/CombiningServices.java b/location/geo-location.shell.examples/src/main/java/fiftyone/geolocation/examples/CombiningServices.java index c3088a99f..73264ba00 100644 --- a/location/geo-location.shell.examples/src/main/java/fiftyone/geolocation/examples/CombiningServices.java +++ b/location/geo-location.shell.examples/src/main/java/fiftyone/geolocation/examples/CombiningServices.java @@ -179,6 +179,10 @@ public static void main(String[] args) throws Exception { System.out.println("IsMobile: " + isMobile.toString()); } } + FindOutMore.write( + System.out, + "https://51degrees.com/documentation/_reverse_geocoding__examples__combining_services.html?utm_source=code&utm_medium=example&utm_campaign=51degrees-java&utm_content=geo-location.shell.examples-combiningservices.java&utm_term=find-out-more", + "https://51degrees.com/location?utm_source=code&utm_medium=example&utm_campaign=51degrees-java&utm_content=geo-location.shell.examples-combiningservices.java&utm_term=find-out-more"); } private static void outputUntilCancelled( diff --git a/location/geo-location.shell.examples/src/main/java/fiftyone/geolocation/examples/FindOutMore.java b/location/geo-location.shell.examples/src/main/java/fiftyone/geolocation/examples/FindOutMore.java new file mode 100644 index 000000000..c4d878857 --- /dev/null +++ b/location/geo-location.shell.examples/src/main/java/fiftyone/geolocation/examples/FindOutMore.java @@ -0,0 +1,76 @@ +/* ********************************************************************* + * 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.geolocation.examples; + +import java.io.PrintStream; + +/** + * Writes the "Find out more" section that ends each Location example's + * output, set apart by a rule above and below. It gives the example's page + * and the Location page on 51degrees.com, each tagged with the example, then + * the repository. + */ +public final class FindOutMore { + + /** + * The heading the section starts with. + */ + public static final String HEADING = "Find out more"; + + /** + * The rule above and below the section. + */ + public static final String RULE = + "----------------------------------------------------------------"; + + /** + * The repository the examples come from. + */ + public static final String REPOSITORY = + "https://github.com/51Degrees/51degrees-java"; + + private FindOutMore() { + } + + /** + * Writes the section. + * @param output where to write, flushed afterwards + * @param examplePage the address of the example's page, with its + * campaign tags + * @param locationPage the address of the Location page, with its + * campaign tags + */ + public static void write( + PrintStream output, + String examplePage, + String locationPage) { + output.println(); + output.println(RULE); + output.println(HEADING); + output.println("\tThis example: " + examplePage); + output.println("\tLocation: " + locationPage); + output.println("\t" + REPOSITORY); + output.println(RULE); + output.flush(); + } +} diff --git a/location/geo-location.shell.examples/src/main/java/fiftyone/geolocation/examples/cloud/GettingStarted.java b/location/geo-location.shell.examples/src/main/java/fiftyone/geolocation/examples/cloud/GettingStarted.java index 8c86dfe01..807eac0db 100644 --- a/location/geo-location.shell.examples/src/main/java/fiftyone/geolocation/examples/cloud/GettingStarted.java +++ b/location/geo-location.shell.examples/src/main/java/fiftyone/geolocation/examples/cloud/GettingStarted.java @@ -25,6 +25,7 @@ import fiftyone.geolocation.GeoLocationPipelineBuilder; import fiftyone.geolocation.core.Enums; import fiftyone.geolocation.core.data.GeoData; +import fiftyone.geolocation.examples.FindOutMore; import fiftyone.pipeline.cloudrequestengine.data.CloudRequestData; import fiftyone.pipeline.core.data.FlowData; import fiftyone.pipeline.core.flowelements.Pipeline; @@ -117,6 +118,10 @@ public static void main(String[] args) throws Exception { System.out.println(flowData.get(GeoData.class).getRegion()); } } + FindOutMore.write( + System.out, + "https://51degrees.com/documentation/_reverse_geocoding__examples__getting_started_51_degrees_cloud.html?utm_source=code&utm_medium=example&utm_campaign=51degrees-java&utm_content=geo-location.shell.examples-gettingstarted.java&utm_term=find-out-more", + "https://51degrees.com/location?utm_source=code&utm_medium=example&utm_campaign=51degrees-java&utm_content=geo-location.shell.examples-gettingstarted.java&utm_term=find-out-more"); } private static void outputUntilCancelled( diff --git a/location/geo-location.shell.examples/src/test/java/fiftyone/geolocation/examples/FindOutMoreTests.java b/location/geo-location.shell.examples/src/test/java/fiftyone/geolocation/examples/FindOutMoreTests.java new file mode 100644 index 000000000..68b751cee --- /dev/null +++ b/location/geo-location.shell.examples/src/test/java/fiftyone/geolocation/examples/FindOutMoreTests.java @@ -0,0 +1,120 @@ +/* ********************************************************************* + * 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.geolocation.examples; + +import fiftyone.geolocation.examples.cloud.GettingStarted; +import org.junit.Test; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import java.nio.charset.StandardCharsets; +import java.util.regex.Pattern; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * Each Location example ends its output with a "Find out more" section, + * which lists pages on 51degrees.com, each with its campaign tags, and the + * repository. With no resource key set, each example says where to create + * one and stops, so these tests need no key. + */ +public class FindOutMoreTests { + + private static final String RULE = + "----------------------------------------------------------------"; + + private static final String HEADING = "Find out more"; + + private static final String REPOSITORY = + "https://github.com/51Degrees/51degrees-java"; + + private static final String NO_KEY = "You need to create a resource key"; + + private static final Pattern TAGGED = Pattern.compile( + "https://51degrees\\.com/[^?\\s]*\\?utm_source=code" + + "&utm_medium=example&utm_campaign=51degrees-java" + + "&utm_content=[a-z0-9][a-z0-9._-]*&utm_term=find-out-more$"); + + /** + * Runs a Location example as a person would. + */ + private interface Example { + void run() throws Exception; + } + + @Test + public void GettingStarted_EndsWithFindOutMore() throws Exception { + assertFindOutMore(run(() -> GettingStarted.main(new String[0]))); + } + + @Test + public void CombiningServices_EndsWithFindOutMore() throws Exception { + assertFindOutMore(run(() -> CombiningServices.main(new String[0]))); + } + + private static void assertFindOutMore(String output) { + int example = output.lastIndexOf(NO_KEY); + int heading = output.lastIndexOf(RULE + "\n" + HEADING + "\n"); + assertTrue("The example wrote nothing:\n" + output, example >= 0); + assertTrue( + "No Find out more section after the example's output:\n" + + output, + heading > example); + String section = output.substring( + heading + RULE.length() + HEADING.length() + 2); + int end = section.indexOf(RULE + "\n"); + assertTrue("The section has no closing rule:\n" + output, end > 0); + section = section.substring(0, end); + int pages = 0; + for (String line : section.split("\n")) { + if (line.contains("51degrees.com")) { + assertTrue( + "A 51degrees.com link without its campaign tags: " + + line, + TAGGED.matcher(line).find()); + pages++; + } + } + assertEquals("The pages listed:\n" + section, 2, pages); + assertTrue("The repository is not listed:\n" + section, + section.contains(REPOSITORY)); + } + + /** + * Runs the example and returns what it wrote, with each line ending in + * a line feed. + */ + private static String run(Example example) throws Exception { + PrintStream original = System.out; + ByteArrayOutputStream captured = new ByteArrayOutputStream(); + System.setOut(new PrintStream(captured, true, "UTF-8")); + try { + example.run(); + } finally { + System.setOut(original); + } + return new String(captured.toByteArray(), StandardCharsets.UTF_8) + .replace("\r\n", "\n"); + } +} diff --git a/pipeline/pipeline.developer-examples/pipeline.developer-examples.cloud-engine/src/main/java/pipeline/developerexamples/cloudengine/Main.java b/pipeline/pipeline.developer-examples/pipeline.developer-examples.cloud-engine/src/main/java/pipeline/developerexamples/cloudengine/Main.java index 963827bdb..b94b6b649 100644 --- a/pipeline/pipeline.developer-examples/pipeline.developer-examples.cloud-engine/src/main/java/pipeline/developerexamples/cloudengine/Main.java +++ b/pipeline/pipeline.developer-examples/pipeline.developer-examples.cloud-engine/src/main/java/pipeline/developerexamples/cloudengine/Main.java @@ -34,6 +34,7 @@ import pipeline.developerexamples.cloudengine.flowelements.SimpleCloudEngine; import pipeline.developerexamples.cloudengine.flowelements.SimpleCloudEngineBuilder; +import java.io.PrintStream; import java.util.concurrent.atomic.AtomicBoolean; public class Main { @@ -233,7 +234,31 @@ public void run() throws Exception { } } + /** + * The rule above and below the "Find out more" section. + */ + private static final String RULE = + "----------------------------------------------------------------"; + + /** + * Ends the output with the pages and repositories that say more about + * what this example shows. + * @param output where to write + */ + static void writeFindOutMore(PrintStream output) { + output.println(); + output.println(RULE); + output.println("Find out more"); + output.println("\tThis example: https://51degrees.com/documentation/_pipeline_api__examples__custom_element__cloud.html?utm_source=code&utm_medium=example&utm_campaign=51degrees-java&utm_content=pipeline.developer-examples.cloud-engine-main.java&utm_term=find-out-more"); + output.println("\tCustom flow elements: https://51degrees.com/documentation/_pipeline_api__features__custom_elements.html?utm_source=code&utm_medium=example&utm_campaign=51degrees-java&utm_content=pipeline.developer-examples.cloud-engine-main.java&utm_term=find-out-more"); + output.println("\thttps://github.com/51Degrees/51degrees-java"); + output.println("\thttps://github.com/51Degrees/specifications"); + output.println(RULE); + output.flush(); + } + public static void main(String[] args) throws Exception { new Example().run(); + writeFindOutMore(System.out); } } diff --git a/pipeline/pipeline.developer-examples/pipeline.developer-examples.cloud-engine/src/test/java/pipeline/developerexamples/cloudengine/FindOutMoreTests.java b/pipeline/pipeline.developer-examples/pipeline.developer-examples.cloud-engine/src/test/java/pipeline/developerexamples/cloudengine/FindOutMoreTests.java new file mode 100644 index 000000000..71df66f69 --- /dev/null +++ b/pipeline/pipeline.developer-examples/pipeline.developer-examples.cloud-engine/src/test/java/pipeline/developerexamples/cloudengine/FindOutMoreTests.java @@ -0,0 +1,104 @@ +/* ********************************************************************* + * 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 pipeline.developerexamples.cloudengine; + +import org.junit.jupiter.api.Test; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import java.nio.charset.StandardCharsets; +import java.util.regex.Pattern; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + +/** + * The example ends its output with a "Find out more" section, which lists + * pages on 51degrees.com, each with its campaign tags, and the repository. + */ +public class FindOutMoreTests { + + private static final String RULE = + "----------------------------------------------------------------"; + + private static final String HEADING = "Find out more"; + + private static final String REPOSITORY = + "https://github.com/51Degrees/51degrees-java"; + + private static final Pattern TAGGED = Pattern.compile( + "https://51degrees\\.com/[^?\\s]*\\?utm_source=code" + + "&utm_medium=example&utm_campaign=51degrees-java" + + "&utm_content=[a-z0-9][a-z0-9._-]*&utm_term=find-out-more$"); + + @Test + public void Main_EndsWithFindOutMore() throws Exception { + if (Main.configuredResourceKey() == null) { + fail("This test runs the example against the live cloud " + + "service, so it needs a resource key in one of " + + String.join(", ", Main.RESOURCE_KEY_NAMES) + "."); + } + String output = runMain(); + int example = output.lastIndexOf("star sign"); + int heading = output.lastIndexOf(RULE + "\n" + HEADING + "\n"); + assertTrue(example >= 0, "The example wrote nothing:\n" + output); + assertTrue(heading > example, + "No Find out more section after the example's output:\n" + + output); + String section = output.substring( + heading + RULE.length() + HEADING.length() + 2); + int end = section.indexOf(RULE + "\n"); + assertTrue(end > 0, "The section has no closing rule:\n" + output); + section = section.substring(0, end); + int pages = 0; + for (String line : section.split("\n")) { + if (line.contains("51degrees.com")) { + assertTrue(TAGGED.matcher(line).find(), + "A 51degrees.com link without its campaign tags: " + + line); + pages++; + } + } + assertEquals(2, pages, "The pages listed:\n" + section); + assertTrue(section.contains(REPOSITORY), + "The repository is not listed:\n" + section); + } + + /** + * Runs the example as a person would and returns what it wrote, with + * each line ending in a line feed. + */ + private static String runMain() throws Exception { + PrintStream original = System.out; + ByteArrayOutputStream captured = new ByteArrayOutputStream(); + System.setOut(new PrintStream(captured, true, "UTF-8")); + try { + Main.main(new String[0]); + } finally { + System.setOut(original); + } + return new String(captured.toByteArray(), StandardCharsets.UTF_8) + .replace("\r\n", "\n"); + } +} diff --git a/pipeline/pipeline.developer-examples/pipeline.developer-examples.flowelement/src/main/java/pipeline/developerexamples/flowelement/Main.java b/pipeline/pipeline.developer-examples/pipeline.developer-examples.flowelement/src/main/java/pipeline/developerexamples/flowelement/Main.java index 76d7e4473..2fe22edcf 100644 --- a/pipeline/pipeline.developer-examples/pipeline.developer-examples.flowelement/src/main/java/pipeline/developerexamples/flowelement/Main.java +++ b/pipeline/pipeline.developer-examples/pipeline.developer-examples.flowelement/src/main/java/pipeline/developerexamples/flowelement/Main.java @@ -30,6 +30,7 @@ import pipeline.developerexamples.flowelement.flowelements.SimpleFlowElement; import pipeline.developerexamples.flowelement.flowelements.SimpleFlowElementBuilder; +import java.io.PrintStream; import java.text.SimpleDateFormat; import java.util.Calendar; @@ -69,7 +70,31 @@ public void run() throws Exception { } } + /** + * The rule above and below the "Find out more" section. + */ + private static final String RULE = + "----------------------------------------------------------------"; + + /** + * Ends the output with the pages and repositories that say more about + * what this example shows. + * @param output where to write + */ + static void writeFindOutMore(PrintStream output) { + output.println(); + output.println(RULE); + output.println("Find out more"); + output.println("\tThis example: https://51degrees.com/documentation/_pipeline_api__examples__custom_element__flow_element.html?utm_source=code&utm_medium=example&utm_campaign=51degrees-java&utm_content=pipeline.developer-examples.flowelement-main.java&utm_term=find-out-more"); + output.println("\tCustom flow elements: https://51degrees.com/documentation/_pipeline_api__features__custom_elements.html?utm_source=code&utm_medium=example&utm_campaign=51degrees-java&utm_content=pipeline.developer-examples.flowelement-main.java&utm_term=find-out-more"); + output.println("\thttps://github.com/51Degrees/51degrees-java"); + output.println("\thttps://github.com/51Degrees/specifications"); + output.println(RULE); + output.flush(); + } + public static void main(String[] args) throws Exception { new Example().run(); + writeFindOutMore(System.out); } } diff --git a/pipeline/pipeline.developer-examples/pipeline.developer-examples.flowelement/src/test/java/pipeline/developerexamples/flowelement/FindOutMoreTests.java b/pipeline/pipeline.developer-examples/pipeline.developer-examples.flowelement/src/test/java/pipeline/developerexamples/flowelement/FindOutMoreTests.java new file mode 100644 index 000000000..b180ac756 --- /dev/null +++ b/pipeline/pipeline.developer-examples/pipeline.developer-examples.flowelement/src/test/java/pipeline/developerexamples/flowelement/FindOutMoreTests.java @@ -0,0 +1,98 @@ +/* ********************************************************************* + * 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 pipeline.developerexamples.flowelement; + +import org.junit.jupiter.api.Test; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import java.nio.charset.StandardCharsets; +import java.util.regex.Pattern; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * The example ends its output with a "Find out more" section, which lists + * pages on 51degrees.com, each with its campaign tags, and the repository. + */ +public class FindOutMoreTests { + + private static final String RULE = + "----------------------------------------------------------------"; + + private static final String HEADING = "Find out more"; + + private static final String REPOSITORY = + "https://github.com/51Degrees/51degrees-java"; + + private static final Pattern TAGGED = Pattern.compile( + "https://51degrees\\.com/[^?\\s]*\\?utm_source=code" + + "&utm_medium=example&utm_campaign=51degrees-java" + + "&utm_content=[a-z0-9][a-z0-9._-]*&utm_term=find-out-more$"); + + @Test + public void Main_EndsWithFindOutMore() throws Exception { + String output = runMain(); + int example = output.lastIndexOf("your star sign is"); + int heading = output.lastIndexOf(RULE + "\n" + HEADING + "\n"); + assertTrue(example >= 0, "The example wrote nothing:\n" + output); + assertTrue(heading > example, + "No Find out more section after the example's output:\n" + + output); + String section = output.substring( + heading + RULE.length() + HEADING.length() + 2); + int end = section.indexOf(RULE + "\n"); + assertTrue(end > 0, "The section has no closing rule:\n" + output); + section = section.substring(0, end); + int pages = 0; + for (String line : section.split("\n")) { + if (line.contains("51degrees.com")) { + assertTrue(TAGGED.matcher(line).find(), + "A 51degrees.com link without its campaign tags: " + + line); + pages++; + } + } + assertEquals(2, pages, "The pages listed:\n" + section); + assertTrue(section.contains(REPOSITORY), + "The repository is not listed:\n" + section); + } + + /** + * Runs the example as a person would and returns what it wrote, with + * each line ending in a line feed. + */ + private static String runMain() throws Exception { + PrintStream original = System.out; + ByteArrayOutputStream captured = new ByteArrayOutputStream(); + System.setOut(new PrintStream(captured, true, "UTF-8")); + try { + Main.main(new String[0]); + } finally { + System.setOut(original); + } + return new String(captured.toByteArray(), StandardCharsets.UTF_8) + .replace("\r\n", "\n"); + } +} diff --git a/pipeline/pipeline.developer-examples/pipeline.developer-examples.fodid/src/main/java/pipeline/developerexamples/fodid/Main.java b/pipeline/pipeline.developer-examples/pipeline.developer-examples.fodid/src/main/java/pipeline/developerexamples/fodid/Main.java index d21426abc..26d0f0b61 100644 --- a/pipeline/pipeline.developer-examples/pipeline.developer-examples.fodid/src/main/java/pipeline/developerexamples/fodid/Main.java +++ b/pipeline/pipeline.developer-examples/pipeline.developer-examples.fodid/src/main/java/pipeline/developerexamples/fodid/Main.java @@ -26,6 +26,7 @@ import com.swancommunity.owid.Crypto; import fiftyone.pipeline.did.FodId; +import java.io.PrintStream; import java.util.Arrays; /** @@ -140,7 +141,31 @@ private static String toHex(byte[] bytes) { } } + /** + * The rule above and below the "Find out more" section. + */ + private static final String RULE = + "----------------------------------------------------------------"; + + /** + * Ends the output with the pages and repositories that say more about + * what this example shows. + * @param output where to write + */ + static void writeFindOutMore(PrintStream output) { + output.println(); + output.println(RULE); + output.println("Find out more"); + output.println("\t51Did: https://51degrees.com/documentation/_identifiers__index.html?utm_source=code&utm_medium=example&utm_campaign=51degrees-java&utm_content=pipeline.developer-examples.fodid-main.java&utm_term=find-out-more"); + output.println("\tAsk about 51Did: https://51degrees.com/contact-us?utm_source=code&utm_medium=example&utm_campaign=51degrees-java&utm_content=pipeline.developer-examples.fodid-main.java&utm_term=find-out-more"); + output.println("\thttps://github.com/51Degrees/51degrees-java"); + output.println("\thttps://github.com/51Degrees/specifications"); + output.println(RULE); + output.flush(); + } + public static void main(String[] args) throws Exception { new Example().run(); + writeFindOutMore(System.out); } } diff --git a/pipeline/pipeline.developer-examples/pipeline.developer-examples.fodid/src/test/java/pipeline/developerexamples/fodid/FindOutMoreTests.java b/pipeline/pipeline.developer-examples/pipeline.developer-examples.fodid/src/test/java/pipeline/developerexamples/fodid/FindOutMoreTests.java new file mode 100644 index 000000000..e34a4bd11 --- /dev/null +++ b/pipeline/pipeline.developer-examples/pipeline.developer-examples.fodid/src/test/java/pipeline/developerexamples/fodid/FindOutMoreTests.java @@ -0,0 +1,98 @@ +/* ********************************************************************* + * 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 pipeline.developerexamples.fodid; + +import org.junit.jupiter.api.Test; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import java.nio.charset.StandardCharsets; +import java.util.regex.Pattern; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * The example ends its output with a "Find out more" section, which lists + * pages on 51degrees.com, each with its campaign tags, and the repository. + */ +public class FindOutMoreTests { + + private static final String RULE = + "----------------------------------------------------------------"; + + private static final String HEADING = "Find out more"; + + private static final String REPOSITORY = + "https://github.com/51Degrees/51degrees-java"; + + private static final Pattern TAGGED = Pattern.compile( + "https://51degrees\\.com/[^?\\s]*\\?utm_source=code" + + "&utm_medium=example&utm_campaign=51degrees-java" + + "&utm_content=[a-z0-9][a-z0-9._-]*&utm_term=find-out-more$"); + + @Test + public void Main_EndsWithFindOutMore() throws Exception { + String output = runMain(); + int example = output.lastIndexOf("Same match key"); + int heading = output.lastIndexOf(RULE + "\n" + HEADING + "\n"); + assertTrue(example >= 0, "The example wrote nothing:\n" + output); + assertTrue(heading > example, + "No Find out more section after the example's output:\n" + + output); + String section = output.substring( + heading + RULE.length() + HEADING.length() + 2); + int end = section.indexOf(RULE + "\n"); + assertTrue(end > 0, "The section has no closing rule:\n" + output); + section = section.substring(0, end); + int pages = 0; + for (String line : section.split("\n")) { + if (line.contains("51degrees.com")) { + assertTrue(TAGGED.matcher(line).find(), + "A 51degrees.com link without its campaign tags: " + + line); + pages++; + } + } + assertEquals(2, pages, "The pages listed:\n" + section); + assertTrue(section.contains(REPOSITORY), + "The repository is not listed:\n" + section); + } + + /** + * Runs the example as a person would and returns what it wrote, with + * each line ending in a line feed. + */ + private static String runMain() throws Exception { + PrintStream original = System.out; + ByteArrayOutputStream captured = new ByteArrayOutputStream(); + System.setOut(new PrintStream(captured, true, "UTF-8")); + try { + Main.main(new String[0]); + } finally { + System.setOut(original); + } + return new String(captured.toByteArray(), StandardCharsets.UTF_8) + .replace("\r\n", "\n"); + } +} diff --git a/pipeline/pipeline.developer-examples/pipeline.developer-examples.onpremise-engine/src/main/java/pipeline/developerexamples/onpremiseengine/Main.java b/pipeline/pipeline.developer-examples/pipeline.developer-examples.onpremise-engine/src/main/java/pipeline/developerexamples/onpremiseengine/Main.java index 8d803d244..0d585136c 100644 --- a/pipeline/pipeline.developer-examples/pipeline.developer-examples.onpremise-engine/src/main/java/pipeline/developerexamples/onpremiseengine/Main.java +++ b/pipeline/pipeline.developer-examples/pipeline.developer-examples.onpremise-engine/src/main/java/pipeline/developerexamples/onpremiseengine/Main.java @@ -30,6 +30,7 @@ import pipeline.developerexamples.onpremiseengine.flowelements.SimpleOnPremiseEngine; import pipeline.developerexamples.onpremiseengine.flowelements.SimpleOnPremiseEngineBuilder; +import java.io.PrintStream; import java.text.SimpleDateFormat; import java.util.Calendar; @@ -72,7 +73,31 @@ public void run() throws Exception { } } + /** + * The rule above and below the "Find out more" section. + */ + private static final String RULE = + "----------------------------------------------------------------"; + + /** + * Ends the output with the pages and repositories that say more about + * what this example shows. + * @param output where to write + */ + static void writeFindOutMore(PrintStream output) { + output.println(); + output.println(RULE); + output.println("Find out more"); + output.println("\tThis example: https://51degrees.com/documentation/_pipeline_api__examples__custom_element__on_premise.html?utm_source=code&utm_medium=example&utm_campaign=51degrees-java&utm_content=pipeline.developer-examples.onpremise-engine-main.java&utm_term=find-out-more"); + output.println("\tCustom flow elements: https://51degrees.com/documentation/_pipeline_api__features__custom_elements.html?utm_source=code&utm_medium=example&utm_campaign=51degrees-java&utm_content=pipeline.developer-examples.onpremise-engine-main.java&utm_term=find-out-more"); + output.println("\thttps://github.com/51Degrees/51degrees-java"); + output.println("\thttps://github.com/51Degrees/specifications"); + output.println(RULE); + output.flush(); + } + public static void main(String[] args) throws Exception { new Example().run(); + writeFindOutMore(System.out); } } diff --git a/pipeline/pipeline.developer-examples/pipeline.developer-examples.onpremise-engine/src/test/java/pipeline/developerexamples/onpremiseengine/FindOutMoreTests.java b/pipeline/pipeline.developer-examples/pipeline.developer-examples.onpremise-engine/src/test/java/pipeline/developerexamples/onpremiseengine/FindOutMoreTests.java new file mode 100644 index 000000000..4acc41328 --- /dev/null +++ b/pipeline/pipeline.developer-examples/pipeline.developer-examples.onpremise-engine/src/test/java/pipeline/developerexamples/onpremiseengine/FindOutMoreTests.java @@ -0,0 +1,98 @@ +/* ********************************************************************* + * 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 pipeline.developerexamples.onpremiseengine; + +import org.junit.jupiter.api.Test; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import java.nio.charset.StandardCharsets; +import java.util.regex.Pattern; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * The example ends its output with a "Find out more" section, which lists + * pages on 51degrees.com, each with its campaign tags, and the repository. + */ +public class FindOutMoreTests { + + private static final String RULE = + "----------------------------------------------------------------"; + + private static final String HEADING = "Find out more"; + + private static final String REPOSITORY = + "https://github.com/51Degrees/51degrees-java"; + + private static final Pattern TAGGED = Pattern.compile( + "https://51degrees\\.com/[^?\\s]*\\?utm_source=code" + + "&utm_medium=example&utm_campaign=51degrees-java" + + "&utm_content=[a-z0-9][a-z0-9._-]*&utm_term=find-out-more$"); + + @Test + public void Main_EndsWithFindOutMore() throws Exception { + String output = runMain(); + int example = output.lastIndexOf("your star sign is"); + int heading = output.lastIndexOf(RULE + "\n" + HEADING + "\n"); + assertTrue(example >= 0, "The example wrote nothing:\n" + output); + assertTrue(heading > example, + "No Find out more section after the example's output:\n" + + output); + String section = output.substring( + heading + RULE.length() + HEADING.length() + 2); + int end = section.indexOf(RULE + "\n"); + assertTrue(end > 0, "The section has no closing rule:\n" + output); + section = section.substring(0, end); + int pages = 0; + for (String line : section.split("\n")) { + if (line.contains("51degrees.com")) { + assertTrue(TAGGED.matcher(line).find(), + "A 51degrees.com link without its campaign tags: " + + line); + pages++; + } + } + assertEquals(2, pages, "The pages listed:\n" + section); + assertTrue(section.contains(REPOSITORY), + "The repository is not listed:\n" + section); + } + + /** + * Runs the example as a person would and returns what it wrote, with + * each line ending in a line feed. + */ + private static String runMain() throws Exception { + PrintStream original = System.out; + ByteArrayOutputStream captured = new ByteArrayOutputStream(); + System.setOut(new PrintStream(captured, true, "UTF-8")); + try { + Main.main(new String[0]); + } finally { + System.setOut(original); + } + return new String(captured.toByteArray(), StandardCharsets.UTF_8) + .replace("\r\n", "\n"); + } +} diff --git a/pipeline/pipeline.developer-examples/pipeline.developer-examples.usage-sharing/src/main/java/pipeline/developerexamples/usagesharing/Main.java b/pipeline/pipeline.developer-examples/pipeline.developer-examples.usage-sharing/src/main/java/pipeline/developerexamples/usagesharing/Main.java index f6da01434..cb4ca6e86 100644 --- a/pipeline/pipeline.developer-examples/pipeline.developer-examples.usage-sharing/src/main/java/pipeline/developerexamples/usagesharing/Main.java +++ b/pipeline/pipeline.developer-examples/pipeline.developer-examples.usage-sharing/src/main/java/pipeline/developerexamples/usagesharing/Main.java @@ -32,6 +32,7 @@ import org.slf4j.LoggerFactory; import java.io.File; +import java.io.PrintStream; import java.util.Objects; /** @@ -115,7 +116,31 @@ public void run() throws Exception { } } + /** + * The rule above and below the "Find out more" section. + */ + private static final String RULE = + "----------------------------------------------------------------"; + + /** + * Ends the output with the pages and repositories that say more about + * what this example shows. + * @param output where to write + */ + static void writeFindOutMore(PrintStream output) { + output.println(); + output.println(RULE); + output.println("Find out more"); + output.println("\tThis example: https://51degrees.com/documentation/_pipeline_api__examples__usage_sharing.html?utm_source=code&utm_medium=example&utm_campaign=51degrees-java&utm_content=pipeline.developer-examples.usage-sharing-main.java&utm_term=find-out-more"); + output.println("\tUsage sharing: https://51degrees.com/documentation/_pipeline_api__features__usage_sharing.html?utm_source=code&utm_medium=example&utm_campaign=51degrees-java&utm_content=pipeline.developer-examples.usage-sharing-main.java&utm_term=find-out-more"); + output.println("\thttps://github.com/51Degrees/51degrees-java"); + output.println("\thttps://github.com/51Degrees/specifications"); + output.println(RULE); + output.flush(); + } + public static void main(String[] args) throws Exception { new Example().run(); + writeFindOutMore(System.out); } } diff --git a/pipeline/pipeline.developer-examples/pipeline.developer-examples.usage-sharing/src/test/java/pipeline/developerexamples/usagesharing/FindOutMoreTests.java b/pipeline/pipeline.developer-examples/pipeline.developer-examples.usage-sharing/src/test/java/pipeline/developerexamples/usagesharing/FindOutMoreTests.java new file mode 100644 index 000000000..9155c5097 --- /dev/null +++ b/pipeline/pipeline.developer-examples/pipeline.developer-examples.usage-sharing/src/test/java/pipeline/developerexamples/usagesharing/FindOutMoreTests.java @@ -0,0 +1,100 @@ +/* ********************************************************************* + * 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 pipeline.developerexamples.usagesharing; + +import org.junit.Test; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import java.nio.charset.StandardCharsets; +import java.util.regex.Pattern; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * The example ends its output with a "Find out more" section, which lists + * pages on 51degrees.com, each with its campaign tags, and the repository. + */ +public class FindOutMoreTests { + + private static final String RULE = + "----------------------------------------------------------------"; + + private static final String HEADING = "Find out more"; + + private static final String REPOSITORY = + "https://github.com/51Degrees/51degrees-java"; + + private static final Pattern TAGGED = Pattern.compile( + "https://51degrees\\.com/[^?\\s]*\\?utm_source=code" + + "&utm_medium=example&utm_campaign=51degrees-java" + + "&utm_content=[a-z0-9][a-z0-9._-]*&utm_term=find-out-more$"); + + @Test + public void Main_EndsWithFindOutMore() throws Exception { + String output = runMain(); + int example = output.lastIndexOf("Pipeline created with share usage element"); + int heading = output.lastIndexOf(RULE + "\n" + HEADING + "\n"); + assertTrue("The example wrote nothing:\n" + output, example >= 0); + assertTrue( + "No Find out more section after the example's output:\n" + + output, + heading > example); + String section = output.substring( + heading + RULE.length() + HEADING.length() + 2); + int end = section.indexOf(RULE + "\n"); + assertTrue("The section has no closing rule:\n" + output, end > 0); + section = section.substring(0, end); + int pages = 0; + for (String line : section.split("\n")) { + if (line.contains("51degrees.com")) { + assertTrue( + "A 51degrees.com link without its campaign tags: " + + line, + TAGGED.matcher(line).find()); + pages++; + } + } + assertEquals("The pages listed:\n" + section, 2, pages); + assertTrue("The repository is not listed:\n" + section, + section.contains(REPOSITORY)); + } + + /** + * Runs the example as a person would and returns what it wrote, with + * each line ending in a line feed. + */ + private static String runMain() throws Exception { + PrintStream original = System.out; + ByteArrayOutputStream captured = new ByteArrayOutputStream(); + System.setOut(new PrintStream(captured, true, "UTF-8")); + try { + Main.main(new String[0]); + } finally { + System.setOut(original); + } + return new String(captured.toByteArray(), StandardCharsets.UTF_8) + .replace("\r\n", "\n"); + } +}