Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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");
}
}
Loading
Loading