1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.webphotos.gui.util.uispec4j;
17
18 import java.io.File;
19 import java.util.Map;
20 import net.sf.webphotos.WebPhotos;
21 import org.uispec4j.Button;
22 import org.uispec4j.ComponentAmbiguityException;
23 import org.uispec4j.ItemNotFoundException;
24 import org.uispec4j.Table;
25 import org.uispec4j.Trigger;
26 import org.uispec4j.UISpec4J;
27 import org.uispec4j.Window;
28 import org.uispec4j.interception.FileChooserHandler;
29 import org.uispec4j.interception.WindowInterceptor;
30 import org.uispec4j.utils.MainClassTrigger;
31
32
33
34
35
36 public class WebPhotosDelegate implements net.sf.webphotos.gui.util.WebPhotosDelegate {
37
38 private static final WebPhotosDelegate WEB_PHOTOS_DELEGATE = new WebPhotosDelegate();
39
40 static {
41 UISpec4J.init();
42 UISpec4J.setWindowInterceptionTimeLimit(30000);
43 }
44 private static Window mainWindow;
45 private static Trigger initialTrigger;
46
47
48
49
50
51
52
53 @Override
54 public void checkIsButtonEnabled(final String button) throws RuntimeException {
55 getButton(button).isEnabled().check();
56 }
57
58
59
60
61
62
63
64
65 @Override
66 public void checkButtonHasText(final String button, final String textShown) throws RuntimeException {
67 getButton(button).textEquals(textShown).check();
68 }
69
70
71
72
73
74
75
76
77 @Override
78 public void checkComboBoxHasText(final String comboBoxName, final String textShown) throws RuntimeException {
79 WebPhotosDelegate.mainWindow.getComboBox(comboBoxName).contains(textShown).check();
80 }
81
82
83
84
85 @Override
86 public void validateMainWindowIsPresent() throws RuntimeException {
87 WebPhotosDelegate.mainWindow.isVisible().check();
88 WebPhotosDelegate.mainWindow.isEnabled().check();
89 }
90
91
92
93
94
95
96 @Override
97 public void tearDownClass() throws Exception {
98 mainWindow.dispose();
99 }
100
101
102
103
104
105
106 @Override
107 public void setUpClass() throws Exception {
108 WebPhotosDelegate.initialTrigger = WindowInterceptor.getModalDialog(new MainClassTrigger(WebPhotos.class, "")).getButton("OK").triggerClick();
109 WebPhotosDelegate.mainWindow = WindowInterceptor.run(WebPhotosDelegate.initialTrigger);
110 }
111
112
113
114
115
116
117
118
119
120 @Override
121 public void addPhotosToAlbumAndCheck(final String[] fileNames, final String buttonName, final File folderNameToVerify, final String fileDialogName) throws RuntimeException {
122 Table tbFotos = addPhotosToAlbum(fileNames, buttonName, folderNameToVerify, fileDialogName);
123 checkPhotosTable(tbFotos, fileNames);
124 }
125
126
127
128
129
130
131
132
133
134 @Override
135 public void fillModalWithText(final String buttonName, final String modalTittle, final String data) throws RuntimeException {
136 WindowInterceptor.init(mainWindowTriggerClick(buttonName)).process(new ModalWindowHandler(modalTittle, data)).run();
137 }
138
139
140
141
142
143
144 public static WebPhotosDelegate getWebPhotosDelegate() {
145 return WEB_PHOTOS_DELEGATE;
146 }
147
148
149
150
151 @Override
152 public void setUp() {
153 }
154
155 @Override
156 public void fillAlbumForm(String albumTitle, String albumDescription, String categoryName, Map<String, String[]> photoData) {
157 mainWindow.getTextBox("txtTitulo").setText(albumTitle);
158 mainWindow.getTextBox("txtDescricao").setText(albumDescription);
159 mainWindow.getComboBox("lstCategoriasAlbum").select(categoryName);
160
161 final Table tbFotos = WebPhotosDelegate.mainWindow.getTable("tbFotos");
162 for (String photoName : photoData.keySet()) {
163 tbFotos.selectRowsWithText(0, photoName);
164 System.out.println("Line Selected (tbFotos.getAwtComponent().getSelectedRow()) : " + tbFotos.getAwtComponent().getSelectedRow());
165 tbFotos.getAwtComponent().setValueAt(photoData.get(photoName)[0], tbFotos.getAwtComponent().getSelectedRow(), 1);
166
167
168
169 mainWindow.getComboBox("lstCreditos").select(photoData.get(photoName)[1]);
170 tbFotos.selectRowsWithText(0, photoName);
171 }
172
173 WindowInterceptor.run(getButton("btNovo").triggerClick());
174
175 }
176
177 @Override
178 public void checkNewAlbum() {
179 Table tbAlbuns = mainWindow.getTable("tbAlbuns");
180 tbAlbuns.rowCountEquals(1).check();
181 }
182
183 private Table addPhotosToAlbum(final String[] fileNames, final String targetButton, final File startUpFolder, final String fileChooserName) throws RuntimeException {
184 FileChooserHandler openDialog = FileChooserHandler.init().titleEquals(fileChooserName).assertAcceptsFilesOnly().assertMultiSelectionEnabled(true).assertCurrentDirEquals(startUpFolder);
185 WindowInterceptor.init(getButton(targetButton).triggerClick()).process(openDialog.select(fileNames)).run();
186 final Table tbFotos = WebPhotosDelegate.mainWindow.getTable("tbFotos");
187 return tbFotos;
188 }
189
190 private Trigger mainWindowTriggerClick(final String buttonName) throws RuntimeException {
191 return getButton(buttonName).triggerClick();
192 }
193
194 private void checkPhotosTable(Table tbFotos, final String[] fileNames) {
195 tbFotos.rowCountEquals(fileNames.length).check();
196 tbFotos.hasHeader().check();
197 tbFotos.columnCountEquals(3).check();
198 for (int i = 0; i < fileNames.length; i++) {
199 System.out.printf("fileNames[%d] = %s", i, fileNames[i]);
200 System.out.println();
201 System.out.printf("tbFotos.getContentAt(%d, 0).toString() = %s", i, tbFotos.getContentAt(i, 0).toString());
202 System.out.println();
203 tbFotos.cellEquals(i + 1, 1, fileNames[i]);
204 }
205 }
206
207 private Button getButton(final String button) throws ItemNotFoundException, ComponentAmbiguityException {
208 return mainWindow.getButton(button);
209 }
210
211
212
213
214 private WebPhotosDelegate() {
215 }
216 }