All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.neo4j.test.extension.DbmsExtension Maven / Gradle / Ivy

There is a newer version: 5.25.1
Show newest version
/*
 * Copyright (c) "Neo4j"
 * Neo4j Sweden AB [https://neo4j.com]
 *
 * This file is part of Neo4j.
 *
 * Neo4j is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see .
 */
package org.neo4j.test.extension;

import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith;
import org.neo4j.dbms.api.DatabaseManagementService;
import org.neo4j.dbms.api.DatabaseManagementServiceBuilder;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.kernel.internal.GraphDatabaseAPI;
import org.neo4j.test.TestDatabaseManagementServiceBuilder;
import org.neo4j.test.utils.TestDirectory;

/**
 * Provides test access to {@link DatabaseManagementService}. If you want an impermanent version, see
 * {@link ImpermanentDbmsExtension}.
 *
 * 

This extension will inject the following fields, if available. *

    *
  • {@link FileSystemAbstraction} as {@link DefaultFileSystemExtension}.
  • *
  • {@link TestDirectory}.
  • *
  • {@link DatabaseManagementService}.
  • *
  • {@link GraphDatabaseService}.
  • *
  • {@link GraphDatabaseAPI}
  • *
* *

You can specify a callback with {@link #configurationCallback()}, this callback is invoked just before * the {@link DatabaseManagementServiceBuilder} completes, allowing further modifications, e.g. adding additional * dependencies, injecting a monitor or extension etc. * *

The annotation can be added to the entire test class or per test method. If any configuration values is * added to the annotation, the one closest to the target will be chosen. E.g. if you add the annotation to the * test class with a configuration, you could then add the annotation to a specific test method and thus override * the configuration for that method. The other test methods will not be affected by this. */ @Inherited @Target({ElementType.TYPE, ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) @Neo4jLayoutExtension @ExtendWith(DbmsSupportExtension.class) public @interface DbmsExtension { /** * Name of a void method that takes a {@link TestDatabaseManagementServiceBuilder} as parameter. The method * must be annotated with {@link ExtensionCallback}. This can be used to issue additional commands on the * builder before it completes. This method will be invoked BEFORE any method annotated with * {@link BeforeEach}, this is because the injected fields should be available in the BeforeEach context. * Setting it to {@code null} or an empty string will disable it. * *

One example is to set some additional configuration values: *

{@code
     *     @ExtensionCallback
     *     void configuration( TestDatabaseManagementServiceBuilder builder )
     *     {
     *         builder.setConfig( ... );
     *     }
     * }
*/ String configurationCallback() default ""; }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy