source: devel/testlink/automation2.0/src/test/java/org/expressolivre/cte/email/ExpressoMailAdminPreferencesTestCase.java @ 4344

Revision 4344, 2.2 KB checked in by luiz-fernando, 13 years ago (diff)

Ticket #1402 - Novos casos de teste para preferencias administrativas

Line 
1package org.expressolivre.cte.email;
2
3import java.lang.reflect.InvocationTargetException;
4import java.lang.reflect.Method;
5
6import org.apache.commons.lang.StringUtils;
7import org.expressolivre.cte.common.Config;
8import org.expressolivre.cte.common.PreferencesTestCase;
9import org.expressolivre.cte.pages.email.ExpressoMailAdminPreferencesPage;
10import org.testng.annotations.Test;
11
12/**
13 * @author L.F.Estivalet (Serpro)
14 *
15 *         Created on Mai 11, 2011 at 2:07:45 PM
16 *
17 */
18public class ExpressoMailAdminPreferencesTestCase extends PreferencesTestCase {
19
20        /**
21         * Teste deve ser executando somente por usuario administrador.
22         *
23         * @throws IllegalArgumentException
24         * @throws IllegalAccessException
25         * @throws InvocationTargetException
26         */
27        @Test
28        public void test() throws IllegalArgumentException, IllegalAccessException,
29                        InvocationTargetException {
30                openPreferencesPage();
31
32                ExpressoMailAdminPreferencesPage prefs = openEmailAdminPreferencesPage();
33                setPreferences(prefs, "user");
34                prefs = openEmailAdminDefaultPreferencesPage();
35                setPreferences(prefs, "default");
36                prefs = openEmailAdminForcedPreferencesPage();
37                setPreferences(prefs, "forced");
38
39        }
40
41        private void setPreferences(ExpressoMailAdminPreferencesPage prefs,
42                        String pref) throws IllegalArgumentException,
43                        IllegalAccessException, InvocationTargetException {
44                // Percorre todos os metodos "setters" da classe
45                // ExpressoMailAdminPreferencesPage para mudar o valor de cada
46                // preferencia.
47                Method[] methods = ExpressoMailAdminPreferencesPage.class.getMethods();
48                for (Method method : methods) {
49                        // Nao pegar os metodos setComboValue e setSavePreferences que nao
50                        // tem correspondentes no arquivo de configuracao.
51                        if (method.getName().startsWith("set")
52                                        && !method.getName().equals("setComboValue")
53                                        && !method.getName().equals("setSavePreferences")) {
54                                String name = StringUtils.uncapitalize(method.getName()
55                                                .substring(3));
56
57                                if (name.startsWith(pref)) {
58                                        // Apenas chama o metodo se a preferencia correspondente ao
59                                        // metodo get estiver definida no arquivo de configuracao.
60                                        String val = Config.getInstance().getEmailAdminPreference(
61                                                        name);
62                                        if (val != null) {
63                                                method.invoke(prefs, val);
64                                        }
65                                }
66                        }
67                }
68                prefs.savePreferences();
69
70        }
71}
Note: See TracBrowser for help on using the repository browser.