View Javadoc

1   /*
2    * #%L
3    * Wao :: Business
4    * %%
5    * Copyright (C) 2009 - 2010 Ifremer
6    * %%
7    * This program is free software: you can redistribute it and/or modify
8    * it under the terms of the GNU Affero General Public License as published by
9    * the Free Software Foundation, either version 3 of the License, or
10   * (at your option) any later version.
11   * 
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Public License for more details.
16   * 
17   * You should have received a copy of the GNU Affero General Public License
18   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19   * #L%
20   */
21  
22  package fr.ifremer.wao.service;
23  
24  import fr.ifremer.wao.WaoServices;
25  import fr.ifremer.wao.bean.ConnectedUser;
26  import fr.ifremer.wao.business.fixtures.ObsMerFixtures;
27  import org.junit.Before;
28  import org.junit.BeforeClass;
29  import org.junit.Rule;
30  import org.slf4j.Logger;
31  import org.slf4j.LoggerFactory;
32  
33  import java.io.File;
34  
35  /**
36   * AbstractServiceTest
37   *
38   * Created: 29 avr. 2010
39   *
40   * @author fdesbois
41   */
42  public abstract class AbstractServiceTest {
43  
44      private static final Logger log =
45                              LoggerFactory.getLogger(AbstractServiceTest.class);
46  
47      protected WaoServices getWaoServices() {
48          // laziness ensure that manager is always available whatever the order
49          // of the rules
50          if (manager == null) {
51              manager = new WaoServices();
52          }
53          return manager;
54      }
55  
56      @Rule
57      public WaoServices manager = getWaoServices();
58  
59      @Rule
60      public ObsMerFixtures obsMerFixtures = new ObsMerFixtures(getWaoServices());
61  
62      @BeforeClass
63      public static void createTempDir() throws Exception {
64          String tmpdir = System.getProperty("java.io.tmpdir");
65          File file = new File(tmpdir);
66          if ( ! file.exists()) {
67              boolean b = file.mkdirs();
68              if (b) {
69                  if (log.isInfoEnabled()) {
70                      log.info("tmp dir : " + file + " was created");
71                  }
72              } else {
73                  if (log.isWarnEnabled()) {
74                      log.warn("Could not create tmp directory : " + file);
75                  }
76              }
77          }
78      }
79  
80  }