Commit 772890eba4811492197a51c11547e820a6f602af

Authored by Emerson Oliveira
1 parent 71b4c9a7
Exists in master

Adição de testes para execução do rollback na transação.

impl/core/src/test/java/transaction/rollback/DummyStrategy.java 0 → 100644
... ... @@ -0,0 +1,88 @@
  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 transaction.rollback;
  38 +
  39 +import br.gov.frameworkdemoiselle.transaction.Transaction;
  40 +
  41 +public class DummyStrategy implements Transaction {
  42 +
  43 + private static final long serialVersionUID = 1L;
  44 +
  45 + private boolean markedRollback = false;
  46 +
  47 + private boolean active = false;
  48 +
  49 + @Override
  50 + public boolean isActive() {
  51 + TransactionManager.setTransactionPassedInIsActiveMethod(true);
  52 + return active;
  53 + }
  54 +
  55 + @Override
  56 + public boolean isMarkedRollback() {
  57 + TransactionManager.setTransactionPassedInIsMarkedRollbackMethod(true);
  58 + return markedRollback;
  59 + }
  60 +
  61 + @Override
  62 + public void begin() {
  63 + TransactionManager.setTransactionPassedInBeginMethod(true);
  64 + active = true;
  65 + TransactionManager.setTransactionActive(true);
  66 + }
  67 +
  68 + @Override
  69 + public void commit() {
  70 + TransactionManager.setTransactionPassedInCommitMethod(true);
  71 + active = false;
  72 + TransactionManager.setTransactionActive(false);
  73 + }
  74 +
  75 + @Override
  76 + public void rollback() {
  77 + TransactionManager.setTransactionPassedInRollbackMethod(true);
  78 + active = false;
  79 + TransactionManager.setTransactionActive(false);
  80 + }
  81 +
  82 + @Override
  83 + public void setRollbackOnly() {
  84 + TransactionManager.setTransactionPassedInSetRollbackOnlyMethod(true);
  85 + markedRollback = true;
  86 + TransactionManager.setTransactionMarkedRollback(true);
  87 + }
  88 +}
... ...
impl/core/src/test/java/transaction/rollback/TransactionExceptionWithDefaultRollback.java 0 → 100644
... ... @@ -0,0 +1,45 @@
  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 transaction.rollback;
  38 +
  39 +import br.gov.frameworkdemoiselle.exception.ApplicationException;
  40 +
  41 +@ApplicationException
  42 +public class TransactionExceptionWithDefaultRollback extends RuntimeException {
  43 +
  44 + private static final long serialVersionUID = 1L;
  45 +}
... ...
impl/core/src/test/java/transaction/rollback/TransactionExceptionWithRollback.java 0 → 100644
... ... @@ -0,0 +1,45 @@
  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 transaction.rollback;
  38 +
  39 +import br.gov.frameworkdemoiselle.exception.ApplicationException;
  40 +
  41 +@ApplicationException(rollback = true)
  42 +public class TransactionExceptionWithRollback extends RuntimeException {
  43 +
  44 + private static final long serialVersionUID = 1L;
  45 +}
... ...
impl/core/src/test/java/transaction/rollback/TransactionExceptionWithoutRollback.java 0 → 100644
... ... @@ -0,0 +1,45 @@
  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 transaction.rollback;
  38 +
  39 +import br.gov.frameworkdemoiselle.exception.ApplicationException;
  40 +
  41 +@ApplicationException(rollback = false)
  42 +public class TransactionExceptionWithoutRollback extends RuntimeException {
  43 +
  44 + private static final long serialVersionUID = 1L;
  45 +}
... ...
impl/core/src/test/java/transaction/rollback/TransactionManager.java 0 → 100644
... ... @@ -0,0 +1,131 @@
  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 transaction.rollback;
  38 +
  39 +public class TransactionManager {
  40 +
  41 + private static boolean transactionMarkedRollback;
  42 +
  43 + private static boolean transactionActive;
  44 +
  45 + private static boolean transactionPassedInIsActiveMethod;
  46 +
  47 + private static boolean transactionPassedInIsMarkedRollbackMethod;
  48 +
  49 + private static boolean transactionPassedInBeginMethod;
  50 +
  51 + private static boolean transactionPassedInCommitMethod;
  52 +
  53 + private static boolean transactionPassedInRollbackMethod;
  54 +
  55 + private static boolean transactionPassedInSetRollbackOnlyMethod;
  56 +
  57 + public void clean() {
  58 + setTransactionMarkedRollback(false);
  59 + setTransactionActive(false);
  60 + setTransactionPassedInIsActiveMethod(false);
  61 + setTransactionPassedInIsMarkedRollbackMethod(false);
  62 + setTransactionPassedInBeginMethod(false);
  63 + setTransactionPassedInCommitMethod(false);
  64 + setTransactionPassedInRollbackMethod(false);
  65 + setTransactionPassedInSetRollbackOnlyMethod(false);
  66 + }
  67 +
  68 + public boolean isTransactionMarkedRollback() {
  69 + return transactionMarkedRollback;
  70 + }
  71 +
  72 + public boolean isTransactionActive() {
  73 + return transactionActive;
  74 + }
  75 +
  76 + public boolean isTransactionPassedInIsActiveMethod() {
  77 + return transactionPassedInIsActiveMethod;
  78 + }
  79 +
  80 + public boolean isTransactionPassedInIsMarkedRollbackMethod() {
  81 + return transactionPassedInIsMarkedRollbackMethod;
  82 + }
  83 +
  84 + public boolean isTransactionPassedInBeginMethod() {
  85 + return transactionPassedInBeginMethod;
  86 + }
  87 +
  88 + public boolean isTransactionPassedInCommitMethod() {
  89 + return transactionPassedInCommitMethod;
  90 + }
  91 +
  92 + public boolean isTransactionPassedInRollbackMethod() {
  93 + return transactionPassedInRollbackMethod;
  94 + }
  95 +
  96 + public boolean isTransactionPassedInSetRollbackOnlyMethod() {
  97 + return transactionPassedInSetRollbackOnlyMethod;
  98 + }
  99 +
  100 + public static void setTransactionMarkedRollback(boolean markedRollback) {
  101 + transactionMarkedRollback = markedRollback;
  102 + }
  103 +
  104 + public static void setTransactionActive(boolean active) {
  105 + transactionActive = active;
  106 + }
  107 +
  108 + public static void setTransactionPassedInIsActiveMethod(boolean passedInIsActiveMethod) {
  109 + transactionPassedInIsActiveMethod = passedInIsActiveMethod;
  110 + }
  111 +
  112 + public static void setTransactionPassedInIsMarkedRollbackMethod(boolean passedInIsMarkedRollbackMethod) {
  113 + transactionPassedInIsMarkedRollbackMethod = passedInIsMarkedRollbackMethod;
  114 + }
  115 +
  116 + public static void setTransactionPassedInBeginMethod(boolean passedInBeginMethod) {
  117 + transactionPassedInBeginMethod = passedInBeginMethod;
  118 + }
  119 +
  120 + public static void setTransactionPassedInCommitMethod(boolean passedInCommitMethod) {
  121 + transactionPassedInCommitMethod = passedInCommitMethod;
  122 + }
  123 +
  124 + public static void setTransactionPassedInRollbackMethod(boolean passedInRollbackMethod) {
  125 + transactionPassedInRollbackMethod = passedInRollbackMethod;
  126 + }
  127 +
  128 + public static void setTransactionPassedInSetRollbackOnlyMethod(boolean passedInSetRollbackOnlyMethod) {
  129 + transactionPassedInSetRollbackOnlyMethod = passedInSetRollbackOnlyMethod;
  130 + }
  131 +}
... ...
impl/core/src/test/java/transaction/rollback/TransactionManagerWithDefaultRollback.java 0 → 100644
... ... @@ -0,0 +1,55 @@
  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 transaction.rollback;
  38 +
  39 +import br.gov.frameworkdemoiselle.exception.ExceptionHandler;
  40 +import br.gov.frameworkdemoiselle.stereotype.Controller;
  41 +import br.gov.frameworkdemoiselle.transaction.Transactional;
  42 +
  43 +@Controller
  44 +public class TransactionManagerWithDefaultRollback extends TransactionManager{
  45 +
  46 + @Transactional
  47 + public void insert() {
  48 + throw new TransactionExceptionWithDefaultRollback();
  49 + }
  50 +
  51 + @ExceptionHandler
  52 + public void handler(TransactionExceptionWithDefaultRollback excepWithDefaultRollback) {
  53 + throw excepWithDefaultRollback;
  54 + }
  55 +}
... ...
impl/core/src/test/java/transaction/rollback/TransactionManagerWithRollback.java 0 → 100644
... ... @@ -0,0 +1,55 @@
  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 transaction.rollback;
  38 +
  39 +import br.gov.frameworkdemoiselle.exception.ExceptionHandler;
  40 +import br.gov.frameworkdemoiselle.stereotype.Controller;
  41 +import br.gov.frameworkdemoiselle.transaction.Transactional;
  42 +
  43 +@Controller
  44 +public class TransactionManagerWithRollback extends TransactionManager{
  45 +
  46 + @Transactional
  47 + public void insert() {
  48 + throw new TransactionExceptionWithRollback();
  49 + }
  50 +
  51 + @ExceptionHandler
  52 + public void handler(TransactionExceptionWithRollback excepWithRollback) {
  53 + throw excepWithRollback;
  54 + }
  55 +}
... ...
impl/core/src/test/java/transaction/rollback/TransactionManagerWithoutRollback.java 0 → 100644
... ... @@ -0,0 +1,55 @@
  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 transaction.rollback;
  38 +
  39 +import br.gov.frameworkdemoiselle.exception.ExceptionHandler;
  40 +import br.gov.frameworkdemoiselle.stereotype.Controller;
  41 +import br.gov.frameworkdemoiselle.transaction.Transactional;
  42 +
  43 +@Controller
  44 +public class TransactionManagerWithoutRollback extends TransactionManager {
  45 +
  46 + @Transactional
  47 + public void insert() {
  48 + throw new TransactionExceptionWithoutRollback();
  49 + }
  50 +
  51 + @ExceptionHandler
  52 + public void handler(TransactionExceptionWithoutRollback excepWithoutRollback) {
  53 + throw excepWithoutRollback;
  54 + }
  55 +}
... ...
impl/core/src/test/java/transaction/rollback/TransactionRollbackTest.java 0 → 100644
... ... @@ -0,0 +1,140 @@
  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 transaction.rollback;
  38 +
  39 +import static junit.framework.Assert.assertFalse;
  40 +import static junit.framework.Assert.assertTrue;
  41 +import static org.junit.Assert.fail;
  42 +
  43 +import javax.enterprise.context.RequestScoped;
  44 +import javax.inject.Inject;
  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.After;
  50 +import org.junit.Before;
  51 +import org.junit.Test;
  52 +import org.junit.runner.RunWith;
  53 +
  54 +import test.Tests;
  55 +
  56 +import br.gov.frameworkdemoiselle.internal.context.ContextManager;
  57 +import br.gov.frameworkdemoiselle.internal.context.ManagedContext;
  58 +
  59 +@RunWith(Arquillian.class)
  60 +public class TransactionRollbackTest {
  61 +
  62 + @Inject
  63 + private TransactionManagerWithDefaultRollback managerWithDefaultRollback;
  64 +
  65 + @Inject
  66 + private TransactionManagerWithRollback managerWithRollback;
  67 +
  68 + @Inject
  69 + private TransactionManagerWithoutRollback managerWithoutRollback;
  70 +
  71 + @Deployment
  72 + public static JavaArchive createDeployment() {
  73 + JavaArchive deployment = Tests.createDeployment(TransactionRollbackTest.class);
  74 + return deployment;
  75 + }
  76 +
  77 + @Before
  78 + public void activeContext() {
  79 + ContextManager.activate(ManagedContext.class, RequestScoped.class);
  80 + }
  81 +
  82 + @After
  83 + public void deactiveContext(){
  84 + ContextManager.deactivate(ManagedContext.class, RequestScoped.class);
  85 + }
  86 +
  87 + @Test
  88 + public void transactionWithDefaultRollback(){
  89 + try{
  90 + managerWithDefaultRollback.clean();
  91 + managerWithDefaultRollback.insert();
  92 + fail();
  93 + }catch(TransactionExceptionWithDefaultRollback exception){
  94 + assertTrue(managerWithDefaultRollback.isTransactionPassedInIsActiveMethod());
  95 + assertTrue(managerWithDefaultRollback.isTransactionPassedInBeginMethod());
  96 + assertTrue(managerWithDefaultRollback.isTransactionMarkedRollback());
  97 + assertTrue(managerWithDefaultRollback.isTransactionPassedInIsMarkedRollbackMethod());
  98 + assertTrue(managerWithDefaultRollback.isTransactionPassedInSetRollbackOnlyMethod());
  99 + assertTrue(managerWithDefaultRollback.isTransactionPassedInRollbackMethod());
  100 + assertFalse(managerWithDefaultRollback.isTransactionPassedInCommitMethod());
  101 + assertFalse(managerWithDefaultRollback.isTransactionActive());
  102 + }
  103 + }
  104 +
  105 + @Test
  106 + public void transactionWithRollback(){
  107 + try{
  108 + managerWithRollback.clean();
  109 + managerWithRollback.insert();
  110 + fail();
  111 + }catch(TransactionExceptionWithRollback exception){
  112 + assertTrue(managerWithRollback.isTransactionPassedInIsActiveMethod());
  113 + assertTrue(managerWithRollback.isTransactionPassedInBeginMethod());
  114 + assertTrue(managerWithRollback.isTransactionMarkedRollback());
  115 + assertTrue(managerWithRollback.isTransactionPassedInIsMarkedRollbackMethod());
  116 + assertTrue(managerWithRollback.isTransactionPassedInSetRollbackOnlyMethod());
  117 + assertTrue(managerWithRollback.isTransactionPassedInRollbackMethod());
  118 + assertFalse(managerWithRollback.isTransactionPassedInCommitMethod());
  119 + assertFalse(managerWithRollback.isTransactionActive());
  120 + }
  121 + }
  122 +
  123 + @Test
  124 + public void transactionWithoutRollback(){
  125 + try{
  126 + managerWithoutRollback.clean();
  127 + managerWithoutRollback.insert();
  128 + fail();
  129 + }catch(TransactionExceptionWithoutRollback exception){
  130 + assertTrue(managerWithRollback.isTransactionPassedInIsActiveMethod());
  131 + assertTrue(managerWithRollback.isTransactionPassedInBeginMethod());
  132 + assertFalse(managerWithRollback.isTransactionMarkedRollback());
  133 + assertTrue(managerWithRollback.isTransactionPassedInIsMarkedRollbackMethod());
  134 + assertFalse(managerWithRollback.isTransactionPassedInSetRollbackOnlyMethod());
  135 + assertFalse(managerWithRollback.isTransactionPassedInRollbackMethod());
  136 + assertTrue(managerWithRollback.isTransactionPassedInCommitMethod());
  137 + assertFalse(managerWithRollback.isTransactionActive());
  138 + }
  139 + }
  140 +}
... ...