Package io.skipcheck.tm1.spring.boot.testcontainers


@NullMarked package io.skipcheck.tm1.spring.boot.testcontainers
Spring Boot @ServiceConnection support for Tm1ServerContainer: a Spring test or a development-time application gets its TM1 connection from the container, with no tm1.* properties.

A test gets the shared server, and is skipped where there's no TM1:

// Skipped without Docker or TM1, like any @RequiresTm1 test
@RequiresTm1
@SpringBootTest(classes = { SalesApplication.class, SalesApplicationTest.Tm1Container.class })
static class SalesApplicationTest {

	@Autowired
	private Tm1Client tm1;

	@Test
	void connectsToTm1() {
		assertNotNull(tm1.session().version().block(Duration.ofSeconds(30)));
	}

	@TestConfiguration(proxyBeanMethods = false)
	static class Tm1Container {

		// The shared server outlives the Spring context, so Spring mustn't stop it
		@Bean(destroyMethod = "")
		@ServiceConnection
		Tm1ServerContainer tm1() {
			return Tm1ServerContainer.shared();
		}

	}

}

An application run locally gets a server of its own, started and stopped with it:

// Run the application locally against TM1 in Docker, with IBM's SData sample
static class TestSalesApplication {

	public static void main(String[] args) {
		SpringApplication.from(SalesApplication::main).with(Tm1Container.class).run(args);
	}

	@TestConfiguration(proxyBeanMethods = false)
	static class Tm1Container {

		@Bean
		@ServiceConnection
		Tm1ServerContainer tm1() {
			return new Tm1ServerContainer(Tm1Source.discover().orElseThrow()).withSeed(Tm1Seed.SDATA);
		}

	}

}

The TM1 servers of a PlanningAnalyticsEnvironment, each by its name, come in through Tm1EnvironmentServers as tm1.servers.<name> instead.

Everything here is non-null unless marked Nullable.