@Test public void shouldConfigureFromFilesystemPropertiesFileURI() throws Exception { File file = new File(getConfigFileAsRelativePath()); FileConfigurationSource source = new FileConfigurationSource(file.toURI().toString()); Configuration configuration = new Configuration.Builder(source).build(); assertThat(configuration.getAutoIndex()).isEqualTo(AutoIndexMode.NONE); assertThat(configuration.getDriverClassName()).isEqualTo("org.neo4j.ogm.drivers.http.driver.HttpDriver"); assertThat(configuration.getCredentials().credentials().toString()).isEqualTo("bmVvNGo6cGFzc3dvcmQ="); assertThat(configuration.getURI()).isEqualTo("http://localhost:7474"); }
@Test public void shouldLoadBoltDriverConfigFromPropertiesFile() { Configuration driverConfig = new Configuration.Builder( new ClasspathConfigurationSource("bolt.driver.properties")).build(); assertThat(driverConfig.getURI()).isEqualTo("bolt://localhost"); assertThat(driverConfig.getConnectionPoolSize()).isEqualTo(150); assertThat(driverConfig.getEncryptionLevel()).isEqualTo("NONE"); assertThat(driverConfig.getTrustStrategy()).isEqualTo("TRUST_ON_FIRST_USE"); assertThat(driverConfig.getTrustCertFile()).isEqualTo("/tmp/cert"); }
@Test public void shouldConfigureCredentialsFromURI() { Configuration configuration = new Configuration.Builder().uri("http://fred:flintstone@localhost:8080").build(); // base 64 encoded credentials, e.g. use echo fred:flintstone | base64 assertThat(configuration.getCredentials().credentials().toString()).isEqualTo("ZnJlZDpmbGludHN0b25l"); assertThat(configuration.getURI()).isEqualTo("http://localhost:8080"); }
@Test public void driverShouldProvideNoopModificationWithoutAnyProvider() { Driver driver = new TestDriver(); driver.configure(new Configuration.Builder().build()); Function<String, String> cypherModification = driver.getCypherModification(); String cypher = "MATCH (n) RETURN n"; assertThat(cypherModification.apply(cypher)).isEqualTo(cypher); }
@Test public void shouldConfigureCredentialsFromURIWithUTF8Characters() { Configuration configuration = new Configuration.Builder() .uri("http://franti\u0161ek:Pass123@localhost:8080") .build(); assertThat(configuration.getCredentials().credentials().toString()).isEqualTo("ZnJhbnRpxaFlazpQYXNzMTIz"); }
@Test(expected = Exception.class) public void shouldThrowExceptionWhenEmbeddedDriverCannotConnect() { Configuration configuration = new Configuration.Builder( new ClasspathConfigurationSource("ogm-embedded-invalid.properties")).build(); SessionFactory sessionFactory = new SessionFactory(configuration, "org.neo4j.ogm.domain.social"); Session session = sessionFactory.openSession(); session.purgeDatabase(); }
@BeforeClass public static void initSessionFactory() { Driver driver = new HttpDriver(); driver.configure(new Configuration.Builder().uri(serverControls.httpURI().toString()).build()); sessionFactory = new SessionFactory(driver, DOMAIN_PACKAGE); }
public static GraphDatabaseService getGraphDatabaseService() { // if using an embedded config, return the db from the driver if (baseConfiguration.build().getURI().startsWith("file")) { if (driver != null) { return driver.unwrap(GraphDatabaseService.class); } else if (sessionFactory != null) { return sessionFactory.unwrap(GraphDatabaseService.class); } } // else (bolt, http), return just a test server (not really used except for indices ?) return testServer.getGraphDatabaseService(); }
@Test public void shouldPreserveNoneConfiguration() { Configuration configuration = getBaseConfiguration().autoIndex("none").build(); assertThat(configuration.getAutoIndex()).isEqualTo(AutoIndexMode.NONE); }
@Test public void shouldParseEmbeddedUriSchemeCaseInsensitive() { Configuration configuration = new Configuration.Builder() .uri("FILE:///somewhere") .build(); assertThat(configuration.getDriverClassName()) .isEqualTo("org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver"); assertThat(configuration.getURI()).isEqualTo("FILE:///somewhere"); }
@Test public void shouldLoadEmbeddedDriverConfigFromPropertiesFile() { Configuration driverConfig = new Configuration.Builder( new ClasspathConfigurationSource("embedded.driver.properties")).build(); assertThat(driverConfig.getURI()).isEqualTo("file:///var/tmp/neo4j.db"); }
@Test public void shouldLoadHttpDriverConfigFromPropertiesFile() { Configuration driverConfig = new Configuration.Builder( new ClasspathConfigurationSource("http.driver.properties")).build(); assertThat(driverConfig.getURI()).isEqualTo("http://localhost:7474"); }
@Test(expected = Exception.class) public void shouldThrowExceptionWhenBoltDriverCannotConnect() { Configuration configuration = new Configuration.Builder( new ClasspathConfigurationSource("ogm-bolt-invalid.properties")).build(); SessionFactory sessionFactory = new SessionFactory(configuration, "org.neo4j.ogm.domain.social"); Session session = sessionFactory.openSession(); session.purgeDatabase(); } }
@Test public void shouldLoadHaBasedOnNeo4ConfFile() { assumeTrue(canRunHATests()); try (EmbeddedDriver driver = new EmbeddedDriver()) { driver.configure(new Configuration.Builder().neo4jConfLocation("classpath:custom-neo4j-ha.conf").build()); GraphDatabaseService databaseService = driver.unwrap(GraphDatabaseService.class); assertThat(databaseService.getClass().getSimpleName()).isEqualTo(NAME_OF_HA_DATABASE_CLASS); } }
@Test public void shouldCreateImpermanentInstanceWhenNoURI() { Configuration configuration = new Configuration.Builder().build(); try (EmbeddedDriver driver = new EmbeddedDriver()) { driver.configure(configuration); assertThat(configuration.getURI()).isNull(); assertThat(driver.unwrap(GraphDatabaseService.class)).isNotNull(); } }
@BeforeClass public static void initSessionFactory() { Driver driver = new EmbeddedDriver(serverControls.graph(), new Configuration.Builder().build()); sessionFactory = new SessionFactory(driver, DOMAIN_PACKAGE); }
@Test @Ignore("this needs local causal cluster running") public void connectToCCUsingConfiguration() throws Exception { Configuration configuration = new Configuration.Builder() .uri("bolt+routing://localhost:1023") .uris(new String[] { "bolt+routing://localhost:7688", "bolt+routing://localhost:7687", "bolt+routing://localhost:7689" }) .verifyConnection(true) .build(); new SessionFactory(configuration, "org.neo4j.ogm.domain.social"); }
@Test public void mergeBasePackagesShouldWorkDealWithNulls() { Configuration configuration = new Configuration.Builder() .withBasePackages("a", null, "b") .build(); String[] basePackages = configuration.mergeBasePackagesWith(null, "c"); assertThat(basePackages).containsExactlyInAnyOrder("a", "b", "c"); }
@Test public void shouldHandleCustomConfFiles() { try (EmbeddedDriver driver = new EmbeddedDriver()) { driver.configure(new Configuration.Builder().neo4jConfLocation("classpath:custom-neo4j.conf").build()); GraphDatabaseService databaseService = driver.unwrap(GraphDatabaseService.class); assertReadOnly(databaseService); } }
@Test(expected = ConnectionException.class) public void shouldThrowServiceUnavailableWhenServerIsOfflineAndVerifyIsTrue() { Configuration configuration = configBuilder.verifyConnection(true) .build(); new SessionFactory(configuration, User.class.getPackage().getName()); }