Repository navigation
TEST: Check the cloud hardware lookup examples return devices - #234
Merged
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_BESPOKEsecret (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 printsvendor 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
Profilesis not among them, the example prints exactly one line, not indented, and makes no lookup:The Cloud Configurator link is
https://51degrees.com/configure/QKyYH5XTand the contact link ishttps://51degrees.com/contact-us, each tagged withutm_source=code,utm_medium=example,utm_campaign=51degrees-java, the example's ownutm_contentandutm_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 printsNo devices are associated with this TAC.orNo 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
QKyYH5XTpreset, 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:
TacCloudTestandNativeModelCloudTeststill read the key from_51DEGREES_RESOURCE_KEY_BESPOKE, give the example the key as_51DEGREES_RESOURCE_KEYin a process of its own, and are skipped whenKeyHelperfinds 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_ENDPOINTfrom the test's environment, so the tests can be pointed at another cloud. Each test now fails withThe resource key in _51DEGREES_RESOURCE_KEY_BESPOKE does not include HardwarePlatform.Profiles, which the TAC lookup needs.(orwhich 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 norUnknown, which is how the examples render a property with no value. If none is found the test fails withNo device with a vendor and a model was listed for the TAC '<tac>'.(orfor the native model name '<name>'.) followed by the output. Finally the test requires exit code 0. The shared checks are inHardwareLookupOutput.java, andHardwareLookupOutputTest.javachecks which lines count as a device.HardwareLookupWithoutProfilesTestruns both examples against a stand-in for the cloud service on 127.0.0.1, on a free port, in the wayCloudDropInTestalready does. The stand-in answersaccessiblepropertieswith the cloud's real answer for a key without the hardware element, cut down to one device property, answersevidencekeyswith the cloud's real evidence key list, and answers anything else with 404 while recording the path. The two answers are fixtures insrc/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 startingWhich 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.How this was verified
Run in
examples/device-detectionwith JDK 21, against the libraries of this branch installed withmvnw install -Pdev -DskipTests -pl device-detection/device-detection.cloud,device-detection/device-detection -amfrom the root. The on-premise hash engine was not rebuilt, because the native build was not needed for the cloud examples.mvnw -Pdev -pl console -am test -Dtest=HardwareLookupWithoutProfilesTest,HardwareLookupOutputTest,CloudExamplesWithoutKeyTest,FindOutMoreCoverageTest,ConsoleConfigurationCoverageTest,CloudDropInTest#cloudResultsReadAsOnPremise,KeyHelperTest,FindOutMoreTest,ExampleProcessTest,PropertyHelperTest -DfailIfNoTests=falsewith every variable holding a key removed-Dtest=HardwareLookupWithoutProfilesTestmvnw -Pdev -pl console -am clean test -Dtest=TacCloudTest,NativeModelCloudTest -DfailIfNoTests=falsewith that key in_51DEGREES_RESOURCE_KEY_BESPOKEand_51DEGREES_CLOUD_ENDPOINTnaming the staging cloudApple iPhone 6 (A1586), TAC 86386802 six Coolpad devices, native model SC-03LSamsung Galaxy S10 (SC-03L)and iPhone11,8 six Apple iPhone XR modelscleanNo device with a vendor and a model was listed for the TAC '35925406'., because the old classes printedApple; iPhone 6; A1586, which shows the device check rejects the old form_51DEGREES_RESOURCE_KEY_BESPOKE, production and stagingThe 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_51DEGREES_RESOURCE_KEY_BESPOKEnot setTacCloudwith a stand-in key and_51DEGREES_CLOUD_ENDPOINTat a closed local portmvnw -pl console -am clean test-compilepwsh ci/check-environment-variable-names.ps1scripts/utm-lint.ps1 -RepoRoot . -Campaign 51degrees-javapwsh ci/check-root-locale.ps1What remains
_51DEGREES_RESOURCE_KEY_BESPOKEsecret is replaced with one that carries every CloudV5Bespoke property. The current key does not include HardwarePlatform.Profiles, soTacCloudTestandNativeModelCloudTestfail with the message above. That failure is intended, because the lookups have not been tested until now.devprofile is active. In the published 4.5.130 packages the pipeline cannot be built for a key without the hardware element (CloudAspectEngineBase.getPropertiesthrowsFailed 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 thedevprofile, which CI uses, or with the packages a publish has just built.hardwareproduct before the example's line. That warning is not an error and is left as it is.NullPointerExceptionrather 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.