/** * Constructs a new {@link SessionFactory} by initialising the object-graph mapping meta-data from the given list of domain * object packages, and also sets the baseConfiguration to be used. * <p> * The package names passed to this constructor should not contain wildcards or trailing full stops, for example, * "org.springframework.data.neo4j.example.domain" would be fine. The default behaviour is for sub-packages to be scanned * and you can also specify fully-qualified class names if you want to cherry pick particular classes. * </p> * Indexes will also be checked or built unless auto index mode is set to <code>NONE</code>. * * @param configuration The baseConfiguration to use * @param packages The packages to scan for domain objects. They will be merged with the configuration. */ public SessionFactory(Configuration configuration, String... packages) { this(newConfiguredDriverInstance(configuration), configuration.mergeBasePackagesWith(packages)); if (configuration.getAutoIndex() != NONE) { runAutoIndexManager(configuration); } }
@Test public void mergeBasePackagesShouldWorkWithNullBase() { Configuration configuration = new Configuration.Builder().build(); String[] basePackages = configuration.mergeBasePackagesWith("a", "b"); assertThat(basePackages).containsExactlyInAnyOrder("a", "b"); }
@Test public void mergeBasePackagesShouldRemoveDups() { Configuration configuration = new Configuration.Builder() .withBasePackages("a", "b") .build(); String[] basePackages = configuration.mergeBasePackagesWith("A", "B", "a"); assertThat(basePackages).containsExactlyInAnyOrder("A", "B", "a", "b"); } }
@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 mergeBasePackagesShouldWorkWithEmptyAdditionalPackages() { Configuration configuration = new Configuration.Builder() .withBasePackages("a", "b") .build(); String[] basePackages = configuration.mergeBasePackagesWith(); assertThat(basePackages).containsExactlyInAnyOrder("a", "b"); }