From 772890eba4811492197a51c11547e820a6f602af Mon Sep 17 00:00:00 2001 From: Emerson Oliveira Date: Wed, 22 May 2013 16:40:53 -0300 Subject: [PATCH] Adição de testes para execução do rollback na transação. --- impl/core/src/test/java/transaction/rollback/DummyStrategy.java | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ impl/core/src/test/java/transaction/rollback/TransactionExceptionWithDefaultRollback.java | 45 +++++++++++++++++++++++++++++++++++++++++++++ impl/core/src/test/java/transaction/rollback/TransactionExceptionWithRollback.java | 45 +++++++++++++++++++++++++++++++++++++++++++++ impl/core/src/test/java/transaction/rollback/TransactionExceptionWithoutRollback.java | 45 +++++++++++++++++++++++++++++++++++++++++++++ impl/core/src/test/java/transaction/rollback/TransactionManager.java | 131 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ impl/core/src/test/java/transaction/rollback/TransactionManagerWithDefaultRollback.java | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ impl/core/src/test/java/transaction/rollback/TransactionManagerWithRollback.java | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ impl/core/src/test/java/transaction/rollback/TransactionManagerWithoutRollback.java | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ impl/core/src/test/java/transaction/rollback/TransactionRollbackTest.java | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 659 insertions(+), 0 deletions(-) create mode 100644 impl/core/src/test/java/transaction/rollback/DummyStrategy.java create mode 100644 impl/core/src/test/java/transaction/rollback/TransactionExceptionWithDefaultRollback.java create mode 100644 impl/core/src/test/java/transaction/rollback/TransactionExceptionWithRollback.java create mode 100644 impl/core/src/test/java/transaction/rollback/TransactionExceptionWithoutRollback.java create mode 100644 impl/core/src/test/java/transaction/rollback/TransactionManager.java create mode 100644 impl/core/src/test/java/transaction/rollback/TransactionManagerWithDefaultRollback.java create mode 100644 impl/core/src/test/java/transaction/rollback/TransactionManagerWithRollback.java create mode 100644 impl/core/src/test/java/transaction/rollback/TransactionManagerWithoutRollback.java create mode 100644 impl/core/src/test/java/transaction/rollback/TransactionRollbackTest.java diff --git a/impl/core/src/test/java/transaction/rollback/DummyStrategy.java b/impl/core/src/test/java/transaction/rollback/DummyStrategy.java new file mode 100644 index 0000000..3e0217f --- /dev/null +++ b/impl/core/src/test/java/transaction/rollback/DummyStrategy.java @@ -0,0 +1,88 @@ +/* + * Demoiselle Framework + * Copyright (C) 2010 SERPRO + * ---------------------------------------------------------------------------- + * This file is part of Demoiselle Framework. + * + * Demoiselle Framework is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License version 3 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License version 3 + * along with this program; if not, see + * or write to the Free Software Foundation, Inc., 51 Franklin Street, + * Fifth Floor, Boston, MA 02110-1301, USA. + * ---------------------------------------------------------------------------- + * Este arquivo é parte do Framework Demoiselle. + * + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação + * do Software Livre (FSF). + * + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português + * para maiores detalhes. + * + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título + * "LICENCA.txt", junto com esse programa. Se não, acesse + * ou escreva para a Fundação do Software Livre (FSF) Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. + */ +package transaction.rollback; + +import br.gov.frameworkdemoiselle.transaction.Transaction; + +public class DummyStrategy implements Transaction { + + private static final long serialVersionUID = 1L; + + private boolean markedRollback = false; + + private boolean active = false; + + @Override + public boolean isActive() { + TransactionManager.setTransactionPassedInIsActiveMethod(true); + return active; + } + + @Override + public boolean isMarkedRollback() { + TransactionManager.setTransactionPassedInIsMarkedRollbackMethod(true); + return markedRollback; + } + + @Override + public void begin() { + TransactionManager.setTransactionPassedInBeginMethod(true); + active = true; + TransactionManager.setTransactionActive(true); + } + + @Override + public void commit() { + TransactionManager.setTransactionPassedInCommitMethod(true); + active = false; + TransactionManager.setTransactionActive(false); + } + + @Override + public void rollback() { + TransactionManager.setTransactionPassedInRollbackMethod(true); + active = false; + TransactionManager.setTransactionActive(false); + } + + @Override + public void setRollbackOnly() { + TransactionManager.setTransactionPassedInSetRollbackOnlyMethod(true); + markedRollback = true; + TransactionManager.setTransactionMarkedRollback(true); + } +} diff --git a/impl/core/src/test/java/transaction/rollback/TransactionExceptionWithDefaultRollback.java b/impl/core/src/test/java/transaction/rollback/TransactionExceptionWithDefaultRollback.java new file mode 100644 index 0000000..7aab3a6 --- /dev/null +++ b/impl/core/src/test/java/transaction/rollback/TransactionExceptionWithDefaultRollback.java @@ -0,0 +1,45 @@ +/* + * Demoiselle Framework + * Copyright (C) 2010 SERPRO + * ---------------------------------------------------------------------------- + * This file is part of Demoiselle Framework. + * + * Demoiselle Framework is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License version 3 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License version 3 + * along with this program; if not, see + * or write to the Free Software Foundation, Inc., 51 Franklin Street, + * Fifth Floor, Boston, MA 02110-1301, USA. + * ---------------------------------------------------------------------------- + * Este arquivo é parte do Framework Demoiselle. + * + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação + * do Software Livre (FSF). + * + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português + * para maiores detalhes. + * + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título + * "LICENCA.txt", junto com esse programa. Se não, acesse + * ou escreva para a Fundação do Software Livre (FSF) Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. + */ +package transaction.rollback; + +import br.gov.frameworkdemoiselle.exception.ApplicationException; + +@ApplicationException +public class TransactionExceptionWithDefaultRollback extends RuntimeException { + + private static final long serialVersionUID = 1L; +} diff --git a/impl/core/src/test/java/transaction/rollback/TransactionExceptionWithRollback.java b/impl/core/src/test/java/transaction/rollback/TransactionExceptionWithRollback.java new file mode 100644 index 0000000..63c5ff5 --- /dev/null +++ b/impl/core/src/test/java/transaction/rollback/TransactionExceptionWithRollback.java @@ -0,0 +1,45 @@ +/* + * Demoiselle Framework + * Copyright (C) 2010 SERPRO + * ---------------------------------------------------------------------------- + * This file is part of Demoiselle Framework. + * + * Demoiselle Framework is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License version 3 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License version 3 + * along with this program; if not, see + * or write to the Free Software Foundation, Inc., 51 Franklin Street, + * Fifth Floor, Boston, MA 02110-1301, USA. + * ---------------------------------------------------------------------------- + * Este arquivo é parte do Framework Demoiselle. + * + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação + * do Software Livre (FSF). + * + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português + * para maiores detalhes. + * + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título + * "LICENCA.txt", junto com esse programa. Se não, acesse + * ou escreva para a Fundação do Software Livre (FSF) Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. + */ +package transaction.rollback; + +import br.gov.frameworkdemoiselle.exception.ApplicationException; + +@ApplicationException(rollback = true) +public class TransactionExceptionWithRollback extends RuntimeException { + + private static final long serialVersionUID = 1L; +} diff --git a/impl/core/src/test/java/transaction/rollback/TransactionExceptionWithoutRollback.java b/impl/core/src/test/java/transaction/rollback/TransactionExceptionWithoutRollback.java new file mode 100644 index 0000000..9585892 --- /dev/null +++ b/impl/core/src/test/java/transaction/rollback/TransactionExceptionWithoutRollback.java @@ -0,0 +1,45 @@ +/* + * Demoiselle Framework + * Copyright (C) 2010 SERPRO + * ---------------------------------------------------------------------------- + * This file is part of Demoiselle Framework. + * + * Demoiselle Framework is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License version 3 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License version 3 + * along with this program; if not, see + * or write to the Free Software Foundation, Inc., 51 Franklin Street, + * Fifth Floor, Boston, MA 02110-1301, USA. + * ---------------------------------------------------------------------------- + * Este arquivo é parte do Framework Demoiselle. + * + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação + * do Software Livre (FSF). + * + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português + * para maiores detalhes. + * + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título + * "LICENCA.txt", junto com esse programa. Se não, acesse + * ou escreva para a Fundação do Software Livre (FSF) Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. + */ +package transaction.rollback; + +import br.gov.frameworkdemoiselle.exception.ApplicationException; + +@ApplicationException(rollback = false) +public class TransactionExceptionWithoutRollback extends RuntimeException { + + private static final long serialVersionUID = 1L; +} diff --git a/impl/core/src/test/java/transaction/rollback/TransactionManager.java b/impl/core/src/test/java/transaction/rollback/TransactionManager.java new file mode 100644 index 0000000..f8fe298 --- /dev/null +++ b/impl/core/src/test/java/transaction/rollback/TransactionManager.java @@ -0,0 +1,131 @@ +/* + * Demoiselle Framework + * Copyright (C) 2010 SERPRO + * ---------------------------------------------------------------------------- + * This file is part of Demoiselle Framework. + * + * Demoiselle Framework is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License version 3 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License version 3 + * along with this program; if not, see + * or write to the Free Software Foundation, Inc., 51 Franklin Street, + * Fifth Floor, Boston, MA 02110-1301, USA. + * ---------------------------------------------------------------------------- + * Este arquivo é parte do Framework Demoiselle. + * + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação + * do Software Livre (FSF). + * + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português + * para maiores detalhes. + * + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título + * "LICENCA.txt", junto com esse programa. Se não, acesse + * ou escreva para a Fundação do Software Livre (FSF) Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. + */ +package transaction.rollback; + +public class TransactionManager { + + private static boolean transactionMarkedRollback; + + private static boolean transactionActive; + + private static boolean transactionPassedInIsActiveMethod; + + private static boolean transactionPassedInIsMarkedRollbackMethod; + + private static boolean transactionPassedInBeginMethod; + + private static boolean transactionPassedInCommitMethod; + + private static boolean transactionPassedInRollbackMethod; + + private static boolean transactionPassedInSetRollbackOnlyMethod; + + public void clean() { + setTransactionMarkedRollback(false); + setTransactionActive(false); + setTransactionPassedInIsActiveMethod(false); + setTransactionPassedInIsMarkedRollbackMethod(false); + setTransactionPassedInBeginMethod(false); + setTransactionPassedInCommitMethod(false); + setTransactionPassedInRollbackMethod(false); + setTransactionPassedInSetRollbackOnlyMethod(false); + } + + public boolean isTransactionMarkedRollback() { + return transactionMarkedRollback; + } + + public boolean isTransactionActive() { + return transactionActive; + } + + public boolean isTransactionPassedInIsActiveMethod() { + return transactionPassedInIsActiveMethod; + } + + public boolean isTransactionPassedInIsMarkedRollbackMethod() { + return transactionPassedInIsMarkedRollbackMethod; + } + + public boolean isTransactionPassedInBeginMethod() { + return transactionPassedInBeginMethod; + } + + public boolean isTransactionPassedInCommitMethod() { + return transactionPassedInCommitMethod; + } + + public boolean isTransactionPassedInRollbackMethod() { + return transactionPassedInRollbackMethod; + } + + public boolean isTransactionPassedInSetRollbackOnlyMethod() { + return transactionPassedInSetRollbackOnlyMethod; + } + + public static void setTransactionMarkedRollback(boolean markedRollback) { + transactionMarkedRollback = markedRollback; + } + + public static void setTransactionActive(boolean active) { + transactionActive = active; + } + + public static void setTransactionPassedInIsActiveMethod(boolean passedInIsActiveMethod) { + transactionPassedInIsActiveMethod = passedInIsActiveMethod; + } + + public static void setTransactionPassedInIsMarkedRollbackMethod(boolean passedInIsMarkedRollbackMethod) { + transactionPassedInIsMarkedRollbackMethod = passedInIsMarkedRollbackMethod; + } + + public static void setTransactionPassedInBeginMethod(boolean passedInBeginMethod) { + transactionPassedInBeginMethod = passedInBeginMethod; + } + + public static void setTransactionPassedInCommitMethod(boolean passedInCommitMethod) { + transactionPassedInCommitMethod = passedInCommitMethod; + } + + public static void setTransactionPassedInRollbackMethod(boolean passedInRollbackMethod) { + transactionPassedInRollbackMethod = passedInRollbackMethod; + } + + public static void setTransactionPassedInSetRollbackOnlyMethod(boolean passedInSetRollbackOnlyMethod) { + transactionPassedInSetRollbackOnlyMethod = passedInSetRollbackOnlyMethod; + } +} diff --git a/impl/core/src/test/java/transaction/rollback/TransactionManagerWithDefaultRollback.java b/impl/core/src/test/java/transaction/rollback/TransactionManagerWithDefaultRollback.java new file mode 100644 index 0000000..eef61ce --- /dev/null +++ b/impl/core/src/test/java/transaction/rollback/TransactionManagerWithDefaultRollback.java @@ -0,0 +1,55 @@ +/* + * Demoiselle Framework + * Copyright (C) 2010 SERPRO + * ---------------------------------------------------------------------------- + * This file is part of Demoiselle Framework. + * + * Demoiselle Framework is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License version 3 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License version 3 + * along with this program; if not, see + * or write to the Free Software Foundation, Inc., 51 Franklin Street, + * Fifth Floor, Boston, MA 02110-1301, USA. + * ---------------------------------------------------------------------------- + * Este arquivo é parte do Framework Demoiselle. + * + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação + * do Software Livre (FSF). + * + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português + * para maiores detalhes. + * + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título + * "LICENCA.txt", junto com esse programa. Se não, acesse + * ou escreva para a Fundação do Software Livre (FSF) Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. + */ +package transaction.rollback; + +import br.gov.frameworkdemoiselle.exception.ExceptionHandler; +import br.gov.frameworkdemoiselle.stereotype.Controller; +import br.gov.frameworkdemoiselle.transaction.Transactional; + +@Controller +public class TransactionManagerWithDefaultRollback extends TransactionManager{ + + @Transactional + public void insert() { + throw new TransactionExceptionWithDefaultRollback(); + } + + @ExceptionHandler + public void handler(TransactionExceptionWithDefaultRollback excepWithDefaultRollback) { + throw excepWithDefaultRollback; + } +} diff --git a/impl/core/src/test/java/transaction/rollback/TransactionManagerWithRollback.java b/impl/core/src/test/java/transaction/rollback/TransactionManagerWithRollback.java new file mode 100644 index 0000000..8b0a359 --- /dev/null +++ b/impl/core/src/test/java/transaction/rollback/TransactionManagerWithRollback.java @@ -0,0 +1,55 @@ +/* + * Demoiselle Framework + * Copyright (C) 2010 SERPRO + * ---------------------------------------------------------------------------- + * This file is part of Demoiselle Framework. + * + * Demoiselle Framework is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License version 3 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License version 3 + * along with this program; if not, see + * or write to the Free Software Foundation, Inc., 51 Franklin Street, + * Fifth Floor, Boston, MA 02110-1301, USA. + * ---------------------------------------------------------------------------- + * Este arquivo é parte do Framework Demoiselle. + * + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação + * do Software Livre (FSF). + * + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português + * para maiores detalhes. + * + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título + * "LICENCA.txt", junto com esse programa. Se não, acesse + * ou escreva para a Fundação do Software Livre (FSF) Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. + */ +package transaction.rollback; + +import br.gov.frameworkdemoiselle.exception.ExceptionHandler; +import br.gov.frameworkdemoiselle.stereotype.Controller; +import br.gov.frameworkdemoiselle.transaction.Transactional; + +@Controller +public class TransactionManagerWithRollback extends TransactionManager{ + + @Transactional + public void insert() { + throw new TransactionExceptionWithRollback(); + } + + @ExceptionHandler + public void handler(TransactionExceptionWithRollback excepWithRollback) { + throw excepWithRollback; + } +} diff --git a/impl/core/src/test/java/transaction/rollback/TransactionManagerWithoutRollback.java b/impl/core/src/test/java/transaction/rollback/TransactionManagerWithoutRollback.java new file mode 100644 index 0000000..b82eaa4 --- /dev/null +++ b/impl/core/src/test/java/transaction/rollback/TransactionManagerWithoutRollback.java @@ -0,0 +1,55 @@ +/* + * Demoiselle Framework + * Copyright (C) 2010 SERPRO + * ---------------------------------------------------------------------------- + * This file is part of Demoiselle Framework. + * + * Demoiselle Framework is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License version 3 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License version 3 + * along with this program; if not, see + * or write to the Free Software Foundation, Inc., 51 Franklin Street, + * Fifth Floor, Boston, MA 02110-1301, USA. + * ---------------------------------------------------------------------------- + * Este arquivo é parte do Framework Demoiselle. + * + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação + * do Software Livre (FSF). + * + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português + * para maiores detalhes. + * + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título + * "LICENCA.txt", junto com esse programa. Se não, acesse + * ou escreva para a Fundação do Software Livre (FSF) Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. + */ +package transaction.rollback; + +import br.gov.frameworkdemoiselle.exception.ExceptionHandler; +import br.gov.frameworkdemoiselle.stereotype.Controller; +import br.gov.frameworkdemoiselle.transaction.Transactional; + +@Controller +public class TransactionManagerWithoutRollback extends TransactionManager { + + @Transactional + public void insert() { + throw new TransactionExceptionWithoutRollback(); + } + + @ExceptionHandler + public void handler(TransactionExceptionWithoutRollback excepWithoutRollback) { + throw excepWithoutRollback; + } +} diff --git a/impl/core/src/test/java/transaction/rollback/TransactionRollbackTest.java b/impl/core/src/test/java/transaction/rollback/TransactionRollbackTest.java new file mode 100644 index 0000000..88e7c71 --- /dev/null +++ b/impl/core/src/test/java/transaction/rollback/TransactionRollbackTest.java @@ -0,0 +1,140 @@ +/* + * Demoiselle Framework + * Copyright (C) 2010 SERPRO + * ---------------------------------------------------------------------------- + * This file is part of Demoiselle Framework. + * + * Demoiselle Framework is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License version 3 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License version 3 + * along with this program; if not, see + * or write to the Free Software Foundation, Inc., 51 Franklin Street, + * Fifth Floor, Boston, MA 02110-1301, USA. + * ---------------------------------------------------------------------------- + * Este arquivo é parte do Framework Demoiselle. + * + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação + * do Software Livre (FSF). + * + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português + * para maiores detalhes. + * + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título + * "LICENCA.txt", junto com esse programa. Se não, acesse + * ou escreva para a Fundação do Software Livre (FSF) Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. + */ +package transaction.rollback; + +import static junit.framework.Assert.assertFalse; +import static junit.framework.Assert.assertTrue; +import static org.junit.Assert.fail; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import test.Tests; + +import br.gov.frameworkdemoiselle.internal.context.ContextManager; +import br.gov.frameworkdemoiselle.internal.context.ManagedContext; + +@RunWith(Arquillian.class) +public class TransactionRollbackTest { + + @Inject + private TransactionManagerWithDefaultRollback managerWithDefaultRollback; + + @Inject + private TransactionManagerWithRollback managerWithRollback; + + @Inject + private TransactionManagerWithoutRollback managerWithoutRollback; + + @Deployment + public static JavaArchive createDeployment() { + JavaArchive deployment = Tests.createDeployment(TransactionRollbackTest.class); + return deployment; + } + + @Before + public void activeContext() { + ContextManager.activate(ManagedContext.class, RequestScoped.class); + } + + @After + public void deactiveContext(){ + ContextManager.deactivate(ManagedContext.class, RequestScoped.class); + } + + @Test + public void transactionWithDefaultRollback(){ + try{ + managerWithDefaultRollback.clean(); + managerWithDefaultRollback.insert(); + fail(); + }catch(TransactionExceptionWithDefaultRollback exception){ + assertTrue(managerWithDefaultRollback.isTransactionPassedInIsActiveMethod()); + assertTrue(managerWithDefaultRollback.isTransactionPassedInBeginMethod()); + assertTrue(managerWithDefaultRollback.isTransactionMarkedRollback()); + assertTrue(managerWithDefaultRollback.isTransactionPassedInIsMarkedRollbackMethod()); + assertTrue(managerWithDefaultRollback.isTransactionPassedInSetRollbackOnlyMethod()); + assertTrue(managerWithDefaultRollback.isTransactionPassedInRollbackMethod()); + assertFalse(managerWithDefaultRollback.isTransactionPassedInCommitMethod()); + assertFalse(managerWithDefaultRollback.isTransactionActive()); + } + } + + @Test + public void transactionWithRollback(){ + try{ + managerWithRollback.clean(); + managerWithRollback.insert(); + fail(); + }catch(TransactionExceptionWithRollback exception){ + assertTrue(managerWithRollback.isTransactionPassedInIsActiveMethod()); + assertTrue(managerWithRollback.isTransactionPassedInBeginMethod()); + assertTrue(managerWithRollback.isTransactionMarkedRollback()); + assertTrue(managerWithRollback.isTransactionPassedInIsMarkedRollbackMethod()); + assertTrue(managerWithRollback.isTransactionPassedInSetRollbackOnlyMethod()); + assertTrue(managerWithRollback.isTransactionPassedInRollbackMethod()); + assertFalse(managerWithRollback.isTransactionPassedInCommitMethod()); + assertFalse(managerWithRollback.isTransactionActive()); + } + } + + @Test + public void transactionWithoutRollback(){ + try{ + managerWithoutRollback.clean(); + managerWithoutRollback.insert(); + fail(); + }catch(TransactionExceptionWithoutRollback exception){ + assertTrue(managerWithRollback.isTransactionPassedInIsActiveMethod()); + assertTrue(managerWithRollback.isTransactionPassedInBeginMethod()); + assertFalse(managerWithRollback.isTransactionMarkedRollback()); + assertTrue(managerWithRollback.isTransactionPassedInIsMarkedRollbackMethod()); + assertFalse(managerWithRollback.isTransactionPassedInSetRollbackOnlyMethod()); + assertFalse(managerWithRollback.isTransactionPassedInRollbackMethod()); + assertTrue(managerWithRollback.isTransactionPassedInCommitMethod()); + assertFalse(managerWithRollback.isTransactionActive()); + } + } +} -- libgit2 0.21.2