1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.aludratest.service.file.impl;
17
18 import org.aludratest.config.ConfigProperties;
19 import org.aludratest.config.ConfigProperty;
20 import org.aludratest.config.Preferences;
21 import org.aludratest.exception.AutomationException;
22 import org.aludratest.service.AbstractConfigurableAludraService;
23 import org.aludratest.service.Implementation;
24 import org.aludratest.service.file.FileCondition;
25 import org.aludratest.service.file.FileInteraction;
26 import org.aludratest.service.file.FileService;
27 import org.aludratest.service.file.FileVerification;
28 import org.apache.commons.vfs2.FileSystemException;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32
33
34
35
36 @Implementation({ FileService.class })
37 @ConfigProperties({
38 @ConfigProperty(name = "wait.max.retries", type = int.class, description = "The maximum number of retries when polling files.", defaultValue = ""
39 + FileServiceConfiguration.DEFAULT_WAIT_MAX_RETRIES),
40 @ConfigProperty(name = "wait.timeout", type = int.class, description = "The maximum time to wait when polling, in milliseconds. The retries are distributed over this time", defaultValue = ""
41 + FileServiceConfiguration.DEFAULT_WAIT_TIMEOUT) })
42 public class FileServiceImpl extends AbstractConfigurableAludraService implements FileService {
43
44
45 private static final Logger LOGGER = LoggerFactory.getLogger(FileServiceImpl.class);
46
47 private FileServiceConfiguration configuration;
48
49
50 private FileActionImpl action;
51
52
53 public FileServiceImpl() {
54
55 }
56
57
58
59 @Override
60 public String getPropertiesBaseName() {
61 return "fileService";
62 }
63
64 @Override
65 public void configure(Preferences preferences) throws AutomationException {
66 try {
67 configuration = new FileServiceConfiguration(preferences);
68 }
69 catch (FileSystemException e) {
70 LOGGER.error("Error configuring FileService", e);
71 throw new AutomationException("Error initializing " + this, e);
72 }
73 }
74
75
76 @Override
77 public void initService() {
78 this.action = new FileActionImpl(configuration);
79 }
80
81
82 @Override
83 public void close() {
84 this.configuration.close();
85 }
86
87
88 @Override
89 public FileInteraction perform() {
90 return this.action;
91 }
92
93
94 @Override
95 public FileVerification verify() {
96 return this.action;
97 }
98
99
100 @Override
101 public FileCondition check() {
102 return this.action;
103 }
104
105 @Override
106 public String getDescription() {
107 String description = "Accessing " + configuration.getBaseUrl();
108 if (configuration.getUser() != null) {
109 description += " as user " + configuration.getUser();
110 }
111 return description;
112 }
113
114 }