1 | package org.expressolivre.cte.email; |
---|
2 | |
---|
3 | import java.io.IOException; |
---|
4 | import java.lang.reflect.InvocationTargetException; |
---|
5 | import java.lang.reflect.Method; |
---|
6 | |
---|
7 | import org.apache.commons.lang.StringUtils; |
---|
8 | import org.expressolivre.cte.common.BaseTestCase; |
---|
9 | import org.expressolivre.cte.common.Config; |
---|
10 | import org.expressolivre.cte.common.IOUtil; |
---|
11 | import org.expressolivre.cte.pages.email.MailPreferencesPage; |
---|
12 | import org.testng.annotations.Parameters; |
---|
13 | import org.testng.annotations.Test; |
---|
14 | |
---|
15 | /** |
---|
16 | * @author L.F.Estivalet (Serpro) |
---|
17 | * |
---|
18 | * Created on Feb 3, 2011 at 11:07:04 AM |
---|
19 | * |
---|
20 | */ |
---|
21 | public class MailPreferencesTestCase extends BaseTestCase { |
---|
22 | |
---|
23 | /** |
---|
24 | * Seta todas as preferencias de acordo com o arquivo configurado em |
---|
25 | * config.properties (propriedade "config.email"). |
---|
26 | * |
---|
27 | * @throws IllegalArgumentException |
---|
28 | * @throws IllegalAccessException |
---|
29 | * @throws InvocationTargetException |
---|
30 | * @throws IOException |
---|
31 | */ |
---|
32 | @Test |
---|
33 | public void setAllPreferences() throws IllegalArgumentException, |
---|
34 | IllegalAccessException, InvocationTargetException, IOException { |
---|
35 | openPreferencesPage(); |
---|
36 | MailPreferencesPage prefs = openEmailPreferencesPage(); |
---|
37 | |
---|
38 | // Clean up the preferences file. |
---|
39 | IOUtil.writeFile("temppref.txt", "", false); |
---|
40 | |
---|
41 | // Percorre todos os metodos "setters" da classe |
---|
42 | // ExpressoMailPreferencesPage para mudar o valor de cada preferencia. |
---|
43 | Method[] methods = MailPreferencesPage.class.getMethods(); |
---|
44 | for (Method method : methods) { |
---|
45 | // Nao pegar os metodos setComboValue e setSavePreferences que nao |
---|
46 | // tem correspondentes no arquivo de configuracao. |
---|
47 | if (method.getName().startsWith("set") |
---|
48 | && !method.getName().equals("setComboValue") |
---|
49 | && !method.getName().equals("setSavePreferences")) { |
---|
50 | String name = StringUtils.uncapitalize(method.getName() |
---|
51 | .substring(3)); |
---|
52 | System.out.println(name); |
---|
53 | |
---|
54 | // Apenas chama o metodo se a preferencia correspondente ao |
---|
55 | // metodo get estiver definida no arquivo de configuracao. |
---|
56 | if (Config.getInstance().getEmailPreference(name) != null) { |
---|
57 | String[] values = Config.getInstance() |
---|
58 | .getEmailPreference(name).split(","); |
---|
59 | System.out.println(name + " " + values[0]); |
---|
60 | |
---|
61 | // Grava apenas as preferencias que o usuario tem disponivel |
---|
62 | // e foram setadas em um arquivo para posterior uso em casos |
---|
63 | // de teste. |
---|
64 | Object response = method.invoke(prefs, values[0]); |
---|
65 | if (response != null) { |
---|
66 | if ((Boolean) response) { |
---|
67 | IOUtil.writeFile( |
---|
68 | "temppref.txt", |
---|
69 | name + System.getProperty("line.separator"), |
---|
70 | true); |
---|
71 | } |
---|
72 | } |
---|
73 | } |
---|
74 | } |
---|
75 | } |
---|
76 | prefs.savePreferences(); |
---|
77 | } |
---|
78 | |
---|
79 | @Test |
---|
80 | @Parameters({ "useImportantFlag" }) |
---|
81 | public void setImportantFlag(String useImportantFlag) { |
---|
82 | openPreferencesPage(); |
---|
83 | MailPreferencesPage prefs = openEmailPreferencesPage(); |
---|
84 | prefs.setUseImportantFlag(useImportantFlag); |
---|
85 | prefs.savePreferences(); |
---|
86 | } |
---|
87 | |
---|
88 | @Test |
---|
89 | @Parameters({ "removeAttachment" }) |
---|
90 | public void setRemoveAttachment(String removeAttachment) { |
---|
91 | openPreferencesPage(); |
---|
92 | MailPreferencesPage prefs = openEmailPreferencesPage(); |
---|
93 | prefs.setRemoveAttachmentsFunction(removeAttachment); |
---|
94 | prefs.savePreferences(); |
---|
95 | } |
---|
96 | |
---|
97 | @Test |
---|
98 | @Parameters({ "returnRecipientDefault" }) |
---|
99 | public void setReturnRecipientDefault(String returnRecipientDefault) { |
---|
100 | openPreferencesPage(); |
---|
101 | MailPreferencesPage prefs = openEmailPreferencesPage(); |
---|
102 | prefs.setReturnRecipientDefault(returnRecipientDefault); |
---|
103 | prefs.savePreferences(); |
---|
104 | } |
---|
105 | |
---|
106 | } |
---|