Skip to content

TEST: Check the cloud hardware lookup examples return devices - #234

Merged
jwrosewell merged 2 commits into
rcfrom
test/hardware-lookup-examples
Nov 23, 2026
Merged

jwrosewell merged 2 commits into
rcfrom
test/hardware-lookup-examples

Conversation

@jwrosewell

@jwrosewell jwrosewell commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up: #235 makes the examples decide from a loaded property list when the first request for it fails, and adds stand-in tests for lookups that match nothing and for a property list that cannot be fetched.

Problem

The cloud TAC lookup example, TacCloud.java, and the cloud native model lookup example, NativeModelCloud.java, need a resource key that includes HardwarePlatform.Profiles. With a key that does not include that property, the examples printed their introduction and the lookup headings with nothing under them, then exited with code 0. The hardware engine gives no devices when the cloud response has no profiles (PropertyKeyedCloudEngineBase.java lines 78 to 83), so the person running the example saw an empty lookup rather than a key that lacks the lookup.

The tests of the two examples, TacCloudTest.java and NativeModelCloudTest.java, only checked the exit code and the introduction, so they passed with no devices listed. The key CI gives them through the _51DEGREES_RESOURCE_KEY_BESPOKE secret (ci/run-unit-tests.ps1 and ci/run-integration-tests.ps1) does not include HardwarePlatform.Profiles, so the lookups have not been tested in CI.

Java also printed each device as vendor; name; model, where every other language prints vendor name (model).

What changed

The examples, in the first commit:

  • After the introduction and before any lookup, each example reads the hardware engine's properties, which come from the cloud's accessible properties for the key. When Profiles is not among them, the example prints exactly one line, not indented, and makes no lookup:

    The resource key does not include HardwarePlatform.Profiles, the hardware lookup this example needs, so no devices are listed. Create a resource key that includes it at <Cloud Configurator link>, or contact us about it at <contact link>.
    

    The Cloud Configurator link is https://51degrees.com/configure/QKyYH5XT and the contact link is https://51degrees.com/contact-us, each tagged with utm_source=code, utm_medium=example, utm_campaign=51degrees-java, the example's own utm_content and utm_term=no-hardware-lookup. The example then prints its "Find out more" section and exits with code 0, with no exception and no logged error.

  • When the cloud's accessible properties could not be fetched at all, nothing is known to be missing, so the example runs the lookups as before and the failure is reported. This keeps a network failure from being reported as a key without the property.

  • Each device is printed as <vendor> <name> (<model>), and a lookup that finds no devices prints No devices are associated with this TAC. or No devices are associated with this native model name., indented by a tab.

  • The native model values are package-private, as the TAC values already were, so the tests can name them.

Every Cloud Configurator link in the two example files, including the message for no resource key at all, already used the QKyYH5XT preset, which selects exactly the hardware and device vendor, name and model properties the examples use. Nothing was replaced, so nothing was removed.

The tests, in the second commit:

  • TacCloudTest and NativeModelCloudTest still read the key from _51DEGREES_RESOURCE_KEY_BESPOKE, give the example the key as _51DEGREES_RESOURCE_KEY in a process of its own, and are skipped when KeyHelper finds no usable key in that variable, meaning it is not set or its value is not shaped like a resource key, as the other live tests in this repository are. The example's process takes _51DEGREES_CLOUD_ENDPOINT from the test's environment, so the tests can be pointed at another cloud. Each test now fails with The resource key in _51DEGREES_RESOURCE_KEY_BESPOKE does not include HardwarePlatform.Profiles, which the TAC lookup needs. (or which the native model lookup needs.) followed by the output when the example prints that line. Otherwise, for each value the example looks up, the test requires a device line under that value's heading whose vendor (the text before the first space) and model (the text in the final parentheses) are neither empty nor Unknown, which is how the examples render a property with no value. If none is found the test fails with No device with a vendor and a model was listed for the TAC '<tac>'. (or for the native model name '<name>'.) followed by the output. Finally the test requires exit code 0. The shared checks are in HardwareLookupOutput.java, and HardwareLookupOutputTest.java checks which lines count as a device.
  • HardwareLookupWithoutProfilesTest runs both examples against a stand-in for the cloud service on 127.0.0.1, on a free port, in the way CloudDropInTest already does. The stand-in answers accessibleproperties with the cloud's real answer for a key without the hardware element, cut down to one device property, answers evidencekeys with the cloud's real evidence key list, and answers anything else with 404 while recording the path. The two answers are fixtures in src/test/resources, and neither holds a key. The test gives the example a stand-in key and points it at the stand-in through _51DEGREES_CLOUD_ENDPOINT. It requires exit code 0, the line above with both tagged links, a "Find out more" section after the line, no line starting Which devices are associated, no lookup request to the stand-in and at least one request for the accessible properties. It needs no real key and no network.
  • AGENTS.md says what the two examples print with and without the property, and which tests check it.

How this was verified

Run in examples/device-detection with JDK 21, against the libraries of this branch installed with mvnw install -Pdev -DskipTests -pl device-detection/device-detection.cloud,device-detection/device-detection -am from the root. The on-premise hash engine was not rebuilt, because the native build was not needed for the cloud examples.

What Command Result
Related tests, no key and no network mvnw -Pdev -pl console -am test -Dtest=HardwareLookupWithoutProfilesTest,HardwareLookupOutputTest,CloudExamplesWithoutKeyTest,FindOutMoreCoverageTest,ConsoleConfigurationCoverageTest,CloudDropInTest#cloudResultsReadAsOnPremise,KeyHelperTest,FindOutMoreTest,ExampleProcessTest,PropertyHelperTest -DfailIfNoTests=false with every variable holding a key removed shared module 22 run, 0 failed. Console 15 run, 0 failed, including the 2 stand-in tests and the 5 tests that run each cloud example with no key
Stand-in test against the examples as they are on rc same, -Dtest=HardwareLookupWithoutProfilesTest 2 run, 2 failed. The old examples made the lookup request, which the stand-in answers with 404, and exited with code 1
Live tests, a key that carries the lookup, against the staging cloud mvnw -Pdev -pl console -am clean test -Dtest=TacCloudTest,NativeModelCloudTest -DfailIfNoTests=false with that key in _51DEGREES_RESOURCE_KEY_BESPOKE and _51DEGREES_CLOUD_ENDPOINT naming the staging cloud 2 run, 0 failed. TAC 35925406 listed Apple iPhone 6 (A1586), TAC 86386802 six Coolpad devices, native model SC-03L Samsung Galaxy S10 (SC-03L) and iPhone11,8 six Apple iPhone XR models
The same, run once before the example classes were rebuilt same, without clean 2 run, 2 failed with No device with a vendor and a model was listed for the TAC '35925406'., because the old classes printed Apple; iPhone 6; A1586, which shows the device check rejects the old form
Live tests, the key behind _51DEGREES_RESOURCE_KEY_BESPOKE, production and staging same, with that key 2 run, 2 failed on each cloud with The resource key in _51DEGREES_RESOURCE_KEY_BESPOKE does not include HardwarePlatform.Profiles, which the TAC lookup needs. and ... which the native model lookup needs. The example output under each shows the new line and the "Find out more" section
Live tests with _51DEGREES_RESOURCE_KEY_BESPOKE not set same 2 run, 2 skipped
A cloud that cannot be reached TacCloud with a stand-in key and _51DEGREES_CLOUD_ENDPOINT at a closed local port no "does not include" line. The lookup ran and the connection failure was reported, exit code 1
Compile against the published 4.5.130 packages, as the fresh clone workflow does mvnw -pl console -am clean test-compile BUILD SUCCESS
Environment variable names pwsh ci/check-environment-variable-names.ps1 clean
Campaign tags common-ci scripts/utm-lint.ps1 -RepoRoot . -Campaign 51degrees-java clean
Locale pwsh ci/check-root-locale.ps1 clean

What remains

  • The live tests will fail in CI until the key behind the _51DEGREES_RESOURCE_KEY_BESPOKE secret is replaced with one that carries every CloudV5Bespoke property. The current key does not include HardwarePlatform.Profiles, so TacCloudTest and NativeModelCloudTest fail with the message above. That failure is intended, because the lookups have not been tested until now.
  • The examples use the packages published to Maven Central unless the dev profile is active. In the published 4.5.130 packages the pipeline cannot be built for a key without the hardware element (CloudAspectEngineBase.getProperties throws Failed to load aspect properties for element 'hardware'), and the cloud request engine does not read _51DEGREES_CLOUD_ENDPOINT. Both were changed on rc after 4.5.130, the first in Build a cloud engine whose product the resource key lacks, and log that once #84 and the second in Give every environment variable one _51DEGREES_ name #105. So until the examples move to a release that includes those changes, a fresh clone run with such a key ends with that exception rather than the new line, and the stand-in test passes only with the dev profile, which CI uses, or with the packages a publish has just built.
  • The library logs its own warning that the key does not include the hardware product before the example's line. That warning is not an error and is left as it is.
  • Noticed and not changed here. With the stand-in answering the lookup request with an empty 404, the cloud request engine on rc logged a NullPointerException rather than a message about the 404.

The same behavior is being brought to the TAC and native model lookup examples and tests in the .NET, Python, Node.js, PHP and Rust repositories, so all six languages print and test these lookups in the same way.

…nd native model examples

With a resource key that does not include HardwarePlatform.Profiles, the
TAC and native model examples printed their introduction and the lookup
headings with no devices under them, so the key looked fine and the
lookup looked empty.

After the introduction each example now reads the hardware engine's
properties, which come from the cloud's accessible properties for the
key. When Profiles is not among them, it prints one line saying the key
does not include HardwarePlatform.Profiles, with tagged links to the
configuration page for the key and to the contact page, makes no lookup,
prints its Find out more section and exits with code 0. When the
accessible properties could not be fetched, nothing is known to be
missing, so the lookups run and report the failure as before.

A device is now printed as "<vendor> <name> (<model>)", the form the
other languages use, and a lookup with no devices prints one line saying
so rather than nothing.

The native model values are now package-private, as the TAC values
already are, so the tests can name them.
TacCloudTest and NativeModelCloudTest only checked that the example
ended with exit code 0 and printed its introduction, so a resource key
without the hardware lookup passed them while the examples listed no
devices.

Each test now fails when the example says the key in
_51DEGREES_RESOURCE_KEY_BESPOKE does not include
HardwarePlatform.Profiles, naming the lookup that needs it. Otherwise it
requires, for each value the example looks up, at least one device line
under that value's heading whose vendor and model both have a value, and
then exit code 0. The example runs in its own process, which takes
_51DEGREES_CLOUD_ENDPOINT from the test's environment, so the tests can be
pointed at another cloud. With no _51DEGREES_RESOURCE_KEY_BESPOKE the
tests are skipped, as before.

HardwareLookupWithoutProfilesTest runs both examples against a stand-in
for the cloud service on this machine, which gives the accessible
properties the cloud gives a key without the hardware element, the
evidence keys the cloud accepts, and 404 for anything else. It requires
the one line with both tagged links, no lookup heading, no lookup
request and exit code 0, with no real key and no network.
HardwareLookupOutputTest checks which lines count as a device.

AGENTS.md says what the examples print with and without the property.
@jwrosewell
jwrosewell marked this pull request as ready for review November 23, 2026 19:37
@jwrosewell
jwrosewell merged commit 3e8ab88 into rc Nov 23, 2026
8 checks passed
@jwrosewell
jwrosewell deleted the test/hardware-lookup-examples branch November 23, 2026 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant