1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
52
53
54
55
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 }