use of org.projectnessie.versioned.persist.adapter.AdjustableDatabaseAdapterConfig in project nessie by projectnessie.
the class DatabaseAdapterExtension method extractCustomConfiguration.
private static Function<AdjustableDatabaseAdapterConfig, DatabaseAdapterConfig> extractCustomConfiguration(NessieDbAdapter adapterAnnotation, ExtensionContext context) {
Function<AdjustableDatabaseAdapterConfig, DatabaseAdapterConfig> applyCustomConfig = c -> c;
if (!adapterAnnotation.configMethod().isEmpty()) {
Method configMethod = findMethod(context.getRequiredTestClass(), adapterAnnotation.configMethod(), AdjustableDatabaseAdapterConfig.class).orElseThrow(() -> new IllegalArgumentException(String.format("%s.configMethod='%s' does not exist in %s", NessieDbAdapter.class.getSimpleName(), adapterAnnotation.configMethod(), context.getRequiredTestClass().getName())));
makeAccessible(configMethod);
if (!Modifier.isStatic(configMethod.getModifiers()) || Modifier.isPrivate(configMethod.getModifiers()) || !DatabaseAdapterConfig.class.isAssignableFrom(configMethod.getReturnType())) {
throw new IllegalArgumentException(String.format("%s.configMethod='%s' must have the signature 'static %s %s(%s)' in %s", NessieDbAdapter.class.getSimpleName(), adapterAnnotation.configMethod(), DatabaseAdapterConfig.class.getSimpleName(), adapterAnnotation.configMethod(), AdjustableDatabaseAdapterConfig.class.getSimpleName(), context.getRequiredTestClass().getName()));
}
applyCustomConfig = c -> {
try {
return (DatabaseAdapterConfig) configMethod.invoke(null, c);
} catch (InvocationTargetException | IllegalAccessException e) {
throw new RuntimeException(e);
}
};
}
return applyCustomConfig;
}
Aggregations