View Javadoc
1   package fr.ifremer.dali;
2   
3   /*-
4    * #%L
5    * Dali :: Core
6    * %%
7    * Copyright (C) 2014 - 2017 Ifremer
8    * %%
9    * This program is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU Affero General Public License as published by
11   * the Free Software Foundation, either version 3 of the License, or
12   * (at your option) any later version.
13   * 
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Public License for more details.
18   * 
19   * You should have received a copy of the GNU Affero General Public License
20   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21   * #L%
22   */
23  
24  import com.google.common.collect.ImmutableList;
25  import com.google.common.collect.Lists;
26  import fr.ifremer.quadrige3.core.config.QuadrigeConfiguration;
27  import fr.ifremer.quadrige3.core.config.QuadrigeCoreConfigurationOption;
28  import fr.ifremer.quadrige3.core.test.InitTests;
29  import fr.ifremer.dali.config.DaliConfiguration;
30  import fr.ifremer.dali.dao.DaliDatabaseResource;
31  import fr.ifremer.dali.service.DaliServiceLocator;
32  import org.apache.commons.logging.Log;
33  import org.apache.commons.logging.LogFactory;
34  
35  import java.util.Arrays;
36  import java.util.List;
37  
38  /**
39   * @author peck7 on 13/10/2017.
40   */
41  public class InitDaliTests extends InitTests {
42  
43      private static final Log LOG = LogFactory.getLog(InitDaliTests.class);
44  
45      public static void main(String[] args) {
46          InitDaliTests initDaliTests = new InitDaliTests();
47          try {
48              initDaliTests.before();
49          } catch (Throwable t) {
50              LOG.error(t.getLocalizedMessage(), t);
51          }
52      }
53  
54      public InitDaliTests() {
55          super();
56          setTargetDbDirectory(DaliDatabaseResource.HSQLDB_SRC_DATABASE_DIRECTORY);
57      }
58  
59      @Override
60      protected void initServiceLocator() {
61          DaliServiceLocator.initDaliDefault();
62      }
63  
64      protected String getModuleName() {
65          return DaliDatabaseResource.MODULE_NAME;
66      }
67  
68      @Override
69      protected String getDbEnumerationResource() {
70          return "classpath*:quadrige3-db-enumerations.properties,classpath*:dali-db-test-enumerations.properties";
71      }
72  
73      @Override
74      protected String[] getConfigArgs() {
75          List<String> args = Lists.newArrayList();
76          args.addAll(Arrays.asList(super.getConfigArgs()));
77          args.addAll(ImmutableList.of("--option", QuadrigeCoreConfigurationOption.AUTHENTICATION_DISABLED.getKey(), Boolean.toString(true)));
78  
79          return args.toArray(new String[args.size()]);
80      }
81  
82  
83      @Override
84      protected QuadrigeConfiguration createConfig() {
85  
86          DaliConfiguration daliConfiguration = new DaliConfiguration(getModuleName() + "-test-write.properties",
87                  getConfigArgs());
88          DaliConfiguration.setInstance(daliConfiguration);
89  
90          return QuadrigeConfiguration.getInstance();
91      }
92  
93  }