View Javadoc

1   /*
2    * #%L
3    * Wao :: Business
4    * 
5    * $Id: WaoServices.java 1327 2011-06-09 09:35:04Z bleny $
6    * $HeadURL: http://svn.forge.codelutin.com/svn/wao/tags/wao-3.4.1/wao-business/src/test/java/fr/ifremer/wao/WaoServices.java $
7    * %%
8    * Copyright (C) 2009 - 2010 Ifremer
9    * %%
10   * This program is free software: you can redistribute it and/or modify
11   * it under the terms of the GNU Affero General Public License as published by
12   * the Free Software Foundation, either version 3 of the License, or
13   * (at your option) any later version.
14   * 
15   * This program is distributed in the hope that it will be useful,
16   * but WITHOUT ANY WARRANTY; without even the implied warranty of
17   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18   * GNU General Public License for more details.
19   * 
20   * You should have received a copy of the GNU Affero General Public License
21   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22   * #L%
23   */
24  
25  package fr.ifremer.wao;
26  
27  import fr.ifremer.wao.service.ServiceBoat;
28  import fr.ifremer.wao.service.ServiceCartography;
29  import fr.ifremer.wao.service.ServiceChart;
30  import fr.ifremer.wao.service.ServiceContact;
31  import fr.ifremer.wao.service.ServiceNews;
32  import fr.ifremer.wao.service.ServiceReferential;
33  import fr.ifremer.wao.service.ServiceSampling;
34  import fr.ifremer.wao.service.ServiceSynthesis;
35  import fr.ifremer.wao.service.ServiceUser;
36  import org.apache.commons.io.IOUtils;
37  import org.junit.Ignore;
38  import org.junit.rules.ExternalResource;
39  import org.nuiton.topia.TopiaException;
40  import org.nuiton.util.ApplicationConfig;
41  import org.nuiton.util.DateUtil;
42  import org.slf4j.Logger;
43  import org.slf4j.LoggerFactory;
44  
45  import java.io.IOException;
46  import java.io.InputStream;
47  import java.util.Date;
48  import java.util.Properties;
49  
50  /**
51   * WaoRunnerTest
52   *
53   * Created: 23 nov. 2009
54   *
55   * @author fdesbois <fdesbois@codelutin.com>
56   */
57  public class WaoServices extends ExternalResource {
58  
59      private static final Logger log = LoggerFactory.getLogger(WaoServices.class);
60  
61      private WaoContextImpl context;
62  
63      @Override
64      protected void before() {
65          InputStream input = null;
66          ApplicationConfig configuration;
67          try {
68              input = getClass().getResourceAsStream("/WaoTest.properties");
69              Properties properties = new Properties();
70              properties.load(input);
71              configuration = new ApplicationConfig(properties);
72          } catch (IOException e) {
73              throw new RuntimeException(e);
74          } finally {
75              IOUtils.closeQuietly(input);
76          }
77  
78          context = new WaoContextImpl();
79          context.loadConfiguration(configuration);
80          context.setI18nBundle("wao-business");
81  
82          setCurrentDate(2009, 9, 23);
83  
84          context.start(getServiceUser());
85      }
86  
87      @Override
88      protected void after() {
89          try {
90              context.getTopiaRootContext().clear(true);
91          } catch (TopiaException eee) {
92              throw new RuntimeException(eee);
93          }
94      }
95  
96      public WaoContext getContext() {
97          return context;
98      }
99  
100     public ServiceBoat getServiceBoat() {
101         return context.getServiceFactory().getServiceBoat();
102     }
103 
104     public ServiceReferential getServiceReferential() {
105         return context.getServiceFactory().getServiceReferential();
106     }
107 
108     public ServiceNews getServiceNews() {
109         return context.getServiceFactory().getServiceNews();
110     }
111 
112     public ServiceSampling getServiceSampling() {
113         return context.getServiceFactory().getServiceSampling();
114     }
115 
116     public ServiceSynthesis getServiceSynthesis() {
117         return context.getServiceFactory().getServiceSynthesis();
118     }
119 
120     public ServiceUser getServiceUser() {
121         return context.getServiceFactory().getServiceUser();
122     }
123 
124     public ServiceContact getServiceContact() {
125         return context.getServiceFactory().getServiceContact();
126     }
127 
128     public ServiceCartography getServiceCartography() {
129         return context.getServiceFactory().getServiceCartography();
130     }
131 
132     public ServiceChart getServiceChart() {
133         return context.getServiceFactory().getServiceChart();
134     }
135 
136     public void setCurrentDate(Date date) {
137         context.setCurrentDate(date);
138     }
139 
140     public void setCurrentDate(int day, int month, int year) {
141         Date date = DateUtil.createDate(day, month, year);
142         setCurrentDate(date);
143     }
144 }