I have a set of test classes in Quarkus that tests my app classes which use io.quarkus.redis.datasource.RedisDataSource
I want to run @BeforeAll
on each test class to reseed the redis db with known data. The BeforeAll method must be static:
@BeforeAll static void resetTestData() { // use a static version of io.quarkus.redis.datasource.RedisDataSource; here // so I can do something like: // GraphCommands<String> gc = ds.graph(); // gc.graphQuery(redisdbkey, "CREATE (:XXX {key:'abcd', name:'fred'})"); }
I can't work out how to make a static instance of io.quarkus.redis.datasource.RedisDataSource;
RedisDataSource ds = new RedisDataSource();
Throws a compiler error "Cannot instantiate the type RedisDataSource"
I tried making a Singleton instance like this:
@Singletonpublic class RedisDataSourceSingleton { private static RedisDataSource instance; @Inject public RedisDataSourceSingleton(RedisDataSource ds) { instance = ds; } public static RedisDataSource getInstance() { if (instance == null) { throw new IllegalStateException("RedisDataSource is not initialized yet."); } return instance; }}
but using the singleton like this:
import io.quarkus.redis.datasource.RedisDataSource;// ... @BeforeAll static void resetTestData() { RedisDataSource ds = RedisDataSourceSingleton.getInstance(); // use ds here }
throws:"The method getInstance() from the type RedisDataSourceSingleton refers to the missing type RedisDataSource"
Is there a way to get a static instance of io.quarkus.redis.datasource.RedisDataSource
so I can use its methods in my @BeforeAll
method? I am probably overthinking it!
Thanks,Murray