Schedule Device Targeting Tests
OpenFrame Documentation
Get the most out of OpenFrame · Book 30 minutes with Conrad, 25 years in IT. He'll show you what Mingo and Fae can take off your list.
OpenFrame Documentation
Schedule Device Targeting Tests is an ordered end-to-end JUnit test suite that verifies how a script schedule targets enrolled devices. It creates future-dated schedules, exercises the GraphQL schedule-device operations, checks picker and selection state, and removes all created data when the suite finishes. The implementation belongs to the OpenFrame OSS Library artifact com.openframe.oss:openframe-test-service-core, which this repository runs through its OpenFrame test service.
The source implementation is ScriptScheduleDevicesTest.java.
The suite covers the device-targeting portion of script scheduling:
assigned flag on each available edge.CRITERIA, and resolves matching devices dynamically.The suite deliberately schedules executions one day ahead. A real enrolled device can therefore be targeted without causing the test schedule to dispatch during the test run.
The test is an integration boundary consumer rather than a scheduling implementation. It uses test-library APIs to create devices' supporting data and issue schedule operations against the deployed OpenFrame services. Its assertions observe the returned schedule and picker models.
flowchart LR
Suite["Schedule Device Targeting Tests"] -->|"creates and deletes scripts"| ScriptApi["Script API test client"]
Suite -->|"creates schedules and changes targets"| ScheduleApi["Script Schedule API test client"]
Suite -->|"selects enrolled target"| DeviceApi["Device API test client"]
DeviceApi -->|"returns machine"| Machine["Enrolled machine"]
ScriptApi -->|"returns script"| Script["Script"]
ScheduleApi -->|"returns state and picker"| Schedule["Script schedule"]
Schedule -->|"targets"| Machine
ScheduleApi -->|"GraphQL requests"| Platform["OpenFrame platform"]
pickDevice() runs once before the ordered tests. It requests an enrolled Windows device first, then falls back to a device from the listed-status filter. Each test invokes requireDevice(), which aborts the test through JUnit assumptions if no usable machine is available. The suite is tagged saas and needs-device; the latter distinguishes it from test runs that intentionally do not provision an agent.
The fixture uses a unique RunId to form an E2E-<run-id> targeting schedule name. A page size of 50 is used whenever the suite asks the picker for matching and assigned devices.
Two schedule/script pairs can be created:
| Fixture | Purpose | Platform alignment |
|---|---|---|
script and schedule |
Exercises valid assignment, bulk, replacement, and criteria workflows. | Script and schedule are created for the selected machine's operating system. |
otherScript and mismatched |
Exercises platform-mismatch rejection. | Script and schedule are created for an operating system different from the selected machine. |
The initial test constructs a script for the selected device's operating system because the platform compatibility condition applies when the schedule is created as well as when devices are targeted.
| Component | Responsibility in this suite |
|---|---|
ScriptScheduleDevicesTest |
Coordinates fixture setup, six ordered scenarios, assertions, assumptions, and cleanup. |
DeviceApi |
Finds a candidate enrolled machine using scoped device filters. |
ScriptApi |
Creates scripts for matching and deliberately mismatched platforms, then deletes them. |
ScriptScheduleApi |
Creates schedules, obtains picker data, performs explicit and criteria-based targeting, captures GraphQL errors, and removes schedules. |
ScriptSchedule |
Returned schedule state, including device count, selection mode, and device criteria. |
ScheduleDevices |
Picker snapshot containing assigned devices, available devices, selection mode, and resolved count. |
ScheduleDeviceEdge |
Represents a picker entry and reports whether it is currently assigned. |
ScheduleDeviceCriteriaInput |
Builds the criteria rule from operating-system and, when present, organization constraints. |
GraphqlError |
Captures the expected error response from a rejected incompatible-platform assignment. |
The JUnit OrderAnnotation method order is intentional: later scenarios reuse the schedule built by the initial valid-assignment case. requireSchedule() first checks the device precondition, then aborts subsequent tests if that initial schedule does not exist.
flowchart TD
Start["Select enrolled machine"] --> Create["Create compatible script and future schedule"]
Create --> Assign["Assign one device and verify picker"]
Assign --> Unassign["Unassign device and verify idempotency"]
Unassign --> Bulk["Assign by hostname search, then clear all"]
Bulk --> Replace["Replace explicit target set"]
Replace --> Criteria["Set criteria-based target selection"]
Criteria --> Mismatch["Create other-platform schedule and reject device"]
Mismatch --> Cleanup["Clear assignments and delete schedules and scripts"]
The suite creates a compatible script and a future schedule with an empty target set. Before assignment, it verifies that:
deviceCount is zero.assignedDevices.availableDevices with assigned=false.It then adds the device and verifies a count of one, persistence in assignedDevices, and a picker edge whose assigned flag is now true. Repeating the add operation must leave the count at one, proving idempotency.
The suite removes the previously assigned device and expects a zero count and no matching entry in assignedDevices. Removing it a second time must remain a no-op with a zero count.
addAllDevices receives the selected machine hostname as a search term. The test permits other matches in a shared tenant, so it asserts that the count is at least one and that the selected machine is included. It then calls removeAllDevices without filters and expects the schedule assignment to be empty.
setDevices is validated as replacement rather than additive behavior. Supplying the selected device creates exactly one target; supplying an empty list clears the explicit target set.
The criteria request always contains the selected device's operating system. When the device has an organization identifier, the test adds that identifier as an organization constraint. The suite then verifies that the returned schedule:
CRITERIA selection mode.A separate picker read confirms that CRITERIA persisted and that the selected device appears in the resolved assigned set.
The suite determines another platform, creates a script and schedule for that platform, then attempts to add the original device. It expects a non-empty GraphQL error list with a non-blank message. It also verifies that the schedule retains zero assignments and that the incompatible device never appears in that schedule's available picker results.
sequenceDiagram
participant Test as Schedule Device Targeting Tests
participant ScheduleApi as Script Schedule API
participant Platform as OpenFrame Platform
participant Picker as Schedule Device Picker
Test->>ScheduleApi: Create compatible future schedule
ScheduleApi->>Platform: Create schedule with supported platform
Platform-->>ScheduleApi: Script schedule with zero devices
Test->>ScheduleApi: Get schedule devices by hostname
ScheduleApi->>Platform: Query assigned and available devices
Platform-->>Picker: Build picker state
Picker-->>ScheduleApi: Available edge with assigned false
Test->>ScheduleApi: Add device
ScheduleApi->>Platform: Persist explicit assignment
Platform-->>ScheduleApi: Schedule with count one
Test->>ScheduleApi: Set device criteria
ScheduleApi->>Platform: Persist operating-system rule
Platform-->>ScheduleApi: Schedule in CRITERIA mode
Test->>ScheduleApi: Get schedule devices
ScheduleApi->>Platform: Resolve criteria
Platform-->>ScheduleApi: Matching machine in assigned devices
The test avoids unintentional execution by using nextSlot(Duration.ofDays(1)) for both valid and mismatched schedules. It scopes device discovery to the test pipeline's context and prefixes generated schedule names with a unique run identifier.
cleanup() performs best-effort teardown after all tests:
This design prevents one failed teardown operation from hiding or blocking cleanup of another resource. A warning that a schedule or script was left in the tenant identifies the residual resource by identifier.
When extending Schedule Device Targeting Tests:
requireSchedule().The test's observed contracts complement the platform scheduling and persistence components: schedule operations are exercised through the test API, while device resolution and persistence occur in the deployed platform rather than within this test class.