Search in sources :

Example 1 with AdjustableDatabaseAdapterConfig

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;
}
Also used : ReflectionUtils.makeAccessible(org.junit.platform.commons.util.ReflectionUtils.makeAccessible) TracingDatabaseAdapter(org.projectnessie.versioned.persist.adapter.spi.TracingDatabaseAdapter) CloseableResource(org.junit.jupiter.api.extension.ExtensionContext.Store.CloseableResource) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) Function(java.util.function.Function) CONFIG_NAME_PREFIX(org.projectnessie.versioned.persist.tests.SystemPropertiesConfigurer.CONFIG_NAME_PREFIX) GenericContentVariantSupplier(org.projectnessie.versioned.persist.store.GenericContentVariantSupplier) ArrayList(java.util.ArrayList) AfterEachCallback(org.junit.jupiter.api.extension.AfterEachCallback) VersionStore(org.projectnessie.versioned.VersionStore) Parameter(java.lang.reflect.Parameter) DatabaseAdapterFactory(org.projectnessie.versioned.persist.adapter.DatabaseAdapterFactory) AnnotationUtils.findRepeatableAnnotations(org.junit.platform.commons.util.AnnotationUtils.findRepeatableAnnotations) Method(java.lang.reflect.Method) ReflectionUtils.isPrivate(org.junit.platform.commons.util.ReflectionUtils.isPrivate) Namespace(org.junit.jupiter.api.extension.ExtensionContext.Namespace) DatabaseAdapter(org.projectnessie.versioned.persist.adapter.DatabaseAdapter) SystemPropertiesConfigurer(org.projectnessie.versioned.persist.tests.SystemPropertiesConfigurer) ReflectionUtils.findMethod(org.junit.platform.commons.util.ReflectionUtils.findMethod) PersistVersionStore(org.projectnessie.versioned.persist.store.PersistVersionStore) ParameterResolutionException(org.junit.jupiter.api.extension.ParameterResolutionException) TracingVersionStore(org.projectnessie.versioned.TracingVersionStore) DatabaseConnectionProvider(org.projectnessie.versioned.persist.adapter.DatabaseConnectionProvider) AnnotationUtils.findAnnotatedFields(org.junit.platform.commons.util.AnnotationUtils.findAnnotatedFields) Field(java.lang.reflect.Field) ExtensionConfigurationException(org.junit.jupiter.api.extension.ExtensionConfigurationException) ReflectionUtils(org.junit.platform.commons.util.ReflectionUtils) InvocationTargetException(java.lang.reflect.InvocationTargetException) Consumer(java.util.function.Consumer) ParameterContext(org.junit.jupiter.api.extension.ParameterContext) List(java.util.List) StoreWorker(org.projectnessie.versioned.StoreWorker) BeforeAllCallback(org.junit.jupiter.api.extension.BeforeAllCallback) AdjustableDatabaseAdapterConfig(org.projectnessie.versioned.persist.adapter.AdjustableDatabaseAdapterConfig) Modifier(java.lang.reflect.Modifier) ExceptionUtils(org.junit.platform.commons.util.ExceptionUtils) Annotation(java.lang.annotation.Annotation) BeforeEachCallback(org.junit.jupiter.api.extension.BeforeEachCallback) DatabaseAdapterConfig(org.projectnessie.versioned.persist.adapter.DatabaseAdapterConfig) Optional(java.util.Optional) AnnotationUtils(org.junit.platform.commons.util.AnnotationUtils) ParameterResolver(org.junit.jupiter.api.extension.ParameterResolver) AnnotatedElement(java.lang.reflect.AnnotatedElement) AdjustableDatabaseAdapterConfig(org.projectnessie.versioned.persist.adapter.AdjustableDatabaseAdapterConfig) DatabaseAdapterConfig(org.projectnessie.versioned.persist.adapter.DatabaseAdapterConfig) AdjustableDatabaseAdapterConfig(org.projectnessie.versioned.persist.adapter.AdjustableDatabaseAdapterConfig) Method(java.lang.reflect.Method) ReflectionUtils.findMethod(org.junit.platform.commons.util.ReflectionUtils.findMethod) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

Annotation (java.lang.annotation.Annotation)1 AnnotatedElement (java.lang.reflect.AnnotatedElement)1 Field (java.lang.reflect.Field)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Modifier (java.lang.reflect.Modifier)1 Parameter (java.lang.reflect.Parameter)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1 Consumer (java.util.function.Consumer)1 Function (java.util.function.Function)1 AfterEachCallback (org.junit.jupiter.api.extension.AfterEachCallback)1 BeforeAllCallback (org.junit.jupiter.api.extension.BeforeAllCallback)1 BeforeEachCallback (org.junit.jupiter.api.extension.BeforeEachCallback)1 ExtensionConfigurationException (org.junit.jupiter.api.extension.ExtensionConfigurationException)1 ExtensionContext (org.junit.jupiter.api.extension.ExtensionContext)1 Namespace (org.junit.jupiter.api.extension.ExtensionContext.Namespace)1 CloseableResource (org.junit.jupiter.api.extension.ExtensionContext.Store.CloseableResource)1 ParameterContext (org.junit.jupiter.api.extension.ParameterContext)1