Annotation Interface RequiresTm1


@Target({TYPE,METHOD}) @Retention(RUNTIME) @Documented @ExtendWith(io.skipcheck.tm1.testcontainers.Tm1Extension.class) public @interface RequiresTm1
Runs a test class or method against a real TM1 server, and skips it when there isn't one.

Tests are skipped, not failed, when Docker isn't available or no Tm1Source is configured, so a build without IBM software (such as GitHub CI) stays green. A source that is configured but wrong, such as a folder with no TM1 in it, fails instead.

Declare a Tm1ServerContainer parameter on a test method, constructor or lifecycle method to get the shared container, started on first use.

Tests share one server, so each test should create its own uniquely named objects and delete them afterwards. A test class that sets up a client once and cleans up after each test:

@RequiresTm1
static class RegionDimensionTest {

	private static final Duration WAIT = Duration.ofSeconds(30);

	private static Tm1Client tm1;

	// One client per class, on the shared server
	@BeforeAll
	static void connect(Tm1ServerContainer server) {
		tm1 = Tm1Client.builder()
			.baseUrl(server.getRestUrl())
			.basicAuth(server.getUsername(), server.getPassword())
			.build();
	}

	@AfterAll
	static void close() {
		tm1.close().block(WAIT);
	}

	// The server is shared, so use a unique name and delete it afterwards
	private final String region = "Region-" + UUID.randomUUID();

	@AfterEach
	void deleteRegion() {
		tm1.dimensions().delete(region).onErrorComplete().block(WAIT);
	}

	@Test
	void createsTheRegions() {
		Dimension created = tm1.dimensions()
			.create(DimensionPatch.builder()
				.name(region)
				.hierarchies(List.of(HierarchyPatch.builder()
					.name(region)
					.elements(List.of(ElementPatch.builder().name("North").type(ElementType.NUMERIC).build(),
							ElementPatch.builder().name("South").type(ElementType.NUMERIC).build()))
					.build()))
				.build())
			.block(WAIT);
		assertEquals(region, created.name());
	}

}

A test that only applies to some TM1 versions checks the server's and skips:

@RequiresTm1
static class NewFeatureTest {

	@Test
	void needsARecentServer(Tm1ServerContainer tm1) {
		// Skips, rather than fails, on servers older than the feature
		Tm1Version introducedIn = Tm1Version.parse("11.8.03000");
		assumeTrue(tm1.getTm1Version().isAtLeast(introducedIn), "needs TM1 " + introducedIn + " or newer");
		// ...
	}

}
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Why tests skip when no source is configured, and what to set.
  • Field Details

    • NO_SOURCE_MESSAGE

      static final String NO_SOURCE_MESSAGE
      Why tests skip when no source is configured, and what to set.
      See Also: