1 | package org.expressolivre.cte.email; |
---|
2 | |
---|
3 | import java.lang.reflect.InvocationTargetException; |
---|
4 | import java.lang.reflect.Method; |
---|
5 | |
---|
6 | import org.apache.commons.lang.StringUtils; |
---|
7 | import org.expressolivre.cte.common.BaseTestCase; |
---|
8 | import org.expressolivre.cte.common.Config; |
---|
9 | import org.expressolivre.cte.pages.email.MailPreferencesPage; |
---|
10 | import org.testng.annotations.Parameters; |
---|
11 | import org.testng.annotations.Test; |
---|
12 | |
---|
13 | /** |
---|
14 | * @author L.F.Estivalet (Serpro) |
---|
15 | * |
---|
16 | * Created on Feb 3, 2011 at 11:07:04 AM |
---|
17 | * |
---|
18 | */ |
---|
19 | public class MailPreferencesTestCase extends BaseTestCase { |
---|
20 | |
---|
21 | /** |
---|
22 | * Seta todas as preferencias de acordo com o arquivo configurado em |
---|
23 | * config.properties (propriedade "config.email"). |
---|
24 | * |
---|
25 | * @throws IllegalArgumentException |
---|
26 | * @throws IllegalAccessException |
---|
27 | * @throws InvocationTargetException |
---|
28 | */ |
---|
29 | @Test |
---|
30 | public void setAllPreferences() throws IllegalArgumentException, |
---|
31 | IllegalAccessException, InvocationTargetException { |
---|
32 | openPreferencesPage(); |
---|
33 | MailPreferencesPage prefs = openEmailPreferencesPage(); |
---|
34 | |
---|
35 | // Percorre todos os metodos "setters" da classe |
---|
36 | // ExpressoMailPreferencesPage para mudar o valor de cada preferencia. |
---|
37 | Method[] methods = MailPreferencesPage.class.getMethods(); |
---|
38 | for (Method method : methods) { |
---|
39 | // Nao pegar os metodos setComboValue e setSavePreferences que nao |
---|
40 | // tem correspondentes no arquivo de configuracao. |
---|
41 | if (method.getName().startsWith("set") |
---|
42 | && !method.getName().equals("setComboValue") |
---|
43 | && !method.getName().equals("setSavePreferences")) { |
---|
44 | String name = StringUtils.uncapitalize(method.getName() |
---|
45 | .substring(3)); |
---|
46 | System.out.println(name); |
---|
47 | |
---|
48 | // Apenas chama o metodo se a preferencia correspondente ao |
---|
49 | // metodo get estiver definida no arquivo de configuracao. |
---|
50 | if (Config.getInstance().getEmailPreference(name) != null) { |
---|
51 | String[] values = Config.getInstance() |
---|
52 | .getEmailPreference(name).split(","); |
---|
53 | System.out.println(name + " " + values[0]); |
---|
54 | method.invoke(prefs, values[0]); |
---|
55 | } |
---|
56 | } |
---|
57 | } |
---|
58 | prefs.savePreferences(); |
---|
59 | } |
---|
60 | |
---|
61 | @Test |
---|
62 | @Parameters({ "useImportantFlag" }) |
---|
63 | public void setImportantFlag(String useImportantFlag) { |
---|
64 | openPreferencesPage(); |
---|
65 | MailPreferencesPage prefs = openEmailPreferencesPage(); |
---|
66 | prefs.setUseImportantFlag(useImportantFlag); |
---|
67 | prefs.savePreferences(); |
---|
68 | } |
---|
69 | |
---|
70 | @Test |
---|
71 | @Parameters({ "removeAttachment" }) |
---|
72 | public void setRemoveAttachment(String removeAttachment) { |
---|
73 | openPreferencesPage(); |
---|
74 | MailPreferencesPage prefs = openEmailPreferencesPage(); |
---|
75 | prefs.setRemoveAttachmentsFunction(removeAttachment); |
---|
76 | prefs.savePreferences(); |
---|
77 | } |
---|
78 | |
---|
79 | } |
---|