package ca.corefacility.bioinformatics.irida.config.data;

import java.util.Properties;

import javax.sql.DataSource;

import org.hibernate.SessionFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
import org.springframework.orm.hibernate4.LocalSessionFactoryBuilder;

import ca.corefacility.bioinformatics.irida.utils.IdentifiableTestEntityRepo;
import ca.corefacility.bioinformatics.irida.utils.IdentifiableTestEntityRepoImpl;

@Configuration
@Profile("test")
public class IridaApiTestDataSourceConfig implements DataConfig {

	@Bean
	public DataSource dataSource() {
		return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.HSQL)
				.build();
	}

	@Bean
	public SessionFactory sessionFactory() {
		LocalSessionFactoryBuilder builder = new LocalSessionFactoryBuilder(
				dataSource());

		builder.scanPackages(
				"ca.corefacility.bioinformatics.irida.model",
				"ca.corefacility.bioinformatics.irida.repositories.relational.auditing",
				"ca.corefacility.bioinformatics.irida.utils");
		Properties properties = new Properties();
		properties.put("hibernate.show_sql", false);
		properties.put("hibernate.hbm2ddl.auto", "create");
		properties
				.put("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");

		builder.addProperties(properties);

		return builder.buildSessionFactory();
	}

	@Bean
	public IdentifiableTestEntityRepo identifiedRepository() {
		return new IdentifiableTestEntityRepoImpl(dataSource(),
				sessionFactory());
	}
}

@@ -52,16 +52,127 @@
 .data;%0A%0A
+import java.io.IOException;%0Aimport java.nio.file.Files;%0Aimport java.nio.file.Path;%0Aimport java.nio.file.Paths;%0A
 import j
@@ -192,16 +192,16 @@
 erties;%0A
-
 %0Aimport 
@@ -650,16 +650,255 @@
 ilder;%0A%0A
+import ca.corefacility.bioinformatics.irida.model.SequenceFile;%0Aimport ca.corefacility.bioinformatics.irida.repositories.CRUDRepository;%0Aimport ca.corefacility.bioinformatics.irida.repositories.filesystem.SequenceFileFilesystemRepository;%0A
 import c
@@ -1149,16 +1149,402 @@
 nfig %7B%0A%0A
+%09@Bean%0A%09public CRUDRepository%3CLong, SequenceFile%3E sequenceFileFilesystemRepository() %7B%0A%09%09Path baseDirectory = Paths.get(%22/tmp%22, %22sequence-files%22);%0A%09%09if (!Files.exists(baseDirectory)) %7B%0A%09%09%09try %7B%0A%09%09%09%09Files.createDirectory(baseDirectory);%0A%09%09%09%7D catch (IOException e) %7B%0A%09%09%09%09e.printStackTrace();%0A%09%09%09%09System.exit(1);%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return new SequenceFileFilesystemRepository(baseDirectory);%0A%09%7D%0A%09%0A
 %09@Bean%0A%09

Add a filesystem repository for the tests that doesn't use the system configured directory.