Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.

public interface ManagementContract

The operational contract of a server with management on, as tests a test class inherits: implement it on a BackendTest with BackendTest.Feature.MANAGEMENT and a port, and its default @Test methods check the probes, the endpoint authentication, the metric schema and the Prometheus scrape against that application.

@BackendTest(webEnvironment = BackendTest.WebEnvironment.RANDOM_PORT,
        features = BackendTest.Feature.MANAGEMENT,
        properties = "cn1.management.token=s3cret")
class OperationsTest implements ManagementContract {
    @Autowired TestRestTemplate rest;
    public TestRestTemplate managementClient() { return rest; }
    public String managementToken() { return "s3cret"; }
}

The same class runs on the JVM and compiled, so a packaged server answers a dashboard and a load balancer the way the JVM one does.

Methods

public abstract TestRestTemplate managementClient()A client rooted at the application, a TestRestTemplate the test injected.
public abstract String managementToken()The cn1.management.token the test configured.
public default String managementPath()The cn1.management.path the test configured.
public default int managementStatus(String path, String token) throws IOExceptionThe status path under the management path answers, with token as a bearer token, or with none when it is null.
public default ResponseEntity<String> managementGet(String path, String token) throws IOExceptionThe answer to GET of path under the management path.
public default void probesNeedNoToken() throws IOExceptionLiveness and readiness answer a probe that carries no token, as an orchestrator’s does.
public default void protectedEndpointsNeedTheToken() throws IOExceptionEverything else refuses a missing or a wrong token and serves the right one.
public default void theSchemaDescribesItsMetrics() throws IOExceptionThe schema names the runtime and describes each metric with its unit and whether this server measures it.
public default void prometheusScrapeIsTyped() throws IOExceptionThe scrape types its families and carries the metrics every runtime has.

Method details

managementClient

public abstract TestRestTemplate managementClient()
A client rooted at the application, a TestRestTemplate the test injected.

managementToken

public abstract String managementToken()
The cn1.management.token the test configured.

managementPath

public default String managementPath()
The cn1.management.path the test configured.

managementStatus

public default int managementStatus(String path, String token) throws IOException
The status path under the management path answers, with token as a bearer token, or with none when it is null.

managementGet

public default ResponseEntity<String> managementGet(String path, String token) throws IOException
The answer to GET of path under the management path.

probesNeedNoToken

public default void probesNeedNoToken() throws IOException
Liveness and readiness answer a probe that carries no token, as an orchestrator’s does.

protectedEndpointsNeedTheToken

public default void protectedEndpointsNeedTheToken() throws IOException
Everything else refuses a missing or a wrong token and serves the right one.

theSchemaDescribesItsMetrics

public default void theSchemaDescribesItsMetrics() throws IOException
The schema names the runtime and describes each metric with its unit and whether this server measures it.

prometheusScrapeIsTyped

public default void prometheusScrapeIsTyped() throws IOException
The scrape types its families and carries the metrics every runtime has.