com.graphaware.test.integration.EmbeddedDatabaseIntegrationTest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tests Show documentation
Show all versions of tests Show documentation
Tools for testing Neo4j-related and GraphAware-related code
/*
* Copyright (c) 2013-2019 GraphAware
*
* This file is part of the GraphAware Framework.
*
* GraphAware Framework 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 com.graphaware.test.integration;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.factory.GraphDatabaseBuilder;
import org.neo4j.test.TestGraphDatabaseFactory;
import org.springframework.core.io.ClassPathResource;
import java.io.File;
import java.io.IOException;
import static com.graphaware.common.util.DatabaseUtils.registerShutdownHook;
import static org.neo4j.kernel.configuration.Settings.FALSE;
/**
* {@link DatabaseIntegrationTest} using an embedded database. Useful for low-level tests of algorithms, queries,
* transaction event handlers, and much more, where the server isn't needed.
*/
public abstract class EmbeddedDatabaseIntegrationTest extends DatabaseIntegrationTest {
/**
* Instantiate a database. By default this will be {@link org.neo4j.test.ImpermanentGraphDatabase}.
*
* @return new database.
*/
@Override
protected GraphDatabaseService createDatabase() {
GraphDatabaseBuilder builder = createGraphDatabaseBuilder();
if (configFile() != null) {
try {
builder = builder.loadPropertiesFromFile(new ClassPathResource(configFile()).getFile().getAbsolutePath());
} catch (IOException e) {
throw new RuntimeException(e);
}
} else {
populateConfig(builder);
}
GraphDatabaseService database = builder.newGraphDatabase();
registerShutdownHook(database);
return database;
}
/**
* Instantiate a db builder.
*
* @return builder.
*/
protected GraphDatabaseBuilder createGraphDatabaseBuilder() {
return new TestGraphDatabaseFactory()
.newImpermanentDatabaseBuilder(new File("target/test-data/impermanent-db-" + System.currentTimeMillis()))
.setConfig("online_backup_enabled", FALSE);
}
/**
* Provide config on a {@link GraphDatabaseBuilder}. Only called iff {@link #configFile()} returns null
.
*
* @param builder to populate config on.
*/
protected void populateConfig(GraphDatabaseBuilder builder) {
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy