[3782] | 1 | package org.expressolivre.cte.email; |
---|
[3745] | 2 | |
---|
[4780] | 3 | import java.io.IOException; |
---|
[3745] | 4 | import java.lang.reflect.InvocationTargetException; |
---|
| 5 | import java.lang.reflect.Method; |
---|
| 6 | |
---|
| 7 | import org.apache.commons.lang.StringUtils; |
---|
[4864] | 8 | import org.expressolivre.cte.common.BaseEmailTestCase; |
---|
[3782] | 9 | import org.expressolivre.cte.common.Config; |
---|
[4780] | 10 | import org.expressolivre.cte.common.IOUtil; |
---|
[4627] | 11 | import org.expressolivre.cte.pages.email.MailPreferencesPage; |
---|
[4675] | 12 | import org.testng.annotations.Parameters; |
---|
[3745] | 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 | */ |
---|
[4864] | 21 | public class MailPreferencesTestCase extends BaseEmailTestCase { |
---|
[3745] | 22 | |
---|
[4675] | 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 |
---|
[4780] | 30 | * @throws IOException |
---|
[4675] | 31 | */ |
---|
[3745] | 32 | @Test |
---|
[4675] | 33 | public void setAllPreferences() throws IllegalArgumentException, |
---|
[4780] | 34 | IllegalAccessException, InvocationTargetException, IOException { |
---|
[3789] | 35 | openPreferencesPage(); |
---|
[4627] | 36 | MailPreferencesPage prefs = openEmailPreferencesPage(); |
---|
[3745] | 37 | |
---|
[4780] | 38 | // Clean up the preferences file. |
---|
| 39 | IOUtil.writeFile("temppref.txt", "", false); |
---|
| 40 | |
---|
[3799] | 41 | // Percorre todos os metodos "setters" da classe |
---|
| 42 | // ExpressoMailPreferencesPage para mudar o valor de cada preferencia. |
---|
[4627] | 43 | Method[] methods = MailPreferencesPage.class.getMethods(); |
---|
[3745] | 44 | for (Method method : methods) { |
---|
[3799] | 45 | // Nao pegar os metodos setComboValue e setSavePreferences que nao |
---|
| 46 | // tem correspondentes no arquivo de configuracao. |
---|
[3745] | 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); |
---|
[3799] | 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]); |
---|
[4780] | 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 | } |
---|
[3799] | 73 | } |
---|
[3745] | 74 | } |
---|
| 75 | } |
---|
[3789] | 76 | prefs.savePreferences(); |
---|
[4675] | 77 | } |
---|
[3745] | 78 | |
---|
[4675] | 79 | @Test |
---|
| 80 | @Parameters({ "useImportantFlag" }) |
---|
| 81 | public void setImportantFlag(String useImportantFlag) { |
---|
| 82 | openPreferencesPage(); |
---|
| 83 | MailPreferencesPage prefs = openEmailPreferencesPage(); |
---|
| 84 | prefs.setUseImportantFlag(useImportantFlag); |
---|
| 85 | prefs.savePreferences(); |
---|
[3745] | 86 | } |
---|
| 87 | |
---|
[4675] | 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 | |
---|
[4780] | 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 | |
---|
[3745] | 106 | } |
---|