/*
 * Copyright (c) 2006-2012 by Public Library of Science
 * http://plos.org
 * http://ambraproject.org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.ambraproject.admin;

import org.ambraproject.admin.service.ArticleCrudService;
import org.ambraproject.admin.service.ArticleCrudServiceImpl;
import org.ambraproject.filestore.FileStoreService;
import org.ambraproject.filestore.impl.FileSystemImpl;
import org.ambraproject.testutils.HibernateTestSessionFactory;
import org.apache.commons.dbcp.BasicDataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.orm.hibernate3.LocalSessionFactoryBean;

import javax.sql.DataSource;
import java.io.File;
import java.io.IOException;
import java.util.Properties;

@Configuration
public class TestConfiguration extends BaseConfiguration {

  /**
   * Dummy object for sanity-checking the unit test configuration.
   *
   * @return a dummy object
   */
  @Bean
  public Object sampleBean() {
    return new Object();
  }

  @Bean
  public DataSource dataSource() {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setUrl("jdbc:hsqldb:mem:testdb");
    dataSource.setDriverClassName("org.hsqldb.jdbcDriver");
    return dataSource;
  }

  @Bean
  public LocalSessionFactoryBean sessionFactory(DataSource dataSource) throws IOException {
    LocalSessionFactoryBean bean = new HibernateTestSessionFactory();
    bean.setDataSource(dataSource);
    bean.setSchemaUpdate(true);
    setAmbraMappings(bean);

    Properties hibernateProperties = new Properties();
    hibernateProperties.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
    bean.setHibernateProperties(hibernateProperties);

    return bean;
  }

  @Bean
  public ArticleCrudService articleCrudService() {
    return new ArticleCrudServiceImpl();
  }

  @Bean
  public FileStoreService fileStoreService() throws IOException {
    final String topDir = ""; // Should be "${project.basedir}/target/test-classes/filestore"
    // TODO Configure this with the correct property
    // This can be made to work temporarily by hard-coding a path to an empty temp directory on your machine

    final String domain = ""; // Blank for the test environment
    FileStoreService service = null; // TODO new FileSystemImpl(new File(topDir), domain);
    return service;
  }

}

@@ -2418,335 +2418,541 @@
 %0A%0A  
-@Bean%0A  public FileS
+/**%0A   * Produce the file s
 tore
-S
+ s
 ervice 
-fileStoreService() throws IOException %7B%0A    final String topDir = %22%22; // Should be %22$%7Bproject.basedir%7D/target/test-classes/filestore%22%0A    // TODO Configure this with the correct property%0A    // This can be made to work temporarily by hard-coding a path to an empty temp directory on your machine
+bean.%0A   * %3Cp/%3E%0A   * This bean-getter has a side effect of creating the mock file store directory if it does not already exist. This%0A   * should be fixed if possible. There is no side effect to calling it more than once.%0A   *%0A   * @return the file store service bean%0A   * @throws IOException%0A   */%0A  @Bean%0A  public FileStoreService fileStoreService() throws IOException %7B%0A    final File topDir = new File(%22target/test-classes/filestore/%22);%0A    topDir.mkdirs(); // TODO Obviate this with Maven?
 %0A%0A  
@@ -3047,22 +3047,8 @@
 ce =
- null; // TODO
  new
@@ -3067,24 +3067,14 @@
 mpl(
-new File(
 topDir
-)
 , do

Configure test's fileStoreService to use relative path