RequiresTm1Engine
import io.skipcheck.tm1.testcontainers.RequiresTm1Engine; Runs a test class or method against a real TM1 v12 engine, and skips it when there
isn't one. For TM1 11, use RequiresTm1.
Tests are skipped, not failed, when Docker isn't available or no
Tm1EngineSource is configured, so a build without IBM software stays green. A
source that is configured but wrong fails instead.
One engine serves the whole test JVM (Tm1EngineContainer.shared), and each
test class gets a database of its own, created when the class first asks for it and
dropped when the class is done. So classes don't see each other's objects. Declare a
Tm1Database parameter on a test method, constructor or lifecycle method to get
it; a Tm1EngineContainer parameter gets the engine.
@RequiresTm1Engine
static class CubeTest {
// A database of this class's own, dropped when the class is done
@Test
void listsCubes(Tm1Database db) throws Exception {
HttpRequest request = db.login()
.authorize(HttpRequest.newBuilder(URI.create(db.getRestUrl() + "Cubes?$select=Name")))
.build();
HttpResponse<String> response = HttpClient.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString());
assertEquals(200, response.statusCode());
}
}
A database takes about 13 seconds to create and 5 to drop. shareDatabase gives
a class the engine's one shared database instead, at no cost: its tests then need
uniquely named objects, and to delete them afterwards:
// The engine's one shared database instead: nothing to create, but give what you
// make a unique name
@RequiresTm1Engine(shareDatabase = true)
static class ServerNameTest {
@Test
void readsTheServersName(Tm1Database db) throws Exception {
HttpRequest request = db.login()
.authorize(HttpRequest.newBuilder(URI.create(db.getRestUrl() + "Configuration/ServerName/$value")))
.build();
HttpResponse<String> response = HttpClient.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString());
assertEquals(200, response.statusCode());
}
}
"A test class" is the unit each language's test framework shares set-up over: a JUnit class here (with its nested classes), a module in pytest, a class in xUnit, and a file in vitest.
Members
NO_SOURCE_MESSAGE static | Why tests skip when no source is configured, and what to set. |
shareDatabase | Whether the class uses the engine's shared database, tm1, rather than one of its own. |
minVersion | The oldest TM1 the tests apply to, such as 12.6; they're skipped on an older engine. |
NO_SOURCE_MESSAGE
staticString NO_SOURCE_MESSAGEWhy tests skip when no source is configured, and what to set.
minVersion
String minVersion() The oldest TM1 the tests apply to, such as 12.6; they're skipped on an
older engine. Checking it starts the engine.
Returns
- the version, or empty for any
Also in the Javadoc.