Commit 4c48f361344329669cbe86e1814755d551712442

Authored by Ednara Oliveira
1 parent 355a0955
Exists in master

Testes de lifecycle

impl/core/src/test/java/lifecycle/LifecycleClassWithPriority.java 0 → 100644
... ... @@ -0,0 +1,89 @@
  1 +/*
  2 + * Demoiselle Framework
  3 + * Copyright (C) 2010 SERPRO
  4 + * ----------------------------------------------------------------------------
  5 + * This file is part of Demoiselle Framework.
  6 + *
  7 + * Demoiselle Framework is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public License version 3
  9 + * as published by the Free Software Foundation.
  10 + *
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License version 3
  17 + * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + * Fifth Floor, Boston, MA 02110-1301, USA.
  20 + * ----------------------------------------------------------------------------
  21 + * Este arquivo é parte do Framework Demoiselle.
  22 + *
  23 + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + * do Software Livre (FSF).
  26 + *
  27 + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + * para maiores detalhes.
  31 + *
  32 + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 + */
  37 +package lifecycle;
  38 +
  39 +import static br.gov.frameworkdemoiselle.annotation.Priority.MAX_PRIORITY;
  40 +import static br.gov.frameworkdemoiselle.annotation.Priority.MIN_PRIORITY;
  41 +
  42 +import java.util.ArrayList;
  43 +import java.util.List;
  44 +
  45 +import javax.enterprise.context.ApplicationScoped;
  46 +
  47 +import br.gov.frameworkdemoiselle.annotation.Priority;
  48 +import br.gov.frameworkdemoiselle.lifecycle.Shutdown;
  49 +import br.gov.frameworkdemoiselle.lifecycle.Startup;
  50 +
  51 +@ApplicationScoped
  52 +public class LifecycleClassWithPriority {
  53 +
  54 + private List<Integer> priorityStartup = new ArrayList<Integer>();
  55 +
  56 + private List<Integer> priorityShutdown = new ArrayList<Integer>();
  57 +
  58 + public List<Integer> getPriorityStartup() {
  59 + return priorityStartup;
  60 + }
  61 +
  62 + public List<Integer> getPriorityShutdown() {
  63 + return priorityShutdown;
  64 + }
  65 +
  66 + @Startup
  67 + @Priority(MIN_PRIORITY)
  68 + public void loadWithMinPriority() {
  69 + priorityStartup.add(2);
  70 + }
  71 +
  72 + @Startup
  73 + @Priority(MAX_PRIORITY)
  74 + public void loadWithMaxPriority() {
  75 + priorityStartup.add(1);
  76 + }
  77 +
  78 + @Shutdown
  79 + @Priority(MIN_PRIORITY)
  80 + public void unloadWithMinPriority() {
  81 + priorityShutdown.add(1);
  82 + }
  83 +
  84 + @Shutdown
  85 + @Priority(MAX_PRIORITY)
  86 + public void unloadWithMaxPriority() {
  87 + priorityShutdown.add(2);
  88 + }
  89 +}
... ...
impl/core/src/test/java/lifecycle/LifecycleSimple.java 0 → 100644
... ... @@ -0,0 +1,68 @@
  1 +/*
  2 + * Demoiselle Framework
  3 + * Copyright (C) 2010 SERPRO
  4 + * ----------------------------------------------------------------------------
  5 + * This file is part of Demoiselle Framework.
  6 + *
  7 + * Demoiselle Framework is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public License version 3
  9 + * as published by the Free Software Foundation.
  10 + *
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License version 3
  17 + * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + * Fifth Floor, Boston, MA 02110-1301, USA.
  20 + * ----------------------------------------------------------------------------
  21 + * Este arquivo é parte do Framework Demoiselle.
  22 + *
  23 + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + * do Software Livre (FSF).
  26 + *
  27 + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + * para maiores detalhes.
  31 + *
  32 + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 + */
  37 +package lifecycle;
  38 +
  39 +import javax.enterprise.context.ApplicationScoped;
  40 +
  41 +import br.gov.frameworkdemoiselle.lifecycle.Shutdown;
  42 +import br.gov.frameworkdemoiselle.lifecycle.Startup;
  43 +
  44 +@ApplicationScoped
  45 +public class LifecycleSimple {
  46 +
  47 + private boolean startup = false;
  48 +
  49 + private boolean shutdown = false;
  50 +
  51 + public boolean isStartup() {
  52 + return startup;
  53 + }
  54 +
  55 + public boolean isShutdown() {
  56 + return shutdown;
  57 + }
  58 +
  59 + @Startup
  60 + public void load() {
  61 + startup = true;
  62 + }
  63 +
  64 + @Shutdown
  65 + public void unload() {
  66 + shutdown = true;
  67 + }
  68 +}
... ...
impl/core/src/test/java/lifecycle/LifecycleSimpleTest.java 0 → 100644
... ... @@ -0,0 +1,83 @@
  1 +/*
  2 + * Demoiselle Framework
  3 + * Copyright (C) 2010 SERPRO
  4 + * ----------------------------------------------------------------------------
  5 + * This file is part of Demoiselle Framework.
  6 + *
  7 + * Demoiselle Framework is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public License version 3
  9 + * as published by the Free Software Foundation.
  10 + *
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License version 3
  17 + * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + * Fifth Floor, Boston, MA 02110-1301, USA.
  20 + * ----------------------------------------------------------------------------
  21 + * Este arquivo é parte do Framework Demoiselle.
  22 + *
  23 + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + * do Software Livre (FSF).
  26 + *
  27 + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + * para maiores detalhes.
  31 + *
  32 + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 + */
  37 +package lifecycle;
  38 +
  39 +import javax.inject.Inject;
  40 +
  41 +import junit.framework.Assert;
  42 +
  43 +import org.jboss.arquillian.container.test.api.Deployment;
  44 +import org.jboss.arquillian.junit.Arquillian;
  45 +import org.jboss.shrinkwrap.api.spec.JavaArchive;
  46 +import org.junit.Test;
  47 +import org.junit.runner.RunWith;
  48 +
  49 +import test.Tests;
  50 +import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess;
  51 +import br.gov.frameworkdemoiselle.lifecycle.AfterStartupProccess;
  52 +import br.gov.frameworkdemoiselle.util.Beans;
  53 +
  54 +@RunWith(Arquillian.class)
  55 +public class LifecycleSimpleTest {
  56 +
  57 + @Inject
  58 + private LifecycleSimple simpleClass;
  59 +
  60 + @Deployment
  61 + public static JavaArchive createDeployment() {
  62 + JavaArchive deployment = Tests.createDeployment(LifecycleSimpleTest.class);
  63 + return deployment;
  64 + }
  65 +
  66 + @Test
  67 + public void testStartup() {
  68 + Beans.getBeanManager().fireEvent(new AfterStartupProccess() {
  69 + });
  70 +
  71 + Assert.assertEquals(true, simpleClass.isStartup());
  72 + }
  73 +
  74 + @Test
  75 + public void testShutdown() {
  76 + Beans.getBeanManager().fireEvent(new AfterShutdownProccess() {
  77 + });
  78 +
  79 + Assert.assertEquals(true, simpleClass.isShutdown());
  80 + }
  81 +
  82 +}
  83 +
... ...
impl/core/src/test/java/lifecycle/LifecycleWithPriorityTest.java 0 → 100644
... ... @@ -0,0 +1,91 @@
  1 +/*
  2 + * Demoiselle Framework
  3 + * Copyright (C) 2010 SERPRO
  4 + * ----------------------------------------------------------------------------
  5 + * This file is part of Demoiselle Framework.
  6 + *
  7 + * Demoiselle Framework is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public License version 3
  9 + * as published by the Free Software Foundation.
  10 + *
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License version 3
  17 + * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + * Fifth Floor, Boston, MA 02110-1301, USA.
  20 + * ----------------------------------------------------------------------------
  21 + * Este arquivo é parte do Framework Demoiselle.
  22 + *
  23 + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + * do Software Livre (FSF).
  26 + *
  27 + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + * para maiores detalhes.
  31 + *
  32 + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 + */
  37 +package lifecycle;
  38 +
  39 +import java.util.ArrayList;
  40 +import java.util.List;
  41 +
  42 +import javax.inject.Inject;
  43 +
  44 +import junit.framework.Assert;
  45 +
  46 +import org.jboss.arquillian.container.test.api.Deployment;
  47 +import org.jboss.arquillian.junit.Arquillian;
  48 +import org.jboss.shrinkwrap.api.spec.JavaArchive;
  49 +import org.junit.Test;
  50 +import org.junit.runner.RunWith;
  51 +
  52 +import test.Tests;
  53 +import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess;
  54 +import br.gov.frameworkdemoiselle.lifecycle.AfterStartupProccess;
  55 +import br.gov.frameworkdemoiselle.util.Beans;
  56 +
  57 +@RunWith(Arquillian.class)
  58 +public class LifecycleWithPriorityTest {
  59 +
  60 + @Inject
  61 + private LifecycleClassWithPriority lifecycleClassWithPriority;
  62 +
  63 + List<Integer> expected = new ArrayList<Integer>();
  64 +
  65 + @Deployment
  66 + public static JavaArchive createDeployment() {
  67 + JavaArchive deployment = Tests.createDeployment(LifecycleWithPriorityTest.class);
  68 + return deployment;
  69 + }
  70 +
  71 + @Test
  72 + public void testStartup() {
  73 + Beans.getBeanManager().fireEvent(new AfterStartupProccess() {
  74 + });
  75 + expected.add(1);
  76 + expected.add(2);
  77 +
  78 + Assert.assertEquals(expected, lifecycleClassWithPriority.getPriorityStartup());
  79 + }
  80 +
  81 + @Test
  82 + public void testShutdown() {
  83 + Beans.getBeanManager().fireEvent(new AfterShutdownProccess() {
  84 + });
  85 + expected.clear();
  86 + expected.add(2);
  87 + expected.add(1);
  88 +
  89 + Assert.assertEquals(expected, lifecycleClassWithPriority.getPriorityShutdown());
  90 + }
  91 +}
... ...
impl/core/src/test/java/lifecycle/LifecycleWithoutPriority.java 0 → 100644
... ... @@ -0,0 +1,92 @@
  1 +/*
  2 + * Demoiselle Framework
  3 + * Copyright (C) 2010 SERPRO
  4 + * ----------------------------------------------------------------------------
  5 + * This file is part of Demoiselle Framework.
  6 + *
  7 + * Demoiselle Framework is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public License version 3
  9 + * as published by the Free Software Foundation.
  10 + *
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License version 3
  17 + * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + * Fifth Floor, Boston, MA 02110-1301, USA.
  20 + * ----------------------------------------------------------------------------
  21 + * Este arquivo é parte do Framework Demoiselle.
  22 + *
  23 + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + * do Software Livre (FSF).
  26 + *
  27 + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + * para maiores detalhes.
  31 + *
  32 + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 + */
  37 +package lifecycle;
  38 +
  39 +import java.util.ArrayList;
  40 +import java.util.List;
  41 +
  42 +import javax.enterprise.context.ApplicationScoped;
  43 +
  44 +import br.gov.frameworkdemoiselle.lifecycle.Shutdown;
  45 +import br.gov.frameworkdemoiselle.lifecycle.Startup;
  46 +
  47 +@ApplicationScoped
  48 +public class LifecycleWithoutPriority {
  49 +
  50 + private List<Integer> priorityStartup = new ArrayList<Integer>();
  51 +
  52 + private List<Integer> priorityShutdown = new ArrayList<Integer>();
  53 +
  54 + public List<Integer> getPriorityStartup() {
  55 + return priorityStartup;
  56 + }
  57 +
  58 + public List<Integer> getPriorityShutdown() {
  59 + return priorityShutdown;
  60 + }
  61 +
  62 + @Startup
  63 + public void loadWithoutPriorityFirst() {
  64 + priorityStartup.add(1);
  65 + }
  66 +
  67 + @Startup
  68 + public void loadWithoutPrioritySecond() {
  69 + priorityStartup.add(3);
  70 + }
  71 +
  72 + @Startup
  73 + public void loadWithoutPriorityThird() {
  74 + priorityStartup.add(2);
  75 + }
  76 +
  77 + @Shutdown
  78 + public void unloadWithoutPriorityFirst() {
  79 + priorityShutdown.add(3);
  80 + }
  81 +
  82 + @Shutdown
  83 + public void unloadWithoutPrioritySecond() {
  84 + priorityShutdown.add(2);
  85 + }
  86 +
  87 + @Shutdown
  88 + public void unloadWithoutPriorityThird() {
  89 + priorityShutdown.add(1);
  90 + }
  91 +
  92 +}
... ...
impl/core/src/test/java/lifecycle/LifecycleWithoutPriorityTest.java 0 → 100644
... ... @@ -0,0 +1,94 @@
  1 +/*
  2 + * Demoiselle Framework
  3 + * Copyright (C) 2010 SERPRO
  4 + * ----------------------------------------------------------------------------
  5 + * This file is part of Demoiselle Framework.
  6 + *
  7 + * Demoiselle Framework is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public License version 3
  9 + * as published by the Free Software Foundation.
  10 + *
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License version 3
  17 + * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + * Fifth Floor, Boston, MA 02110-1301, USA.
  20 + * ----------------------------------------------------------------------------
  21 + * Este arquivo é parte do Framework Demoiselle.
  22 + *
  23 + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + * do Software Livre (FSF).
  26 + *
  27 + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + * para maiores detalhes.
  31 + *
  32 + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 + */
  37 +package lifecycle;
  38 +
  39 +import java.util.ArrayList;
  40 +import java.util.List;
  41 +
  42 +import javax.inject.Inject;
  43 +
  44 +import junit.framework.Assert;
  45 +
  46 +import org.jboss.arquillian.container.test.api.Deployment;
  47 +import org.jboss.arquillian.junit.Arquillian;
  48 +import org.jboss.shrinkwrap.api.spec.JavaArchive;
  49 +import org.junit.Test;
  50 +import org.junit.runner.RunWith;
  51 +
  52 +import test.Tests;
  53 +import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess;
  54 +import br.gov.frameworkdemoiselle.lifecycle.AfterStartupProccess;
  55 +import br.gov.frameworkdemoiselle.util.Beans;
  56 +
  57 +@RunWith(Arquillian.class)
  58 +public class LifecycleWithoutPriorityTest {
  59 +
  60 + @Inject
  61 + private LifecycleWithoutPriority lifecycleWithoutPriority;
  62 +
  63 + List<Integer> expected = new ArrayList<Integer>();
  64 +
  65 + @Deployment
  66 + public static JavaArchive createDeployment() {
  67 + JavaArchive deployment = Tests.createDeployment(LifecycleWithoutPriorityTest.class);
  68 + return deployment;
  69 + }
  70 +
  71 + @Test
  72 + public void testStartup() {
  73 + Beans.getBeanManager().fireEvent(new AfterStartupProccess() {
  74 + });
  75 + expected.add(1);
  76 + expected.add(3);
  77 + expected.add(2);
  78 +
  79 + Assert.assertEquals(expected, lifecycleWithoutPriority.getPriorityStartup());
  80 + }
  81 +
  82 + @Test
  83 + public void testShutdown() {
  84 + Beans.getBeanManager().fireEvent(new AfterShutdownProccess() {
  85 + });
  86 + expected.clear();
  87 + expected.add(3);
  88 + expected.add(2);
  89 + expected.add(1);
  90 +
  91 + Assert.assertEquals(expected, lifecycleWithoutPriority.getPriorityShutdown());
  92 + }
  93 +
  94 +}
... ...